index.vue 7.9 KB

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