detail.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. var productDetail = new Vue({
  2. el: "#productDetail",
  3. mixins: [beautyArchiveDetailMixin,cmSysVitaMixins],
  4. data: {
  5. showProduct: false,
  6. productId: 0,
  7. typeId:0,
  8. userId: 0,
  9. identity:0,
  10. number: 0,
  11. productStock: 0,
  12. pcActType: 0,
  13. images: [],
  14. priceObj: {
  15. actStatus: 0,
  16. ladderPriceFlag: 0,
  17. minBuyNumber: 1,
  18. price: 0,
  19. costPrice: 0,
  20. priceFlag: 3,
  21. productId: 0,
  22. promotions: '',
  23. step: 1,
  24. supplierId: 0,
  25. userIdentity: 0 //2-会员机构;3-供应商;4-普通机构
  26. },
  27. product:{},// 商品信息
  28. ladderList: [],//阶梯价
  29. promotions: {},//促销活动信息
  30. promotionsId: 0,//活动id
  31. addStatus: true,
  32. recommendType: 0,//相关推荐类型 0自动选择; 1手动推荐
  33. recommendPage: 1,
  34. recommends: [],
  35. parameters: [],
  36. tabsIndex: 0,
  37. disabledText: '',
  38. isNoneDisabled: false,
  39. isServiceInfo: false,
  40. isTrainingMethod: false,
  41. isQualificationImg: false,
  42. productTypeName: "",
  43. beautyActFlag: '',
  44. trainingMethodText: '',
  45. trainingType: '',
  46. isShowPopup: false,
  47. currentTab: 1,
  48. listQuery:{
  49. source:1,
  50. userId:0,
  51. productId:0,
  52. pageNum:1,
  53. pageSize:30,
  54. },
  55. couponParam: {// 获取弹窗优惠券领取参数
  56. userId: 0,
  57. productId: 0,
  58. status: 1,
  59. source: 1
  60. },
  61. isCouponEmpty: false,
  62. isProductChecked:false,
  63. productCoupon: [], // 优惠券
  64. productCouponList: [], // 优惠券弹窗列表
  65. collectionType:false, // 商品收藏状态
  66. supportingList:[],
  67. productDetailChose:2,
  68. defaultSupportingList:[],
  69. isShowSupportingList:false,
  70. isShowMoreButton:false,
  71. totalPrice:0, // 勾选配套商品总价格
  72. totalNumber:0, // 勾选配套商品总数量
  73. isShowCaimeiShop:false,
  74. isHideButton:false
  75. },
  76. filters: {
  77. TypeFormat: function (value) {
  78. switch (value) {
  79. case 0:
  80. return '活动券';
  81. break;
  82. case 1:
  83. return '品类券';
  84. break;
  85. case 2:
  86. return '用户专享券';
  87. break;
  88. case 3:
  89. return '店铺券';
  90. break;
  91. case 4:
  92. return '新用户券';
  93. break;
  94. }
  95. },
  96. NumFormat:function(value) {
  97. return Number(value).toFixed(2);
  98. }
  99. },
  100. methods: {
  101. // 是否显示vip标签价格
  102. showVipPriceTag: function(product){
  103. return (product.priceFlag !== 1 && product.svipProductFlag === 1 && ((GLOBAL_USER_IDENTITY === 4 && GLOBAL_VIP_FLAG === 1) || GLOBAL_USER_IDENTITY === 2));
  104. },
  105. PromotionsFormat:function(promo){//促销活动类型数据处理
  106. if(promo!=null){
  107. if(promo.type == 1 && promo.mode == 1){
  108. return true
  109. }else{
  110. return false
  111. }
  112. }
  113. return false
  114. },
  115. getCommodityCombinationList: function () {// 获取收藏商品列表
  116. var _self = this;
  117. ProductApi.getCommodityCombinationList(_self.listQuery,function (response) {
  118. if (response.code === 0 ) {
  119. var data = response.data;
  120. if(data.results.length > 0 ){
  121. var list = data.results.map((el,index)=>{
  122. el.isChecked = false;
  123. el.number = el.minBuyNumber;
  124. return el;
  125. });
  126. _self.supportingList = list;
  127. _self.defaultSupportingList = _self.supportingList.slice(0,5);
  128. if(_self.supportingList.length > 5 ){
  129. _self.isShowMoreButton = true;
  130. }
  131. }else{
  132. _self.supportingList = [];
  133. }
  134. }else {
  135. CAIMEI.Alert(response.msg, '确定');
  136. }
  137. });
  138. },
  139. // getImages: function () {
  140. // var _self = this;
  141. // if (!this.productId) {
  142. // return;
  143. // }
  144. // ProductApi.GetProductDdtailsImages({productId: _self.productId}, function (response) {
  145. // if (response.code === 0 && response.data) {
  146. // _self.images = response.data;
  147. // setTimeout(function () {
  148. // if (isPC) {
  149. // var magnifier = new ImageMagnifier(
  150. // '#imgShown .smallImage li',
  151. // '#imgShown .bigImage',
  152. // '#imgShown .zoomImage',
  153. // '#imgShown .mask',
  154. // '#imgShown .zoom',
  155. // "on"
  156. // ).init();
  157. // } else {
  158. // var swiper = new Swiper('#swiperImage', {
  159. // loop: true,
  160. // autoplay: {
  161. // delay: 2000,
  162. // disableOnInteraction: false
  163. // },
  164. // pagination: {
  165. // el: '.swiper-pagination',
  166. // type: 'fraction'
  167. // }
  168. // });
  169. // }
  170. // }, 500);
  171. // }
  172. // });
  173. // },
  174. getProductDetails: function () {
  175. var _self = this;
  176. ProductApi.GetProductDdtails({userId: GLOBAL_USER_ID, productId: _self.productId,typeId:_self.typeId}, function (response) {
  177. if (response.code == 0) {
  178. var product = response.data;
  179. var $pageLabel = '';
  180. _self.product = response.data;
  181. _self.pcActType = product.pcActType;
  182. _self.beautyActFlag = product.beautyActFlag;
  183. _self.productTypeName = product.typeName;
  184. _self.recommendType = product.recommendType ? product.recommendType : 0;
  185. _self.archiveId = product.archiveId; // 保存资料列表id
  186. _self.productDetailChose = product.productDetailChose; // 同资质机构显示商品详情
  187. if(product.tinyTypeName){
  188. $pageLabel = product.tinyTypeName
  189. }else if(!product.tinyTypeName && product.smallTypeName){
  190. $pageLabel = product.smallTypeName
  191. }else{
  192. $pageLabel = product.bigTypeName
  193. }
  194. _self.cmSysParams.pageLabel = `${$pageLabel}-${product.brandName?product.brandName:''}`;//设置统计数据标签
  195. if(product.shopType == 2){
  196. _self.isShowCaimeiShop = true
  197. }
  198. if (product.userLike && product.userLike == 1) {// 商品收藏
  199. _self.collectionType = true
  200. } else {
  201. _self.collectionType = false
  202. }
  203. if (product.productDetail.orderInfo != '' && product.productDetail.serviceInfo != '') {
  204. _self.isServiceInfo = true;
  205. }
  206. if(product.qualificationImg){//商品资质
  207. _self.isQualificationImg = true
  208. }else{
  209. _self.isQualificationImg = false
  210. }
  211. if (product.commodityType == 2 && product.trainingMethod) {
  212. _self.isTrainingMethod = true;
  213. _self.trainingMethodText = product.trainingMethod == 1 ? '线上培训' : '线下培训';
  214. _self.trainingType = product.trainingType == 1 ? '¥' + product.trainingFee : '售价已包含';
  215. }
  216. if (product.validFlag == 3 || product.validFlag == 9 || product.validFlag == 0 || product.validFlag == 10 || product.stock == 0) {
  217. _self.isNoneDisabled = true;
  218. } else {
  219. _self.isNoneDisabled = false;
  220. }
  221. if (product.validFlag == 3) {
  222. _self.disabledText = '下架'
  223. }
  224. if (product.validFlag == 10) {
  225. _self.disabledText = '停售'
  226. }
  227. if (product.validFlag == 9 || product.validFlag == 0) {
  228. _self.disabledText = '失效'
  229. }
  230. if (product.stock == 0 && product.validFlag != 3) {
  231. _self.disabledText = '售罄'
  232. }
  233. _self.handleShowProductType(product.commodityDetailsFlag);
  234. _self.getRecommends();
  235. _self.getProdcutArchiveDetails(); //获取资料列表
  236. // 获取路由hash标识,设置默认展开tab
  237. var str = CAIMEI.getUrlParam('open');
  238. if (str === 'caimei365' && _self.archiveId > 0) {
  239. _self.tabsIndex = 4;
  240. }
  241. } else {
  242. console.log('<===Error===>',response.msg)
  243. }
  244. })
  245. },
  246. handleShowProductType: function (flag = ''){
  247. // 根据商品详情可见度显示弹窗 flag 1.所有人可见 2.所有机构可见 3.仅会员机构可见 4.仅医美机构可见
  248. let showModal = false;
  249. const flagMap = {
  250. '2': true,
  251. '3': true,
  252. '4': true
  253. }
  254. const textMap = {
  255. '2': '该商品仅限已注册机构查看,请注册机构账户后继续查看。有采美账号的,请直接登录',
  256. '3': '该商品仅限资质机构查看,请注册资质机构后继续查看。有采美账号的,请直接登录。',
  257. '4': '该商品仅限医美类机构查看,请注册医美机构后继续查看。有采美账号的,请直接登录。',
  258. '34': '该商品仅限资质机构查看,请升级为资质机构后继续查看。',
  259. '44': '该商品仅限医美类机构查看,请升级为医美机构后继续查看。',
  260. '42': '该商品仅限医美类机构查看,您暂无权限。您可去机构资料页面查看机构类型。'
  261. }
  262. const code = flag === 4 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE !== 1 ? '42' : `${flag}${GLOBAL_USER_IDENTITY}`
  263. if (GLOBAL_USER_ID === 0) {
  264. showModal = flagMap[flag];
  265. this.showProsPopup(showModal,textMap[flag],'去注册/登录','/login.html')
  266. return
  267. }
  268. if(GLOBAL_VIP_FLAG === 1){ return; }
  269. if (flag === 3 && GLOBAL_USER_IDENTITY === 4) {
  270. showModal = true
  271. this.showProsPopup(showModal,textMap[code],'去升级','/user/setting/upgrade.html')
  272. return
  273. }
  274. if (flag === 4 && GLOBAL_USER_IDENTITY === 4) {
  275. showModal = true
  276. this.showProsPopup(showModal,textMap[code],'去升级','/user/setting/upgrade.html')
  277. return
  278. }
  279. if (flag === 4 && GLOBAL_USER_IDENTITY=== 2 && GLOBAL_CLUB_TYPE !== 1) {
  280. showModal = true
  281. this.showProsPopup(showModal,textMap[code],'去查看资料','/user/setting/information.html')
  282. return
  283. }
  284. },
  285. showProsPopup:function (showFlag,content,confitmBtnText,href) {// 商品详情限制弹窗
  286. if(showFlag){
  287. CAIMEI.Popup({
  288. content: `<div class="payAlert"><p>${content}</p></div>`,
  289. confitmBtnText: confitmBtnText,
  290. cancelBtnText: '关闭',
  291. closeIcon:false
  292. },function(){
  293. // 确定
  294. window.location.href = href;
  295. },function(){
  296. // 关闭
  297. if(window.history.length === 1){
  298. window.location.href="/index.html";
  299. window.close();
  300. }else{
  301. window.history.go(-1);
  302. }
  303. });
  304. }
  305. },
  306. getProductPrice: function () {//获取商品价格
  307. var _self = this;
  308. if (_self.productId === 0) {
  309. return;
  310. }
  311. ProductApi.GetProductDdtailsPrice({
  312. userId: GLOBAL_USER_ID,
  313. productId: _self.productId
  314. }, function (response) {
  315. if (response.code === 0 && response.data) {
  316. _self.priceObj = response.data;
  317. _self.number = response.data.minBuyNumber;
  318. if (response.data.ladderPriceFlag === 1) {
  319. _self.ladderPrice();
  320. }
  321. if (response.data.actStatus == 1) {
  322. _self.promotions = response.data.promotions;
  323. _self.promotionsId = response.data.promotions.id;
  324. }
  325. console.log('userIdentity',_self.priceObj.userIdentity)
  326. if(_self.userId === 0 || GLOBAL_USER_IDENTITY === 2 || GLOBAL_USER_IDENTITY === 4){
  327. _self.isShowSupportingList = true;
  328. }
  329. }
  330. });
  331. },
  332. ladderPrice: function () {//获取商品阶梯价格
  333. var _self = this;
  334. if (!this.productId) {
  335. return;
  336. }
  337. ProductApi.GetProductDdtailsLadderPrice({productId: _self.productId}, function (response) {
  338. if (response.code === 0 && response.data) {
  339. _self.ladderList = response.data;
  340. _self.numberResize();
  341. }
  342. });
  343. },
  344. // getParameters: function () {//获取商品参数
  345. // var _self = this;
  346. // if (!this.productId) {
  347. // return;
  348. // }
  349. // ProductApi.GetProductDdtailsParameter({productId: _self.productId}, function (response) {
  350. // if (response.code === 0 && response.data) {
  351. // _self.parameters = response.data;
  352. // console.log(_self.parameters)
  353. // }
  354. // });
  355. // },
  356. toggleThisLadder: function (event) {
  357. var el = event.currentTarget;
  358. if ($(el).hasClass("on")) {
  359. $(el).removeClass("on").siblings('.mFixed').hide();
  360. if (!isPC) {
  361. looseBody();
  362. }
  363. } else {
  364. $(el).addClass("on").siblings('.mFixed').show();
  365. if (!isPC) {
  366. fixedBody();
  367. }
  368. }
  369. },
  370. hideThisLadder: function (event) {
  371. var el = event.currentTarget;
  372. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  373. if (!isPC) {
  374. looseBody();
  375. }
  376. },
  377. numberSub: function () {
  378. this.number -= this.priceObj.step;
  379. this.numberResize();
  380. },
  381. numberAdd: function () {
  382. this.number += this.priceObj.step;
  383. this.numberResize();
  384. },
  385. numberChange: function () {
  386. this.number = Math.ceil(this.number / this.priceObj.step) * this.priceObj.step;
  387. this.numberResize();
  388. },
  389. numberResize: function () {
  390. var _self = this;
  391. if (this.number < this.priceObj.minBuyNumber) {
  392. this.number = this.priceObj.minBuyNumber;
  393. }
  394. if (this.number > this.productStock) {
  395. this.number = this.productStock;
  396. }
  397. if (this.priceObj.ladderPriceFlag) {
  398. this.ladderList.forEach(function (ladder) {
  399. if (_self.number >= ladder.buyNum) {
  400. _self.priceObj.price = ladder.buyPrice;
  401. }
  402. });
  403. }
  404. },
  405. handleCollection:function (){// 收藏操作
  406. var _self = this;
  407. console.log('_self.userId',_self.userId)
  408. if (_self.userId > 0) {
  409. ProductApi.getProductUserLike({userId: _self.userId, productId: _self.productId}, function (response) {
  410. if (response.code === 0 && response.data) {
  411. _self.collectionType = !_self.collectionType
  412. CAIMEI.dialog(response.data,false);
  413. } else {
  414. CAIMEI.Alert(response.msg, '确定', false);
  415. }
  416. });
  417. }else{
  418. _self.toLogin();
  419. }
  420. },
  421. toLogin: function () {
  422. setBeforeUrl();
  423. window.location.href = '/login.html';
  424. },
  425. toUpgrade: function () {
  426. setBeforeUrl();
  427. window.location.href = '/user/setting/upgrade.html';
  428. },
  429. addShopCart: function(){ //加入购物车
  430. var _self = this;
  431. if(_self.addStatus){
  432. _self.addStatus = false;
  433. ShoppingApi.ClubAddCart(
  434. {
  435. productCount:this.number,
  436. productId:this.productId,
  437. userId:this.userId,
  438. source:1
  439. },
  440. function (response){
  441. if(response.code == 0){
  442. _self.addStatus = true;
  443. $.confirm({
  444. useBootstrap: false,
  445. boxWidth: (isPC?'338px':'74.6vw'),
  446. title: false,
  447. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  448. closeIcon: true,
  449. animation: 'opacity',
  450. closeAnimation: 'opacity',
  451. animateFromElement: false,
  452. scrollToPreviousElement: false,
  453. buttons: {
  454. login: {
  455. text: '去结算',
  456. btnClass: 'btn-to-cart',
  457. action: function(){
  458. window.location.href = '/shopping/cart.html';
  459. }
  460. },
  461. close: {
  462. text: '继续购物',
  463. btnClass: 'btn-to-goon',
  464. action:function(){
  465. }
  466. }
  467. }
  468. });
  469. globalHead.getHeadCart(_self.userId);
  470. }else{
  471. CAIMEI.dialog('加入购物车失败!',true,function () {
  472. _self.addStatus = true;
  473. });
  474. }
  475. }
  476. )
  477. }
  478. },
  479. buyNowSubmit: function(){ // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  480. var _self = this;
  481. if(_self.productId && _self.number){
  482. window.location.href = '/shopping/confirm.html?type=2&productId='+_self.productId+'&count='+_self.number;
  483. }
  484. },
  485. getRecommends: function () {
  486. var _self = this;
  487. if (!this.productId) {
  488. return;
  489. }
  490. ProductApi.GetProductDdtailsRecommend(
  491. {
  492. productId: _self.productId,
  493. recommendType: _self.recommendType,
  494. userId: _self.userId
  495. },
  496. function (response) {
  497. if (response.code === 0 && response.data) {
  498. if (response.data.length > 0) {
  499. _self.recommends = response.data;
  500. _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
  501. setTimeout(function () {
  502. if (isPC) {
  503. $('#productRecommend').slide({
  504. mainCell: ".swiper-wrapper",
  505. titCell: ".swiper-pagination span",
  506. effect: "leftLoop",
  507. interTime: 3000,
  508. autoPlay: true,
  509. scroll: 7,
  510. vis: 7,
  511. trigger: "mouseover"
  512. });
  513. } else {
  514. var swiper = new Swiper('#productRecommend', {
  515. slidesPerView: 3,
  516. spaceBetween: 0,
  517. autoplay: {
  518. delay: 3000,
  519. disableOnInteraction: false
  520. },
  521. pagination: {
  522. el: '.swiper-pagination'
  523. }
  524. });
  525. }
  526. }, 500);
  527. }
  528. }
  529. });
  530. },
  531. queryProductDetilsCoupons: function() {// 初始化商品详情优惠券信息
  532. var _self = this;
  533. ProductApi.QueryProductDetilsCoupons(_self.couponParam, function (response) {
  534. if (response.code == 0) {
  535. var data = response.data;
  536. if (isPC) {
  537. _self.productCoupon = response.data.list.splice(0, 3);
  538. } else {
  539. _self.productCoupon = response.data.list.splice(0, 2);
  540. }
  541. } else {
  542. console.log('获取优惠券列表失败');
  543. }
  544. })
  545. },
  546. queryPopupCoupons: function () {// 获取弹窗优惠券列表
  547. var _self = this;
  548. ProductApi.QueryProductDetilsCoupons(_self.couponParam, function (response) {
  549. if (response.code == 0) {
  550. var data = response.data;
  551. if (data.couponList && data.couponList.length > 0) {
  552. _self.productCouponList = data.couponList;
  553. _self.isCouponEmpty = false;
  554. console.log('有优惠券')
  555. console.log(_self.productCouponList)
  556. } else {
  557. console.log('没有优惠券')
  558. _self.isCouponEmpty = true;
  559. }
  560. } else {
  561. console.log('获取优惠券列表失败')
  562. }
  563. })
  564. },
  565. toDeductCoupon:function (coupon) {// 点击购买按钮事件处理
  566. var _self = this;
  567. console.log(coupon)
  568. if(_self.listQuery.userId == 0){
  569. window.location.href='/login.html';
  570. }else{
  571. ProductApi.CreatePayCouponBeans({userId:_self.couponParam.userId, couponId:coupon.couponId, source:2}, function (response) {
  572. if(response.code == 0){
  573. CAIMEI.dialog('抵扣成功',true,function () {
  574. setTimeout(function(){
  575. _self.currentTab = 2;
  576. _self.couponParam.status = 2;
  577. _self.queryPopupCoupons();
  578. },200)
  579. });
  580. }else{
  581. CAIMEI.Alert(response.msg, '确定', false);
  582. }
  583. })
  584. }
  585. },
  586. receiveCoupon: function (coupon) {// 点击领取优惠券
  587. var _self = this;
  588. ProductApi.ReceiveCoupon({
  589. userId: _self.couponParam.userId,
  590. couponId: coupon.couponId,
  591. source: 2
  592. }, function (response) {
  593. if (response.code == 0) {
  594. _self.currentTab = 2;
  595. _self.couponParam.status = 2;
  596. _self.queryPopupCoupons();
  597. } else {
  598. CAIMEI.Alert(response.msg, '确定', false);
  599. }
  600. })
  601. },
  602. queryCouponTabs: function (value) {// 切换优惠券
  603. var _self = this;
  604. _self.currentTab = _self.couponParam.status = value;
  605. _self.queryPopupCoupons();
  606. },
  607. showPopup: function () {// 显示优惠券弹窗
  608. var _self = this;
  609. if (_self.userId > 0) {
  610. _self.productCouponList = [];
  611. _self.currentTab = 1;
  612. _self.couponParam.status = 1;
  613. _self.queryPopupCoupons();
  614. _self.isShowPopup = true;
  615. } else {
  616. window.location.href = '/login.html';
  617. }
  618. },
  619. hidePopup: function () {// 隐藏优惠券弹窗
  620. var _self = this;
  621. _self.isShowPopup = false;
  622. },
  623. detailsClicktab: function (index) {
  624. var _self = this;
  625. _self.tabsIndex = index;
  626. if (index !== 4) return;
  627. // 只有当前用户权限为0,并且未初始化时初始化图片预览
  628. if (_self.permission === 0) {
  629. setTimeout(function () {
  630. _self.initPreviewImage()
  631. })
  632. }
  633. },
  634. supportingNumberSub: function(pros){// 配套商品数量减减
  635. var _self = this;
  636. if (pros.number <= pros.minBuyNumber) {
  637. pros.number = pros.minBuyNumber
  638. return
  639. } else {
  640. if (pros.step === 2) {
  641. pros.number -= pros.minBuyNumber
  642. } else {
  643. pros.number--
  644. }
  645. }
  646. _self.numberChange(pros);
  647. },
  648. supportingNumberAdd: function(pros){ // 配套商品数量加加
  649. var _self = this;
  650. if (pros.step === 2) {
  651. pros.number += pros.minBuyNumber
  652. } else {
  653. pros.number++
  654. }
  655. _self.numberChange(pros);
  656. },
  657. supportingNumberChange: function(pros){ // 配套商品数量输入
  658. var _self = this;
  659. pros.number = Math.ceil(pros.number/pros.step)*pros.step;
  660. _self.numberChange(pros);
  661. },
  662. numberChange: function(pros){
  663. var _self = this;
  664. if(pros.ladderPriceFlag){
  665. pros.ladderPrices.forEach(function(ladder){
  666. if(pros.number>=ladder.buyNum){
  667. pros.price = ladder.buyPrice;
  668. pros.originalPrice = ladder.buyPrice;
  669. }
  670. });
  671. }
  672. // 计算价格
  673. _self.calculatetTtalPrice();
  674. },
  675. calculatetTtalPrice: function () { // 计算配套商品总价格
  676. var _self = this;
  677. var totalPrice = 0;
  678. var totalNumber = 0;
  679. _self.supportingList.forEach(function (pros) {
  680. if(pros.isChecked){
  681. pros.totalPrice = pros.number*pros.price;
  682. totalNumber+= pros.number
  683. }else{
  684. pros.totalPrice = 0;
  685. }
  686. totalPrice += pros.totalPrice;
  687. })
  688. _self.totalPrice = totalPrice;
  689. _self.totalNumber = totalNumber;
  690. },
  691. checkedSoperv:function (pros) {// 勾选配套商品
  692. console.log(pros)
  693. var _self = this;
  694. var goodsCheckedLength = 0;
  695. pros.isChecked = !pros.isChecked
  696. _self.supportingList.forEach(el => {
  697. if(el.isChecked) {
  698. goodsCheckedLength++;
  699. }
  700. })
  701. if(goodsCheckedLength>0){
  702. _self.isProductChecked = true
  703. }else{
  704. _self.isProductChecked = false
  705. }
  706. _self.calculatetTtalPrice();
  707. },
  708. handleSupportingSubmit:function (type) {
  709. var _self = this;
  710. if (_self.userId > 0) {
  711. switch (type) {
  712. case 'buy':
  713. console.log('立即购买')
  714. _self.toConfirmation()
  715. break
  716. case 'add':
  717. console.log('加入购物车')
  718. _self.getAddProductCart()
  719. break
  720. }
  721. } else {
  722. _self.toLogin();
  723. }
  724. },
  725. getAddProductCart:function () {
  726. //批量增加购物车成功和toast弹窗提示成功
  727. var _self = this;
  728. var checkedList = [];
  729. if(!_self.isProductChecked){
  730. CAIMEI.dialog('请先选择商品',false);
  731. return;
  732. }
  733. _self.supportingList.forEach((el)=>{
  734. if(el.isChecked){
  735. checkedList.push({ productId:el.productId , productCount: el.number });
  736. }
  737. })
  738. ShoppingApi.ShoppingAddCarts({userId:_self.listQuery.userId,productInfo:JSON.stringify(checkedList)},function(response){
  739. if(response.code === 0){
  740. globalHead.getHeadCart(_self.listQuery.userId);
  741. $.confirm({
  742. useBootstrap: false,
  743. boxWidth: (isPC?'338px':'74.6vw'),
  744. title: false,
  745. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  746. closeIcon: true,
  747. animation: 'opacity',
  748. closeAnimation: 'opacity',
  749. animateFromElement: false,
  750. scrollToPreviousElement: false,
  751. buttons: {
  752. login: {
  753. text: '去结算',
  754. btnClass: 'btn-to-cart',
  755. action: function(){
  756. window.location.href = '/shopping/cart.html';
  757. }
  758. },
  759. close: {
  760. text: '继续购物',
  761. btnClass: 'btn-to-goon'
  762. }
  763. }
  764. });
  765. } else {
  766. dialog("加入购物车失败!");
  767. }
  768. })
  769. },
  770. toConfirmation:function () {
  771. var _self = this;
  772. //跳转确认订单页面
  773. var checkedList = []
  774. if(!_self.isProductChecked){
  775. CAIMEI.dialog('请先选择商品',false);
  776. return;
  777. }
  778. _self.supportingList.forEach((el)=>{
  779. if(el.isChecked){
  780. checkedList.push({ id:el.productId , count: el.number })
  781. }
  782. })
  783. CAIMEI.Storage.setItem('KEY_SUPPORE', JSON.stringify(checkedList));
  784. window.location.href = '/shopping/confirm.html?type=3';
  785. },
  786. toBuyCoupon:function (coupon) {// 点击购买按钮事件处理
  787. var _self = this;
  788. ProductApi.createCouponRecord({userId:_self.listQuery.userId, couponId:coupon.couponId}, function (response) {
  789. if(response.code == 0){
  790. let couponRecordId = response.data.couponRecordId
  791. window.location.href = '/pay/caimei-hlbpay.html?pageType=3&couponId='+coupon.couponId+'&couponRecordId='+couponRecordId;
  792. }else{
  793. if(response.code == -1){//个人机构不能购买
  794. CAIMEI.Alert('该优惠券仅限医美机构购买,请升级为医美机构后再次购买。', '去升级', true, function(){
  795. window.location.href = "/user/setting/upgrade.html";
  796. });
  797. }else if(response.code == -2){//会员机构不是医美机构不能购买
  798. CAIMEI.dialog('该优惠券仅限医美机构购买',false,function () {});
  799. }else{
  800. CAIMEI.Alert(response.msg, '确定', false);
  801. }
  802. }
  803. })
  804. },
  805. showSupportingMore:function () {
  806. var _self = this;
  807. _self.isShowMoreButton = false;
  808. _self.defaultSupportingList = _self.supportingList;
  809. },
  810. // 是否显示vip标签价格
  811. showVipPriceTag: function(pros){
  812. //非会员
  813. if(!GLOBAL_VIP_FLAG === 1) return false;
  814. // 商品所有机构可见
  815. if(pros.priceFlag === 0 && pros.svipProductFlag === 1 ) return true;
  816. // 商品价格仅资质机构可见
  817. if(pros.priceFlag === 2 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2) return true;
  818. // 商品价格仅医美机构可见
  819. if(pros.priceFlag === 3 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE == 1) return true;
  820. // 其它
  821. return false;
  822. },
  823. },
  824. created: function () {
  825. this.productId = this.couponParam.productId = this.listQuery.productId = $("#productId").val();
  826. this.cmSysParams.pageType = 6;
  827. this.cmSysParams.productId = this.productId;
  828. this.typeId = $("#typeId").val();
  829. console.log('typeId', this.typeId)
  830. this.userId = this.couponParam.userId = this.listQuery.userId = GLOBAL_USER_ID;
  831. this.productStock = $("#productStock").val();
  832. // this.getImages();
  833. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  834. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见 4:仅医美机构可见
  835. // var visible = $("#productVisibility").val() * 1;
  836. // console.log('visible',visible)
  837. // var identity = GLOBAL_USER_IDENTITY;
  838. // console.log('identity',identity)
  839. // this.showProduct = visible === 3 || visible == 4 || identity === 1 || identity === 2 || (identity === 4 && visible === 2);
  840. // if (!this.showProduct) {
  841. // window.location.href = "/404.html?error=未查询到该商品";
  842. // }
  843. },
  844. mounted: function () {
  845. this.userId = this.couponParam.userId = GLOBAL_USER_ID;
  846. this.getProductDetails();
  847. this.getProductPrice();
  848. // this.getParameters();
  849. this.queryProductDetilsCoupons();
  850. this.getCommodityCombinationList();
  851. console.log('GLOBAL_CLUB_TYPE',GLOBAL_CLUB_TYPE)
  852. // $('.productInfo').slide({
  853. // mainCell:".tabCon"
  854. // ,titCell:".tabTit span"
  855. // ,trigger: "click"
  856. // });
  857. setTimeout(function () {
  858. if (isPC) {
  859. var magnifier = new ImageMagnifier(
  860. '#imgShown .smallImage li',
  861. '#imgShown .bigImage',
  862. '#imgShown .zoomImage',
  863. '#imgShown .mask',
  864. '#imgShown .zoom',
  865. "on"
  866. ).init();
  867. } else {
  868. var swiper = new Swiper('#swiperImage', {
  869. loop: true,
  870. autoplay: {
  871. delay: 2000,
  872. disableOnInteraction: false
  873. },
  874. pagination: {
  875. el: '.swiper-pagination',
  876. type: 'fraction'
  877. }
  878. });
  879. }
  880. }, 500);
  881. setTimeout(function () {
  882. if (isPC) {
  883. $('#productRecommend').slide({
  884. mainCell: ".swiper-wrapper",
  885. titCell: ".swiper-pagination span",
  886. effect: "leftLoop",
  887. interTime: 3000,
  888. autoPlay: true,
  889. scroll: 7,
  890. vis: 7,
  891. trigger: "mouseover"
  892. });
  893. } else {
  894. var swiper = new Swiper('#productRecommend', {
  895. slidesPerView: 3,
  896. spaceBetween: 0,
  897. autoplay: {
  898. delay: 3000,
  899. disableOnInteraction: false
  900. },
  901. pagination: {
  902. el: '.swiper-pagination'
  903. }
  904. });
  905. }
  906. }, 500);
  907. }
  908. });