index.vue 12 KB

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