exchange-popup.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <u-popup :show="popupShow" round="17" mode="bottom" @close="close" :closeable="true" @touchmove.prevent.stop>
  3. <view class="choiceShow-wrap">
  4. <!-- 商品信息 -->
  5. <view class="flex goods">
  6. <view class="goods-left">
  7. <view class="goods-left__image flex">
  8. <image class="image-goods" :src="payInfo.picUrl" mode="aspectFit"></image>
  9. </view>
  10. <view class="goods-left-content flex">
  11. <view class="goods-left-content__title ells-one">{{ detailInfo.title }}</view>
  12. <view class="goods-left-content__coin flex">
  13. <image class="image-coin" src="../../static/goods_coin.png" mode=""></image>
  14. <view>× {{ payInfo.exValue }}</view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="goods-right">库存:{{ payInfo.quantity }}</view>
  19. </view>
  20. <!-- sku -->
  21. <view class="sku" v-for="(item, index) in skuList" :key="index">
  22. <view class="sku-title">{{ item.name }}</view>
  23. <view class="flex sku-list">
  24. <view
  25. class="sku-list-item"
  26. :class="{'action': item.actionIndex == indexs}"
  27. v-for="(ele, indexs) in item.value" :key="indexs" @click="getSku(ele, item, indexs)">
  28. {{ ele }}
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 数量 -->
  33. <view class="flex quantity">
  34. <view class="quantity-title">商品数量</view>
  35. <view class="quantity-title">
  36. <u-number-box v-model="orderNum" :min="1" :disabledInput="true"
  37. @change="valChange($event, payInfo)"></u-number-box>
  38. </view>
  39. </view>
  40. <!-- 按钮 -->
  41. <view class="flex btn">
  42. <view class="flex btn-left">
  43. <view class="title">应付:</view>
  44. <view class="flex coin">
  45. <image src="../../static/goods_coin.png" mode=""></image>
  46. <view>× {{ payInfo.exchangePrice }}</view>
  47. </view>
  48. </view>
  49. <view class="btn-right">
  50. <view class="confirm" @click="confirmPrize">立即兑换</view>
  51. </view>
  52. </view>
  53. </view>
  54. </u-popup>
  55. </template>
  56. <script>
  57. import env from '@/config/env.js'
  58. import $http from '@/utils/request.js'
  59. export default {
  60. name: "exchange-popup",
  61. props: {
  62. popupShow: {
  63. type: [Boolean],
  64. default: false
  65. },
  66. skuListInit: {
  67. type: Array,
  68. default: () => []
  69. },
  70. skuList: {
  71. type: Array,
  72. default: () => []
  73. },
  74. detailInfo: {
  75. type: [Object],
  76. default: {}
  77. },
  78. popupInfo: {
  79. type: [Object],
  80. default: {}
  81. }
  82. },
  83. data() {
  84. return {
  85. orderNum: 1,
  86. payInfo: {}
  87. };
  88. },
  89. created() {
  90. this.payInfo = this.popupInfo
  91. },
  92. methods: {
  93. valChange(e, item) {
  94. let value = e.value
  95. this.$set(item, 'exchangePrice', value * item.exValue)
  96. if (this.payInfo.quantity < value) {
  97. uni.$u.toast('库存不足');
  98. }
  99. },
  100. getSku(e, item, indexs) {
  101. this.$set(item, 'txt', `${item.name}:${e}`)
  102. this.$set(item, 'actionIndex', indexs)
  103. this.orderNum = 1
  104. let actionSku = this.skuList.map(item => {
  105. return item.txt
  106. }).join(';')
  107. let sku = this.skuListInit.find(item => {
  108. return item.properties == actionSku
  109. })
  110. this.payInfo = {
  111. ...sku,
  112. exValue: sku.exchangePrice,
  113. picUrl: env.filePublic + sku.picUrl
  114. }
  115. },
  116. confirmPrize() {
  117. let flag = false
  118. let data = {
  119. goodsId: this.payInfo.goodsId,
  120. skuId: this.payInfo.skuId,
  121. orderNum: this.orderNum,
  122. }
  123. if (flag) return
  124. if (this.payInfo.quantity == 0) {
  125. uni.$u.toast('库存不足');
  126. return
  127. }
  128. if (this.payInfo.quantity < this.orderNum) {
  129. uni.$u.toast('库存不足');
  130. return
  131. }
  132. uni.showLoading({
  133. title: '兑换中'
  134. });
  135. flag = true
  136. $http.post('/api/v1/mp/user/exchange/submit', data).then(res => {
  137. uni.hideLoading();
  138. flag = false
  139. if (res.code == 0) {
  140. this.$emit('success')
  141. } else if (res.code == 1021) {
  142. uni.$u.toast(res.msg);
  143. }
  144. }).catch(() => {
  145. flag = false
  146. uni.hideLoading();
  147. })
  148. },
  149. close() {
  150. this.$emit('close')
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .choiceShow-wrap {
  157. min-height: 400rpx;
  158. padding: 34rpx;
  159. // 商品
  160. .goods {
  161. justify-content: space-between;
  162. margin-bottom: 66rpx;
  163. &-left {
  164. flex: 1;
  165. display: flex;
  166. &__image {
  167. width: 154rpx;
  168. height: 154rpx;
  169. border: 1px solid #EEEEEE;
  170. border-radius: 18rpx;
  171. margin-right: 24rpx;
  172. .image-goods {
  173. width: 154rpx;
  174. height: 154rpx;
  175. }
  176. }
  177. &-content {.image-goods {
  178. width: 154rpx;
  179. height: 154rpx;
  180. border-radius: 18rpx;
  181. border: 1px solid #EEEEEE;
  182. margin-right: 24rpx;
  183. }
  184. height: 154rpx;
  185. flex-direction: column;
  186. align-items: flex-start;
  187. justify-content: space-between;
  188. padding: 34rpx 0;
  189. &__title {
  190. font-size: 30rpx;
  191. line-height: 30rpx;
  192. font-weight: bold;
  193. }
  194. &__coin {
  195. color: #FF2929;
  196. .image-coin {
  197. width: 34rpx;
  198. height: 30rpx;
  199. }
  200. }
  201. }
  202. }
  203. &-right {
  204. color: #666;
  205. }
  206. }
  207. // sku
  208. .sku {
  209. &-title {
  210. font-size: 30rpx;
  211. line-height: 30rpx;
  212. font-weight: bold;
  213. margin-bottom: 34rpx;
  214. }
  215. &-list {
  216. justify-content: flex-start;
  217. flex-wrap: wrap;
  218. &-item {
  219. padding: 20rpx 66rpx;
  220. border-radius: 36rpx;
  221. margin-right: 18rpx;
  222. background: #F5F6F8;
  223. margin-bottom: 34rpx;
  224. }
  225. .action {
  226. background-color: rgba(250, 130, 44, .25);
  227. color: #FA822C;
  228. }
  229. }
  230. }
  231. // 数量
  232. .quantity {
  233. justify-content: space-between;
  234. margin: 34rpx 0;
  235. &-title {
  236. font-size: 30rpx;
  237. line-height: 30rpx;
  238. font-weight: bold;
  239. }
  240. }
  241. // 按钮
  242. .btn {
  243. justify-content: space-between;
  244. padding-top: 36rpx;
  245. border-top: 1px solid #eee;
  246. &-left {
  247. .coin {
  248. display: flex;
  249. align-items: center;
  250. font-size: 26rpx;
  251. line-height: 30rpx;
  252. color: #FF2929;
  253. image {
  254. width: 34rpx;
  255. height: 30rpx;
  256. }
  257. }
  258. }
  259. &-right {
  260. .confirm {
  261. width: 414rpx;
  262. height: 88rpx;
  263. line-height: 88rpx;
  264. background: #FA362C;
  265. border-radius: 44rpx;
  266. font-size: 36rpx;
  267. color: #fff;
  268. text-align: center;
  269. }
  270. }
  271. }
  272. }
  273. </style>