purchase-popup.vue 5.8 KB

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