goods-select-sku.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <u-popup v-model="show" mask mode="bottom" mask-close-able closeable border-radius="16" safe-area-inset-bottom>
  3. <view class="info">
  4. <view class="pic"><u-image :src="data.cover" width="190rpx" height="190rpx"></u-image></view>
  5. <view class="desc">
  6. <view class="price">
  7. <text>¥</text>
  8. <text>{{ selectdSku.price_selling }}</text>
  9. </view>
  10. <view class="select">
  11. <text>已选</text>
  12. <text>{{ selectdSku.difference }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="sku">
  17. <view class="title">规格</view>
  18. <view class="list">
  19. <view class="item" :class="{ 'select': item.id == selectdSku.id,'disable':(item.stock_total<=0||Number(item.price_selling)<=0)}" v-for="(item, index) in data.sku" :key="index" @click="selectSkuFun(index)">
  20. {{ item.difference }}
  21. <span class="price">(优惠价:&yen;{{item.price_selling}})</span>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="num">
  26. <view class="title">数量</view>
  27. <!-- :disabled-input="true" -->
  28. <!-- {{selectdSku.stock_total}} -->
  29. <u-number-box v-model="num" :min="1" :max="maxBuy" @change="changeNum"></u-number-box>
  30. </view>
  31. <view class="operate">
  32. <view class="soldOutBtn btn shu-elip-1" v-if="selectdSku.stock_total<=0||Number(data.price_selling)<=0">已售罄</view>
  33. <template v-else>
  34. <view class="joinCartBtn btn shu-elip-1" @click="addCartHandle">加入购物车</view>
  35. <view class="buyBtn btn shu-elip-1" @click="bugNowHandle">立即购买</view>
  36. </template>
  37. </view>
  38. </u-popup>
  39. </template>
  40. <script>
  41. export default {
  42. props:{
  43. expressInfo: {
  44. type: Object,
  45. default: ()=>{
  46. return {max_buy_nums:-1}
  47. }
  48. }
  49. },
  50. computed:{
  51. maxBuy(){
  52. if(this.expressInfo.max_buy_nums==-1 || this.expressInfo.max_buy_nums>Number(this.selectdSku.stock_total)){
  53. return Number(this.selectdSku.stock_total)
  54. }else{
  55. return this.expressInfo.max_buy_nums;
  56. }
  57. }
  58. },
  59. data() {
  60. return {
  61. show: false,
  62. // 数据源
  63. data: {},
  64. // 数量
  65. num: 1,
  66. selectdSkuIndex:0,
  67. selectdSku:{
  68. id:'',
  69. difference:'',
  70. price_selling:null,
  71. stock_total:0,
  72. },
  73. };
  74. },
  75. methods: {
  76. // 打开popup
  77. open(data, index) {
  78. console.log(333);
  79. this.show = true;
  80. this.data = data;
  81. // this.selectSkuFun();
  82. // this.selectdSku = selectSku;
  83. },
  84. initSkuFun(data){
  85. this.data = data;
  86. // 默认
  87. this.selectdSkuIndex = this.data.sku[1]?1:0;
  88. if(this.data.sku[this.selectdSkuIndex].stock_total<=0&&this.data.sku.findIndex(e=>e.stock_total>0)>-1){
  89. this.selectdSkuIndex = this.data.sku.findIndex(e=>e.stock_total>0);
  90. }
  91. this.selectSkuFun(this.selectdSkuIndex);
  92. },
  93. // 切换sku
  94. selectSkuFun(index) {
  95. console.log(index);
  96. // if(this.data.sku[selI].stock_total<0||Number(this.data.sku[selI].price_selling)<=0){
  97. // return false;
  98. // }
  99. this.selectdSkuIndex = index;
  100. this.selectdSku = this.data.sku[index];
  101. this.$emit('change', this.selectdSku);
  102. },
  103. // 数量改变时
  104. changeNum(e) {},
  105. // 关闭
  106. close() {},
  107. // 加入购物车
  108. addCartHandle() {
  109. // uni.showToast({
  110. // title: '添加购物车成功',
  111. // icon: 'none'
  112. // });
  113. this.$u.api.addCartAjax({
  114. goods_id:this.data.id,
  115. nums: this.num,
  116. sku_id:this.selectdSku.id,//1是测试,应该传入skuId,外层没有返回,需要接口返回一下
  117. }).then(({code})=>{
  118. if(code==1){
  119. this.$u.toast('添加购物车成功');
  120. this.show = false;
  121. // setTimeout(()=>{
  122. // this.show = false;
  123. // },800)
  124. }
  125. })
  126. },
  127. // 立即购买
  128. bugNowHandle() {
  129. const token = uni.getStorageSync('token');
  130. if(!token){
  131. uni.navigateTo({
  132. url:'/pages/login/index'
  133. })
  134. return false;
  135. }
  136. // 数组形式,兼容多商品同时购买
  137. let orderInfo = [
  138. {
  139. id: this.data.id,
  140. cover: this.data.cover,
  141. isbn:this.data.isbn,
  142. price_selling:this.data.price_selling,
  143. publish:this.data.publish,
  144. title:this.data.title,
  145. nums:this.num,
  146. selectdSku:this.selectdSku,
  147. }
  148. ]
  149. // return;
  150. // expresstemplate:this.data.expresstemplate
  151. uni.navigateTo({
  152. url: '/pages-mall/pages/order/submit?orderInfo='+encodeURIComponent(JSON.stringify(orderInfo))
  153. });
  154. }
  155. }
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. .info {
  160. padding: 30rpx 30rpx 0 30rpx;
  161. display: flex;
  162. align-items: flex-end;
  163. .pic {
  164. margin-right: 30rpx;
  165. }
  166. .desc {
  167. .price {
  168. margin-bottom: 20rpx;
  169. text:nth-child(1) {
  170. font-size: 24rpx;
  171. color: $app-theme-text-money-color;
  172. vertical-align: bottom;
  173. }
  174. text:nth-child(2) {
  175. font-size: 36rpx;
  176. color: $app-theme-text-money-color;
  177. vertical-align: bottom;
  178. }
  179. }
  180. .select {
  181. text:nth-child(1) {
  182. font-size: 24rpx;
  183. color: $app-theme-card-gray-deep-color;
  184. margin-right: 20rpx;
  185. }
  186. text:nth-child(2) {
  187. font-size: 24rpx;
  188. color: $app-theme-text-black-color;
  189. }
  190. }
  191. }
  192. }
  193. .sku {
  194. padding: 30rpx 30rpx 0 30rpx;
  195. .title {
  196. font-size: 28rpx;
  197. color: $app-theme-text-black-color;
  198. margin-bottom: 16rpx;
  199. }
  200. .list {
  201. // display: flex;
  202. // justify-content: flex-start;
  203. // align-items: center;
  204. // flex-wrap: wrap;
  205. .item {
  206. height: 80rpx;
  207. padding: 0 30rpx;
  208. margin-bottom: 24rpx;
  209. // margin-right: 20rpx;
  210. // background-color: $app-theme-sku-gray-color;
  211. font-size: 28rpx;
  212. // color: $app-theme-text-black-color;
  213. border: 1rpx solid #eee;
  214. color: $app-theme-color;
  215. display: flex;
  216. justify-content: space-between;
  217. align-items: center;
  218. border-radius: 10rpx;
  219. &.select {
  220. // color: $app-theme-color;
  221. font-weight: bold;
  222. border: 1rpx solid $app-theme-color;
  223. }
  224. &.disable{
  225. color: #ddd;
  226. }
  227. }
  228. }
  229. }
  230. .num {
  231. padding: 30rpx;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. .title {
  236. font-size: 28rpx;
  237. color: $app-theme-text-black-color;
  238. }
  239. }
  240. .operate {
  241. display: flex;
  242. align-items: center;
  243. height: 100rpx;
  244. padding-left: 20rpx;
  245. /* /deep/button {
  246. height: 100rpx;
  247. line-height: 100rpx;
  248. border-radius: 0 !important;
  249. &::after {
  250. border: initial;
  251. }
  252. } */
  253. // .btn {
  254. // min-width: 220rpx;
  255. // line-height: 66rpx;
  256. // padding: 0 30rpx;
  257. // border-radius: 36rpx;
  258. // color: #ffffff;
  259. // margin-right: 20rpx;
  260. // text-align: center;
  261. // flex: 1;
  262. // padding: 0 30rpx;
  263. // }
  264. // .soldOutBtn{
  265. // background-color: $app-theme-nobuy-bg-color;
  266. // }
  267. // .joinCartBtn {
  268. // background-color: $app-theme-joincart-bg-color;
  269. // }
  270. // .buyBtn {
  271. // background-color: $app-theme-buybtn-bg-color;
  272. // }
  273. }
  274. </style>