detail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. },
  41. computed: {},
  42. methods: {
  43. getImages: function(){
  44. var _self = this;
  45. if(!this.productId){return;}
  46. ProductApi.GetProductDdtailsImages({productId: _self.productId},function (response) {
  47. if (response.code === 0 && response.data) {
  48. _self.images = response.data;
  49. setTimeout(function(){
  50. if (isPC) {
  51. var magnifier = new ImageMagnifier(
  52. '#imgShown .smallImage li'
  53. ,'#imgShown .bigImage'
  54. ,'#imgShown .zoomImage'
  55. ,'#imgShown .mask'
  56. ,'#imgShown .zoom'
  57. ,"on"
  58. ).init();
  59. } else {
  60. var swiper = new Swiper('#swiperImage', {
  61. loop : true,
  62. autoplay: {
  63. delay: 2000,
  64. disableOnInteraction: false
  65. },
  66. pagination: {
  67. el: '.swiper-pagination',
  68. type: 'fraction'
  69. }
  70. });
  71. }
  72. },500);
  73. }
  74. });
  75. },
  76. getProductDetails:function(){
  77. var _self = this;
  78. ProductApi.GetProductDdtails({userId:GLOBAL_USER_ID,productId:_self.productId},function (response) {
  79. if(response.code == 0){
  80. var product = response.data;
  81. _self.beautyActFlag = product.beautyActFlag
  82. _self.productTypeName = product.typeName;
  83. _self.recommendType = product.recommendType ? product.recommendType : 0;
  84. if(product.productDetail.orderInfo!='' && product.productDetail.serviceInfo!=''){
  85. _self.isServiceInfo = true;
  86. }
  87. if(product.commodityType == 2){
  88. _self.isTrainingMethod = true;
  89. _self.trainingMethodText = product.trainingMethod == 1 ? '线上培训' : '线下培训';
  90. _self.trainingType = product.trainingType == 1 ? '¥'+product.trainingFee : '售价已包含';
  91. }
  92. if(product.validFlag =='3' || product.validFlag =='9' || product.validFlag =='0' || product.validFlag =='10' || product.stock == 0 ){
  93. _self.isNoneDisabled = true;
  94. }else{
  95. _self.isNoneDisabled = false;
  96. }
  97. if(product.validFlag =='3'){
  98. _self.disabledText = '下架'
  99. }
  100. if(product.validFlag =='10'){
  101. _self.disabledText = '停售'
  102. }
  103. if(product.validFlag =='9' || product.validFlag =='0'){
  104. _self.disabledText = '失效'
  105. }
  106. if(product.stock == 0 && product.validFlag !='3'){
  107. _self.disabledText = '售罄'
  108. }
  109. _self.getRecommends();
  110. }else{
  111. CAIMEI.Alert(response.msg, '确定', false);
  112. }
  113. })
  114. },
  115. getProductPrice:function(){//获取商品价格
  116. var _self = this;
  117. if(_self.productId ===0){return;}
  118. ProductApi.GetProductDdtailsPrice({ userId: GLOBAL_USER_ID,productId: _self.productId},function (response) {
  119. if (response.code === 0 && response.data) {
  120. _self.priceObj = response.data;
  121. _self.number = response.data.minBuyNumber;
  122. if(response.data.ladderPriceFlag===1){
  123. _self.ladderPrice();
  124. }
  125. if(response.data.actStatus==1){
  126. _self.promotions = response.data.promotions;
  127. _self.promotionsId = response.data.promotions.id;
  128. }
  129. }
  130. });
  131. },
  132. ladderPrice:function(){//获取商品阶梯价格
  133. var _self = this;
  134. if(!this.productId){return;}
  135. ProductApi.GetProductDdtailsLadderPrice({ productId: _self.productId },function (response) {
  136. if (response.code === 0 && response.data) {
  137. _self.ladderList =response.data;
  138. _self.numberResize();
  139. }
  140. });
  141. },
  142. getParameters: function(){//获取商品参数
  143. var _self = this;
  144. if(!this.productId){return;}
  145. ProductApi.GetProductDdtailsParameter({ productId: _self.productId},function (response) {
  146. if (response.code === 0 && response.data) {
  147. _self.parameters = response.data;
  148. console.log(_self.parameters)
  149. }
  150. });
  151. },
  152. toggleThisLadder: function(event){
  153. var el = event.currentTarget;
  154. if($(el).hasClass("on")){
  155. $(el).removeClass("on").siblings('.mFixed').hide();
  156. if(!isPC){looseBody();}
  157. }else{
  158. $(el).addClass("on").siblings('.mFixed').show();
  159. if(!isPC){fixedBody();}
  160. }
  161. },
  162. hideThisLadder: function(event){
  163. var el = event.currentTarget;
  164. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  165. if(!isPC){looseBody();}
  166. },
  167. numberSub: function(){
  168. this.number -= this.priceObj.step;
  169. this.numberResize();
  170. },
  171. numberAdd: function(){
  172. this.number += this.priceObj.step;
  173. this.numberResize();
  174. },
  175. numberChange: function(){
  176. this.number = Math.ceil(this.number/this.priceObj.step)*this.priceObj.step;
  177. this.numberResize();
  178. },
  179. numberResize: function(){
  180. var _self = this;
  181. if (this.number<this.priceObj.minBuyNumber){
  182. this.number = this.priceObj.minBuyNumber;
  183. }
  184. if (this.number>this.productStock){
  185. this.number = this.productStock;
  186. }
  187. if(this.priceObj.ladderPriceFlag){
  188. this.ladderList.forEach(function(ladder){
  189. if(_self.number>=ladder.buyNum){
  190. _self.priceObj.price = ladder.buyPrice;
  191. }
  192. });
  193. }
  194. },
  195. toLogin: function() {
  196. setBeforeUrl();
  197. window.location.href = '/login.html';
  198. },
  199. toUpgrade: function() {
  200. setBeforeUrl();
  201. window.location.href = '/user/setting/upgrade.html';
  202. },
  203. addShopCart: function(){ //加入购物车
  204. var _self = this;
  205. if(this.addStatus){
  206. _self.addStatus = false;
  207. addShoppingCart(this.userId, this.productId, this.number,function(){
  208. _self.addStatus = true;
  209. });
  210. }
  211. },
  212. buyNowSubmit: function(){
  213. if(this.productId && this.number){
  214. // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  215. window.location.href = '/shopping/confirm.html?type=2&id='+this.productId+'&count='+this.number;
  216. }
  217. },
  218. getRecommends: function(){
  219. var _self = this;
  220. if(!this.productId){return;}
  221. ProductApi.GetProductDdtailsRecommend(
  222. {
  223. productId: _self.productId,
  224. recommendType: _self.recommendType,
  225. userId: _self.userId
  226. },
  227. function (response) {
  228. if (response.code === 0 && response.data) {
  229. if(response.data.length > 0){
  230. _self.recommends = response.data;
  231. _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
  232. setTimeout(function(){
  233. if (isPC) {
  234. $('#productRecommend').slide({
  235. mainCell:".swiper-wrapper",
  236. titCell:".swiper-pagination span",
  237. effect: "leftLoop",
  238. interTime: 3000,
  239. autoPlay: true,
  240. scroll:7,
  241. vis:7,
  242. trigger: "mouseover"
  243. });
  244. } else {
  245. var swiper = new Swiper('#productRecommend', {
  246. slidesPerView: 3,
  247. spaceBetween: 0,
  248. autoplay: {
  249. delay: 3000,
  250. disableOnInteraction: false
  251. },
  252. pagination: {
  253. el: '.swiper-pagination'
  254. }
  255. });
  256. }
  257. },500);
  258. }
  259. }
  260. });
  261. },
  262. detailsClicktab:function(index){
  263. var _self = this;
  264. _self.tabsIndex = index;
  265. }
  266. },
  267. created: function () {
  268. this.productId = $("#productId").val();
  269. this.productStock = $("#productStock").val();
  270. this.getImages();
  271. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  272. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
  273. var visible = $("#productVisibility").val()*1;
  274. var identity = GLOBAL_USER_IDENTITY;
  275. this.showProduct = visible === 3 || identity === 1 || identity === 2 || (identity === 4 && visible === 2);
  276. if(!this.showProduct) {
  277. window.location.href = "/404.html?error=未查询到该商品";
  278. }
  279. },
  280. mounted: function () {
  281. this.userId = GLOBAL_USER_ID;
  282. this.getProductDetails();
  283. this.getProductPrice();
  284. this.getParameters();
  285. // $('.productInfo').slide({
  286. // mainCell:".tabCon"
  287. // ,titCell:".tabTit span"
  288. // ,trigger: "click"
  289. // });
  290. }
  291. });