index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="">
  3. <lucency-header :lang="lang" page-key="solution" />
  4. <item-banner :lang="lang" :title="`解决方案`" :sub-title="`专业,高效,稳定解决方案`"/>
  5. <solution-types :lang="lang" :type="type"></solution-types>
  6. <solution-list :lang="lang" :solution-list="solutions"></solution-list>
  7. <page-select :page="page" :count="nowCount" :total="nowTotal"></page-select>
  8. <default-footer :lang="lang"/>
  9. <site-bar wechat-src="/image/wechat.jpg"></site-bar>
  10. </div>
  11. </template>
  12. <script>
  13. import qs from "qs"
  14. import productBanner from "~/components/banner/productBanner";
  15. import itemBanner from "~/components/banner/itemBanner";
  16. import solutionTypes from "~/components/solutionTypes";
  17. import solutionList from "~/components/solutionList";
  18. import langMap from "~/map/langMap";
  19. import handle from "~/until/handle";
  20. import axios from "axios";
  21. const pageLimit = 5;
  22. export default {
  23. name: "solutionIndex",
  24. props:['uLang','pType','pKey','pSolution'],
  25. components:{
  26. productBanner,
  27. itemBanner,
  28. solutionTypes,
  29. solutionList
  30. },
  31. async asyncData(ctx){
  32. // ctx.searchProduct();
  33. const queryData = {};
  34. // console.log(ctx)
  35. queryData['key']=ctx.key;
  36. queryData['type']=ctx.type;
  37. queryData['page']=1;
  38. queryData['limit']=pageLimit;
  39. // 获取数据
  40. let url = 'http://szhfy.com.cn/api/searchSolution.php';
  41. let [err,res] = await handle(axios.post(
  42. url,
  43. qs.stringify(queryData)
  44. ));
  45. if(err){
  46. console.log(err);
  47. return {};
  48. }
  49. let result = res.data;
  50. if(result.rcode === 1){
  51. return {solutions:result.data}
  52. }else{
  53. console.error(result.msg);
  54. console.log(result);
  55. return {solutions:[]}
  56. }
  57. },
  58. data(){
  59. return {
  60. lang: this.uLang?this.uLang:langMap.lang.cn,
  61. type: this.pType?this.pType:'all',
  62. key: this.pKey?this.pKey:'',
  63. page: 1,
  64. nowCount: 199,
  65. nowTotal: 2,
  66. limit:pageLimit,
  67. solutions:this.pSolution?this.pSolution:[],
  68. pageSave: {
  69. }
  70. }
  71. },
  72. mounted() {
  73. this.$root.$on('changeLang',this.switchLang);
  74. this.$root.$on('changeSolutionType',this.selectType);
  75. this.$root.$on('changePage',this.changePageHandle);
  76. // this.$root.$on('changeProductType',this.selectType);
  77. const queryData = {};
  78. // console.log(ctx)
  79. queryData['key']=this.key;
  80. queryData['type']=this.type;
  81. queryData['page']=this.page;
  82. queryData['limit']=this.limit;
  83. let data = qs.stringify(queryData);
  84. this.loadPageData(data);
  85. },
  86. methods:{
  87. switchLang(nextLang){
  88. if(nextLang){
  89. this.lang = nextLang;
  90. }else{
  91. if(this.lang === langMap.lang.cn){
  92. this.lang = langMap.lang.en
  93. }else{
  94. this.lang = langMap.lang.cn
  95. }
  96. }
  97. },
  98. selectType(nextType){
  99. console.log(nextType)
  100. this.type = nextType;
  101. this.page = 1;
  102. this.searchSolution();
  103. },
  104. changePageHandle(nextPage){
  105. this.page = nextPage;
  106. this.searchSolution();
  107. },
  108. async searchSolution(){
  109. // const formData = new FormData();
  110. // formData.append('key',this.key);
  111. // formData.append('type',this.type);
  112. // formData.append('page',this.page);
  113. const queryData = {};
  114. // console.log(ctx)
  115. queryData['key']=this.key;
  116. queryData['type']=this.type;
  117. queryData['page']=this.page;
  118. queryData['limit']=this.limit;
  119. // 获取数据
  120. let url = '/api/searchSolution.php';
  121. let data = qs.stringify(queryData);
  122. let [err,res] = await handle(this.$axios.post(
  123. url,
  124. data
  125. ));
  126. if(err){
  127. console.log(err);
  128. return null;
  129. }
  130. let result = res.data;
  131. console.log(result)
  132. if(result.rcode === 1){
  133. this.solutions = result.data?result.data:[];
  134. this.loadPageData(data);
  135. }else{
  136. console.error(result.msg);
  137. console.log(result);
  138. }
  139. },
  140. async loadPageData(queryData){
  141. let url = '/api/getSolutionPage.php';
  142. // let
  143. let err,res;
  144. let pageData = null;
  145. if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
  146. pageData = this.pageSave[this.type][this.key]
  147. }else{
  148. [err,res] = await handle(this.$axios.post(
  149. url,
  150. queryData
  151. ));
  152. if(err){
  153. console.error(err);
  154. }else{
  155. let result = res.data;
  156. if(result.rcode === 1){
  157. pageData = result.data?result.data:{};
  158. }else{
  159. console.error(result.msg);
  160. console.log(result);
  161. }
  162. }
  163. }
  164. if (pageData){
  165. this.nowTotal = Math.ceil(pageData.count / pageData.limit);
  166. this.nowCount = pageData.count;
  167. if(!this.pageSave[this.type]){
  168. this.pageSave[this.type] = {}
  169. }
  170. if(!this.pageSave[this.type][this.key]){
  171. this.pageSave[this.type][this.key] = pageData;
  172. }
  173. }else{
  174. this.nowTotal = 1;
  175. this.nowCount = 1;
  176. }
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped>
  182. </style>