index.vue 4.9 KB

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