index.vue 4.6 KB

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