index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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><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. if (type.value == 2) {
  271. // data.value 2为指定优惠券 0为通用优惠券
  272. uni.navigateTo({
  273. url: `/pages/prize/detail?info=${ JSON.stringify(item) }`
  274. })
  275. } else {
  276. // 3为线上票使用
  277. if (data.value == 3) {
  278. uni.navigateTo({
  279. url: `/pages/ticketBox/index`
  280. })
  281. }
  282. //0为通用优惠券
  283. if (data.value == 0) {
  284. uni.navigateTo({
  285. url: `/pages/ticketBox/index`
  286. })
  287. }
  288. // 4为线下票使用
  289. if (data.value == 4) {
  290. uni.navigateTo({
  291. url: `/pages/prize/detail?info=${ JSON.stringify(item) }`
  292. })
  293. }
  294. }
  295. }
  296. },
  297. onReachBottom() {
  298. // 判断是否有数据
  299. if (this.total > this.pageNum * 20) {
  300. setTimeout(() => {
  301. ++this.pageNum
  302. this.getList()
  303. }, 500)
  304. } else {
  305. uni.$u.toast('没有更多数据了')
  306. }
  307. },
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .info-now {
  312. margin-top: 10rpx;
  313. color: #848484;
  314. font-size: 30rpx;
  315. height: 100rpx;
  316. line-height: 90rpx;
  317. text-align: center;
  318. }
  319. .info-now view {
  320. height: 2rpx;
  321. margin: 0 10rpx;
  322. background-image: linear-gradient(to right, #cfcfcf 0%, #cfcfcf 50%, transparent 1%);
  323. background-size: 25rpx 10rpx;
  324. }
  325. </style>
  326. <style lang="scss" scoped>
  327. .empty {
  328. height: 60vh;
  329. }
  330. .prize-state {
  331. position: fixed;
  332. background-color: #FFFFFF;
  333. width: 100%;
  334. padding-bottom: 16rpx;
  335. z-index: 10;
  336. box-shadow: 0 5rpx 5rpx #ececec;
  337. }
  338. .prize-goods {
  339. margin-top: 90rpx;
  340. padding: 40rpx 20rpx 200rpx;
  341. &-list {
  342. &-item {
  343. justify-content: space-between;
  344. padding: 36rpx 16rpx;
  345. background-color: #fff;
  346. border-radius: 10rpx;
  347. margin-bottom: 30rpx;
  348. .checkbox {}
  349. .info {
  350. flex: 1;
  351. justify-content: flex-start;
  352. }
  353. image {
  354. width: 200rpx;
  355. height: 200rpx;
  356. }
  357. .desc {
  358. height: 200rpx;
  359. padding-left: 22rpx;
  360. flex: 1;
  361. font-size: 30rpx;
  362. flex-direction: column;
  363. align-items: flex-start;
  364. justify-content: space-between;
  365. }
  366. .content {
  367. line-height: 40rpx;
  368. font-weight: bold;
  369. }
  370. .sku {
  371. color: #848484;
  372. }
  373. .num {
  374. width: 100%;
  375. color: #8C8C8C;
  376. justify-content: space-between;
  377. }
  378. }
  379. &-item:last-child {
  380. margin-bottom: 0;
  381. }
  382. }
  383. }
  384. .prize-coupon {
  385. margin-top: 90rpx;
  386. padding: 40rpx 20rpx 150rpx;
  387. &-list {
  388. &-item {
  389. position: relative;
  390. background-color: #FFFFFF;
  391. margin-bottom: 20rpx;
  392. border-radius: 10rpx;
  393. image {
  394. width: 100%;
  395. height: 156rpx;
  396. margin-bottom: 24rpx;
  397. }
  398. .info {
  399. padding-left: 40rpx;
  400. padding-bottom: 8rpx;
  401. .info-item {
  402. line-height: 40rpx;
  403. color: #333333;
  404. margin-bottom: 12rpx;
  405. }
  406. }
  407. .price-title {
  408. justify-content: flex-start;
  409. position: absolute;
  410. top: 0;
  411. width: 100%;
  412. padding: 36rpx 0 0 40rpx;
  413. .price {
  414. color: #FFFFFF;
  415. font-size: 60rpx;
  416. margin-right: 20rpx;
  417. text {
  418. font-size: 40rpx;
  419. }
  420. }
  421. .title {
  422. color: #FFFFFF;
  423. font-size: 48rpx;
  424. }
  425. }
  426. }
  427. &-item:last-child {
  428. margin-bottom: 0;
  429. }
  430. }
  431. }
  432. .prize-action {
  433. position: fixed;
  434. bottom: var(--window-bottom);
  435. left: 0;
  436. right: 0;
  437. z-index: 10;
  438. box-shadow: 0 -4rpx 10rpx 0 rgba(151, 151, 151, 0.24);
  439. background: #fff;
  440. width: 100%;
  441. // 设置ios刘海屏底部横线安全区域
  442. padding-bottom: constant(safe-area-inset-bottom);
  443. padding-bottom: env(safe-area-inset-bottom);
  444. &-goods {
  445. justify-content: space-between;
  446. padding: 20rpx 40rpx;
  447. .all {
  448. margin-right: 10rpx;
  449. }
  450. .btn {
  451. width: 280rpx;
  452. height: 90rpx;
  453. font-size: 36rpx;
  454. line-height: 90rpx;
  455. border-radius: 10rpx;
  456. background-color: rgba(235, 112, 9, 100);
  457. color: rgba(255, 255, 255, 100);
  458. text-align: center;
  459. }
  460. }
  461. &-coupon {
  462. padding: 30rpx 40rpx;
  463. .title {
  464. margin-right: 20rpx;
  465. line-height: 40rpx;
  466. }
  467. }
  468. }
  469. </style>