index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <view>
  3. <view v-if="pagesNum > 1">
  4. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="我的奖品库"></u-navbar>
  5. </view>
  6. <view v-else>
  7. <u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" title="我的奖品库">
  8. <view class="nav-left flex" slot="left" @click="toIndex">
  9. <u-icon name="arrow-left" size="20" color="#333"></u-icon>
  10. </view>
  11. </u-navbar>
  12. </view>
  13. <!-- 奖品选择 -->
  14. <view class="prize-state">
  15. <!-- 类型 -->
  16. <view class="prize-state-tabs">
  17. <u-tabs @change="changeTab" :scrollable="false" :list="stateArr" lineWidth="30" lineHeight="3"
  18. :current='currentIndex' lineColor="#F9822C " :activeStyle="{
  19. color: '#333 ',
  20. transform: 'scale(1.1)',
  21. width: '120px'
  22. }" :inactiveStyle="{
  23. color: '#999',
  24. transform: 'scale(1)',
  25. width: '120px'
  26. }" itemStyle="padding-left: 20px; padding-right: 15px; height: 44px; text-align: center;">
  27. </u-tabs>
  28. </view>
  29. <!-- 商品状态 -->
  30. <view class="prize-state-type flex" v-if="state == 0">
  31. <view class="prize-state-type-item" :class="{ 'prize-state-type-item__action': index == typeIndex }"
  32. v-for="(item, index) in typeList" :key="index" @click="typeIndex = index">{{ item.name }}</view>
  33. </view>
  34. </view>
  35. <!-- 实物商品 -->
  36. <view class="prize-goods" v-if="state == 0">
  37. <view class="prize-goods-list">
  38. <view class="prize-goods-list-item" v-for="(item, index) in list" :key="index">
  39. <!-- 商品 -->
  40. <view class="prize-goods-list-item__content flex">
  41. <view class="flex">
  42. <u-checkbox-group>
  43. <u-checkbox size="24" :value="item.checked" shape="circle" :checked="item.checked"
  44. activeColor="#F9822C" @change="changeChecked($event, item)"></u-checkbox>
  45. </u-checkbox-group>
  46. </view>
  47. <view class="info flex" @click="toPrizeGoods(item)">
  48. <image :src="item.picUrl" mode="aspectFill"></image>
  49. <view class="desc flex">
  50. <view class="ells title">{{ item.title }}</view>
  51. <view class="num flex">
  52. <view class="sku ells-one">规格:{{ item.properties || '-' }}</view>
  53. <view class="">数量:{{ item.goodsNum }}</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 来源 -->
  59. <view class="prize-goods-list-item__btn flex">
  60. <view class="type">来自:{{ item.inType && item.inType.desc }}</view>
  61. <view class="btn" @click="toRecovery(item)" v-if="item.inType.value == '1' || item.inType.value == '2'">兑换盲豆</view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="flex empty" v-if="!list.length && !loading">
  66. <u-empty text="数据为空" mode="order" />
  67. </view>
  68. </view>
  69. <!-- 优惠券 -->
  70. <view class="prize-coupon" v-else>
  71. <view class="prize-coupon-list">
  72. <!-- <navigator :url="`/pages/prize/detail?info=${ JSON.stringify(item) }`" class="flex prize-coupon-list-item" hover-class="navigator-hover" v-for="(item, index) in list" :key="index">
  73. <image :src="item.picUrl" mode="aspectFill"></image>
  74. <view class="flex info">
  75. <view class="flex desc">
  76. <view class="title">{{ item.title }}</view>
  77. <view class="txt">使用期限:{{ $parseTime(item.validStart, '{y}.{m}.{d}') }}-{{ $parseTime(item.validEnd, '{y}.{m}.{d}') }}</view>
  78. <view class="txt">使用范围:{{ item.useAreaDesc }}</view>
  79. </view>
  80. <view class="flex btn">
  81. <view class="amt"><text>¥</text>{{ item.discount / 100 }}</view>
  82. <view class="action">立即使用</view>
  83. </view>
  84. </view>
  85. </navigator> -->
  86. <view @click="toPrizeDetail(item)" class="prize-coupon-list-item" hover-class="navigator-hover"
  87. v-for="(item, index) in list" :key="index">
  88. <image src="../../static/icon/coupon_bg.png" mode=""></image>
  89. <view class="info">
  90. <view class="info-item">
  91. <text>使用期限:</text>
  92. <text>{{ $parseTime(item.validStart, '{y}.{m}.{d}') }}-{{ $parseTime(item.validEnd, '{y}.{m}.{d}') }}</text>
  93. </view>
  94. <view class="info-item">
  95. <text>使用范围:</text>
  96. <text>{{ item.useAreaDesc || '-' }}</text>
  97. </view>
  98. </view>
  99. <view class="info-now">
  100. <view></view>
  101. <view v-if="JSON.parse(item.useArea).value != '4'">立即使用</view>
  102. <view v-else>查看详情</view>
  103. </view>
  104. <view class="flex price-title">
  105. <view class="price"><text>¥</text>{{ item.discount / 100 }}</view>
  106. <view class="title">{{ item.title }}</view>
  107. </view>
  108. </view>
  109. </view>
  110. <view class="flex empty" v-if="!list.length && !loading">
  111. <u-empty text="数据为空" mode="order" />
  112. </view>
  113. </view>
  114. <view class="prize-action">
  115. <!-- 实物商品提货 -->
  116. <view class="flex prize-action-goods" v-if="state == 0">
  117. <view class="flex checkbox">
  118. <view class="all">全选</view>
  119. <u-checkbox-group>
  120. <u-checkbox v-model="checkedAll" shape="circle" size="24" :checked="checkedAll"
  121. activeColor="#F9822C" @change="changeCheckedAll($event)"></u-checkbox>
  122. </u-checkbox-group>
  123. </view>
  124. <view class="btn" @click="toSettlement">立即提货</view>
  125. </view>
  126. <!-- 优惠券使用记录 -->
  127. <view class="flex prize-action-coupon" @click="toCoupon" v-else>
  128. <view class="title">优惠券使用记录</view>
  129. <u-icon name="arrow-right" size="15" color="#333"></u-icon>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. <script>
  135. import env from '../../config/env.js'
  136. import $http from '@/utils/request.js'
  137. export default {
  138. data() {
  139. return {
  140. loading: false,
  141. stateArr: [{
  142. name: ' 实物商品',
  143. }, {
  144. name: ' 优惠券',
  145. }],
  146. typeList: [{
  147. name: '待兑换'
  148. }, {
  149. name: '已兑换'
  150. }],
  151. typeIndex: 0,
  152. state: 0,
  153. checkedAll: false,
  154. pageNum: 1,
  155. total: 0,
  156. list: [],
  157. currentIndex: 0,
  158. pagesNum: "",
  159. };
  160. },
  161. onShow() {
  162. this.pagesNum = getCurrentPages().length
  163. this.pageList()
  164. this.couponNum()
  165. },
  166. onLoad(opthios) {
  167. if (opthios != undefined) {
  168. if (opthios.coupon == 1) {
  169. this.currentIndex = 1
  170. this.state = 1
  171. } else {
  172. this.currentIndex = 0
  173. this.state = 0
  174. }
  175. }
  176. },
  177. methods: {
  178. getList() {
  179. let _this = this
  180. let url = _this.state == 0 ? '/api/v1/mp/user/mine/prize/list' : '/api/v1/mp/user/mine/coupon/list'
  181. let data = _this.state == 0 ? {} : {
  182. status: 1
  183. }
  184. uni.showLoading({
  185. title: '加载中'
  186. });
  187. this.loading = true
  188. this.checkedAll = false
  189. $http.post(`${ url }?pageNum=${_this.pageNum}&pageSize=20`, data).then(res => {
  190. uni.hideLoading();
  191. this.loading = false
  192. if (res.code == 0) {
  193. res.rows.forEach(item => {
  194. let picUrlArr = item.picUrl.split(',')
  195. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  196. if (_this.state == 0) {
  197. item.checked = false
  198. item.inType = JSON.parse(item.inType)
  199. }
  200. })
  201. _this.total = res.total
  202. _this.list = _this.list.concat(res.rows)
  203. }
  204. }).catch(() => {
  205. uni.hideLoading();
  206. this.loading = false
  207. })
  208. },
  209. toIndex() {
  210. uni.switchTab({
  211. url: '/pages/user/index'
  212. })
  213. },
  214. toRecovery(item) {
  215. uni.navigateTo({
  216. url: `/packageGoods/recovery/index?goodsId=${ item.goodsId}&num=${ item.goodsNum }&storageId=${ item.storageId }&properties=${item.properties }&skuId=${ item.skuId }`
  217. })
  218. },
  219. pageList() {
  220. this.pageNum = 1
  221. this.list = []
  222. this.getList()
  223. },
  224. // 切换奖品
  225. changeTab(e) {
  226. if (e.index == 0) {
  227. this.state = 0
  228. } else if (e.index == 1) {
  229. this.state = 1
  230. }
  231. this.pageList()
  232. this.checkedAll = false
  233. },
  234. changeChecked(e, item) {
  235. this.$set(item, 'checked', e)
  236. let flag = this.list.every(item => item.checked == true)
  237. this.checkedAll = flag
  238. this.$forceUpdate()
  239. },
  240. changeCheckedAll(e) {
  241. this.checkedAll = e
  242. this.list.forEach(item => {
  243. item.checked = e
  244. })
  245. this.$forceUpdate()
  246. },
  247. // 查看优惠券使用记录
  248. toCoupon() {
  249. uni.navigateTo({
  250. url: '/packagePrize/coupon/use'
  251. })
  252. },
  253. // 立即提货
  254. toSettlement() {
  255. let arr = []
  256. this.list.forEach(item => {
  257. if (item.checked) {
  258. arr.push(item)
  259. }
  260. })
  261. if (!arr.length) {
  262. uni.$u.toast('请选择商品');
  263. return
  264. }
  265. uni.showLoading({
  266. title: '提货中'
  267. });
  268. let ids = JSON.stringify(arr.map(item => item.storageId))
  269. uni.hideLoading();
  270. uni.navigateTo({
  271. url: `/packageGoods/order/settlement?ids=${ ids }`
  272. })
  273. },
  274. couponNum() {
  275. $http.post(`/api/v1/mp/user/mine/prize/list?pageNum=1&pageSize=10`, {
  276. }).then(res => {
  277. $http.post(`/api/v1/mp/user/mine/coupon/list?pageNum=1&pageSize=10`, {
  278. status: 1
  279. }).then(data => {
  280. if (res.code == 0) {
  281. this.stateArr = [{
  282. name: ' 实物商品 (' + res.total + ') '
  283. },
  284. {
  285. name: ' 优惠券 (' + data.total + ') '
  286. },
  287. ]
  288. } else {
  289. this.stateArr = [{
  290. name: ' 实物商品 (0)'
  291. },
  292. {
  293. name: ' 优惠券 (0)'
  294. },
  295. ]
  296. }
  297. })
  298. });
  299. },
  300. toPrizeGoods(item) {
  301. uni.navigateTo({
  302. url: `/packagePrize/goods/detail?id=${ item.goodsId }`
  303. })
  304. },
  305. toPrizeDetail(item) {
  306. let data = JSON.parse(item.useArea)
  307. let type = JSON.parse(item.type)
  308. // 1判断type,如果为门店直接跳转不需要判断useArec
  309. if (type.value == 2) {
  310. // data.value 2为指定优惠券 0为通用优惠券
  311. uni.navigateTo({
  312. url: `/packagePrize/coupon/detail?id=${ item.id }`
  313. })
  314. } else {
  315. // 3为线上票使用
  316. if (data.value == 3) {
  317. uni.navigateTo({
  318. url: `/packageGoods/ticket/index`
  319. })
  320. }
  321. //0为通用优惠券
  322. if (data.value == 0) {
  323. uni.navigateTo({
  324. url: `/packageGoods/ticket/index`
  325. })
  326. }
  327. // 4为线下票使用
  328. if (data.value == 4) {
  329. uni.navigateTo({
  330. url: `/packagePrize/coupon/detail?id=${ item.id }`
  331. })
  332. }
  333. }
  334. }
  335. },
  336. onReachBottom() {
  337. // 判断是否有数据
  338. if (this.total > this.pageNum * 20) {
  339. setTimeout(() => {
  340. ++this.pageNum
  341. this.getList()
  342. }, 500)
  343. } else {
  344. uni.$u.toast('已经到底了')
  345. }
  346. },
  347. }
  348. </script>
  349. <style lang="scss" scoped>
  350. .empty {
  351. height: 60vh;
  352. }
  353. .prize-state {
  354. position: fixed;
  355. background-color: #FFFFFF;
  356. width: 100%;
  357. z-index: 10;
  358. box-shadow: 0 2rpx 2rpx #ececec;
  359. // 类型
  360. &-tabs {
  361. display: flex;
  362. box-shadow: 0 5rpx 5rpx #ececec;
  363. }
  364. // 商品状态
  365. &-type {
  366. justify-content: flex-start;
  367. padding: 24rpx 34rpx;
  368. &-item {
  369. margin-right: 34rpx;
  370. padding: 12rpx 36rpx;
  371. border-radius: 24rpx;
  372. color: #FFAB4D;
  373. }
  374. &-item__action {
  375. background: #FFAB4D;
  376. color: #fff;
  377. }
  378. }
  379. }
  380. // 实物商品
  381. .prize-goods {
  382. margin-top: 180rpx;
  383. padding: 34rpx 34rpx 200rpx;
  384. &-list {
  385. &-item {
  386. padding: 34rpx 22rpx 34rpx;
  387. background-color: #fff;
  388. border-radius: 18rpx;
  389. margin-bottom: 30rpx;
  390. &__content {
  391. justify-content: space-between;
  392. padding-bottom: 22rpx;
  393. border-bottom: 1px solid #E5E5E5;
  394. .info {
  395. padding-left: 16rpx;
  396. flex: 1;
  397. justify-content: flex-start;
  398. image {
  399. width: 200rpx;
  400. height: 200rpx;
  401. border-radius: 12rpx;
  402. }
  403. .desc {
  404. height: 200rpx;
  405. padding-left: 22rpx;
  406. flex: 1;
  407. font-size: 30rpx;
  408. flex-direction: column;
  409. align-items: flex-start;
  410. justify-content: space-between;
  411. .title {
  412. line-height: 40rpx;
  413. font-weight: bold;
  414. }
  415. .num {
  416. width: 100%;
  417. color: #666666;
  418. font-size: 26rpx;
  419. justify-content: space-between;
  420. .sku {
  421. flex: 1;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. &__btn {
  428. justify-content: space-between;
  429. padding-top: 22rpx;
  430. .type {
  431. font-size: 30rpx;
  432. color: #999999;
  433. line-height: 30rpx;
  434. padding-left: 70rpx;
  435. }
  436. .btn {
  437. width: 200rpx;
  438. height: 66rpx;
  439. line-height: 66rpx;
  440. text-align: center;
  441. color: #fff;
  442. background: #F9822C;
  443. border-radius: 34rpx;
  444. }
  445. }
  446. }
  447. &-item:last-child {
  448. margin-bottom: 0;
  449. }
  450. }
  451. }
  452. .prize-coupon {
  453. margin-top: 85rpx;
  454. padding: 40rpx 20rpx 150rpx;
  455. &-list {
  456. &-item {
  457. position: relative;
  458. background-color: #FFFFFF;
  459. margin-bottom: 20rpx;
  460. border-radius: 10rpx;
  461. image {
  462. width: 100%;
  463. height: 156rpx;
  464. margin-bottom: 24rpx;
  465. }
  466. .info {
  467. padding-left: 40rpx;
  468. padding-bottom: 8rpx;
  469. .info-item {
  470. line-height: 40rpx;
  471. color: #333333;
  472. margin-bottom: 12rpx;
  473. }
  474. }
  475. .info-now {
  476. margin-top: 10rpx;
  477. color: #848484;
  478. font-size: 30rpx;
  479. height: 100rpx;
  480. line-height: 90rpx;
  481. text-align: center;
  482. }
  483. .info-now view {
  484. height: 2rpx;
  485. margin: 0 10rpx;
  486. background-image: linear-gradient(to right, #cfcfcf 0%, #cfcfcf 50%, transparent 1%);
  487. background-size: 25rpx 10rpx;
  488. }
  489. .price-title {
  490. justify-content: flex-start;
  491. position: absolute;
  492. top: 0;
  493. width: 100%;
  494. padding: 36rpx 0 0 40rpx;
  495. .price {
  496. color: #FFFFFF;
  497. font-size: 60rpx;
  498. margin-right: 20rpx;
  499. text {
  500. font-size: 40rpx;
  501. }
  502. }
  503. .title {
  504. color: #FFFFFF;
  505. font-size: 48rpx;
  506. }
  507. }
  508. }
  509. &-item:last-child {
  510. margin-bottom: 0;
  511. }
  512. }
  513. }
  514. .prize-action {
  515. position: fixed;
  516. bottom: var(--window-bottom);
  517. left: 0;
  518. right: 0;
  519. z-index: 10;
  520. box-shadow: 0 -4rpx 10rpx 0 rgba(151, 151, 151, 0.24);
  521. background: #fff;
  522. width: 100%;
  523. // 设置ios刘海屏底部横线安全区域
  524. padding-bottom: constant(safe-area-inset-bottom);
  525. padding-bottom: env(safe-area-inset-bottom);
  526. &-goods {
  527. justify-content: space-between;
  528. padding: 20rpx 40rpx;
  529. .all {
  530. margin-right: 10rpx;
  531. }
  532. .btn {
  533. width: 280rpx;
  534. height: 90rpx;
  535. font-size: 36rpx;
  536. line-height: 90rpx;
  537. border-radius: 10rpx;
  538. background-color: rgba(235, 112, 9, 100);
  539. color: rgba(255, 255, 255, 100);
  540. text-align: center;
  541. }
  542. }
  543. &-coupon {
  544. padding: 30rpx 40rpx;
  545. .title {
  546. margin-right: 20rpx;
  547. line-height: 40rpx;
  548. }
  549. }
  550. }
  551. </style>