$(function() { var that = null; var vmm = new Vue({ el: "#container", data: { //1銆 浜у搧绫诲瀷銆侀瀹氱數鍘嬨€侀瀹氱數娴併€佽Е鐐瑰舰寮忋€佹渶澶х數闃汇€佸簲鐢ㄩ鍩 baseApi: 'https://ry.pro.tokeys.com/api', //璇锋眰鍦板潃 baseUrl: '', firstTemplate: false, //1:骞茬哀缁х數鍣 true:鐩存祦缁х數鍣 productPicture: '浜у搧鍥剧墖', productModel: '浜у搧鍨嬪彿', productSeries: '浜у搧绯诲垪', coilVoltage: '绾垮湀鐢靛帇', contactForm: '瑙︾偣褰㈠紡', switchingPower: '鍒囨崲鍔熺巼', dwitchingVoltage: '鍒囨崲鐢靛帇(Max)', dielectricStrength: '浠嬭川鑰愬帇', installationForm: '瀹夎褰㈠紡', optional: '鍙€夐」', inquiry: '璇环', download: '涓嬭浇', ratedCurrent: '棰濆畾璐熻浇鐢垫祦', maximumVoltage: '鏈€澶у垏鎹㈢數鍘?, searchBtnTxt: '纭鎼滅储', lastPageTxt: '涓婁竴椤?, nextPageTxt: '涓嬩竴椤?, detailTxt: '璇︽儏', noData: '娌℃湁鍖归厤鐨勬暟鎹?, categoryList: [], //浜岀骇鍒嗙被 categoryId: '', screenTree: [], //绛涢€夐」 productList: [], totalCount: 0, totalPages: 0, searchParams: { "page": "1", "pageSize": "10", "cid": "", "opts": [] } }, mounted() { if (location.hostname == '127.0.0.1') { this.baseUrl = 'http://2107305422.pool202-site.make.yun300.cn/'; } if (!location.search.length) { let urlStr = decodeURI(location.href); let productId = (urlStr.substr(urlStr.indexOf('/product/')).replace('/product/', '')) .replace('/', ''); this.searchParams.cid = productId } if (this.getParams('page')) { this.searchParams.page = this.getParams("page"); if (decodeURI(location.href).indexOf('/product/') == -1) { this.searchParams.cid = ''; } if (this.getParams('pId')) { this.searchParams.cid = this.getParams("pId"); } } if (this.searchParams.cid == 7||this.searchParams.cid == 10) { this.firstTemplate = true } this.searchScreenOption(); setTimeout(() => { $('.NavList_a1').attr('id', 'NavList_a1').menu({ a_type: 'slide', p_type: false, f_type: 'mob_js' }); }, 500) }, methods: { // 閲嶇疆鍦板潃鏍 resetPageUrl: function() { var state = { title: '', url: window.location.href }; var param = `?page=${this.searchParams.page}&pId=${this.searchParams.cid}&cateId=${this.categoryId}`; this.screenTree.forEach(item => { if (item.value) { let id = item.id; param += `&${item.name}=${item.value}` } }); history.pushState(state, '', window.location.pathname + param); }, // 鑾峰彇鍦板潃鏍忓弬鏁 getParams: function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var url = decodeURI(window.location.search) var r = url.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; }, // 纭鎼滅储 headleSelectOption() { this.searchParams.page = 1; this.searchProductList(); }, // 鍒嗛〉 handleCurrentChange(e) { this.searchParams.page = e; this.searchProductList(); }, // 鎵嬫満绔垎椤 handleMobileCurrentChange(type) { switch (type) { case 'add': //鍔 if (this.searchParams.page < this.totalPages) { this.searchParams.page++; this.searchProductList(); } break; case 'cut': //鍑 if (this.searchParams.page > 1) { this.searchParams.page--; this.searchProductList(); } break; } }, // 琛ㄦ牸琛岀偣鍑昏烦杞鎯 handlerRowClick(val) { window.location.href = `/product/${val.productId}.html` }, handleClickDownLink(item){ window.open(item.downlingk, '_blank'); }, // 鏌ヨ绛涢€夋潯浠 searchScreenOption() { if (this.searchParams.cid == 6) { this.maximumVoltage = '鍒囨崲鐢靛帇锛圡ax锛?; this.installationForm = '灏佽褰㈠紡'; } axios.get( `${this.baseApi}/getOpts?cid=${this.searchParams.cid}` ).then((resp) => { var res = resp.data; if (res.code == 200) { var urlStr = decodeURI(location.search); var parameter = new Object(); //鍔犺浇椤甸潰鏃舵槸鍚︿紶鍏ュ垎绫籭d if (urlStr.indexOf("?") != -1) { var str = urlStr.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { parameter[strs[i].split("=")[0]] = strs[i].split("=")[1]; } } for (var key in parameter) { res.data.opts.forEach(item => { if (key == item.name) { item.value = parameter[key] } }) } this.categoryList = res.data.cs; if (parameter.cateId) { this.categoryId = parameter.cateId; } else { this.categoryId = res.data.cs[0].id; } this.screenTree = res.data.opts; this.searchProductList(); } }) }, // 鏌ヨ浜у搧鍒楄〃 searchProductList() { let params = [] this.screenTree.forEach(item => { if (item.value) { let id = item.id; params.push({ name: item.name, value: item.value }) } }); this.searchParams.opts = params; this.resetPageUrl(); let searchParams = { ...this.searchParams, cid: this.categoryId } axios.post( `${this.baseApi}/getProducts`, searchParams ).then((resp) => { let res = resp.data; this.productList = []; if (res.data.length) { res.data.forEach(item => { item.cover = this.baseUrl + item.cover; }) this.productList = res.data; this.totalCount = res.totalCount; //鎬绘潯鏁 this.totalPages = res.totalPages //鎬婚〉鏁 } else if (res.code == 200) { this.$message.error(this.noData) } else { this.$message.error(res.message) } }) }, } }) })