purchase-popup.vue 6.2 KB

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