index.vue 12 KB

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