index.vue 11 KB

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