purchase-popup.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // num: this.orderNum,
  118. // resource:'PAYMENT',
  119. // }
  120. // console.log(data);
  121. if (flag) return
  122. if (this.payInfo.quantity == 0) {
  123. uni.$u.toast('库存不足');
  124. return
  125. }
  126. if (this.payInfo.quantity < this.orderNum) {
  127. uni.$u.toast('库存不足');
  128. return
  129. }
  130. uni.showLoading({
  131. title: '购买中'
  132. });
  133. flag = true
  134. uni.hideLoading();
  135. uni.navigateTo({
  136. url: `/packageGoods/order/settlement?goodsId=${ this.payInfo.goodsId }&skuId=${ this.payInfo.skuId?this.payInfo.skuId:0 }&num=${ this.orderNum }`
  137. })
  138. },
  139. close() {
  140. this.$emit('close')
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .choiceShow-wrap {
  147. min-height: 400rpx;
  148. padding: 34rpx;
  149. // 商品
  150. .goods {
  151. justify-content: space-between;
  152. margin-bottom: 66rpx;
  153. &-left {
  154. flex: 1;
  155. display: flex;
  156. &__image {
  157. width: 154rpx;
  158. height: 154rpx;
  159. border: 1px solid #EEEEEE;
  160. border-radius: 18rpx;
  161. margin-right: 24rpx;
  162. .image-goods {
  163. width: 154rpx;
  164. height: 154rpx;
  165. }
  166. }
  167. &-content {
  168. height: 154rpx;
  169. flex-direction: column;
  170. align-items: flex-start;
  171. justify-content: space-between;
  172. padding: 34rpx 0;
  173. .image-goods {
  174. width: 154rpx;
  175. height: 154rpx;
  176. border-radius: 18rpx;
  177. border: 1px solid #EEEEEE;
  178. margin-right: 24rpx;
  179. }
  180. &__title {
  181. height: 30rpx;
  182. overflow: hidden;
  183. font-size: 30rpx;
  184. line-height: 30rpx;
  185. font-weight: bold;
  186. }
  187. &__price {
  188. color: #F42D4E;
  189. font-size: 26rpx;
  190. }
  191. }
  192. }
  193. &-right {
  194. color: #666;
  195. }
  196. }
  197. // sku
  198. .sku {
  199. &-title {
  200. font-size: 30rpx;
  201. line-height: 30rpx;
  202. font-weight: bold;
  203. margin-bottom: 34rpx;
  204. }
  205. &-list {
  206. justify-content: flex-start;
  207. flex-wrap: wrap;
  208. &-item {
  209. padding: 20rpx 66rpx;
  210. border-radius: 36rpx;
  211. margin-right: 18rpx;
  212. background: #F5F6F8;
  213. margin-bottom: 34rpx;
  214. }
  215. .action {
  216. background-color: rgba(250, 130, 44, .25);
  217. color: #FA822C;
  218. }
  219. }
  220. }
  221. // 数量
  222. .quantity {
  223. justify-content: space-between;
  224. margin: 34rpx 0;
  225. &-title {
  226. font-size: 30rpx;
  227. line-height: 30rpx;
  228. font-weight: bold;
  229. }
  230. }
  231. // 按钮
  232. .btn {
  233. justify-content: space-between;
  234. padding-top: 36rpx;
  235. border-top: 1px solid #eee;
  236. &-left {
  237. .price {
  238. font-size: 26rpx;
  239. color: #F42D4E;
  240. }
  241. }
  242. &-right {
  243. .confirm {
  244. width: 414rpx;
  245. height: 88rpx;
  246. line-height: 88rpx;
  247. background: #FA362C;
  248. border-radius: 44rpx;
  249. font-size: 36rpx;
  250. color: #fff;
  251. text-align: center;
  252. }
  253. }
  254. }
  255. }
  256. </style>