index.vue 8.7 KB

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