index.vue 9.9 KB

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