index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. import LucencyHeader from "~/components/header/lucencyHeader.vue";
  23. import DefaultFooter from "~/components/footer/defaultFooter.vue";
  24. import {apiMap, baseUrl} from "~/map/apiMap";
  25. const pageLimit = 5;
  26. export default {
  27. name: "solutionIndex",
  28. props:['uLang','pType','pKey','pSolution','pPageData'],
  29. components:{
  30. DefaultFooter,
  31. LucencyHeader,
  32. productBanner,
  33. itemBanner,
  34. solutionTypes,
  35. solutionList
  36. },
  37. head(){
  38. return {
  39. title: `合方圆-解决方案`,
  40. meta: [
  41. { hid: 'description', name: 'description', content: `合方圆-解决方案` },
  42. { hid: 'keywords', name: 'keywords', content: `合方圆-解决方案,合方圆科技-解决方案,` },
  43. ]
  44. }
  45. },
  46. async asyncData(ctx){
  47. // 获取数据
  48. let url = baseUrl + apiMap.searchSolution.path;
  49. url += `?type=all&p=1&l=5`
  50. let [err,res] = await handle(axios.get( url));
  51. if(err){
  52. console.log(err);
  53. return {};
  54. }
  55. let result = res.data;
  56. if(result.code === 1){
  57. let pageData = {
  58. limit: result.limit,
  59. page: result.page,
  60. total: result.total,
  61. count: result.count,
  62. }
  63. return {
  64. solutions: result.data,
  65. basePageData: pageData,
  66. }
  67. }else{
  68. console.error(result.msg);
  69. console.log(result);
  70. return {solutions:[]}
  71. }
  72. },
  73. data(){
  74. return {
  75. lang: this.uLang?this.uLang:langMap.lang.cn,
  76. type: this.pType?this.pType:'all',
  77. key: this.pKey?this.pKey:'',
  78. page: 1,
  79. nowCount: 199,
  80. nowTotal: 2,
  81. limit:pageLimit,
  82. solutions:this.pSolution?this.pSolution:[],
  83. basePageData: {},
  84. pageSave: {},
  85. isPhone: false
  86. }
  87. },
  88. beforeMount() {
  89. let pageData;
  90. if (this.pPageData){
  91. this.basePageData = this.pPageData
  92. }
  93. pageData = this.basePageData;
  94. this.updatePageData(pageData);
  95. },
  96. mounted() {
  97. this.isPhone = isMediaView(0,1024);
  98. this.$root.$on('changeLang',this.switchLang);
  99. this.$root.$on('changeSolutionType',this.selectType);
  100. this.$root.$on('changePage',this.changePageHandle);
  101. // this.$root.$on('changeProductType',this.selectType);
  102. },
  103. methods:{
  104. switchLang(nextLang){
  105. if(nextLang){
  106. this.lang = nextLang;
  107. }else{
  108. if(this.lang === langMap.lang.cn){
  109. this.lang = langMap.lang.en
  110. }else{
  111. this.lang = langMap.lang.cn
  112. }
  113. }
  114. },
  115. selectType(nextType){
  116. console.log(nextType)
  117. this.type = nextType;
  118. this.page = 1;
  119. this.searchSolution();
  120. },
  121. changePageHandle(nextPage){
  122. this.page = nextPage;
  123. this.searchSolution();
  124. },
  125. async searchSolution(){
  126. // 获取数据
  127. let url = apiMap.searchSolution.path;
  128. url += `?key=${this.key}&type=${this.type}&p=${this.page}&l=5`
  129. let [err,res] = await handle(axios.get(url));
  130. if(err){ console.log(err); return null; }
  131. let result = res.data;
  132. if(result.code === 1){
  133. this.solutions = result.data;
  134. let pageData;
  135. if(result.total){
  136. // 更新页面信息
  137. pageData = {
  138. limit: result.limit,
  139. page: result.page,
  140. total: result.total,
  141. count: result.count,
  142. }
  143. }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
  144. pageData = this.pageSave[this.type][this.key]
  145. }
  146. this.updatePageData(pageData);
  147. }else{
  148. console.error(result.msg);
  149. console.log(result);
  150. }
  151. },
  152. updatePageData(pageData){
  153. if(!this.pageSave[this.type]){
  154. this.pageSave[this.type] = {}
  155. }
  156. if(!this.pageSave[this.type][this.key]){
  157. this.pageSave[this.type][this.key] = pageData;
  158. }
  159. let nowTotal = Math.ceil(pageData.total / pageData.limit);
  160. let nowCount = pageData.total;
  161. this.nowTotal = nowTotal;
  162. this.nowCount = nowCount;
  163. }
  164. }
  165. }
  166. </script>
  167. <style scoped>
  168. </style>