index.vue 8.1 KB

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