index.vue 11 KB

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