index.vue 8.0 KB

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