index.vue 23 KB

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