index.vue 12 KB

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