exchange-popup.vue 6.6 KB

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