|
@@ -5,32 +5,70 @@
|
|
|
<product-banner :lang="lang" />
|
|
<product-banner :lang="lang" />
|
|
|
<!-- 产品类别 -->
|
|
<!-- 产品类别 -->
|
|
|
<product-types :lang="lang" :type="type"></product-types>
|
|
<product-types :lang="lang" :type="type"></product-types>
|
|
|
|
|
+<!-- 产品列表 -->
|
|
|
|
|
+ <product-list :lang="lang" :product-list="products"></product-list>
|
|
|
|
|
+ <page-select :page="page" :count="nowCount" :total="nowTotal"></page-select>
|
|
|
|
|
+ <default-footer :lang="lang"/>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import langMap from "@/map/langMap";
|
|
import langMap from "@/map/langMap";
|
|
|
import productBanner from "@/components/banner/productBanner";
|
|
import productBanner from "@/components/banner/productBanner";
|
|
|
-
|
|
|
|
|
|
|
+import qs from "qs"
|
|
|
|
|
+import axios from "axios"
|
|
|
|
|
+import handle from "~/until/handle";
|
|
|
export default {
|
|
export default {
|
|
|
name: "index",
|
|
name: "index",
|
|
|
- props:['uLang','pType','pKey'],
|
|
|
|
|
|
|
+ props:['uLang','pType','pKey','pProduct'],
|
|
|
components:{
|
|
components:{
|
|
|
productBanner
|
|
productBanner
|
|
|
},
|
|
},
|
|
|
|
|
+ async asyncData(ctx){
|
|
|
|
|
+ // ctx.searchProduct();
|
|
|
|
|
+ const queryData = {};
|
|
|
|
|
+ // console.log(ctx)
|
|
|
|
|
+ queryData['key']=ctx.key;
|
|
|
|
|
+ queryData['type']=ctx.type;
|
|
|
|
|
+ queryData['page']=1;
|
|
|
|
|
+ // 获取数据
|
|
|
|
|
+ let url = 'http://szhfy.com.cn/api/searchProduct.php';
|
|
|
|
|
+ let [err,res] = await handle(axios.post(
|
|
|
|
|
+ url,
|
|
|
|
|
+ qs.stringify(queryData)
|
|
|
|
|
+ ));
|
|
|
|
|
+ if(err){
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
|
|
+ let result = res.data;
|
|
|
|
|
+ if(result.rcode === 1){
|
|
|
|
|
+ return {products:result.data}
|
|
|
|
|
+ }else{
|
|
|
|
|
+ console.error(result.msg);
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ return {products:[]}
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
data(){
|
|
data(){
|
|
|
return {
|
|
return {
|
|
|
lang: this.uLang?this.uLang:langMap.lang.cn,
|
|
lang: this.uLang?this.uLang:langMap.lang.cn,
|
|
|
type: this.pType?this.pType:'all',
|
|
type: this.pType?this.pType:'all',
|
|
|
key: this.pKey?this.pKey:'',
|
|
key: this.pKey?this.pKey:'',
|
|
|
page: 1,
|
|
page: 1,
|
|
|
- productTypes: [],
|
|
|
|
|
|
|
+ nowCount: 199,
|
|
|
|
|
+ nowTotal: 2,
|
|
|
|
|
+ products: this.pProduct?this.pProduct:[],
|
|
|
|
|
+ pageSave: {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
|
this.$root.$on('changeLang',this.switchLang);
|
|
this.$root.$on('changeLang',this.switchLang);
|
|
|
this.$root.$on('searchProductKey',this.changeProductKeyHandle);
|
|
this.$root.$on('searchProductKey',this.changeProductKeyHandle);
|
|
|
this.$root.$on('changeProductType',this.selectType);
|
|
this.$root.$on('changeProductType',this.selectType);
|
|
|
|
|
+ this.$root.$on('changePage',this.changePageHandle);
|
|
|
// this.loadData();
|
|
// this.loadData();
|
|
|
},
|
|
},
|
|
|
methods:{
|
|
methods:{
|
|
@@ -48,6 +86,7 @@ export default {
|
|
|
selectType(nextType){
|
|
selectType(nextType){
|
|
|
console.log(nextType)
|
|
console.log(nextType)
|
|
|
this.type = nextType;
|
|
this.type = nextType;
|
|
|
|
|
+ this.page = 1;
|
|
|
this.searchProduct();
|
|
this.searchProduct();
|
|
|
},
|
|
},
|
|
|
changeProductKeyHandle(key){
|
|
changeProductKeyHandle(key){
|
|
@@ -55,15 +94,82 @@ export default {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
this.key = key;
|
|
this.key = key;
|
|
|
|
|
+ this.page = 1;
|
|
|
|
|
+ this.searchProduct();
|
|
|
|
|
+ },
|
|
|
|
|
+ changePageHandle(nextPage){
|
|
|
|
|
+ this.page = nextPage;
|
|
|
this.searchProduct();
|
|
this.searchProduct();
|
|
|
},
|
|
},
|
|
|
async searchProduct(){
|
|
async searchProduct(){
|
|
|
- const formData = new FormData();
|
|
|
|
|
- formData.append('key',this.key);
|
|
|
|
|
- formData.append('type',this.type);
|
|
|
|
|
- formData.append('page',this.page);
|
|
|
|
|
|
|
+ // const formData = new FormData();
|
|
|
|
|
+ // formData.append('key',this.key);
|
|
|
|
|
+ // formData.append('type',this.type);
|
|
|
|
|
+ // formData.append('page',this.page);
|
|
|
|
|
+ const queryData = {};
|
|
|
|
|
+ // console.log(ctx)
|
|
|
|
|
+ queryData['key']=this.key;
|
|
|
|
|
+ queryData['type']=this.type;
|
|
|
|
|
+ queryData['page']=this.page;
|
|
|
// 获取数据
|
|
// 获取数据
|
|
|
- let [err,res] = await handle(this.$axios.get())
|
|
|
|
|
|
|
+ let url = '/api/searchProduct.php';
|
|
|
|
|
+ let data = qs.stringify(queryData);
|
|
|
|
|
+ let [err,res] = await handle(this.$axios.post(
|
|
|
|
|
+ url,
|
|
|
|
|
+ data
|
|
|
|
|
+ ));
|
|
|
|
|
+ if(err){
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ let result = res.data;
|
|
|
|
|
+ if(result.rcode === 1){
|
|
|
|
|
+ this.products = result.data;
|
|
|
|
|
+ this.loadPageData(data);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ console.error(result.msg);
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ async loadPageData(queryData){
|
|
|
|
|
+ let url = '/api/getProductPage.php';
|
|
|
|
|
+ // let
|
|
|
|
|
+ let err,res;
|
|
|
|
|
+ let pageData = null;
|
|
|
|
|
+ if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
|
|
|
|
|
+ pageData = this.pageSave[this.type][this.key]
|
|
|
|
|
+ }else{
|
|
|
|
|
+ [err,res] = await handle(this.$axios.post(
|
|
|
|
|
+ url,
|
|
|
|
|
+ queryData
|
|
|
|
|
+ ));
|
|
|
|
|
+ if(err){
|
|
|
|
|
+ console.error(err);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ let result = res.data;
|
|
|
|
|
+ if(result.rcode === 1){
|
|
|
|
|
+ pageData = result.data;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ console.error(result.msg);
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pageData){
|
|
|
|
|
+ this.nowTotal = Math.ceil(pageData.count / pageData.limit);
|
|
|
|
|
+ this.nowCount = pageData.count;
|
|
|
|
|
+ if(!this.pageSave[this.type]){
|
|
|
|
|
+ this.pageSave[this.type] = {}
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!this.pageSave[this.type][this.key]){
|
|
|
|
|
+ this.pageSave[this.type][this.key] = pageData;
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+ this.nowTotal = 1;
|
|
|
|
|
+ this.nowCount = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|