index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. <!-- 类型 -->
  16. <view class="prize-state-tabs">
  17. <u-tabs @change="changeTab" :scrollable="false" :list="stateArr" lineWidth="30" lineHeight="3"
  18. :current='currentIndex' lineColor="#F9822C " :activeStyle="{
  19. color: '#333 ',
  20. transform: 'scale(1.1)',
  21. width: '120px'
  22. }" :inactiveStyle="{
  23. color: '#999',
  24. transform: 'scale(1)',
  25. width: '120px'
  26. }" itemStyle="padding-left: 20px; padding-right: 15px; height: 44px; text-align: center;">
  27. </u-tabs>
  28. </view>
  29. <!-- 商品状态 -->
  30. <view class="prize-state-type flex" v-if="state == 0">
  31. <view class="prize-state-type-item" :class="{ 'prize-state-type-item__action': index == typeIndex }"
  32. v-for="(item, index) in typeList" :key="index" @click="typeState(index)">{{ item.name }}</view>
  33. </view>
  34. </view>
  35. <!-- 实物商品 -->
  36. <view class="prize-goods" v-if="state == 0">
  37. <view class="prize-goods-list">
  38. <view class="prize-goods-list-item" v-for="(item, index) in list" :key="index">
  39. <!-- <view class="prize-goods-list-item" v-for="(item, index) in list" :key="index" > -->
  40. <!-- 商品 -->
  41. <view class="prize-goods-list-item__content flex">
  42. <view class="flex" v-if="item.status == 1">
  43. <u-checkbox-group>
  44. <u-checkbox size="24" :value="item.checked" shape="circle" :checked="item.checked"
  45. activeColor="#F9822C" @change="changeChecked($event, item)"></u-checkbox>
  46. </u-checkbox-group>
  47. </view>
  48. <view class="info flex" @click="toPrizeGoods(item)">
  49. <image :src="item.picUrl" mode="aspectFill"></image>
  50. <view class="desc flex">
  51. <view class="ells title">{{ item.title }}</view>
  52. <view class="num flex">
  53. <view class="sku ells-one">规格:{{ item.properties || '-' }}</view>
  54. <view class="">共{{ item.goodsNum }}件</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 来源 -->
  60. <view class="prize-goods-list-item__btn flex" v-if="item.status == 1">
  61. <view class="type">来自:{{ item.inType && item.inType.desc }}</view>
  62. <view class="btn" @click="toRecovery(item)" v-if="item.inType.value == '1' || item.inType.value == '2'">兑换盲豆</view>
  63. </view>
  64. <view class="prize-goods-list-item__btn flex" v-else>
  65. <view class="type"></view>
  66. <view class="btnTwo">已兑换</view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="flex empty" v-if="!list.length && !loading">
  71. <view class="center">
  72. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_3.png" mode=""></image>
  73. <view class="center-font">还没有商品</view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 优惠券 -->
  78. <view class="prize-coupon" v-else>
  79. <view class="prize-coupon-list">
  80. <view @click="toPrizeDetail(item)" class="prize-coupon-list-item" v-for="(item, index) in list" :key="index">
  81. <view class="content flex">
  82. <view class="content-left flex">
  83. <image src="../static/prize_coupon.png" mode=""></image>
  84. <view class="price flex">
  85. <text>{{ item.discount / 100 }}</text>
  86. <text>元</text>
  87. </view>
  88. </view>
  89. <view class="content-right flex">
  90. <view class="title ells-one">{{ item.title }}</view>
  91. <view class="desc">适用范围:{{ item.useAreaDesc || '-' }}</view>
  92. <view class="desc">使用期限:{{ $parseTime(item.validStart, '{y}.{m}.{d}') }} ~ {{ $parseTime(item.validEnd, '{y}.{m}.{d}') }}</view>
  93. </view>
  94. </view>
  95. <view class="btn flex">
  96. <view class="btn-title" v-if="JSON.parse(item.useArea).value != '4'">立即使用</view>
  97. <view class="btn-title" v-else>查看详情</view>
  98. </view>
  99. </view>
  100. </view>
  101. <view class="flex empty" v-if="!list.length && !loading">
  102. <view class="center">
  103. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_1.png" mode=""></image>
  104. <view class="center-font">还没有优惠券</view>
  105. </view>
  106. </view>
  107. </view>
  108. <view class="prize-action" v-if="statusIndex == 1">
  109. <!-- 实物商品提货 -->
  110. <view class="flex prize-action-goods" v-if="state == 0">
  111. <view class="flex checkbox">
  112. <u-checkbox-group>
  113. <u-checkbox v-model="checkedAll" shape="circle" size="24" :checked="checkedAll"
  114. activeColor="#F9822C" @change="changeCheckedAll($event)"></u-checkbox>
  115. </u-checkbox-group>
  116. <view class="all">全选</view>
  117. </view>
  118. <view class="btn" @click="toSettlement">立即提货</view>
  119. </view>
  120. <!-- 优惠券使用记录 -->
  121. <view class="flex prize-action-coupon" @click="toCoupon" v-else>
  122. <view class="title">优惠券使用记录</view>
  123. <u-icon name="arrow-right" size="15" color="#999"></u-icon>
  124. </view>
  125. </view>
  126. </view>
  127. </template>
  128. <script>
  129. import env from '../../config/env.js'
  130. import $http from '@/utils/request.js'
  131. export default {
  132. data() {
  133. return {
  134. loading: false,
  135. stateArr: [{
  136. name: ' 实物商品',
  137. }, {
  138. name: ' 优惠券',
  139. }],
  140. typeList: [{
  141. name: '待提货'
  142. }, {
  143. name: '已兑换'
  144. }],
  145. typeIndex: 0,
  146. state: 0,
  147. checkedAll: false,
  148. pageNum: 1,
  149. total: 0,
  150. list: [],
  151. currentIndex: 0,
  152. pagesNum: "",
  153. statusIndex: 1,
  154. };
  155. },
  156. onShow() {
  157. this.pagesNum = getCurrentPages().length
  158. this.pageList()
  159. this.couponNum()
  160. },
  161. onLoad(opthios) {
  162. if (opthios != undefined) {
  163. if (opthios.coupon == 1) {
  164. this.currentIndex = 1
  165. this.state = 1
  166. } else {
  167. this.currentIndex = 0
  168. this.state = 0
  169. }
  170. }
  171. },
  172. methods: {
  173. getList() {
  174. let _this = this
  175. let url = _this.state == 0 ? '/api/v1/mp/user/mine/prize/list' : '/api/v1/mp/user/mine/coupon/list'
  176. let data = _this.state == 0 ? { } : {
  177. status: 1
  178. }
  179. uni.showLoading({
  180. title: '加载中'
  181. });
  182. this.loading = true
  183. this.checkedAll = false
  184. $http.post(`${ url }?pageNum=${_this.pageNum}&pageSize=20`, data).then(res => {
  185. uni.hideLoading();
  186. this.loading = false
  187. if (res.code == 0) {
  188. res.rows.forEach(item => {
  189. item.status = JSON.parse(item.status).value
  190. let picUrlArr = item.picUrl.split(',')
  191. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  192. if (_this.state == 0) {
  193. item.checked = false
  194. item.inType = JSON.parse(item.inType)
  195. }
  196. })
  197. _this.total = res.total
  198. _this.list = _this.list.concat(res.rows)
  199. }
  200. }).catch(() => {
  201. uni.hideLoading();
  202. this.loading = false
  203. })
  204. },
  205. getListTwo(){
  206. let _this = this
  207. let url = '/api/v1/mp/user/prize/recovery/list'
  208. this.loading = true
  209. this.checkedAll = false
  210. $http.post(`${ url }?pageNum=${_this.pageNum}&pageSize=20`, {}).then(res => {
  211. uni.hideLoading();
  212. this.loading = false
  213. if (res.code == 0) {
  214. console.log(res);
  215. res.rows.forEach(item => {
  216. item.status = 3
  217. item.goodsNum = item.num
  218. let picUrlArr = item.picUrl.split(',')
  219. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  220. })
  221. _this.list = _this.list.concat(res.rows)
  222. }
  223. }).catch(() => {
  224. uni.hideLoading();
  225. this.loading = false
  226. })
  227. },
  228. typeState(index){
  229. this.list = []
  230. this.typeIndex = index//样式改变
  231. // this.statusIndex = index
  232. if(index == 0 ){
  233. this.statusIndex = 1 //待提货
  234. this.pageNum = 1
  235. this.getList()
  236. }
  237. if(index == 1 ){
  238. this.statusIndex = 3 //已兑换
  239. this.pageNum = 1
  240. this.getListTwo()
  241. }
  242. },
  243. toIndex() {
  244. uni.switchTab({
  245. url: '/pages/user/index'
  246. })
  247. },
  248. toRecovery(item) {
  249. uni.navigateTo({
  250. url: `/packageGoods/recovery/index?goodsId=${ item.goodsId}&num=${ item.goodsNum }&storageId=${ item.storageId }&properties=${item.properties }&skuId=${ item.skuId }`
  251. })
  252. },
  253. pageList() {
  254. this.typeIndex = 0
  255. this.pageNum = 1
  256. this.list = []
  257. this.getList()
  258. },
  259. // 切换奖品
  260. changeTab(e) {
  261. if (e.index == 0) {
  262. this.state = 0
  263. } else if (e.index == 1) {
  264. this.state = 1
  265. }
  266. this.pageList()
  267. this.checkedAll = false
  268. },
  269. changeChecked(e, item) {
  270. this.$set(item, 'checked', e)
  271. let flag = this.list.every(item => item.checked == true)
  272. this.checkedAll = flag
  273. this.$forceUpdate()
  274. },
  275. changeCheckedAll(e) {
  276. this.checkedAll = e
  277. this.list.forEach(item => {
  278. item.checked = e
  279. })
  280. this.$forceUpdate()
  281. },
  282. // 查看优惠券使用记录
  283. toCoupon() {
  284. uni.navigateTo({
  285. url: '/packagePrize/coupon/use'
  286. })
  287. },
  288. // 立即提货
  289. toSettlement() {
  290. let arr = []
  291. this.list.forEach(item => {
  292. if (item.checked) {
  293. arr.push(item)
  294. }
  295. })
  296. if (!arr.length) {
  297. uni.$u.toast('请选择商品');
  298. return
  299. }
  300. uni.showLoading({
  301. title: '提货中'
  302. });
  303. let ids = JSON.stringify(arr.map(item => item.storageId))
  304. uni.hideLoading();
  305. uni.navigateTo({
  306. url: `/packageGoods/order/settlement?ids=${ ids }`
  307. })
  308. },
  309. couponNum() {
  310. $http.post(`/api/v1/mp/user/mine/prize/list?pageNum=1&pageSize=10`, {
  311. }).then(res => {
  312. $http.post(`/api/v1/mp/user/mine/coupon/list?pageNum=1&pageSize=10`, {
  313. status: 1
  314. }).then(data => {
  315. if (res.code == 0) {
  316. this.stateArr = [{
  317. name: ' 实物商品 (' + res.total + ') '
  318. },
  319. {
  320. name: ' 优惠券 (' + data.total + ') '
  321. },
  322. ]
  323. } else {
  324. this.stateArr = [{
  325. name: ' 实物商品 (0)'
  326. },
  327. {
  328. name: ' 优惠券 (0)'
  329. },
  330. ]
  331. }
  332. })
  333. });
  334. },
  335. toPrizeGoods(item) {
  336. uni.navigateTo({
  337. url: `/packagePrize/goods/detail?id=${ item.goodsId }`
  338. })
  339. },
  340. toPrizeDetail(item) {
  341. let data = JSON.parse(item.useArea)
  342. let type = JSON.parse(item.type)
  343. // 1判断type,如果为门店直接跳转不需要判断useArec
  344. if (type.value == 2) {
  345. // data.value 2为指定优惠券 0为通用优惠券
  346. uni.navigateTo({
  347. url: `/packagePrize/coupon/detail?id=${ item.id }`
  348. })
  349. } else {
  350. // 3为线上票使用
  351. if (data.value == 3) {
  352. uni.navigateTo({
  353. url: `/packageGoods/ticket/index`
  354. })
  355. }
  356. //0为通用优惠券
  357. if (data.value == 0) {
  358. uni.navigateTo({
  359. url: `/packageGoods/ticket/index`
  360. })
  361. }
  362. // 4为线下票使用
  363. if (data.value == 4) {
  364. uni.navigateTo({
  365. url: `/packagePrize/coupon/detail?id=${ item.id }`
  366. })
  367. }
  368. }
  369. }
  370. },
  371. onReachBottom() {
  372. // 判断是否有数据
  373. if (this.total > this.pageNum * 20) {
  374. setTimeout(() => {
  375. ++this.pageNum
  376. this.statusIndex == 3?this.getListTwo():this.getList()
  377. }, 500)
  378. } else {
  379. uni.$u.toast('已经到底了')
  380. }
  381. },
  382. }
  383. </script>
  384. <style lang="scss" scoped>
  385. .empty {
  386. height: 60vh;
  387. }
  388. .prize-state {
  389. position: fixed;
  390. background-color: #FFFFFF;
  391. width: 100%;
  392. z-index: 10;
  393. box-shadow: 0 2rpx 2rpx #ececec;
  394. // 类型
  395. &-tabs {
  396. display: flex;
  397. box-shadow: 0 5rpx 5rpx #ececec;
  398. }
  399. // 商品状态
  400. &-type {
  401. justify-content: flex-start;
  402. padding: 24rpx 34rpx;
  403. &-item {
  404. margin-right: 34rpx;
  405. padding: 12rpx 36rpx;
  406. border-radius: 24rpx;
  407. color: #FFAB4D;
  408. }
  409. &-item__action {
  410. background: #FFAB4D;
  411. color: #fff;
  412. }
  413. }
  414. }
  415. // 实物商品
  416. .prize-goods {
  417. margin-top: 180rpx;
  418. padding: 34rpx 34rpx 200rpx;
  419. &-list {
  420. &-item {
  421. padding: 34rpx 22rpx 34rpx;
  422. background-color: #fff;
  423. border-radius: 18rpx;
  424. margin-bottom: 30rpx;
  425. &__content {
  426. justify-content: space-between;
  427. padding-bottom: 34rpx;
  428. .info {
  429. padding-left: 16rpx;
  430. flex: 1;
  431. justify-content: flex-start;
  432. image {
  433. width: 176rpx;
  434. height: 176rpx;
  435. border-radius: 12rpx;
  436. }
  437. .desc {
  438. height: 176rpx;
  439. padding-left: 22rpx;
  440. flex: 1;
  441. font-size: 30rpx;
  442. flex-direction: column;
  443. align-items: flex-start;
  444. justify-content: space-between;
  445. .title {
  446. line-height: 40rpx;
  447. font-weight: bold;
  448. }
  449. .num {
  450. width: 100%;
  451. color: #666666;
  452. font-size: 26rpx;
  453. justify-content: space-between;
  454. .sku {
  455. flex: 1;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. &__btn {
  462. justify-content: space-between;
  463. .type {
  464. font-size: 26rpx;
  465. color: #999999;
  466. line-height: 26rpx;
  467. padding-left: 70rpx;
  468. }
  469. .btn {
  470. width: 168rpx;
  471. height: 60rpx;
  472. line-height: 60rpx;
  473. text-align: center;
  474. color: #F9822C;
  475. border: 1px solid #F9822C;
  476. border-radius: 30rpx;
  477. }
  478. .btnTwo {
  479. width: 168rpx;
  480. height: 60rpx;
  481. line-height: 60rpx;
  482. text-align: center;
  483. border-radius: 30rpx;
  484. background-color: #f1f1f1;
  485. color: #666;
  486. border: 2rpx solid #999;
  487. }
  488. }
  489. }
  490. &-item:last-child {
  491. margin-bottom: 0;
  492. }
  493. }
  494. }
  495. // 优惠券
  496. .prize-coupon {
  497. margin-top: 85rpx;
  498. padding: 20rpx 20rpx 150rpx;
  499. &-list {
  500. &-item {
  501. padding-top: 30rpx;
  502. margin-bottom: 30rpx;
  503. background-color: #fff;
  504. .content {
  505. width: 100%;
  506. height: 184rpx;
  507. justify-content: flex-start;
  508. margin-bottom: 40rpx;
  509. &-left {
  510. width: 210rpx;
  511. height: 100%;
  512. margin-right: 20rpx;
  513. image {
  514. width: 100%;
  515. height: 100%;
  516. }
  517. .price {
  518. position: absolute;
  519. color: #fff;
  520. text:first-child {
  521. font-size: 70rpx;
  522. padding-right: 20rpx;
  523. }
  524. text:last-child {
  525. font-size: 40rpx;
  526. }
  527. }
  528. }
  529. &-right {
  530. flex: 1;
  531. align-items: flex-start;
  532. flex-direction: column;
  533. justify-content: space-between;
  534. height: 100%;
  535. padding: 24rpx 0;
  536. .title {
  537. font-size: 32rpx;
  538. line-height: 32rpx;
  539. height: 32rpx;
  540. overflow: hidden;
  541. font-weight: bold;
  542. }
  543. .desc {
  544. font-size: 24rpx;
  545. line-height: 24rpx;
  546. color: #999999;
  547. }
  548. }
  549. }
  550. .btn {
  551. padding: 20rpx 0 22rpx;
  552. margin: 0 30rpx 0;
  553. border-top: 1px solid #F2F2F2;
  554. &-title {
  555. font-size: 30rpx;
  556. line-height: 30rpx;
  557. height: 30rpx;
  558. font-weight: bold;
  559. color: #F9822C;
  560. }
  561. }
  562. }
  563. &-item:last-child {
  564. margin-bottom: 0;
  565. }
  566. }
  567. }
  568. .prize-action {
  569. position: fixed;
  570. bottom: var(--window-bottom);
  571. left: 0;
  572. right: 0;
  573. z-index: 10;
  574. box-shadow: 0 -4rpx 10rpx 0 rgba(151, 151, 151, 0.24);
  575. background: #fff;
  576. width: 100%;
  577. // 设置ios刘海屏底部横线安全区域
  578. padding-bottom: constant(safe-area-inset-bottom);
  579. padding-bottom: env(safe-area-inset-bottom);
  580. &-goods {
  581. justify-content: space-between;
  582. padding: 20rpx 40rpx;
  583. .all {
  584. margin-right: 10rpx;
  585. }
  586. .btn {
  587. width: 225rpx;
  588. height: 82rpx;
  589. font-size: 28rpx;
  590. line-height: 82rpx;
  591. border-radius: 40rpx;
  592. background-color: #F9822C;
  593. color: #fff;
  594. text-align: center;
  595. }
  596. }
  597. &-coupon {
  598. padding: 30rpx 40rpx;
  599. .title {
  600. margin-right: 10rpx;
  601. color: #999;
  602. line-height: 40rpx;
  603. }
  604. }
  605. }
  606. .empty {
  607. height: 60vh;
  608. .center {
  609. text-align: center;
  610. &-img {
  611. width: 228rpx;
  612. height: 320rpx;
  613. }
  614. &-font {
  615. font-size: 30rpx;
  616. font-weight: 400;
  617. color: #999999;
  618. margin-bottom: 350rpx;
  619. }
  620. }
  621. }
  622. </style>