index.vue 11 KB

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