detail.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. var productDetail = new Vue({
  2. el: "#productDetail",
  3. data: {
  4. showProduct: false,
  5. productId: 0,
  6. userId: 0,
  7. number: 0,
  8. productStock: 0,
  9. images: [],
  10. priceObj: {
  11. actStatus: 0,
  12. ladderPriceFlag: 0,
  13. minBuyNumber: 1,
  14. price: 0,
  15. costPrice: 0,
  16. priceFlag: 3,
  17. productId: 0,
  18. promotions: '',
  19. step: 1,
  20. supplierId: 0,
  21. userIdentity: 0 //2-会员机构;3-供应商;4-普通机构
  22. },
  23. ladderList:[],//阶梯价
  24. promotions:{},//促销活动信息
  25. promotionsId:0,//活动id
  26. addStatus: true,
  27. recommendType: 0,//相关推荐类型 0自动选择; 1手动推荐
  28. recommendPage: 1,
  29. recommends: [],
  30. parameters: [],
  31. tabsIndex:0,
  32. disabledText:'',
  33. isNoneDisabled:false,
  34. isServiceInfo:false,
  35. isTrainingMethod:false,
  36. productTypeName:"",
  37. beautyActFlag:'',
  38. trainingMethodText:'',
  39. trainingType:'',
  40. isShowPopup:true,
  41. currentTab:0,
  42. dataList:[
  43. {
  44. maxMoney:5000,
  45. minMoney:1000,
  46. couponType:1,
  47. couponTime:'2021.06.28~2021.07.28',
  48. couponText:'华熙生物技术有限公司',
  49. useType:1,
  50. couponBtnType:0,
  51. status:0,
  52. },
  53. {
  54. maxMoney:2000,
  55. minMoney:200,
  56. couponType:2,
  57. couponTime:'2021.06.28~2021.07.28',
  58. couponText:'华熙生物技术有限公司',
  59. useType:2,
  60. couponBtnType:0,
  61. status:1,
  62. },
  63. {
  64. maxMoney:4000,
  65. minMoney:800,
  66. couponType:3,
  67. couponTime:'2021.06.28~2021.07.28',
  68. couponText:'华熙生物技术有限公司',
  69. useType:3,
  70. couponBtnType:0,
  71. status:2,
  72. },
  73. {
  74. maxMoney:6000,
  75. minMoney:1000,
  76. couponType:4,
  77. couponTime:'2021.06.28~2021.07.28',
  78. couponText:'华熙生物技术有限公司',
  79. useType:1,
  80. couponBtnType:0,
  81. status:0,
  82. },
  83. {
  84. maxMoney:6000,
  85. minMoney:1000,
  86. couponType:4,
  87. couponTime:'2021.06.28~2021.07.28',
  88. couponText:'华熙生物技术有限公司',
  89. useType:1,
  90. couponBtnType:0,
  91. status:0,
  92. },
  93. {
  94. maxMoney:6000,
  95. minMoney:1000,
  96. couponType:4,
  97. couponTime:'2021.06.28~2021.07.28',
  98. couponText:'华熙生物技术有限公司',
  99. useType:1,
  100. couponBtnType:0,
  101. status:1,
  102. },
  103. {
  104. maxMoney:6000,
  105. minMoney:1000,
  106. couponType:4,
  107. couponTime:'2021.06.28~2021.07.28',
  108. couponText:'华熙生物技术有限公司',
  109. useType:1,
  110. couponBtnType:0,
  111. status:2,
  112. },
  113. {
  114. maxMoney:6000,
  115. minMoney:1000,
  116. couponType:5,
  117. couponTime:'2021.06.28~2021.07.28',
  118. couponText:'华熙生物技术有限公司',
  119. useType:2,
  120. couponBtnType:0,
  121. status:1,
  122. }
  123. ],
  124. },
  125. filters: {
  126. TypeFormat:function(value) {
  127. switch (value) {
  128. case 1:
  129. return '活动券';
  130. break;
  131. case 2:
  132. return '品类券';
  133. break;
  134. case 3:
  135. return '店铺券';
  136. break;
  137. case 4:
  138. return '专享券';
  139. break;
  140. case 5:
  141. return '新用户券';
  142. break;
  143. }
  144. },
  145. TypeFormatText:function(value) {
  146. switch (value) {
  147. case 1:
  148. return '全商城商品通用';
  149. break;
  150. case 2:
  151. return '仅限购买仪器类商品';
  152. break;
  153. case 3:
  154. return '仅可购买店铺';
  155. break;
  156. }
  157. }
  158. },
  159. computed: {},
  160. methods: {
  161. getImages: function(){
  162. var _self = this;
  163. if(!this.productId){return;}
  164. ProductApi.GetProductDdtailsImages({productId: _self.productId},function (response) {
  165. if (response.code === 0 && response.data) {
  166. _self.images = response.data;
  167. setTimeout(function(){
  168. if (isPC) {
  169. var magnifier = new ImageMagnifier(
  170. '#imgShown .smallImage li',
  171. '#imgShown .bigImage',
  172. '#imgShown .zoomImage',
  173. '#imgShown .mask',
  174. '#imgShown .zoom',
  175. "on"
  176. ).init();
  177. } else {
  178. var swiper = new Swiper('#swiperImage', {
  179. loop : true,
  180. autoplay: {
  181. delay: 2000,
  182. disableOnInteraction: false
  183. },
  184. pagination: {
  185. el: '.swiper-pagination',
  186. type: 'fraction'
  187. }
  188. });
  189. }
  190. },500);
  191. }
  192. });
  193. },
  194. getProductDetails:function(){
  195. var _self = this;
  196. ProductApi.GetProductDdtails({userId:GLOBAL_USER_ID,productId:_self.productId},function (response) {
  197. if(response.code == 0){
  198. var product = response.data;
  199. _self.beautyActFlag = product.beautyActFlag
  200. _self.productTypeName = product.typeName;
  201. _self.recommendType = product.recommendType ? product.recommendType : 0;
  202. if(product.productDetail.orderInfo!='' && product.productDetail.serviceInfo!=''){
  203. _self.isServiceInfo = true;
  204. }
  205. if(product.commodityType == 2 && product.trainingMethod){
  206. _self.isTrainingMethod = true;
  207. _self.trainingMethodText = product.trainingMethod == 1 ? '线上培训' : '线下培训';
  208. _self.trainingType = product.trainingType == 1 ? '¥'+product.trainingFee : '售价已包含';
  209. }
  210. if(product.validFlag == 3 || product.validFlag == 9 || product.validFlag == 0 || product.validFlag == 10 || product.stock == 0 ){
  211. _self.isNoneDisabled = true;
  212. }else{
  213. _self.isNoneDisabled = false;
  214. }
  215. if(product.validFlag ==3){
  216. _self.disabledText = '下架'
  217. }
  218. if(product.validFlag ==10){
  219. _self.disabledText = '停售'
  220. }
  221. if(product.validFlag ==9 || product.validFlag ==0){
  222. _self.disabledText = '失效'
  223. }
  224. if(product.stock == 0 && product.validFlag !=3){
  225. _self.disabledText = '售罄'
  226. }
  227. _self.getRecommends();
  228. }else{
  229. CAIMEI.Alert(response.msg, '确定', false);
  230. }
  231. })
  232. },
  233. getProductPrice:function(){//获取商品价格
  234. var _self = this;
  235. if(_self.productId ===0){return;}
  236. ProductApi.GetProductDdtailsPrice({ userId: GLOBAL_USER_ID,productId: _self.productId},function (response) {
  237. if (response.code === 0 && response.data) {
  238. _self.priceObj = response.data;
  239. _self.number = response.data.minBuyNumber;
  240. if(response.data.ladderPriceFlag===1){
  241. _self.ladderPrice();
  242. }
  243. if(response.data.actStatus==1){
  244. _self.promotions = response.data.promotions;
  245. _self.promotionsId = response.data.promotions.id;
  246. }
  247. }
  248. });
  249. },
  250. ladderPrice:function(){//获取商品阶梯价格
  251. var _self = this;
  252. if(!this.productId){return;}
  253. ProductApi.GetProductDdtailsLadderPrice({ productId: _self.productId },function (response) {
  254. if (response.code === 0 && response.data) {
  255. _self.ladderList =response.data;
  256. _self.numberResize();
  257. }
  258. });
  259. },
  260. getParameters: function(){//获取商品参数
  261. var _self = this;
  262. if(!this.productId){return;}
  263. ProductApi.GetProductDdtailsParameter({ productId: _self.productId},function (response) {
  264. if (response.code === 0 && response.data) {
  265. _self.parameters = response.data;
  266. console.log(_self.parameters)
  267. }
  268. });
  269. },
  270. toggleThisLadder: function(event){
  271. var el = event.currentTarget;
  272. if($(el).hasClass("on")){
  273. $(el).removeClass("on").siblings('.mFixed').hide();
  274. if(!isPC){looseBody();}
  275. }else{
  276. $(el).addClass("on").siblings('.mFixed').show();
  277. if(!isPC){fixedBody();}
  278. }
  279. },
  280. hideThisLadder: function(event){
  281. var el = event.currentTarget;
  282. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  283. if(!isPC){looseBody();}
  284. },
  285. numberSub: function(){
  286. this.number -= this.priceObj.step;
  287. this.numberResize();
  288. },
  289. numberAdd: function(){
  290. this.number += this.priceObj.step;
  291. this.numberResize();
  292. },
  293. numberChange: function(){
  294. this.number = Math.ceil(this.number/this.priceObj.step)*this.priceObj.step;
  295. this.numberResize();
  296. },
  297. numberResize: function(){
  298. var _self = this;
  299. if (this.number<this.priceObj.minBuyNumber){
  300. this.number = this.priceObj.minBuyNumber;
  301. }
  302. if (this.number>this.productStock){
  303. this.number = this.productStock;
  304. }
  305. if(this.priceObj.ladderPriceFlag){
  306. this.ladderList.forEach(function(ladder){
  307. if(_self.number>=ladder.buyNum){
  308. _self.priceObj.price = ladder.buyPrice;
  309. }
  310. });
  311. }
  312. },
  313. toLogin: function() {
  314. setBeforeUrl();
  315. window.location.href = '/login.html';
  316. },
  317. toUpgrade: function() {
  318. setBeforeUrl();
  319. window.location.href = '/user/setting/upgrade.html';
  320. },
  321. addShopCart: function(){ //加入购物车
  322. var _self = this;
  323. if(this.addStatus){
  324. _self.addStatus = false;
  325. addShoppingCart(this.userId, this.productId, this.number,function(){
  326. _self.addStatus = true;
  327. });
  328. }
  329. },
  330. buyNowSubmit: function(){
  331. if(this.productId && this.number){
  332. // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  333. window.location.href = '/shopping/confirm.html?type=2&id='+this.productId+'&count='+this.number;
  334. }
  335. },
  336. getRecommends: function(){
  337. var _self = this;
  338. if(!this.productId){return;}
  339. ProductApi.GetProductDdtailsRecommend(
  340. {
  341. productId: _self.productId,
  342. recommendType: _self.recommendType,
  343. userId: _self.userId
  344. },
  345. function (response) {
  346. if (response.code === 0 && response.data) {
  347. if(response.data.length > 0){
  348. _self.recommends = response.data;
  349. _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
  350. setTimeout(function(){
  351. if (isPC) {
  352. $('#productRecommend').slide({
  353. mainCell:".swiper-wrapper",
  354. titCell:".swiper-pagination span",
  355. effect: "leftLoop",
  356. interTime: 3000,
  357. autoPlay: true,
  358. scroll:7,
  359. vis:7,
  360. trigger: "mouseover"
  361. });
  362. } else {
  363. var swiper = new Swiper('#productRecommend', {
  364. slidesPerView: 3,
  365. spaceBetween: 0,
  366. autoplay: {
  367. delay: 3000,
  368. disableOnInteraction: false
  369. },
  370. pagination: {
  371. el: '.swiper-pagination'
  372. }
  373. });
  374. }
  375. },500);
  376. }
  377. }
  378. });
  379. },
  380. queryCouponTabs:function (value){// 切换优惠券
  381. var _self = this;
  382. _self.currentTab = value;
  383. },
  384. showPopup:function(){// 显示优惠券弹窗
  385. var _self = this;
  386. _self.isShowPopup = true;
  387. },
  388. hidePopup:function(){// 隐藏优惠券弹窗
  389. var _self = this;
  390. _self.isShowPopup = false;
  391. },
  392. detailsClicktab:function(index){
  393. var _self = this;
  394. _self.tabsIndex = index;
  395. }
  396. },
  397. created: function () {
  398. this.productId = $("#productId").val();
  399. this.productStock = $("#productStock").val();
  400. this.getImages();
  401. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  402. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
  403. var visible = $("#productVisibility").val()*1;
  404. var identity = GLOBAL_USER_IDENTITY;
  405. this.showProduct = visible === 3 || identity === 1 || identity === 2 || (identity === 4 && visible === 2);
  406. if(!this.showProduct) {
  407. window.location.href = "/404.html?error=未查询到该商品";
  408. }
  409. },
  410. mounted: function () {
  411. this.userId = GLOBAL_USER_ID;
  412. this.getProductDetails();
  413. this.getProductPrice();
  414. this.getParameters();
  415. // $('.productInfo').slide({
  416. // mainCell:".tabCon"
  417. // ,titCell:".tabTit span"
  418. // ,trigger: "click"
  419. // });
  420. }
  421. });