detail.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. var productDetail = new Vue({
  2. el: "#productDetail",
  3. mixins: [beautyArchiveDetailMixin],
  4. data: {
  5. showProduct: false,
  6. productId: 0,
  7. userId: 0,
  8. number: 0,
  9. productStock: 0,
  10. pcActType: 0,
  11. images: [],
  12. priceObj: {
  13. actStatus: 0,
  14. ladderPriceFlag: 0,
  15. minBuyNumber: 1,
  16. price: 0,
  17. costPrice: 0,
  18. priceFlag: 3,
  19. productId: 0,
  20. promotions: '',
  21. step: 1,
  22. supplierId: 0,
  23. userIdentity: 0 //2-会员机构;3-供应商;4-普通机构
  24. },
  25. ladderList: [],//阶梯价
  26. promotions: {},//促销活动信息
  27. promotionsId: 0,//活动id
  28. addStatus: true,
  29. recommendType: 0,//相关推荐类型 0自动选择; 1手动推荐
  30. recommendPage: 1,
  31. recommends: [],
  32. parameters: [],
  33. tabsIndex: 0,
  34. disabledText: '',
  35. isNoneDisabled: false,
  36. isServiceInfo: false,
  37. isTrainingMethod: false,
  38. productTypeName: "",
  39. beautyActFlag: '',
  40. trainingMethodText: '',
  41. trainingType: '',
  42. isShowPopup: false,
  43. currentTab: 1,
  44. couponParam: {// 获取弹窗优惠券领取参数
  45. userId: 0,
  46. productId: 0,
  47. status: 1,
  48. source: 1
  49. },
  50. isCouponEmpty: false,
  51. productCoupon: [], // 优惠券
  52. productCouponList: [], // 优惠券弹窗列表
  53. collectionType:false, // 商品收藏状态
  54. },
  55. filters: {
  56. TypeFormat: function (value) {
  57. switch (value) {
  58. case 0:
  59. return '活动券';
  60. break;
  61. case 1:
  62. return '品类券';
  63. break;
  64. case 2:
  65. return '用户专享券';
  66. break;
  67. case 3:
  68. return '店铺券';
  69. break;
  70. case 4:
  71. return '新用户券';
  72. break;
  73. }
  74. }
  75. },
  76. methods: {
  77. getImages: function () {
  78. var _self = this;
  79. if (!this.productId) {
  80. return;
  81. }
  82. ProductApi.GetProductDdtailsImages({productId: _self.productId}, function (response) {
  83. if (response.code === 0 && response.data) {
  84. _self.images = response.data;
  85. setTimeout(function () {
  86. if (isPC) {
  87. var magnifier = new ImageMagnifier(
  88. '#imgShown .smallImage li',
  89. '#imgShown .bigImage',
  90. '#imgShown .zoomImage',
  91. '#imgShown .mask',
  92. '#imgShown .zoom',
  93. "on"
  94. ).init();
  95. } else {
  96. var swiper = new Swiper('#swiperImage', {
  97. loop: true,
  98. autoplay: {
  99. delay: 2000,
  100. disableOnInteraction: false
  101. },
  102. pagination: {
  103. el: '.swiper-pagination',
  104. type: 'fraction'
  105. }
  106. });
  107. }
  108. }, 500);
  109. }
  110. });
  111. },
  112. getProductDetails: function () {
  113. var _self = this;
  114. ProductApi.GetProductDdtails({userId: GLOBAL_USER_ID, productId: _self.productId}, function (response) {
  115. if (response.code == 0) {
  116. var product = response.data;
  117. _self.pcActType = product.pcActType;
  118. _self.beautyActFlag = product.beautyActFlag;
  119. _self.productTypeName = product.typeName;
  120. _self.recommendType = product.recommendType ? product.recommendType : 0;
  121. _self.archiveId = product.archiveId; // 保存资料列表id
  122. if (product.userLike && product.userLike == 1) {// 商品收藏
  123. _self.collectionType = true
  124. } else {
  125. _self.collectionType = false
  126. }
  127. if (product.productDetail.orderInfo != '' && product.productDetail.serviceInfo != '') {
  128. _self.isServiceInfo = true;
  129. }
  130. if (product.commodityType == 2 && product.trainingMethod) {
  131. _self.isTrainingMethod = true;
  132. _self.trainingMethodText = product.trainingMethod == 1 ? '线上培训' : '线下培训';
  133. _self.trainingType = product.trainingType == 1 ? '¥' + product.trainingFee : '售价已包含';
  134. }
  135. if (product.validFlag == 3 || product.validFlag == 9 || product.validFlag == 0 || product.validFlag == 10 || product.stock == 0) {
  136. _self.isNoneDisabled = true;
  137. } else {
  138. _self.isNoneDisabled = false;
  139. }
  140. if (product.validFlag == 3) {
  141. _self.disabledText = '下架'
  142. }
  143. if (product.validFlag == 10) {
  144. _self.disabledText = '停售'
  145. }
  146. if (product.validFlag == 9 || product.validFlag == 0) {
  147. _self.disabledText = '失效'
  148. }
  149. if (product.stock == 0 && product.validFlag != 3) {
  150. _self.disabledText = '售罄'
  151. }
  152. _self.getRecommends();
  153. _self.getProdcutArchiveDetails(); //获取资料列表
  154. // 获取路由hash标识,设置默认展开tab
  155. var str = CAIMEI.getUrlParam('open');
  156. if (str === 'caimei365' && _self.archiveId > 0) {
  157. _self.tabsIndex = 4;
  158. }
  159. } else {
  160. CAIMEI.Alert(response.msg, '确定', false);
  161. }
  162. })
  163. },
  164. getProductPrice: function () {//获取商品价格
  165. var _self = this;
  166. if (_self.productId === 0) {
  167. return;
  168. }
  169. ProductApi.GetProductDdtailsPrice({
  170. userId: GLOBAL_USER_ID,
  171. productId: _self.productId
  172. }, function (response) {
  173. if (response.code === 0 && response.data) {
  174. _self.priceObj = response.data;
  175. _self.number = response.data.minBuyNumber;
  176. if (response.data.ladderPriceFlag === 1) {
  177. _self.ladderPrice();
  178. }
  179. if (response.data.actStatus == 1) {
  180. _self.promotions = response.data.promotions;
  181. _self.promotionsId = response.data.promotions.id;
  182. }
  183. }
  184. });
  185. },
  186. ladderPrice: function () {//获取商品阶梯价格
  187. var _self = this;
  188. if (!this.productId) {
  189. return;
  190. }
  191. ProductApi.GetProductDdtailsLadderPrice({productId: _self.productId}, function (response) {
  192. if (response.code === 0 && response.data) {
  193. _self.ladderList = response.data;
  194. _self.numberResize();
  195. }
  196. });
  197. },
  198. getParameters: function () {//获取商品参数
  199. var _self = this;
  200. if (!this.productId) {
  201. return;
  202. }
  203. ProductApi.GetProductDdtailsParameter({productId: _self.productId}, function (response) {
  204. if (response.code === 0 && response.data) {
  205. _self.parameters = response.data;
  206. console.log(_self.parameters)
  207. }
  208. });
  209. },
  210. toggleThisLadder: function (event) {
  211. var el = event.currentTarget;
  212. if ($(el).hasClass("on")) {
  213. $(el).removeClass("on").siblings('.mFixed').hide();
  214. if (!isPC) {
  215. looseBody();
  216. }
  217. } else {
  218. $(el).addClass("on").siblings('.mFixed').show();
  219. if (!isPC) {
  220. fixedBody();
  221. }
  222. }
  223. },
  224. hideThisLadder: function (event) {
  225. var el = event.currentTarget;
  226. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  227. if (!isPC) {
  228. looseBody();
  229. }
  230. },
  231. numberSub: function () {
  232. this.number -= this.priceObj.step;
  233. this.numberResize();
  234. },
  235. numberAdd: function () {
  236. this.number += this.priceObj.step;
  237. this.numberResize();
  238. },
  239. numberChange: function () {
  240. this.number = Math.ceil(this.number / this.priceObj.step) * this.priceObj.step;
  241. this.numberResize();
  242. },
  243. numberResize: function () {
  244. var _self = this;
  245. if (this.number < this.priceObj.minBuyNumber) {
  246. this.number = this.priceObj.minBuyNumber;
  247. }
  248. if (this.number > this.productStock) {
  249. this.number = this.productStock;
  250. }
  251. if (this.priceObj.ladderPriceFlag) {
  252. this.ladderList.forEach(function (ladder) {
  253. if (_self.number >= ladder.buyNum) {
  254. _self.priceObj.price = ladder.buyPrice;
  255. }
  256. });
  257. }
  258. },
  259. handleCollection:function (){// 收藏操作
  260. var _self = this;
  261. console.log('_self.userId',_self.userId)
  262. if (_self.userId > 0) {
  263. ProductApi.getProductUserLike({userId: _self.userId, productId: _self.productId}, function (response) {
  264. if (response.code === 0 && response.data) {
  265. _self.collectionType = !_self.collectionType
  266. CAIMEI.dialog(response.data,false);
  267. } else {
  268. CAIMEI.Alert(response.msg, '确定', false);
  269. }
  270. });
  271. }else{
  272. _self.toLogin();
  273. }
  274. },
  275. toLogin: function () {
  276. setBeforeUrl();
  277. window.location.href = '/login.html';
  278. },
  279. toUpgrade: function () {
  280. setBeforeUrl();
  281. window.location.href = '/user/setting/upgrade.html';
  282. },
  283. addShopCart: function(){ //加入购物车
  284. var _self = this;
  285. if(_self.addStatus){
  286. _self.addStatus = false;
  287. ShoppingApi.ClubAddCart(
  288. {
  289. productCount:this.number,
  290. productId:this.productId,
  291. userId:this.userId,
  292. source:1
  293. },
  294. function (response){
  295. if(response.code == 0){
  296. _self.addStatus = true;
  297. $.confirm({
  298. useBootstrap: false,
  299. boxWidth: (isPC?'338px':'74.6vw'),
  300. title: false,
  301. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  302. closeIcon: true,
  303. animation: 'opacity',
  304. closeAnimation: 'opacity',
  305. animateFromElement: false,
  306. scrollToPreviousElement: false,
  307. buttons: {
  308. login: {
  309. text: '去结算',
  310. btnClass: 'btn-to-cart',
  311. action: function(){
  312. window.location.href = '/shopping/cart.html';
  313. }
  314. },
  315. close: {
  316. text: '继续购物',
  317. btnClass: 'btn-to-goon',
  318. action:function(){
  319. }
  320. }
  321. }
  322. });
  323. globalHead.getHeadCart(_self.userId);
  324. }else{
  325. CAIMEI.dialog('加入购物车失败!',true,function () {
  326. _self.addStatus = true;
  327. });
  328. }
  329. }
  330. )
  331. }
  332. },
  333. buyNowSubmit: function(){ // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  334. var _self = this;
  335. if(_self.productId && _self.number){
  336. window.location.href = '/shopping/confirm.html?type=2&productId='+_self.productId+'&count='+_self.number;
  337. }
  338. },
  339. getRecommends: function () {
  340. var _self = this;
  341. if (!this.productId) {
  342. return;
  343. }
  344. ProductApi.GetProductDdtailsRecommend(
  345. {
  346. productId: _self.productId,
  347. recommendType: _self.recommendType,
  348. userId: _self.userId
  349. },
  350. function (response) {
  351. if (response.code === 0 && response.data) {
  352. if (response.data.length > 0) {
  353. _self.recommends = response.data;
  354. _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
  355. setTimeout(function () {
  356. if (isPC) {
  357. $('#productRecommend').slide({
  358. mainCell: ".swiper-wrapper",
  359. titCell: ".swiper-pagination span",
  360. effect: "leftLoop",
  361. interTime: 3000,
  362. autoPlay: true,
  363. scroll: 7,
  364. vis: 7,
  365. trigger: "mouseover"
  366. });
  367. } else {
  368. var swiper = new Swiper('#productRecommend', {
  369. slidesPerView: 3,
  370. spaceBetween: 0,
  371. autoplay: {
  372. delay: 3000,
  373. disableOnInteraction: false
  374. },
  375. pagination: {
  376. el: '.swiper-pagination'
  377. }
  378. });
  379. }
  380. }, 500);
  381. }
  382. }
  383. });
  384. },
  385. queryProductDetilsCoupons: function() {// 初始化商品详情优惠券信息
  386. var _self = this;
  387. ProductApi.QueryProductDetilsCoupons(_self.couponParam, function (response) {
  388. if (response.code == 0) {
  389. var data = response.data;
  390. if (isPC) {
  391. _self.productCoupon = response.data.list.splice(0, 3);
  392. } else {
  393. _self.productCoupon = response.data.list.splice(0, 2);
  394. }
  395. } else {
  396. console.log('获取优惠券列表失败');
  397. }
  398. })
  399. },
  400. queryPopupCoupons: function () {// 获取弹窗优惠券列表
  401. var _self = this;
  402. ProductApi.QueryProductDetilsCoupons(_self.couponParam, function (response) {
  403. if (response.code == 0) {
  404. var data = response.data;
  405. if (data.couponList && data.couponList.length > 0) {
  406. _self.productCouponList = data.couponList;
  407. _self.isCouponEmpty = false;
  408. console.log('有优惠券')
  409. console.log(_self.productCouponList)
  410. } else {
  411. console.log('没有优惠券')
  412. _self.isCouponEmpty = true;
  413. }
  414. } else {
  415. console.log('获取优惠券列表失败')
  416. }
  417. })
  418. },
  419. receiveCoupon: function (coupon) {// 点击领取优惠券
  420. var _self = this;
  421. ProductApi.ReceiveCoupon({
  422. userId: _self.couponParam.userId,
  423. couponId: coupon.couponId,
  424. source: 1
  425. }, function (response) {
  426. if (response.code == 0) {
  427. _self.currentTab = 2;
  428. _self.couponParam.status = 2;
  429. _self.queryPopupCoupons();
  430. } else {
  431. CAIMEI.Alert(response.msg, '确定', false);
  432. }
  433. })
  434. },
  435. queryCouponTabs: function (value) {// 切换优惠券
  436. var _self = this;
  437. _self.currentTab = _self.couponParam.status = value;
  438. _self.queryPopupCoupons();
  439. },
  440. showPopup: function () {// 显示优惠券弹窗
  441. var _self = this;
  442. if (_self.userId > 0) {
  443. _self.productCouponList = [];
  444. _self.currentTab = 1;
  445. _self.couponParam.status = 1;
  446. _self.queryPopupCoupons();
  447. _self.isShowPopup = true;
  448. } else {
  449. window.location.href = '/login.html';
  450. }
  451. },
  452. hidePopup: function () {// 隐藏优惠券弹窗
  453. var _self = this;
  454. _self.isShowPopup = false;
  455. },
  456. detailsClicktab: function (index) {
  457. var _self = this;
  458. _self.tabsIndex = index;
  459. if (index !== 4) return;
  460. // 只有当前用户权限为0,并且未初始化时初始化图片预览
  461. if (_self.permission === 0) {
  462. setTimeout(function () {
  463. _self.initPreviewImage()
  464. })
  465. }
  466. },
  467. // 是否显示vip标签价格
  468. showVipPriceTag(product){
  469. return (product.priceFlag !== 1 && product.svipProductFlag === 1 && ((GLOBAL_USER_IDENTITY === 4 && GLOBAL_VIP_FLAG === 1) || GLOBAL_USER_IDENTITY === 2));
  470. }
  471. },
  472. created: function () {
  473. this.productId = this.couponParam.productId = $("#productId").val();
  474. this.userId = this.couponParam.userId = GLOBAL_USER_ID;
  475. this.productStock = $("#productStock").val();
  476. this.getImages();
  477. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  478. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
  479. var visible = $("#productVisibility").val() * 1;
  480. var identity = GLOBAL_USER_IDENTITY;
  481. this.showProduct = visible === 3 || identity === 1 || identity === 2 || (identity === 4 && visible === 2);
  482. if (!this.showProduct) {
  483. window.location.href = "/404.html?error=未查询到该商品";
  484. }
  485. },
  486. mounted: function () {
  487. this.userId = this.couponParam.userId = GLOBAL_USER_ID;
  488. this.getProductDetails();
  489. this.getProductPrice();
  490. this.getParameters();
  491. this.queryProductDetilsCoupons();
  492. // $('.productInfo').slide({
  493. // mainCell:".tabCon"
  494. // ,titCell:".tabTit span"
  495. // ,trigger: "click"
  496. // });
  497. }
  498. });