index.vue 12 KB

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