exchange-popup.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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/public/goods_coin.png" mode="scaleToFill"></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/public/goods_coin.png" mode="scaleToFill"></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. skuListPopup: {
  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. skuList: []
  88. };
  89. },
  90. created() {
  91. this.payInfo = this.popupInfo
  92. this.skuList = this.skuListPopup
  93. },
  94. methods: {
  95. valChange(e, item) {
  96. let value = e.value
  97. this.$set(item, 'exchangePrice', value * item.exValue)
  98. if (this.payInfo.quantity < value) {
  99. uni.$u.toast('库存不足');
  100. }
  101. },
  102. getSku(e, item, indexs) {
  103. this.$set(item, 'txt', `${item.name}:${e}`)
  104. this.$set(item, 'actionIndex', indexs)
  105. this.orderNum = 1
  106. let actionSku = this.skuList.map(item => {
  107. return item.txt
  108. }).join(';')
  109. let sku = this.skuListInit.find(item => {
  110. return item.properties == actionSku
  111. })
  112. this.payInfo = {
  113. ...sku,
  114. exValue: sku.exchangePrice,
  115. picUrl: env.filePublic + sku.picUrl
  116. }
  117. },
  118. confirmPrize() {
  119. let flag = false
  120. let data = {
  121. goodsId: this.payInfo.goodsId,
  122. skuId: this.payInfo.skuId,
  123. orderNum: this.orderNum,
  124. }
  125. if (flag) return
  126. if (this.payInfo.quantity == 0) {
  127. uni.$u.toast('库存不足');
  128. return
  129. }
  130. if (this.payInfo.quantity < this.orderNum) {
  131. uni.$u.toast('库存不足');
  132. return
  133. }
  134. uni.showLoading({
  135. title: '兑换中'
  136. });
  137. flag = true
  138. $http.post('/api/v1/mp/user/exchange/submit', data).then(res => {
  139. uni.hideLoading();
  140. flag = false
  141. if (res.code == 0) {
  142. this.$emit('success')
  143. } else if (res.code == 1021) {
  144. uni.$u.toast(res.msg);
  145. }
  146. }).catch(() => {
  147. flag = false
  148. uni.hideLoading();
  149. })
  150. },
  151. close() {
  152. this.$emit('close')
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .choiceShow-wrap {
  159. min-height: 400rpx;
  160. padding: 34rpx;
  161. // 商品
  162. .goods {
  163. justify-content: space-between;
  164. margin-bottom: 66rpx;
  165. &-left {
  166. flex: 1;
  167. display: flex;
  168. &__image {
  169. width: 154rpx;
  170. height: 154rpx;
  171. border: 1px solid #EEEEEE;
  172. border-radius: 18rpx;
  173. margin-right: 24rpx;
  174. .image-goods {
  175. width: 154rpx;
  176. height: 154rpx;
  177. }
  178. }
  179. &-content {
  180. height: 154rpx;
  181. flex-direction: column;
  182. align-items: flex-start;
  183. justify-content: space-between;
  184. padding: 34rpx 0;
  185. .image-goods {
  186. width: 154rpx;
  187. height: 154rpx;
  188. border-radius: 18rpx;
  189. border: 1px solid #EEEEEE;
  190. margin-right: 24rpx;
  191. }
  192. &__title {
  193. font-size: 30rpx;
  194. line-height: 30rpx;
  195. font-weight: bold;
  196. height: 30rpx;
  197. overflow: hidden;
  198. }
  199. &__coin {
  200. color: #FA822C;
  201. .image-coin {
  202. width: 34rpx;
  203. height: 30rpx;
  204. }
  205. }
  206. }
  207. }
  208. &-right {
  209. color: #666;
  210. }
  211. }
  212. // sku
  213. .sku {
  214. &-title {
  215. font-size: 30rpx;
  216. line-height: 30rpx;
  217. font-weight: bold;
  218. margin-bottom: 34rpx;
  219. }
  220. &-list {
  221. justify-content: flex-start;
  222. flex-wrap: wrap;
  223. &-item {
  224. padding: 20rpx 66rpx;
  225. border-radius: 36rpx;
  226. margin-right: 18rpx;
  227. background: #F5F6F8;
  228. margin-bottom: 34rpx;
  229. }
  230. .action {
  231. background-color: rgba(250, 130, 44, .25);
  232. color: #FA822C;
  233. }
  234. }
  235. }
  236. // 数量
  237. .quantity {
  238. justify-content: space-between;
  239. margin: 34rpx 0;
  240. &-title {
  241. font-size: 30rpx;
  242. line-height: 30rpx;
  243. font-weight: bold;
  244. }
  245. }
  246. // 按钮
  247. .btn {
  248. justify-content: space-between;
  249. padding-top: 36rpx;
  250. border-top: 1px solid #eee;
  251. &-left {
  252. .coin {
  253. display: flex;
  254. align-items: center;
  255. font-size: 26rpx;
  256. line-height: 30rpx;
  257. color: #FA822C;
  258. image {
  259. width: 34rpx;
  260. height: 30rpx;
  261. }
  262. }
  263. }
  264. &-right {
  265. .confirm {
  266. width: 414rpx;
  267. height: 88rpx;
  268. line-height: 88rpx;
  269. background: #FA822C;
  270. border-radius: 44rpx;
  271. font-size: 36rpx;
  272. color: #fff;
  273. text-align: center;
  274. }
  275. }
  276. }
  277. }
  278. </style>