Spec.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <view :class="Visible ? 'product-popup open' : 'product-popup close'" @touchmove.stop.prevent="" @click="closePopup">
  3. <view class="popup-bg"></view>
  4. <view class="main" v-on:click.stop>
  5. <view class="header">
  6. <image :src="form.show_sku.sku_image" mode="aspectFit" class="avt"></image>
  7. <view class="price d-s-c">
  8. <text class="f24">所需积分</text>
  9. <text class="num fb f34">{{ form.show_sku.point_num }}</text>
  10. <text>+</text>
  11. <text class="old-price">¥{{ form.show_sku.point_money }}</text>
  12. </view>
  13. <view class="stock">库存:{{ form.show_sku.point_stock }}</view>
  14. <view class="p-20-0 select_spec">{{ selectSpec }}</view>
  15. <view class="close-btn" @click="closePopup"><text class="icon iconfont icon-jiantoushang"></text></view>
  16. </view>
  17. <view class="body">
  18. <!--规格-->
  19. <view>
  20. <scroll-view scroll-y="true" class="specs mt20" style="max-height: 600rpx;" v-if="form.specData !=null">
  21. <view class="specs mt20" v-for="(item_attr,attr_index) in form.specData.spec_attr" :key="attr_index">
  22. <view class="specs-hd p-20-0">
  23. <text class="f24 gray9">{{item_attr.group_name}}</text>
  24. <text class="ml10 red" v-if="form.productSpecArr[attr_index]==null">
  25. 请选择{{item_attr.group_name}}
  26. </text>
  27. </view>
  28. <view class="specs-list">
  29. <button :class="item.checked ? 'btn-checked' : 'btn-checke'" v-for="(item,item_index) in item_attr.spec_items"
  30. :key="item_index" @click="selectAttr(attr_index, item_index)">{{item.spec_value}}
  31. </button>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. <!--选择数量-->
  37. <view class="level-box count_choose">
  38. <text class="key">数量</text>
  39. <view class="d-s-c">
  40. <view class="icon-box minus d-c-c" @click="sub()" :class="{ 'num-wrap': !issub }"><text class="icon iconfont icon-jian"
  41. style="font-size: 20rpx;color: #333333;"></text></view>
  42. <view class="text-wrap"><input type="text" v-model="form.show_sku.sum" value="" /></view>
  43. <view class="icon-box plus d-c-c" :class="{ 'num-wrap': !isadd }" @click="add()"><text class="icon iconfont icon-jia"
  44. style="font-size: 20rpx;color: #333333;"></text></view>
  45. </view>
  46. </view>
  47. </view>
  48. <view class="btns white"><button class="confirm-btn" @click="confirmFunc(form)">确认</button></view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. judgeSelect
  55. } from '@/common/specSelect.js';
  56. export default {
  57. data() {
  58. return {
  59. /*是否可见*/
  60. Visible: false,
  61. form: {
  62. detail: {
  63. product_sku: {},
  64. show_sku: {},
  65. show_point_sku: {
  66. point_price: 0
  67. }
  68. },
  69. show_sku: {
  70. sum: 1
  71. }
  72. },
  73. /*当前商品总库存*/
  74. stock: 0,
  75. /*选择提示*/
  76. selectSpec: '',
  77. /*规格是否选择完整*/
  78. isAll: false,
  79. /*是否改变*/
  80. is_change: false
  81. };
  82. },
  83. props: ['isPopup', 'productModel'],
  84. onLoad() {},
  85. mounted() {},
  86. computed: {
  87. /*判断增加数量*/
  88. isadd: function() {
  89. return this.form.show_sku.sum >= this.stock || this.form.show_sku.sum >= this.form.detail.limit_num;
  90. },
  91. /*判断减少数量*/
  92. issub: function() {
  93. return this.form.show_sku.sum <= 1;
  94. }
  95. },
  96. watch: {
  97. 'isPopup': function(n, o) {
  98. if (n != o) {
  99. this.Visible = n;
  100. if (!this.isOpenSpec) {
  101. this.form = this.productModel;
  102. this.isOpenSpec = true;
  103. this.initShowSku();
  104. this.form.specData.spec_attr.forEach((item,index)=>{
  105. this.selectAttr(index,0);
  106. })
  107. }
  108. this.form.type = this.productModel.type;
  109. console.log(this.productModel)
  110. }
  111. },
  112. 'form.specData': {
  113. handler(n, o) {
  114. let str = '',
  115. select = '';
  116. this.isAll = true;
  117. if (n) {
  118. for (let i = 0; i < n.spec_attr.length; i++) {
  119. if (this.form.productSpecArr[i] == null) {
  120. this.isAll = false;
  121. str += n.spec_attr[i].group_name + ' ';
  122. } else {
  123. n.spec_attr[i].spec_items.forEach(item => {
  124. if (this.form.productSpecArr[i] == item.item_id) {
  125. select += '\"' + item.spec_value + '\" ';
  126. }
  127. });
  128. }
  129. }
  130. if (!this.isAll) {
  131. str = '请选择: ' + str;
  132. } else {
  133. select = '已选: ' + select;
  134. }
  135. }
  136. this.selectSpec = this.isAll ? select : str;
  137. },
  138. deep: true,
  139. immediate: true
  140. }
  141. },
  142. methods: {
  143. /*关闭弹窗*/
  144. closePopup() {
  145. this.$emit('close', this.form.specData, null);
  146. },
  147. /*确认提交*/
  148. confirmFunc() {
  149. if (this.form.specData != null && !this.isAll) {
  150. uni.showToast({
  151. title: '请选择规格',
  152. icon: 'none',
  153. duration: 2000
  154. });
  155. return;
  156. }
  157. this.createdOrder();
  158. },
  159. /*初始化*/
  160. initShowSku() {
  161. this.form.show_sku.sku_image = this.form.detail.product.image[0].file_path;
  162. this.form.show_sku.point_price = this.form.detail.point_price;
  163. this.form.show_sku.product_sku_id = 0;
  164. this.form.show_sku.line_price = this.form.detail.line_price;
  165. this.form.show_sku.point_stock = this.form.detail.stock;
  166. this.form.show_sku.point_product_sku_id = 0;
  167. this.form.show_sku.point_num = this.form.detail.sku[0].point_num;
  168. this.form.show_sku.point_money = this.form.detail.sku[0].point_money;
  169. this.form.show_sku.product_sku_id = 0;
  170. this.stock = this.form.detail.stock;
  171. },
  172. /*选择属性*/
  173. selectAttr(attr_index, item_index) {
  174. let self = this;
  175. let items = self.form.specData.spec_attr[attr_index].spec_items;
  176. let curItem = items[item_index];
  177. if (curItem.checked) {
  178. curItem.checked = false;
  179. self.form.productSpecArr[attr_index] = null;
  180. } else {
  181. for (let i = 0; i < items.length; i++) {
  182. items[i].checked = false;
  183. }
  184. curItem.checked = true;
  185. self.form.productSpecArr[attr_index] = curItem.item_id;
  186. }
  187. /*判断哪些规格可以选*/
  188. judgeSelect(self.form.specData.spec_attr, attr_index, self.form.productSpecArr, self.form.productSku);
  189. let isall = true;
  190. for (let i = 0; i < self.form.productSpecArr.length; i++) {
  191. let item = self.form.productSpecArr[i];
  192. if (item == null) {
  193. isall = false;
  194. self.initShowSku();
  195. return;
  196. }
  197. }
  198. if (!isall) {
  199. self.initShowSku();
  200. return;
  201. }
  202. // 更新商品规格信息
  203. self.updateSpecProduct();
  204. },
  205. /*更新商品规格信息*/
  206. updateSpecProduct() {
  207. let self = this;
  208. let specSkuId = self.form.productSpecArr.join('_');
  209. // 查找skuItem
  210. let spec_list = self.form.specData.spec_list,
  211. skuItem = spec_list.find(val => {
  212. return val.spec_sku_id == specSkuId;
  213. });
  214. // 记录product_sku_id
  215. // 更新商品价格、划线价、库存
  216. if (typeof skuItem === 'object') {
  217. let point_sku_list = self.form.detail.sku,
  218. pointSkuItem = point_sku_list.find(val => {
  219. return val.product_sku_id == skuItem.product_sku_id;
  220. });
  221. console.log(pointSkuItem);
  222. /*保存当前规格*/
  223. self.stock = pointSkuItem.point_stock;
  224. if (self.form.show_sku.sum > self.stock) {
  225. self.form.show_sku.sum = self.stock > 0 ? self.stock : 1;
  226. }
  227. self.form.show_sku.line_price = skuItem.spec_form.product_price;
  228. self.form.show_sku.product_sku_id = skuItem.spec_sku_id;
  229. self.form.show_sku.point_price = pointSkuItem.point_price;
  230. self.form.show_sku.point_product_sku_id = pointSkuItem.point_product_sku_id;
  231. self.form.show_sku.point_stock = pointSkuItem.point_stock;
  232. if (skuItem.spec_form.image_id > 0) {
  233. self.form.show_sku.sku_image = skuItem.spec_form.image_path;
  234. } else {
  235. self.form.show_sku.sku_image = self.form.detail.product.image[0].file_path;
  236. }
  237. }
  238. },
  239. /*创建订单*/
  240. createdOrder() {
  241. let self = this;
  242. let point_product_id = self.form.detail.point_product_id;
  243. let num = self.form.show_sku.sum;
  244. let product_sku_id = self.form.show_sku.product_sku_id;
  245. let point_product_sku_id = self.form.show_sku.point_product_sku_id;
  246. self.gotoPage('/pages/order/confirm-order?product_num=' +
  247. num +
  248. '&point_product_id=' +
  249. point_product_id +
  250. '&product_sku_id=' +
  251. product_sku_id +
  252. '&point_product_sku_id=' +
  253. point_product_sku_id +
  254. '&order_type=points');
  255. },
  256. /*商品增加*/
  257. add() {
  258. if (this.stock <= 0) {
  259. return;
  260. }
  261. if (this.form.show_sku.sum >= this.stock) {
  262. uni.showToast({
  263. title: '数量超过了库存',
  264. icon: 'none',
  265. duration: 2000
  266. });
  267. return false;
  268. }
  269. if (this.form.show_sku.sum >= this.form.detail.limit_num) {
  270. uni.showToast({
  271. title: '数量超过了限购数量',
  272. icon: 'none',
  273. duration: 2000
  274. });
  275. return false;
  276. }
  277. this.form.show_sku.sum++;
  278. },
  279. /*商品减少*/
  280. sub() {
  281. if (this.stock <= 0) {
  282. return;
  283. }
  284. if (this.form.show_sku.sum < 2) {
  285. uni.showToast({
  286. title: '商品数量至少为1',
  287. icon: 'none',
  288. duration: 2000
  289. });
  290. return false;
  291. }
  292. this.form.show_sku.sum--;
  293. }
  294. }
  295. };
  296. </script>
  297. <style lang="scss">
  298. .product-popup {}
  299. .product-popup .popup-bg {
  300. position: fixed;
  301. top: 0;
  302. right: 0;
  303. bottom: 0;
  304. left: 0;
  305. background: rgba(0, 0, 0, .6);
  306. z-index: 99;
  307. }
  308. .product-popup .main {
  309. position: fixed;
  310. width: 100%;
  311. bottom: 0;
  312. min-height: 200rpx;
  313. // max-height: 900rpx;
  314. background-color: #fff;
  315. transform: translate3d(0, 980rpx, 0);
  316. transition: transform .2s cubic-bezier(0, 0, .25, 1);
  317. border-radius: 12rpx;
  318. //bottom: env(safe-area-inset-bottom);
  319. z-index: 99;
  320. }
  321. .product-popup.open .main {
  322. transform: translate3d(0, 0, 0);
  323. z-index: 99;
  324. }
  325. .product-popup.close .popup-bg {
  326. display: none;
  327. }
  328. .product-popup.close .main {
  329. display: none;
  330. z-index: -1;
  331. }
  332. .product-popup .header {
  333. min-height: 120rpx;
  334. padding: 40rpx 0 40rpx 250rpx;
  335. position: relative;
  336. border-bottom: 1px solid #eeeeee;
  337. }
  338. .product-popup .header .avt {
  339. position: absolute;
  340. top: 40rpx;
  341. left: 30rpx;
  342. width: 200rpx;
  343. height: 200rpx;
  344. border: 2px solid #ffffff;
  345. background: #ffffff;
  346. border-radius: 12rpx;
  347. }
  348. .product-popup .header .stock {
  349. font-size: 26rpx;
  350. color: #999999;
  351. }
  352. .product-popup .close-btn {
  353. position: absolute;
  354. width: 40rpx;
  355. height: 40rpx;
  356. top: 40rpx;
  357. right: 30rpx;
  358. }
  359. .product-popup .price {
  360. height: 80rpx;
  361. color: $dominant-color;
  362. font-size: 30rpx;
  363. }
  364. .product-popup .price .num {
  365. padding: 0 4rpx;
  366. font-size: 50rpx;
  367. }
  368. .product-popup .old-price {
  369. margin-left: 10rpx;
  370. font-size: 30rpx;
  371. color: #999999;
  372. }
  373. .product-popup .body {
  374. padding: 20rpx 30rpx 39rpx 30rpx;
  375. // max-height: 600rpx;
  376. overflow-y: auto;
  377. }
  378. .product-popup .level-box {
  379. display: flex;
  380. justify-content: space-between;
  381. align-items: center;
  382. }
  383. .product-popup .level-box .key {
  384. font-size: 24rpx;
  385. color: #999999;
  386. }
  387. .product-popup .level-box .icon-box {
  388. width: 48rpx;
  389. height: 40rpx;
  390. background: #e0e0e0;
  391. }
  392. .product-popup .num-wrap .iconfont {
  393. color: #666;
  394. }
  395. .product-popup .num-wrap.no-stock .iconfont {
  396. color: #cccccc;
  397. }
  398. .product-popup .level-box .text-wrap {
  399. margin: 0 4rpx;
  400. height: 60rpx;
  401. border: none;
  402. background: #ffffff;
  403. }
  404. .product-popup .level-box .text-wrap input {
  405. padding: 0 10rpx;
  406. height: 60rpx;
  407. line-height: 60rpx;
  408. width: 80rpx;
  409. text-align: center;
  410. font-size: 32rpx;
  411. }
  412. .specs .specs-list {
  413. display: flex;
  414. justify-content: flex-start;
  415. align-items: center;
  416. flex-wrap: wrap;
  417. }
  418. .specs .specs-list button {
  419. margin-right: 10rpx;
  420. margin-bottom: 10rpx;
  421. font-size: 24rpx;
  422. }
  423. .specs .specs-list button:after,
  424. .product-popup .btns button,
  425. .product-popup .btns button:after {
  426. border: 0;
  427. margin-bottom: 55rpx;
  428. border-radius: 0;
  429. }
  430. .product-popup .btns .confirm-btn {
  431. width: 710rpx;
  432. height: 80rpx;
  433. background: linear-gradient(90deg, #FF6B6B 4%, #F6220C 100%);
  434. border-radius: 40rpx;
  435. margin: 0 auto;
  436. margin-bottom: 55rpx;
  437. background-color: #FFFFFF;
  438. color: #FFFFFF;
  439. line-height: 80rpx;
  440. font-size: 32rpx;
  441. }
  442. .btn-checked {
  443. border: 1px solid #F6220C;
  444. border-radius: 6px;
  445. color: #F6220C;
  446. font-size: 26rpx;
  447. background-color: #FFFFFF;
  448. }
  449. .btn-checke {
  450. border: 1rpx solid #D9D9D9;
  451. border-radius: 6rpx;
  452. font-size: 26rpx;
  453. color: #333333;
  454. background-color: #FFFFFF;
  455. }
  456. </style>