index.vue 12 KB

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