index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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">兑换盲豆</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. pageList() {
  215. this.pageNum = 1
  216. this.list = []
  217. this.getList()
  218. },
  219. // 切换奖品
  220. changeTab(e) {
  221. if (e.index == 0) {
  222. this.state = 0
  223. } else if (e.index == 1) {
  224. this.state = 1
  225. }
  226. this.pageList()
  227. this.checkedAll = false
  228. },
  229. changeChecked(e, item) {
  230. this.$set(item, 'checked', e)
  231. let flag = this.list.every(item => item.checked == true)
  232. this.checkedAll = flag
  233. this.$forceUpdate()
  234. },
  235. changeCheckedAll(e) {
  236. this.checkedAll = e
  237. this.list.forEach(item => {
  238. item.checked = e
  239. })
  240. this.$forceUpdate()
  241. },
  242. // 查看优惠券使用记录
  243. toCoupon() {
  244. uni.navigateTo({
  245. url: '/packagePrize/coupon/use'
  246. })
  247. },
  248. // 立即提货
  249. toSettlement() {
  250. let arr = []
  251. this.list.forEach(item => {
  252. if (item.checked) {
  253. arr.push(item)
  254. }
  255. })
  256. if (!arr.length) {
  257. uni.$u.toast('请选择商品');
  258. return
  259. }
  260. uni.showLoading({
  261. title: '提货中'
  262. });
  263. let ids = JSON.stringify(arr.map(item => item.storageId))
  264. uni.hideLoading();
  265. uni.navigateTo({
  266. url: `/packageGoods/order/settlement?ids=${ ids }`
  267. })
  268. },
  269. couponNum() {
  270. $http.post(`/api/v1/mp/user/mine/prize/list?pageNum=1&pageSize=10`, {
  271. }).then(res => {
  272. $http.post(`/api/v1/mp/user/mine/coupon/list?pageNum=1&pageSize=10`, {
  273. status: 1
  274. }).then(data => {
  275. if (res.code == 0) {
  276. this.stateArr = [{
  277. name: ' 实物商品 (' + res.total + ') '
  278. },
  279. {
  280. name: ' 优惠券 (' + data.total + ') '
  281. },
  282. ]
  283. } else {
  284. this.stateArr = [{
  285. name: ' 实物商品 (0)'
  286. },
  287. {
  288. name: ' 优惠券 (0)'
  289. },
  290. ]
  291. }
  292. })
  293. });
  294. },
  295. toPrizeGoods(item) {
  296. uni.navigateTo({
  297. url: `/packagePrize/goods/detail?id=${ item.goodsId }`
  298. })
  299. },
  300. toPrizeDetail(item) {
  301. let data = JSON.parse(item.useArea)
  302. let type = JSON.parse(item.type)
  303. // 1判断type,如果为门店直接跳转不需要判断useArec
  304. if (type.value == 2) {
  305. // data.value 2为指定优惠券 0为通用优惠券
  306. uni.navigateTo({
  307. url: `/packagePrize/coupon/detail?id=${ item.id }`
  308. })
  309. } else {
  310. // 3为线上票使用
  311. if (data.value == 3) {
  312. uni.navigateTo({
  313. url: `/packageGoods/ticket/index`
  314. })
  315. }
  316. //0为通用优惠券
  317. if (data.value == 0) {
  318. uni.navigateTo({
  319. url: `/packageGoods/ticket/index`
  320. })
  321. }
  322. // 4为线下票使用
  323. if (data.value == 4) {
  324. uni.navigateTo({
  325. url: `/packagePrize/coupon/detail?id=${ item.id }`
  326. })
  327. }
  328. }
  329. }
  330. },
  331. onReachBottom() {
  332. // 判断是否有数据
  333. if (this.total > this.pageNum * 20) {
  334. setTimeout(() => {
  335. ++this.pageNum
  336. this.getList()
  337. }, 500)
  338. } else {
  339. uni.$u.toast('已经到底了')
  340. }
  341. },
  342. }
  343. </script>
  344. <style lang="scss" scoped>
  345. .empty {
  346. height: 60vh;
  347. }
  348. .prize-state {
  349. position: fixed;
  350. background-color: #FFFFFF;
  351. width: 100%;
  352. z-index: 10;
  353. box-shadow: 0 2rpx 2rpx #ececec;
  354. // 类型
  355. &-tabs {
  356. display: flex;
  357. box-shadow: 0 5rpx 5rpx #ececec;
  358. }
  359. // 商品状态
  360. &-type {
  361. justify-content: flex-start;
  362. padding: 24rpx 34rpx;
  363. &-item {
  364. margin-right: 34rpx;
  365. padding: 12rpx 36rpx;
  366. border-radius: 24rpx;
  367. color: #FFAB4D;
  368. }
  369. &-item__action {
  370. background: #FFAB4D;
  371. color: #fff;
  372. }
  373. }
  374. }
  375. // 实物商品
  376. .prize-goods {
  377. margin-top: 180rpx;
  378. padding: 34rpx 34rpx 200rpx;
  379. &-list {
  380. &-item {
  381. padding: 34rpx 22rpx 34rpx;
  382. background-color: #fff;
  383. border-radius: 18rpx;
  384. margin-bottom: 30rpx;
  385. &__content {
  386. justify-content: space-between;
  387. padding-bottom: 22rpx;
  388. border-bottom: 1px solid #E5E5E5;
  389. .info {
  390. padding-left: 16rpx;
  391. flex: 1;
  392. justify-content: flex-start;
  393. image {
  394. width: 200rpx;
  395. height: 200rpx;
  396. border-radius: 12rpx;
  397. }
  398. .desc {
  399. height: 200rpx;
  400. padding-left: 22rpx;
  401. flex: 1;
  402. font-size: 30rpx;
  403. flex-direction: column;
  404. align-items: flex-start;
  405. justify-content: space-between;
  406. .title {
  407. line-height: 40rpx;
  408. font-weight: bold;
  409. }
  410. .num {
  411. width: 100%;
  412. color: #666666;
  413. font-size: 26rpx;
  414. justify-content: space-between;
  415. .sku {
  416. flex: 1;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. &__btn {
  423. justify-content: space-between;
  424. padding-top: 22rpx;
  425. .type {
  426. font-size: 30rpx;
  427. color: #999999;
  428. line-height: 30rpx;
  429. padding-left: 70rpx;
  430. }
  431. .btn {
  432. width: 200rpx;
  433. height: 66rpx;
  434. line-height: 66rpx;
  435. text-align: center;
  436. color: #fff;
  437. background: #F9822C;
  438. border-radius: 34rpx;
  439. }
  440. }
  441. }
  442. &-item:last-child {
  443. margin-bottom: 0;
  444. }
  445. }
  446. }
  447. .prize-coupon {
  448. margin-top: 85rpx;
  449. padding: 40rpx 20rpx 150rpx;
  450. &-list {
  451. &-item {
  452. position: relative;
  453. background-color: #FFFFFF;
  454. margin-bottom: 20rpx;
  455. border-radius: 10rpx;
  456. image {
  457. width: 100%;
  458. height: 156rpx;
  459. margin-bottom: 24rpx;
  460. }
  461. .info {
  462. padding-left: 40rpx;
  463. padding-bottom: 8rpx;
  464. .info-item {
  465. line-height: 40rpx;
  466. color: #333333;
  467. margin-bottom: 12rpx;
  468. }
  469. }
  470. .info-now {
  471. margin-top: 10rpx;
  472. color: #848484;
  473. font-size: 30rpx;
  474. height: 100rpx;
  475. line-height: 90rpx;
  476. text-align: center;
  477. }
  478. .info-now view {
  479. height: 2rpx;
  480. margin: 0 10rpx;
  481. background-image: linear-gradient(to right, #cfcfcf 0%, #cfcfcf 50%, transparent 1%);
  482. background-size: 25rpx 10rpx;
  483. }
  484. .price-title {
  485. justify-content: flex-start;
  486. position: absolute;
  487. top: 0;
  488. width: 100%;
  489. padding: 36rpx 0 0 40rpx;
  490. .price {
  491. color: #FFFFFF;
  492. font-size: 60rpx;
  493. margin-right: 20rpx;
  494. text {
  495. font-size: 40rpx;
  496. }
  497. }
  498. .title {
  499. color: #FFFFFF;
  500. font-size: 48rpx;
  501. }
  502. }
  503. }
  504. &-item:last-child {
  505. margin-bottom: 0;
  506. }
  507. }
  508. }
  509. .prize-action {
  510. position: fixed;
  511. bottom: var(--window-bottom);
  512. left: 0;
  513. right: 0;
  514. z-index: 10;
  515. box-shadow: 0 -4rpx 10rpx 0 rgba(151, 151, 151, 0.24);
  516. background: #fff;
  517. width: 100%;
  518. // 设置ios刘海屏底部横线安全区域
  519. padding-bottom: constant(safe-area-inset-bottom);
  520. padding-bottom: env(safe-area-inset-bottom);
  521. &-goods {
  522. justify-content: space-between;
  523. padding: 20rpx 40rpx;
  524. .all {
  525. margin-right: 10rpx;
  526. }
  527. .btn {
  528. width: 280rpx;
  529. height: 90rpx;
  530. font-size: 36rpx;
  531. line-height: 90rpx;
  532. border-radius: 10rpx;
  533. background-color: rgba(235, 112, 9, 100);
  534. color: rgba(255, 255, 255, 100);
  535. text-align: center;
  536. }
  537. }
  538. &-coupon {
  539. padding: 30rpx 40rpx;
  540. .title {
  541. margin-right: 20rpx;
  542. line-height: 40rpx;
  543. }
  544. }
  545. }
  546. </style>