Square2.0.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div>
  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" @click="gotoHome" style="cursor: pointer">
  8. <img class="logo-img" src="../../assets/image/logo-transparent.png" />
  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 " class="">
  15. <el-tabs v-model="searchType" type="card" @tab-click="handleTypeClick">
  16. <el-tab-pane v-for="item in tabArr" :label="item.label" :name="item.name" :key="item.label"></el-tab-pane>
  17. </el-tabs>
  18. <div class="search-input">
  19. <el-input placeholder="请输入内容" v-model="searchVal" class="input-with-select" ref="searchInput">
  20. <el-button class="search-button" slot="append" type="primary" @click="handleSearchData">搜索</el-button>
  21. </el-input>
  22. </div>
  23. </div>
  24. </div>
  25. </el-col>
  26. <el-col :span="6">
  27. <el-button type="primary pull-right" class="releaseBtn" @click="checkLogin()">免费发布众测需求</el-button>
  28. </el-col>
  29. </el-row>
  30. <!--TabNav-->
  31. <el-tabs v-model="currTab" @tab-click="handleTabClick" class="square-tab" >
  32. <el-tab-pane v-for="item in menuArr" :name="item.name" :key="item.name">
  33. <span slot="label" style="font-size: 18px">{{item.label}}</span>
  34. </el-tab-pane>
  35. </el-tabs>
  36. <div>
  37. </div>
  38. </div>
  39. <div class="container">
  40. <el-row>
  41. <el-col :span="18" class="project-task">
  42. <el-row :gutter="15" style="margin-bottom: 10px">
  43. <el-col v-if="!projectAndTaskArr.length" style="text-align: center;padding: 5px 0"><span>暂无数据</span></el-col>
  44. <el-col :span="8" v-for="(item,index) in projectAndTaskArr" :key="index" style="margin-bottom: 15px">
  45. <SquareCard :card="item"></SquareCard>
  46. </el-col>
  47. </el-row>
  48. <el-pagination
  49. v-if="currTab!=='squareHome'&&projectAndTaskArr&&projectAndTaskArr.length"
  50. :page-size="12"
  51. layout="prev, pager, next"
  52. :total="totalElements"
  53. :current-page = "activePage"
  54. @current-change="handlePageChange"
  55. class="pull-right"
  56. >
  57. </el-pagination>
  58. </el-col>
  59. <el-col :span="6" class="popular-modules" style="padding-left: 15px">
  60. <PopularProject :hotCrowdTestProjectVOs="hotCrowdTestProjectVOs" style="margin-bottom: 15px"/>
  61. <PopularTask :hotCrowdTaskVOs="hotCrowdTaskVOs"/>
  62. </el-col>
  63. </el-row>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import Http from '@/js/http.js'
  69. import Apis from '@/js/api.js'
  70. import SearchBar from '../../components/commons/SearchBar'
  71. import SquareCard from './SquareCard'
  72. import PopularProject from './PopularProject'
  73. import PopularTask from './PopularTask'
  74. import {storageGet} from '@/js/index.js'
  75. import {notify} from "../../constants";
  76. export default {
  77. name: 'Square2.0',
  78. data(){
  79. return {
  80. user: {},
  81. isLogin: false,
  82. searchType:'project',
  83. searchVal: '',
  84. currTab:'squareHome',
  85. tabArr : [
  86. {label:"项目",name:"project"},
  87. {label:"任务",name:"task"}
  88. ],
  89. menuArr: [
  90. {label:"首页",name:"squareHome"},
  91. {label:"测试项目",name:"project"},
  92. {label:"测试任务",name:"task"}
  93. ],
  94. projectAndTaskArr:[],
  95. type: 0,
  96. hotCrowdTestProjectVOs:[],
  97. hotCrowdTaskVOs:[],
  98. activePage:1,
  99. totalElements:0
  100. }
  101. },
  102. components: {
  103. SearchBar,
  104. SquareCard,
  105. PopularProject,
  106. PopularTask
  107. },
  108. computed:{
  109. },
  110. methods:{
  111. gotoHome(){
  112. this.$router.push('/home');
  113. },
  114. handleTabClick(tab){
  115. console.log("handleTabClick ");
  116. this.currTab = tab.name
  117. this.activePage = 1;
  118. this.searchVal = '';
  119. this.searchData()
  120. },
  121. handleTabClickSearch(){
  122. this.activePage = 1;
  123. this.searchData()
  124. },
  125. searchData(index){
  126. if(this.currTab === 'squareHome'){
  127. this.getData();
  128. }else{
  129. this.searchType = this.currTab;
  130. this.handleSearchData();
  131. }
  132. },
  133. handleTypeClick(tab){
  134. this.searchType = tab.name;
  135. this.activePage = 1;
  136. this.$refs.searchInput.focus()
  137. },
  138. loadData(){
  139. if (storageGet('user') != null) {
  140. this.isLogin = true;
  141. }
  142. // this.projectAndTaskArr = this.$route.params.projectAndTaskArr;
  143. // this.type = this.$route.params.type;
  144. // 从首页项目搜索框跳转过来
  145. this.currTab = this.$route.params.currTab;
  146. if(this.currTab === "project"){
  147. this.searchVal = this.$route.params.searchVal;
  148. this.searchType = this.$route.params.searchType;
  149. this.getHotData();
  150. this.handleTabClickSearch();
  151. }
  152. // // 从热门项目和任务跳转过来
  153. // else if(this.type == 1){
  154. // console.log("type " + this.type);
  155. // this.getHotData();
  156. // }
  157. // 正常点击众测广场跳转过来
  158. else{
  159. this.searchVal = this.$route.params.searchVal;
  160. this.searchType = 'project';
  161. this.currTab = "squareHome"
  162. this.getData();
  163. }
  164. },
  165. getData(){
  166. Http.get('/api/square/list').then((res)=>{
  167. let crowdTestProjectVOs = res.data.crowdTestProjectVOs;
  168. let crowdTestTaskVOS = res.data.crowdTestTaskVOS;
  169. let projectAndTaskArr = crowdTestProjectVOs.concat(crowdTestTaskVOS);
  170. this.hotCrowdTestProjectVOs = res.data.hotCrowdTestProjectVOs;
  171. this.hotCrowdTaskVOs = res.data.hotCrowdTaskVOs;
  172. this.projectAndTaskArr = projectAndTaskArr;
  173. })
  174. },
  175. getHotData(){
  176. Http.get('/api/square/list').then((res)=>{
  177. this.hotCrowdTestProjectVOs = res.data.hotCrowdTestProjectVOs;
  178. this.hotCrowdTaskVOs = res.data.hotCrowdTaskVOs;
  179. })
  180. },
  181. checkLogin() {
  182. this.checkCreateProjectAuth();
  183. },
  184. checkCreateProjectAuth() {
  185. if (!this.isLogin) {
  186. console.log("请登录后访问");
  187. notify('warning', '请登录后访问');
  188. } else if (this.isLogin) {
  189. Http.get(Apis.USER.IS_PART.replace('{userId}', this.user.id)).then((res) => {
  190. this.$router.push('/project/create');
  191. }).catch((error) => {
  192. notify('error', error.data)
  193. })
  194. }
  195. },
  196. handleSearchData(){
  197. let url = '/api/square/search/list';
  198. let params = {
  199. "keyword": this.searchVal,//搜索关键字
  200. "activePage": this.activePage,//指定页面
  201. "columnFilters":
  202. [
  203. {
  204. "type": this.searchType // 查询项目就是project,任务就是task
  205. }
  206. ]
  207. };
  208. Http.post(url,params).then((res)=>{
  209. this.currTab = this.searchType;
  210. this.projectAndTaskArr = res.data.content;
  211. this.totalElements=res.data.totalElements;
  212. })
  213. },
  214. handlePageChange(index){
  215. this.activePage = index;
  216. this.searchData();
  217. },
  218. setUserInfo() {
  219. this.user = storageGet('user') && storageGet('user').userVO;
  220. }
  221. },
  222. mounted() {
  223. this.setUserInfo();
  224. this.loadData();
  225. }
  226. }
  227. </script>
  228. <style lang="scss">
  229. @import "../../style/search-nav.scss";
  230. .project-task {
  231. padding: 15px 0;
  232. .el-card {
  233. border: none;
  234. }
  235. }
  236. .popular-modules {
  237. padding: 15px 0 15px 15px;
  238. }
  239. </style>