index.vue 8.6 KB

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