index.vue 8.2 KB

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