index.vue 8.6 KB

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