detail.js 36 KB

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