detail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. var productDetail = new Vue({
  2. el: "#productDetail",
  3. data: {
  4. productId: 0,
  5. userId: 0,
  6. userIdentity: '', //2-会员机构;3-供应商;4-普通机构
  7. userToken: '',
  8. images: [],
  9. price: 564,
  10. priceFlag: 2,
  11. recommendType: 1,
  12. recommendPage: 1,
  13. recommends: [],
  14. parameters: [],
  15. isShow:false,
  16. ladderList:[],//阶梯价
  17. deailData:{},
  18. promotions:{},//促销活动信息
  19. recommde:false,
  20. recommdeindex:0,
  21. number:0,
  22. minBuyNumber:0,
  23. buyRetailPrice:0,
  24. allTotalPrice:0,
  25. typedata:0,
  26. promotionsId:0,//活动id
  27. isQuantity:false,
  28. isStock:false,
  29. cartAlert:false
  30. },
  31. computed: {},
  32. methods: {
  33. getImages: function(){
  34. var _self = this;
  35. if(!this.productId){return;}
  36. $.getJSON(spiServer + "/product/detail/images",{productId: this.productId}).done(function (r) {
  37. if (r.code === 0 && r.data) {
  38. _self.images = r.data;
  39. setTimeout(function(){
  40. if (isPC) {
  41. var magnifier = new ImageMagnifier(
  42. '#imgShown .smallImage li'
  43. ,'#imgShown .bigImage'
  44. ,'#imgShown .zoomImage'
  45. ,'#imgShown .mask'
  46. ,'#imgShown .zoom'
  47. ,"on"
  48. ).init();
  49. } else {
  50. var swiper = new Swiper('#swiperImage', {
  51. loop : true,
  52. autoplay: {
  53. delay: 2000,
  54. disableOnInteraction: false
  55. },
  56. pagination: {
  57. el: '.swiper-pagination',
  58. type: 'fraction'
  59. }
  60. });
  61. }
  62. },500);
  63. }
  64. });
  65. },
  66. toLogin:function() {
  67. location.href ='/login.html';
  68. },
  69. productDetail:function(){
  70. var _self = this;
  71. if(_self.productId ===0){return;}
  72. $.getJSON(spiServer + "/product/detail/price",{
  73. // userId:this.userId,
  74. // productId: this.productId
  75. userId:10684,
  76. productId: _self.productId
  77. }).done(function (r) {
  78. if (r.code === 0 && r.data) {
  79. _self.priceFlag = r.data.priceFlag;
  80. _self.number = r.data.minBuyNumber;//最小起訂量
  81. _self.buyRetailPriceStep = r.data.step;
  82. _self.minBuyNumber = r.data.minBuyNumber;
  83. _self.buyRetailPrice = r.data.price;
  84. console.log(r)
  85. if(r.data.ladderPriceFlag==1){
  86. _self.ladderPrice();
  87. }else {
  88. _self.allTotalPrice = _self.number * _self.deailData.price;
  89. }
  90. _self.deailData =r.data;
  91. if(_self.deailData.actStatus==1){
  92. _self.promotions = _self.deailData.promotions;
  93. _self.promotionsId = _self.deailData.promotions.id;
  94. }
  95. }
  96. });
  97. },
  98. toggleThisLadder: function(event){
  99. var el = event.currentTarget;
  100. if($(el).hasClass("on")){
  101. $(el).removeClass("on").siblings('.mFixed').hide();
  102. if(!isPC){looseBody();}
  103. }else{
  104. $(el).addClass("on").siblings('.mFixed').show();
  105. if(!isPC){fixedBody();}
  106. }
  107. },
  108. hideThisLadder: function(event){
  109. var el = event.currentTarget;
  110. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  111. if(!isPC){looseBody();}
  112. },
  113. changeCountAdd:function () { //数量增加按钮
  114. var _this = this;
  115. if(_this.buyRetailPriceStep == 2){
  116. _this.number += _this.minBuyNumber
  117. }else{
  118. _this.number++
  119. }
  120. _this.allTotalPrice = _this.number * _this.deailData.price;
  121. _this.calculatPerice()
  122. },
  123. changeCountSub:function(){//popup弹窗数量减按钮
  124. var _this = this;
  125. if(_this.number<=_this.minBuyNumber){
  126. _this.number= _this.minBuyNumber;
  127. _this.isQuantity =true;
  128. layer.tips('此商品最小起批量为' + _this.minBuyNumber, $(this).parent().find(".calc-input"), {
  129. tips: 1,
  130. time: 3000
  131. });
  132. return
  133. }else{
  134. if(_this.buyRetailPriceStep == 2){
  135. _this.number-=_this.minBuyNumber
  136. }else{
  137. _this.number--
  138. }
  139. _this.allTotalPrice = _this.number * _this.deailData.price;
  140. _this.calculatPerice();
  141. _this.isQuantity =false
  142. }
  143. },
  144. changeNumber:function(e){
  145. var _this=this;
  146. var _value = e.detail.value;
  147. if(!_value){
  148. _this.number = _this.minBuyNumber
  149. }else if(_value < _this.minBuyNumber){
  150. _this.layer.msg('该商品最小起订量为'+_this.minBuyNumber,2000);
  151. _this.number = _this.minBuyNumber
  152. }else if( _value % _this.minBuyNumber !=0 ){
  153. _this.layer.msg('购买量必须为起订量的整数倍',2000);
  154. _this.number = _this.minBuyNumber
  155. }else{
  156. _this.number = e.detail.value;
  157. _this.allTotalPrice = _this.number * _this.deailData.price;
  158. _this.calculatPerice();
  159. }
  160. },
  161. calculatPerice:function(){//判断是否为阶梯价然后做计算价格处理
  162. var _this = this;
  163. if(_this.deailData.ladderPriceFlag == '1'){
  164. _this.ladderList.forEach(function (item,index) {
  165. if(_this.number>=item.buyNum){
  166. _this.buyRetailPrice = item.buyPrice
  167. _this.allTotalPrice = _this.number*item.buyPrice
  168. }
  169. })
  170. }else{
  171. _this.buyRetailPrice = _this.deailData.price;
  172. }
  173. },
  174. addShopCart:function(){ //加入购物车
  175. var _this = this;
  176. tokenAjax("post", "/shoppingCart/addCart", {
  177. userID: this.userId,
  178. productID: this.productId,
  179. productCount: this.number
  180. },function (res) {
  181. alertInfo(res.msg);
  182. });
  183. },
  184. Continueshop:function(){ //继续购物
  185. var _this = this;
  186. _this.cartAlert = false;
  187. location.reload()
  188. },
  189. settlement:function(){//去结算
  190. window.location.href = "/shopping/cart.html"
  191. },
  192. buyNowSubmit: function(){
  193. if(this.productId && this.number){
  194. // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  195. window.location.href = '/shopping/confirm.html?type=2&id='+this.productId+'&count='+this.number;
  196. }
  197. },
  198. getRecommends: function(){
  199. var _self = this;
  200. if(!this.productId){return;}
  201. $.getJSON(spiServer + "/product/detail/recommend",{
  202. productId: this.productId,
  203. recommendType: this.recommendType
  204. }).done(function (r) {
  205. if (r.code === 0 && r.data) {
  206. // _self.recommendPage = Math.ceil(r.data.length / 7);
  207. if(r.data.length > 0){
  208. _self.recommends = r.data;
  209. _self.recommde =true;
  210. }else {
  211. _self.recommde =false;
  212. }
  213. if(r.data.length<7){
  214. var length = 7-r.data.length;
  215. _self.recommdeindex = length;
  216. }else {
  217. var remainderres=r.data.length%7;
  218. _self.recommdeindex= 7-remainderres;
  219. }
  220. }
  221. });
  222. },
  223. ladderPrice:function(){
  224. var _self = this;
  225. if(!this.productId){return;}
  226. $.getJSON(spiServer + "/product/ladderPrice",{
  227. productId: this.productId
  228. }).done(function (r) {
  229. if (r.code === 0 && r.data) {
  230. console.log(r)
  231. _self.ladderList =r.data;
  232. _self.ladderList.forEach(function (item,index) {
  233. if(_self.number>=item.buyNum){
  234. _self.buyRetailPrice = item.buyPrice
  235. _self.allTotalPrice = _self.buyRetailPrice*_self.number;
  236. }
  237. })
  238. }
  239. });
  240. },
  241. clubupgrade:function(){
  242. location.href='/myAccount/club/clubupgrade.jsp'
  243. },
  244. getParameters: function(){
  245. var _self = this;
  246. if(!this.productId){return;}
  247. $.getJSON(spiServer + "/product/detail/parameter",{
  248. productId: this.productId
  249. }).done(function (r) {
  250. if (r.code === 0 && r.data) {
  251. _self.parameters = r.data;
  252. }
  253. });
  254. }
  255. },
  256. created: function () {
  257. this.productId = $("#productId").val();
  258. var userInfo = localStorage.getItem('userInfo');
  259. if(userInfo){
  260. this.userId = JSON.parse(userInfo).userId*1;
  261. }
  262. this.getImages();
  263. },
  264. mounted: function () {
  265. this.productDetail();
  266. this.getRecommends();
  267. $('.productInfo').slide({
  268. mainCell:".tabCon"
  269. ,titCell:".tabTit span"
  270. ,trigger: "click"
  271. });
  272. if(globalUserData){
  273. console.log(globalUserData)
  274. globalUserData.userId ? globalUserData.userId : globalUserData.userID;
  275. this.userIdentity = globalUserData.identity ? globalUserData.identity : globalUserData.userIdentity;
  276. this.userToken = globalUserData.token;
  277. }
  278. //相關推薦輪播
  279. var mySwiper = new Swiper('#productRecommend',{
  280. slidesPerView: 7,
  281. spaceBetween: 12,
  282. slidesPerGroup: 7,
  283. autoplay: {
  284. delay:10000,
  285. disableOnInteraction: false,//是否禁止autoplay。默认为true:停止。
  286. },
  287. loop: false,
  288. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  289. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  290. pagination: {
  291. el: '.swiper-pagination',
  292. clickable: true,
  293. },
  294. on:{
  295. init:function() {
  296. var length = this.slides.length;
  297. if(length < 8) {
  298. this.autoplay.stop();
  299. }
  300. }
  301. }
  302. })
  303. }
  304. });