index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. <template>
  2. <view v-if="isShowPop">
  3. <view class="mask" @tap="hidePopup"></view>
  4. <view class="popup">
  5. <view class="close" @tap="hidePopup"><image class="image" src="/static/pages/images/close.png"></image></view>
  6. <view class="popinfo dflex">
  7. <image class="image" :src="skuPic + '?x-oss-process=style/w160'" v-if="skuPic" @click="previewSkuPic()"></image>
  8. <image class="image" :src="product.pic + '?x-oss-process=style/w160'" v-else @click="previewSkuPic()"></image>
  9. <view class="flex">
  10. <view class="title">{{ product.title }}</view>
  11. <view class="price" v-if="orderType == 991">
  12. <text v-if="productPrice">{{productPrice}}</text>
  13. <text v-else>{{product.minSalePrice}}<block v-if="product.maxSalePrice>product.minSalePrice">-{{product.maxSalePrice}}</block></text>
  14. <!-- <text class="origin"
  15. v-if="product.salePrice == product.actualPrice && product.marketPrice > 0">¥{{product.marketPrice}}</text> -->
  16. </view>
  17. <block v-else>
  18. <view class="price" v-if="product.mode != 2">
  19. <text>{{ show_membership_price == 1 && product.actualPrice < product.salePrice ? product.actualPrice : product.salePrice }}</text>
  20. <!-- <text class="origin"
  21. v-if="product.salePrice == product.actualPrice && product.marketPrice > 0">¥{{product.marketPrice}}</text> -->
  22. </view>
  23. <view class="price dflex" v-if="product.mode == 2">
  24. <text>{{ product.integral }}积分</text>
  25. <text class="money">+¥{{ product.actualPrice }}</text>
  26. <text class="origin" v-if="product.salePrice == product.actualPrice && product.marketPrice > 0">¥{{ product.marketPrice }}</text>
  27. </view>
  28. </block>
  29. </view>
  30. </view>
  31. <view class="pop-cons">
  32. <view class="sku-con" v-if="orderType == 991">
  33. <view class="tits">套餐</view>
  34. <view class="pguige dflex">
  35. <view :class="'li tover ' + (it.active ? 'active' : '')" @tap="checkSku(it, ind)" v-for="(it, ind) in priceList" :key="ind">{{ it.title }}</view>
  36. </view>
  37. </view>
  38. <!-- sku参数 -->
  39. <view class="sku-con" v-for="(item, index) in skuParam" :key="index" v-else>
  40. <view class="tits">{{ item.name }}</view>
  41. <view class="pguige dflex">
  42. <view :class="'li tover ' + (it.active ? 'active' : '')" @tap="chooseSku(index, ind)" v-for="(it, ind) in item.params" :key="ind">{{ it.name }}</view>
  43. </view>
  44. </view>
  45. <!-- <block v-if="skuList&& skuList.length > 0">
  46. <view class="tits">规格</view>
  47. <view class="pguige dflex">
  48. <view v-for="(item, index) in skuList" :key="index" :class="'li ' + (item.active ? 'active' : '')"
  49. @tap="chooseSku" :data-index="index" :data-ind="ind">{{item.skuStr}}</view>
  50. </view>
  51. </block> -->
  52. <view class="shuliang dflex">
  53. <view class="tits">
  54. 数量
  55. <text>库存{{ stock }}件</text>
  56. </view>
  57. <view class="num" v-if="stock > 0">
  58. <view class="jian" @tap="jianQuantity">-</view>
  59. <!-- <text class="nums">{{initNum}}</text> -->
  60. <input class="nums" :value="initNum" type="number" @input="getNum" @blur="minNum" />
  61. <view class="jian" @tap="jiaQuantity">+</view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="pro-p-btn dflex">
  66. <view :class="'pro-buy fflex ' + (product.quantity > 0 ? 'mbglinear' : 'mbglinear-gray')" @click="buyNow()" v-if="orderType == 991">马上抢</view>
  67. <block v-else>
  68. <view :class="stock > 0 ? 'pro-add' : 'pro-addgray'" @click="addCart()">加入购物车</view>
  69. <view :class="'pro-buy ' + (stock > 0 ? 'mbglinear' : 'mbglinear-gray')" @click="directBuy()">{{ product.isOtc == 1 ? '预约下单' : '立即购买' }}</view>
  70. </block>
  71. </view>
  72. <!-- <view class="confirm mbglinear" @tap="confirmBuy">确定</view> -->
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. const req = require('../../utils/request');
  78. const utils = require('../../utils/util');
  79. import h5util from "../../utils/h5util";
  80. export default {
  81. data() {
  82. return {
  83. isShowPop: false,
  84. skuList: [],
  85. skuParam: [],
  86. params: [],
  87. //规格参数List数据
  88. initNum: 1,
  89. show_membership_price: 0,
  90. stock: 0,
  91. skuPic: '',//当前sku图片
  92. skuPicList: [],//sku图片列表
  93. skuIndex: 0,
  94. productPrice: 0,
  95. priceList: [],
  96. mergeProduct: {}
  97. };
  98. },
  99. components: {},
  100. props: {
  101. actId: String, //产品id
  102. activityId: Number, //活动id
  103. product: Object, //产品
  104. maxBuy: Number, //最大购买量
  105. orderType: {
  106. //订单类型
  107. type: Number,
  108. default: 1
  109. },
  110. isCart: {
  111. //是否加入购物车
  112. type: Boolean,
  113. default: false
  114. },
  115. isTimely: {
  116. //是否及时达
  117. type: Number,
  118. default: 0
  119. },
  120. merchant: Object, //门店
  121. merchantId: String, //门店id
  122. index: String, //荣康判断
  123. shopId: String ,//小店id
  124. isDai: {
  125. //是否是代客下单
  126. type: Boolean,
  127. default: false
  128. }
  129. },
  130. options: {
  131. addGlobalClass: true
  132. },
  133. // created(){
  134. // console.log(this.data.merchant)
  135. // req.getRequest('/api/merchant/getMerchantList',{}, res => {
  136. // res = res.filter(it=>it.isDefault==1)
  137. // this.setData({merchant:res[0]})
  138. // })
  139. // },
  140. mounted() {
  141. console.log('merchantId==',this.merchantId)
  142. if(this.orderType != 991){
  143. this.getMerchant();
  144. }else{
  145. this.isShowPop = true;
  146. this.priceList = this.product.priceList;
  147. this.productPrice = this.priceList[0].salePrice;
  148. this.priceList[0].active = true;
  149. this.mergeProduct = this.priceList[0];
  150. this.stock = this.product.quantity;
  151. }
  152. this.getConfig();
  153. },
  154. methods: {
  155. loadSkuParams(from) {
  156. let _ts = this;
  157. return new Promise((resolve, reject) => {
  158. req.getRequest(
  159. '/api/product/skuParam',
  160. from,
  161. data => {
  162. if (data && data.length > 0) {
  163. let arr = [];
  164. _ts.skuParam = data.map(it => {
  165. it.params.map(its => {
  166. let par = {
  167. name: its,
  168. active: false,
  169. };
  170. arr.push(par);
  171. });
  172. // let stock = _ts.stock;
  173. // console.log('stock==' + stock);
  174. // if (stock > 0) {
  175. // if (_ts.product.properties) {
  176. // let propertiesList = _ts.product.properties.split(' / ');
  177. // propertiesList.map(pit => {
  178. // arr.map(its => {
  179. // if (its.name == pit) {
  180. // console.log('its.name==' + its.name+'>>>>>>pit=='+pit);
  181. // its.active = true;
  182. // }
  183. // return its;
  184. // });
  185. // });
  186. // }
  187. // } else {
  188. //遍历出默认选中有库存的规格
  189. // let skuList = _ts.skuList;
  190. // for(var i=0;i<skuList.length;i++){
  191. // var skuit=skuList[i];
  192. // var properties = JSON.parse(skuit.properties);
  193. // for(var k=0;k<properties.length;k++){
  194. // var pit=properties[k];
  195. // for(var j=0;j<arr.length;j++){
  196. // var ait=arr[j];
  197. // if(_ts.stock==0&&skuit.stock > 0 && pit.value == ait.name){
  198. // arr[j].active=true;
  199. // _ts.stock = skuit.stock;
  200. // console.log(arr[j].name+'stock222==' + _ts.stock )
  201. // // return;
  202. // }
  203. // }
  204. // }
  205. // }
  206. // }
  207. // console.log('arr》》》》》',JSON.stringify(arr));
  208. // skuList.map(skuit=>{
  209. // console.log('skuit》》》》》',skuit.properties)
  210. // var properties = JSON.parse(skuit.properties);
  211. // properties.map(pit=>{
  212. // arr.some(ait => {
  213. // if(skuit.stock > 0 && pit.value == ait.name){
  214. // ait.active = true;
  215. // _ts.stock = skuit.stock;
  216. // console.log('stock222==' + _ts.stock )
  217. // }
  218. // return ait;
  219. // })
  220. // })
  221. // })
  222. console.log('arr》》》》》', JSON.stringify(arr));
  223. return {
  224. id: it.id,
  225. name: it.paramName,
  226. params: arr
  227. };
  228. });
  229. _ts.skuList.map(it=>{
  230. arr.map((arrIt,index)=>{
  231. let properties = JSON.parse(it.properties);
  232. properties.map(pit=>{
  233. if(arrIt.name===pit.value){
  234. _ts.skuPicList[index] = it.skuPic
  235. }
  236. })
  237. })
  238. })
  239. console.log('_ts.skuPicList==',_ts.skuPicList)
  240. //遍历出默认选中有库存的规格
  241. let skuList = _ts.skuList;
  242. for (var i = 0; i < skuList.length; i++) {
  243. var skuit = skuList[i];
  244. //如果有库存
  245. if (skuit.stock > 0) {
  246. var properties = JSON.parse(skuit.properties); //得到对应的sku组合对象
  247. for (var k = 0; k < properties.length; k++) {
  248. var pit = properties[k];
  249. for (var g = 0; g < _ts.skuParam.length; g++) {
  250. var skuArr = _ts.skuParam[g].params;
  251. for (var f = 0; f < skuArr.length; f++) {
  252. var ait = skuArr[f];
  253. if (pit.value == ait.name) {
  254. _ts.skuParam[g].params[f].active = true;
  255. }
  256. }
  257. }
  258. }
  259. _ts.stock = skuit.stock;
  260. this.setSkuData(skuit);
  261. return;
  262. }
  263. }
  264. // for (var j = 0; j < arr.length; j++) {
  265. // var ait = arr[j];
  266. // for (var i = 0; i < skuList.length; i++) {
  267. // var skuit = skuList[i];
  268. // var properties = JSON.parse(skuit.properties);
  269. // for (var k = 0; k < properties.length; k++) {
  270. // var pit = properties[k];
  271. // if (skuit.stock > 0 && pit.value == ait.name) {
  272. // arr[j].active = true;
  273. // _ts.stock = skuit.stock;
  274. // console.log(arr[j].name + 'stock222==' + _ts.stock);
  275. // return;
  276. // }
  277. // }
  278. // }
  279. // }
  280. }
  281. resolve();
  282. },
  283. true
  284. );
  285. });
  286. },
  287. analysisSku(propterties) {
  288. if (propterties === -1 || propterties === 'DEFAULT_SKU') return false;
  289. const ties = JSON.parse(propterties);
  290. this.setData({
  291. params: this.params.map(it => {
  292. let value = ties.filter(r => r.id === it.id)[0].value;
  293. it.active = it.nodes.indexOf(value);
  294. return it;
  295. })
  296. });
  297. },
  298. async getMerchant() {
  299. // await this.loadSkuParams();
  300. let _ts = this;
  301. let from = {
  302. id: this.product.id
  303. };
  304. if (!this.merchantId && this.index != 'index') {
  305. // console.log(222);
  306. from.merchantId = this.merchantId;
  307. } else {
  308. from.merchantId = this.merchantId;
  309. } // }
  310. await this.loadProductSku(from);
  311. await this.loadSkuParams(from);
  312. },
  313. loadProductSku(from) {
  314. let _ts = this;
  315. // console.log(from);
  316. if (this.actId) {
  317. from.actId = this.actId;
  318. }
  319. uni.showLoading({
  320. title: '加载中'
  321. })
  322. return new Promise((resolve, reject) => {
  323. req.getRequest(
  324. '/api/product/sku',
  325. from,
  326. res => {
  327. // console.log("sku数据===" + JSON.stringify(res));
  328. let data = {}; //将规格数据抽离出来;
  329. if (res && res.length > 0) {
  330. // if (res[0].properties === -1 || res[0].properties === 'DEFAULT_SKU') {
  331. // } else {
  332. res.forEach(it => {
  333. if (it.properties === -1 || it.properties === 'DEFAULT_SKU') {
  334. } else {
  335. it.skuStr = JSON.parse(it.properties)
  336. .map(ij => ij.value.replace(' ', ''))
  337. .join(' ');
  338. it.active = false;
  339. }
  340. });
  341. res[0].active = true;
  342. _ts.skuIndex = 0
  343. _ts.skuPic = res[0].skuPic;
  344. data.skuList = res;
  345. // }
  346. }else{
  347. if (_ts.product) {
  348. _ts.stock = _ts.product.stock;
  349. }
  350. }
  351. data['product.marketPrice'] = res[0].marketPrice;
  352. data['activityId'] = res[0].apId;
  353. data.sku = res[0]; //当是活动时销售价格统一
  354. // if (!_ts.data.activityId) data['product.salePrice'] = res[0].salePrice;
  355. // console.log(!_ts.activityId);
  356. // console.log('sku价格数据>>>>>==' + JSON.stringify(data.skuList));
  357. _ts.setData(data); // _ts.analysisSku(res[0].properties);
  358. data.skuList.map(it => {
  359. if (it.skuId === _ts.product.skuId) {
  360. _ts.stock = it.stock;
  361. // console.log('skuStock==' + _ts.stock);
  362. }
  363. });
  364. this.isShowPop = true;
  365. uni.hideLoading();
  366. resolve();
  367. },
  368. true
  369. );
  370. });
  371. },
  372. getConfig() {
  373. var _this = this;
  374. return new Promise((resolve, reject) => {
  375. req.getRequest('/api/config', {}, function(res) {
  376. if (res && res.show_membership_price == 1) {
  377. _this.setData({
  378. show_membership_price: 1
  379. });
  380. }
  381. resolve();
  382. });
  383. });
  384. },
  385. // chooseSku(event) {
  386. // const index = event.currentTarget.dataset.index;
  387. // this.skuList.forEach(it => {
  388. // it.active = false;
  389. // });
  390. // this.skuList[index].active = true;
  391. // let data = {};
  392. // data.skuList = this.skuList;
  393. // const filters = this.skuList[index]; // if (filters && filters.length > 0) {
  394. // data.sku = filters;
  395. // // this.product.skuId=filters.skuId
  396. // data['product.skuId'] = filters.skuId
  397. // data['product.marketPrice'] = filters.marketPrice;
  398. // data['product.actualPrice'] = filters.actualPrice
  399. // // this.product.marketPrice=filters.marketPrice
  400. // this.activityId = filters.apId
  401. // data['product.actId'] = filters.apId
  402. // data['product.salePrice'] = filters.salePrice;
  403. // this.setData(data); // }
  404. // this.$emit('getPor', {
  405. // detail: this.product
  406. // });
  407. // // console.log(this.product, filters.marketPrice, filters.salePrice, filters.actualPrice, filters)
  408. // },
  409. getChooseParams: function() {
  410. var data = [];
  411. this.skuParam.forEach(sku => {
  412. sku.params.forEach(sk => {
  413. if (sk.active) {
  414. var params = {
  415. id: sku.id,
  416. name: sk.name,
  417. skuPic: sk.skuPic
  418. };
  419. if (
  420. !data.some(dt => {
  421. return dt.id === sku.id;
  422. })
  423. ) {
  424. data.push(params);
  425. } else {
  426. const chooseIndex = data.findIndex(dt => dt.id === sku.id);
  427. data[chooseIndex] = params;
  428. }
  429. }
  430. });
  431. });
  432. return data;
  433. },
  434. chooseSku(index, ind) {
  435. console.log('index==' + index);
  436. console.log('ind==' + ind);
  437. this.skuParam[index].params.map((it, idx) => {
  438. it.active = false;
  439. return it;
  440. });
  441. this.skuParam[index].params[ind].active = true;
  442. const data = this.getChooseParams();
  443. console.log('data==' + JSON.stringify(data));
  444. const filters = this.skuList.filter(it => {
  445. if (it.properties == -1 || it.properties == 'DEFAULT_SKU') {
  446. } else {
  447. var properties = JSON.parse(it.properties);
  448. if (properties.length == data.length) {
  449. return (
  450. properties.filter(pro => {
  451. return data.some(ds => {
  452. return ds.id == pro.id && ds.name == pro.value;
  453. });
  454. }).length == data.length
  455. );
  456. }
  457. }
  458. return false;
  459. });
  460. console.log('filters==', filters);
  461. this.skuIndex = ind;
  462. if (filters && filters.length > 0) {
  463. let sku = filters[0];
  464. this.sku = sku;
  465. console.log('sku==' + JSON.stringify(sku));
  466. console.log('sku.stock==' + JSON.stringify(sku.stock));
  467. this.stock = sku.stock;
  468. this.skuPic = sku.skuPic;
  469. if (sku.stock === 0) return req.msg('库存不足');
  470. this.setSkuData(sku);
  471. } else {
  472. this.stock = 0;
  473. req.msg('库存不足');
  474. }
  475. },
  476. checkSku(item, index){
  477. this.productPrice = item.salePrice;
  478. this.mergeProduct = item;
  479. this.priceList.map((it, idx) => {
  480. it.active = false;
  481. return it;
  482. });
  483. this.priceList[index].active = true;
  484. },
  485. setSkuData(sku) {
  486. let params = {};
  487. params['product.marketPrice'] = sku.marketPrice;
  488. params['product.actualPrice'] = sku.actualPrice;
  489. if (!this.activityId) {
  490. params['product.salePrice'] = sku.salePrice;
  491. }
  492. params['product.properties'] = JSON.parse(sku.properties)
  493. .map(pro => {
  494. return pro.value;
  495. })
  496. .join(' / ');
  497. params['product.skuId'] = sku.skuId;
  498. if(this.activityId) params['product.actId'] = this.activityId
  499. this.setData(params);
  500. this.$emit('getPor', {
  501. detail: this.product
  502. });
  503. },
  504. hidePopup() {
  505. // this.$emit('hidePopup', {
  506. // detail: this
  507. // });
  508. this.$emit('hidePopup');
  509. },
  510. jianQuantity() {
  511. const quantity = parseInt(this.initNum) - 1;
  512. this.setData({
  513. initNum: quantity < 1 ? 1 : quantity
  514. });
  515. },
  516. jiaQuantity() {
  517. const quantity = parseInt(this.initNum) + 1;
  518. if (this.product.maxBuy > 0) {
  519. if (quantity > this.product.maxBuy) {
  520. return req.msg('非常的抱歉,本产品最多可购买' + this.product.maxBuy);
  521. }
  522. if (quantity > this.stock) {
  523. return req.msg('非常的抱歉,本产品最多可购买' + this.stock);
  524. }
  525. this.setData({
  526. initNum: quantity
  527. });
  528. } else {
  529. this.setData({
  530. initNum: quantity
  531. });
  532. }
  533. },
  534. // 获取输入的值
  535. getNum(e) {
  536. const quantity = parseInt(e.detail.value);
  537. // console.log(e.detail.value == '');
  538. if (this.product.maxBuy > 0) {
  539. // console.log(e.detail.value, quantity);
  540. if (quantity > this.product.maxBuy) {
  541. this.setData({
  542. initNum: this.product.maxBuy
  543. });
  544. return req.msg('非常的抱歉,本产品最多可购买' + this.product.maxBuy);
  545. }
  546. if (quantity > this.stock) {
  547. this.setData({
  548. initNum: this.stock
  549. });
  550. return req.msg('非常的抱歉,本产品最多可购买' + this.stock);
  551. }
  552. this.setData({
  553. initNum: e.detail.value
  554. });
  555. } else {
  556. if (quantity > this.stock) {
  557. this.setData({
  558. initNum: this.stock
  559. });
  560. return req.msg('非常的抱歉,本产品最多可购买' + this.stock);
  561. }
  562. this.setData({
  563. initNum: e.detail.value
  564. });
  565. }
  566. },
  567. // 失去焦点
  568. minNum(e) {
  569. // console.log(this.product);
  570. // console.log(e.detail.value == '');
  571. if (e.detail.value == '') {
  572. this.setData({
  573. initNum: 1
  574. });
  575. } else {
  576. this.setData({
  577. initNum: e.detail.value
  578. });
  579. }
  580. },
  581. getParams() {
  582. //加入购物车
  583. let _ts = this;
  584. //直接购买
  585. // let merchant = req.getStorage('MERCHANT');
  586. console.log('this.product==',this.product);
  587. if (this.product.payQuantity) {
  588. if (this.product.stock - this.product.payQuantity < 1) return req.msg('产品已售罄,平台正在紧急补货中...');
  589. if (this.product.stock - this.product.payQuantity < this.initNum)
  590. return req.msg('购买数量超出剩余库存' + (this.product.stock - this.product.payQuantity) + ',请重新选择');
  591. } else {
  592. if (this.initNum > this.product.stock) return req.msg('非常的抱歉,本产品库存量剩余' + this.product.stock);
  593. } // console.log(merchant)
  594. const params = {
  595. skuId: this.product.skuId,
  596. quantity: this.initNum,
  597. productId: this.product.id
  598. };
  599. if (this.product.isOtc == 5) {
  600. this.setData({
  601. orderType: 10
  602. });
  603. } // if(this.data.merchant&&this.data.merchant.type==2&&this.data.merchantId!=''){
  604. // params.merchantId=this.data.merchant.merchantDTO.id
  605. // params.shopId=this.data.merchant.id
  606. // }else{
  607. // params.merchantId=this.data.merchant.id
  608. // }
  609. if(this.merchantId){
  610. params.merchantId = this.merchantId;
  611. }else{
  612. if (!this.merchant) {
  613. } else {
  614. if (this.merchant.type == 5) {
  615. (params.shopId = this.merchant.id), (params.merchantId = this.merchant.merchantDTO.id);
  616. } else {
  617. params.merchantId = this.merchant.id;
  618. }
  619. }
  620. }
  621. if (this.activityId) params.activityId = this.activityId;
  622. if(this.isDai){//添加人类型:1 C端用户自己,2 代客下单类型
  623. params.addType = 2;
  624. } else delete params.addType;
  625. return params;
  626. },
  627. async addCart() {
  628. let _ts = this;
  629. if(_ts.initNum == 0) return req.msg('请输入商品数量');
  630. if (_ts.stock === 0) return req.msg('库存不足');
  631. let params = _ts.getParams();
  632. // console.log(this.merchantId, params.merchantId);
  633. params.orderType = _ts.orderType;
  634. let isShowLoading = false;
  635. if (!isShowLoading) {
  636. req.loadIng('加载中');
  637. isShowLoading = true;
  638. }
  639. // console.log(params);
  640. let quantity = await new Promise((r,j)=>{
  641. req.postRequest('/api/purchase/cart', params, res => {
  642. if (isShowLoading) {
  643. uni.hideLoading();
  644. isShowLoading = false;
  645. req.msg('加入购物车成功', () => {
  646. r(params.quantity)
  647. });
  648. }else{
  649. r(0)
  650. }
  651. });
  652. })
  653. _ts.$emit('addCartSuccess', {
  654. detail: {
  655. quantity: quantity
  656. }
  657. });
  658. this.$emit('hidePopup');
  659. // this.$emit('hidePopup', {
  660. // detail: this
  661. // });
  662. },
  663. directBuy() {
  664. let _ts = this;
  665. if(_ts.initNum == 0) return req.msg('请输入商品数量');
  666. if (_ts.stock === 0) return req.msg('库存不足');
  667. let params = _ts.getParams();
  668. // console.log(this.merchantId, params.merchantId);
  669. if (req.getStorage('configRes')) {
  670. let config = JSON.parse(req.getStorage('configRes')); // JSON.parse(req.getStorage('configRes'))
  671. if (config.Min_Order_Money) {
  672. if (parseFloat(config.Min_Order_Money - (this.show_membership_price == 1 ? this.product.actualPrice : this.product.salePrice) * this.initNum).toFixed(2) > 0)
  673. return req.msg('最小下单金额为' + config.Min_Order_Money + '元');
  674. }
  675. }
  676. let isShowLoading = false;
  677. if (!isShowLoading) {
  678. req.loadIng('加载中');
  679. isShowLoading = true;
  680. }
  681. req.postRequest('/api/purchase/direct/buy', params, res => {
  682. let redirect;
  683. if(this.isDai){//代客下单
  684. redirect = '/valet/subOrder/subOrder?ids=' + res;
  685. }else{
  686. redirect = '/product/subOrder/subOrder?ids=' + res;
  687. }
  688. // let redirect = '/product/subOrder/subOrder?ids=' + res;
  689. let orderType = this.orderType;
  690. // console.log(orderType); // if (orderType === 1 && this.data.isTimely === 1) orderType = 5;
  691. redirect += '&orderType=' + orderType;
  692. if (!this.merchantId) {
  693. redirect += '&merchantId=' + this.merchant.id;
  694. } else {
  695. redirect += '&merchantId=' + this.merchantId;
  696. }
  697. if (!this.activityId) {
  698. } else {
  699. redirect += '&activityId=' + this.activityId;
  700. }
  701. if (!this.shopId) {
  702. } else {
  703. redirect += '&shopId=' + this.shopId;
  704. }
  705. if (isShowLoading) {
  706. uni.hideLoading();
  707. isShowLoading = false;
  708. }
  709. // h5util.jumpUrlExternal({url:redirect})
  710. uni.navigateTo({
  711. url: redirect
  712. });
  713. });
  714. this.$emit('hidePopup');
  715. // this.$emit('hidePopup', {
  716. // detail: this
  717. // });
  718. },
  719. buyNow() {
  720. let _ts = this;
  721. if(_ts.initNum == 0) return req.msg('请输入商品数量');
  722. if (_ts.stock === 0) return req.msg('库存不足');
  723. if (req.getStorage('configRes')) {
  724. let config = JSON.parse(req.getStorage('configRes')); // JSON.parse(req.getStorage('configRes'))
  725. if (config.Min_Order_Money) {
  726. if (parseFloat(config.Min_Order_Money - this.productPrice * this.initNum).toFixed(2) > 0)
  727. return req.msg('最小下单金额为' + config.Min_Order_Money + '元');
  728. }
  729. }
  730. this.$emit('hidePopup');
  731. req.removeStorage('mergeProduct');
  732. req.setStorage('mergeProduct',this.mergeProduct);
  733. // h5util.jumpUrlExternal({url:'/product/subMerge/subOrder?mergeQuantity=' + _ts.initNum + '&id=' + this.product.id})
  734. uni.navigateTo({
  735. url: '/product/subMerge/subOrder?mergeQuantity=' + _ts.initNum + '&id=' + this.product.id
  736. })
  737. // this.$emit('hidePopup', {
  738. // detail: this
  739. // });
  740. },
  741. confirmBuy() {
  742. //直接购买
  743. // let merchant = req.getStorage('MERCHANT');
  744. // console.log(this.product);
  745. if (this.product.payQuantity) {
  746. if (this.product.stock - this.product.payQuantity < 1) return req.msg('产品已售罄,平台正在紧急补货中...');
  747. if (this.product.stock - this.product.payQuantity < this.initNum)
  748. return req.msg('购买数量超出剩余库存' + (this.product.stock - this.product.payQuantity) + ',请重新选择');
  749. } else {
  750. if (this.initNum > this.product.stock) return req.msg('非常的抱歉,本产品库存量剩余' + this.product.stock);
  751. } // console.log(merchant)
  752. console.log('this.product==',this.product);
  753. const params = {
  754. skuId: this.product.skuId,
  755. quantity: this.initNum,
  756. productId: this.product.id
  757. };
  758. if (this.product.isOtc == 5) {
  759. this.setData({
  760. orderType: 10
  761. });
  762. } // if(this.data.merchant&&this.data.merchant.type==2&&this.data.merchantId!=''){
  763. // params.merchantId=this.data.merchant.merchantDTO.id
  764. // params.shopId=this.data.merchant.id
  765. // }else{
  766. // params.merchantId=this.data.merchant.id
  767. // }
  768. if (!this.merchant) {
  769. } else {
  770. if (this.merchant.type == 5) {
  771. (params.shopId = this.merchant.id), (params.merchantId = this.merchant.merchantDTO.id);
  772. } else {
  773. params.merchantId = this.merchant.id;
  774. }
  775. }
  776. if (this.activityId) params.activityId = this.activityId;
  777. // console.log(this.merchantId, params.merchantId);
  778. if (this.isCart) {
  779. //加入购物车
  780. let _ts = this;
  781. params.orderType = this.orderType;
  782. console.log('this.isDai==',this.isDai)
  783. if(this.isDai){//添加人类型:1 C端用户自己,2 代客下单类型
  784. params.addType = 2;
  785. } else delete params.addType;
  786. let isShowLoading = false;
  787. if (!isShowLoading) {
  788. req.loadIng('加载中');
  789. isShowLoading = true;
  790. }
  791. // console.log(params);
  792. req.postRequest('/api/purchase/cart', params, res => {
  793. if (isShowLoading) {
  794. uni.hideLoading();
  795. isShowLoading = false;
  796. req.msg('加入购物车成功', () => {
  797. _ts.$emit('addCartSuccess', {
  798. detail: {
  799. quantity: params.quantity
  800. }
  801. });
  802. });
  803. }
  804. });
  805. } else {
  806. if (req.getStorage('configRes')) {
  807. let config = JSON.parse(req.getStorage('configRes')); // JSON.parse(req.getStorage('configRes'))
  808. if (config.Min_Order_Money) {
  809. if (
  810. parseFloat(config.Min_Order_Money - (this.show_membership_price == 1 ? this.product.actualPrice : this.product.salePrice) * this.initNum).toFixed(2) > 0
  811. )
  812. return req.msg('最小下单金额为' + config.Min_Order_Money + '元');
  813. }
  814. }
  815. let isShowLoading = false;
  816. if (!isShowLoading) {
  817. req.loadIng('加载中');
  818. isShowLoading = true;
  819. }
  820. req.postRequest('/api/purchase/direct/buy', params, res => {
  821. let redirect = '/product/subOrder/subOrder?ids=' + res;
  822. let orderType = this.orderType;
  823. // console.log(orderType); // if (orderType === 1 && this.data.isTimely === 1) orderType = 5;
  824. redirect += '&orderType=' + orderType;
  825. if (!this.merchantId) {
  826. } else {
  827. redirect += '&merchantId=' + this.merchantId;
  828. }
  829. if (!this.activityId) {
  830. } else {
  831. redirect += '&activityId=' + this.activityId;
  832. }
  833. if (!this.shopId) {
  834. } else {
  835. redirect += '&shopId=' + this.shopId;
  836. }
  837. if (isShowLoading) {
  838. uni.hideLoading();
  839. isShowLoading = false;
  840. }
  841. // h5util.jumpUrlExternal({url:redirect})
  842. uni.navigateTo({
  843. url: redirect
  844. });
  845. });
  846. }
  847. this.$emit('hidePopup', {
  848. detail: this
  849. });
  850. },
  851. previewSkuPic(){
  852. let that = this;
  853. let arr = []
  854. if(this.skuPic){
  855. arr = this.skuPicList;
  856. }else{
  857. arr[0] = this.product.pic
  858. }
  859. uni.previewImage({
  860. current: this.skuIndex, //当前为第几张
  861. urls: arr,
  862. complete() {
  863. that.$emit('freshen', this);
  864. }
  865. // indicator: 'number',
  866. // loop: true
  867. });
  868. }
  869. }
  870. };
  871. </script>
  872. <style>
  873. @import './index.css';
  874. </style>