purchase-popup.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 {.image-goods {
  168. width: 154rpx;
  169. height: 154rpx;
  170. border-radius: 18rpx;
  171. border: 1px solid #EEEEEE;
  172. margin-right: 24rpx;
  173. }
  174. height: 154rpx;
  175. flex-direction: column;
  176. align-items: flex-start;
  177. justify-content: space-between;
  178. padding: 34rpx 0;
  179. &__title {
  180. font-size: 30rpx;
  181. line-height: 30rpx;
  182. font-weight: bold;
  183. }
  184. &__price {
  185. color: #F42D4E;
  186. font-size: 26rpx;
  187. }
  188. }
  189. }
  190. &-right {
  191. color: #666;
  192. }
  193. }
  194. // sku
  195. .sku {
  196. &-title {
  197. font-size: 30rpx;
  198. line-height: 30rpx;
  199. font-weight: bold;
  200. margin-bottom: 34rpx;
  201. }
  202. &-list {
  203. justify-content: flex-start;
  204. flex-wrap: wrap;
  205. &-item {
  206. padding: 20rpx 66rpx;
  207. border-radius: 36rpx;
  208. margin-right: 18rpx;
  209. background: #F5F6F8;
  210. margin-bottom: 34rpx;
  211. }
  212. .action {
  213. background-color: rgba(250, 130, 44, .25);
  214. color: #FA822C;
  215. }
  216. }
  217. }
  218. // 数量
  219. .quantity {
  220. justify-content: space-between;
  221. margin: 34rpx 0;
  222. &-title {
  223. font-size: 30rpx;
  224. line-height: 30rpx;
  225. font-weight: bold;
  226. }
  227. }
  228. // 按钮
  229. .btn {
  230. justify-content: space-between;
  231. padding-top: 36rpx;
  232. border-top: 1px solid #eee;
  233. &-left {
  234. .price {
  235. font-size: 26rpx;
  236. color: #F42D4E;
  237. }
  238. }
  239. &-right {
  240. .confirm {
  241. width: 414rpx;
  242. height: 88rpx;
  243. line-height: 88rpx;
  244. background: #FA362C;
  245. border-radius: 44rpx;
  246. font-size: 36rpx;
  247. color: #fff;
  248. text-align: center;
  249. }
  250. }
  251. }
  252. }
  253. </style>