index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. console.log(data)
  216. if (res.code == 0) {
  217. this.stateArr = [{
  218. name: ' 实物商品 (' + res.total + ') '
  219. },
  220. {
  221. name: ' 优惠券 (' + data.total + ') '
  222. },
  223. ]
  224. } else {
  225. this.stateArr = [{
  226. name: ' 实物商品 (0) '
  227. },
  228. {
  229. name: ' 优惠券 (0) '
  230. },
  231. ]
  232. }
  233. })
  234. });
  235. }
  236. },
  237. onReachBottom() {
  238. // 判断是否有数据
  239. if (this.total > this.pageNum * 20) {
  240. setTimeout(() => {
  241. ++this.pageNum
  242. this.getList()
  243. }, 500)
  244. } else {
  245. uni.$u.toast('没有更多数据了')
  246. }
  247. },
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. .empty {
  252. height: 60vh;
  253. }
  254. .prize-state {
  255. position: fixed;
  256. background-color: #FFFFFF;
  257. width: 100%;
  258. padding-bottom: 16rpx;
  259. z-index: 10;
  260. box-shadow: 0 5rpx 5rpx #ececec;
  261. }
  262. .prize-goods {
  263. margin-top: 90rpx;
  264. padding: 40rpx 20rpx 200rpx;
  265. &-list {
  266. &-item {
  267. justify-content: space-between;
  268. padding: 36rpx 16rpx;
  269. background-color: #fff;
  270. border-radius: 10rpx;
  271. margin-bottom: 30rpx;
  272. .checkbox {}
  273. .info {
  274. flex: 1;
  275. justify-content: flex-start;
  276. }
  277. image {
  278. width: 200rpx;
  279. height: 200rpx;
  280. }
  281. .desc {
  282. height: 200rpx;
  283. padding-left: 22rpx;
  284. flex: 1;
  285. font-size: 30rpx;
  286. flex-direction: column;
  287. align-items: flex-start;
  288. justify-content: space-between;
  289. }
  290. .content {
  291. line-height: 40rpx;
  292. font-weight: bold;
  293. }
  294. .sku {
  295. color: #848484;
  296. }
  297. .num {
  298. width: 100%;
  299. color: #8C8C8C;
  300. justify-content: space-between;
  301. }
  302. }
  303. &-item:last-child {
  304. margin-bottom: 0;
  305. }
  306. }
  307. }
  308. .prize-coupon {
  309. margin-top: 90rpx;
  310. padding: 40rpx 20rpx 150rpx;
  311. &-list {
  312. &-item {
  313. position: relative;
  314. background-color: #FFFFFF;
  315. margin-bottom: 20rpx;
  316. border-radius: 10rpx;
  317. image {
  318. width: 100%;
  319. height: 156rpx;
  320. margin-bottom: 24rpx;
  321. }
  322. .info {
  323. padding-left: 40rpx;
  324. padding-bottom: 8rpx;
  325. .info-item {
  326. line-height: 40rpx;
  327. color: #333333;
  328. margin-bottom: 12rpx;
  329. }
  330. }
  331. .price-title {
  332. justify-content: flex-start;
  333. position: absolute;
  334. top: 0;
  335. width: 100%;
  336. padding: 36rpx 0 0 40rpx;
  337. .price {
  338. color: #FFFFFF;
  339. font-size: 60rpx;
  340. margin-right: 20rpx;
  341. text {
  342. font-size: 40rpx;
  343. }
  344. }
  345. .title {
  346. color: #FFFFFF;
  347. font-size: 48rpx;
  348. }
  349. }
  350. }
  351. &-item:last-child {
  352. margin-bottom: 0;
  353. }
  354. }
  355. }
  356. .prize-action {
  357. position: fixed;
  358. bottom: var(--window-bottom);
  359. left: 0;
  360. right: 0;
  361. z-index: 10;
  362. box-shadow: 0 -4rpx 10rpx 0 rgba(151, 151, 151, 0.24);
  363. background: #fff;
  364. width: 100%;
  365. // 设置ios刘海屏底部横线安全区域
  366. padding-bottom: constant(safe-area-inset-bottom);
  367. padding-bottom: env(safe-area-inset-bottom);
  368. &-goods {
  369. justify-content: space-between;
  370. padding: 20rpx 40rpx;
  371. .all {
  372. margin-right: 10rpx;
  373. }
  374. .btn {
  375. width: 280rpx;
  376. height: 90rpx;
  377. font-size: 36rpx;
  378. line-height: 90rpx;
  379. border-radius: 10rpx;
  380. background-color: rgba(235, 112, 9, 100);
  381. color: rgba(255, 255, 255, 100);
  382. text-align: center;
  383. }
  384. }
  385. &-coupon {
  386. padding: 30rpx 40rpx;
  387. .title {
  388. margin-right: 20rpx;
  389. line-height: 40rpx;
  390. }
  391. }
  392. }
  393. </style>