index.vue 5.1 KB

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