Homepage.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="home-wrapper">
  3. <div class="nav" stype="height:500px">
  4. <!--搜索框-->
  5. <el-row class="search-nav" style="padding: 30px 0 20px 0">
  6. <el-col :span="6">
  7. <div class="pull-left">
  8. <img class="logo-img" src="../../assets/image/logo-transparent.png" :to="'/home'"/>
  9. <span class="logo-title">群智众测平台</span>
  10. </div>
  11. </el-col>
  12. <el-col :span="12">
  13. <div class="search-nav">
  14. <div id="search-block ">
  15. <el-tabs v-model="searchType" type="card" @tab-click="handleTypeClick">
  16. <el-tab-pane v-for="item in searchTypeArr" v-if="item.value!=='all'" :label="item.name"
  17. :name="item.value" :key="item.value"></el-tab-pane>
  18. </el-tabs>
  19. <div class="search-input">
  20. <el-input ref="searchInput" placeholder="请输入内容" v-model="searchVal" class="input-with-select">
  21. <el-button class="search-button" slot="append" type="primary" @click="handleSearchData">搜索</el-button>
  22. </el-input>
  23. </div>
  24. </div>
  25. </div>
  26. </el-col>
  27. <el-col :span="6">
  28. <el-button type="primary pull-right" class="releaseBtn" @click="checkLogin()">免费发布众测需求</el-button>
  29. </el-col>
  30. </el-row>
  31. <!--TabNav-->
  32. <el-tabs v-model="currTab" @tab-click="handleTabClick" class="square-tab">
  33. <el-tab-pane v-for="item in homeTabArr.menuArr1" :label="item.label" :name="item.name"
  34. :key="item.name"></el-tab-pane>
  35. <el-tab-pane v-for="item in homeTabArr.menuArr2" :label="item.name" :name="item.code"
  36. :key="item.code"></el-tab-pane>
  37. <el-tab-pane v-for="item in homeTabArr.menuArr3" :label="item.label" :name="item.name"
  38. :key="item.name"></el-tab-pane>
  39. </el-tabs>
  40. <div>
  41. </div>
  42. </div>
  43. <div class="home-page container" >
  44. <el-row>
  45. <el-col :span="19" class="test-type-wrapper">
  46. <TestMenu :testTypeList="homeData.testTypeList"></TestMenu>
  47. <TestCard :applicationTypeList="homeData.applicationTypeList"></TestCard>
  48. <el-row style="margin-top: 10px">
  49. <ResourceAndTool :resourceList="homeDataNoCache.resourceList"></ResourceAndTool>
  50. </el-row>
  51. <el-row>
  52. <BrandCard :residentAgencyList=homeData.residentAgencyList></BrandCard>
  53. </el-row>
  54. </el-col>
  55. <el-col :span="5" class="homepage-right-modules">
  56. <LoginCard/>
  57. <HotCrowd :applicationTypeRank="homeDataNoCache.applicationTypeRank"/>
  58. <HotAgency :agencyRank="homeDataNoCache.agencyRank"/>
  59. <HotUser :userRank="homeDataNoCache.userRank"/>
  60. <HotContest :competitionList="homeData.competitionList"/>
  61. </el-col>
  62. </el-row>
  63. <InstitutionCard></InstitutionCard>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. // import commonData from '../../constants/tabMenu'
  69. import SearchBar from '../../components/commons/SearchBar'
  70. import TestMenu from './TestMenu'
  71. import LoginCard from './LoginCard'
  72. import BrandCard from './BrandCard'
  73. import ResourceAndTool from './ResourceAndTool'
  74. import TestCard from './TestCard'
  75. import InstitutionCard from './InstitutionCard'
  76. import HotCrowd from './HotCrowd'
  77. import HotAgency from './HotAgency'
  78. import HotUser from './HotUser'
  79. import HotContest from './HotContest'
  80. import PopularProject from '../Square/PopularProject'
  81. import Http from '@/js/http.js'
  82. import {mapGetters} from 'vuex'
  83. import Waterfall from 'vue-waterfall/lib/waterfall'
  84. import WaterfallSlot from 'vue-waterfall/lib/waterfall-slot'
  85. import {getAllFields, storageGet} from '@/js/index.js'
  86. import {notify} from "../../constants";
  87. import Apis from '@/js/api'
  88. // console.log(commonData);
  89. export default {
  90. name: 'Homepage',
  91. components: {
  92. HotCrowd,
  93. HotContest,
  94. HotUser,
  95. HotAgency,
  96. InstitutionCard,
  97. SearchBar,
  98. TestMenu,
  99. PopularProject,
  100. LoginCard,
  101. TestCard,
  102. BrandCard,
  103. ResourceAndTool,
  104. Waterfall,
  105. WaterfallSlot
  106. // vueWaterfallEasy
  107. },
  108. data() {
  109. return {
  110. user: {},
  111. isLogin: false,
  112. loading: false,
  113. searchType: '0',
  114. searchTypeArr: [
  115. {
  116. "name": "全部",
  117. "value": "all"
  118. },
  119. {
  120. "name": "项目",
  121. "value": "0"
  122. },
  123. {
  124. "name": "机构",
  125. "value": "1"
  126. },
  127. {
  128. "name": "资源",
  129. "value": "2"
  130. },
  131. {
  132. "name": "专家",
  133. "value": "3"
  134. }],
  135. searchVal: '',
  136. homeTabArr: {
  137. menuArr1: [
  138. {label: "首页", name: "homepage", linkTo: '/home'},
  139. {label: "众测广场", name: "square", linkTo: '/square'},
  140. {label: "众测技术", name: "technology", linkTo: 'technology'}
  141. ],
  142. menuArr2: [
  143. {code: '', name: ''}
  144. ],
  145. menuArr3: [
  146. {label: "找机构", name: "findInstitution", linkTo: '/agency/list/show'},
  147. {label: "找专家", name: "findExpert", linkTo: '/expert/list'},
  148. ],
  149. },
  150. homeData: {},
  151. homeDataNoCache: {},
  152. currTab: 'homepage'
  153. }
  154. },
  155. computed: {
  156. ...mapGetters(['getUserInfo'])
  157. },
  158. methods: {
  159. loadData() {
  160. this.showLoading();
  161. if (storageGet('user') != null) {
  162. this.isLogin = true;
  163. }
  164. this.setFields();
  165. let p1 = new Promise((resolve, reject) => {
  166. Http.get('/api/common/index/info/cache').then((res) => {
  167. this.homeData = res.data;
  168. // this.homeData.applicationTypeList.map((item)=>{
  169. // item.height = (item.testTypeList.length / 2) * 24 + 100;
  170. // return item;
  171. // })
  172. resolve(res.data);
  173. }).catch((error) => {
  174. notify('error', error.data)
  175. reject(error)
  176. })
  177. });
  178. let p2 = new Promise((resolve, reject) => {
  179. Http.get('/api/common/index/info/nocache').then((res) => {
  180. this.homeDataNoCache = res.data;
  181. resolve(res.data);
  182. }).catch((error) => {
  183. notify('error', error.data)
  184. reject(error)
  185. })
  186. });
  187. Promise.all([p1, p2]).then((result) => {
  188. this.hideLoading();
  189. }).catch((error) => {
  190. notify('error', error.data)
  191. })
  192. },
  193. setFields() {
  194. getAllFields().then((res) => {
  195. this.homeTabArr.menuArr2 = res
  196. })
  197. },
  198. checkLogin() {
  199. this.checkCreateProjectAuth();
  200. },
  201. checkCreateProjectAuth() {
  202. if (!this.isLogin) {
  203. notify('warning', '请登录后访问');
  204. } else if (this.isLogin) {
  205. Http.get(Apis.USER.IS_PART.replace('{userId}', this.user.id)).then((res) => {
  206. this.$router.push('/project/create');
  207. }).catch((error) => {
  208. notify('error', error)
  209. })
  210. }
  211. },
  212. handleTabClick(tab) {
  213. this.currTab = tab.name;
  214. // console.log(this.currTab + " " + tab.index + " " + tab.name );
  215. for (let i = 0; i < this.homeTabArr.menuArr3.length; i++) {
  216. if (this.currTab === this.homeTabArr.menuArr3[i].name) {
  217. this.$router.push(this.homeTabArr.menuArr3[i].linkTo);
  218. }
  219. }
  220. for (let i = 0; i < this.homeTabArr.menuArr2.length; i++) {
  221. if (this.currTab === this.homeTabArr.menuArr2[i].code) {
  222. this.$router.push('/field/detail');
  223. }
  224. }
  225. this.$router.push(this.homeTabArr.menuArr1[Number(tab.index)]&&this.homeTabArr.menuArr1[Number(tab.index)].linkTo);
  226. },
  227. handleTypeClick(tab,e) {
  228. this.searchType = tab.name;
  229. // e.target.style.backgroundColor = $color-primary
  230. this.$refs.searchInput.focus()
  231. },
  232. handleSearchData() {
  233. if (this.searchType == 0) {
  234. this.$router.push({
  235. name: 'Square',
  236. params: {searchVal: this.searchVal, searchType: "project", currTab: "project"}
  237. });
  238. } else if (this.searchType == 1) {
  239. this.$router.push({name: 'AgencyList', params: {searchVal: this.searchVal}});
  240. } else if (this.searchType == 2) {
  241. this.$router.push({name: 'ResourceList', params: {searchVal: this.searchVal}});
  242. } else if (this.searchType == 3) {
  243. this.$router.push({name: 'ExpertList', params: {searchVal: this.searchVal}});
  244. }
  245. },
  246. showLoading() {
  247. this.loading = true
  248. },
  249. hideLoading() {
  250. this.loading = false
  251. },
  252. setUserInfo() {
  253. this.user = storageGet('user') && storageGet('user').userVO;
  254. }
  255. },
  256. mounted(){
  257. this.setUserInfo();
  258. this.loadData();
  259. this.$refs.searchInput.focus()
  260. },
  261. watch:{
  262. getUserInfo(val){
  263. this.setUserInfo();
  264. this.loadData();
  265. }
  266. }
  267. }
  268. </script>
  269. <style lang="scss">
  270. @import "../../style/search-nav.scss";
  271. .home-wrapper {
  272. /deep/ .square-tab .el-tabs__item {
  273. font-size: 16px !important;
  274. margin-right: 0px !important;
  275. }
  276. /deep/ .login-card .popular-list {
  277. padding: 0 10px !important;
  278. }
  279. .home-page {
  280. padding: 15px 0;
  281. }
  282. .test-type-wrapper {
  283. padding-right: 15px;
  284. margin-bottom: 15px;
  285. }
  286. .homepage-right-modules {
  287. .login-card .el-card__body {
  288. padding: 10px !important;
  289. }
  290. .popular-card .el-card__header {
  291. padding: 10px !important;
  292. }
  293. .popular-card .el-card__body {
  294. padding: 10px !important;
  295. }
  296. }
  297. }
  298. </style>