杨磊
4 天以前 ef37c59e055a990ce247b265b27d3fcef430a243
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
  <div class="contentBox">
    <div class="crumbs">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ name: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>搜索结果</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-row>
      <el-button
        size="small"
        :type="defaultType == 1 ? 'primary' : ''"
        @click="switchType(1)"
        >教学服务</el-button
      >
      <el-button
        size="small"
        :type="defaultType == 2 ? 'primary' : ''"
        @click="switchType(2)"
        >书城</el-button
      >
    </el-row>
    <List
      :channel="channel"
      :searchFields="searchFields"
      :searchValue="searchValue"
      :detailRoute="detailRoute"
    ></List>
  </div>
</template>
<script>
import List from "@/components/list/data";
export default {
  name: "search",
  components: {
    List,
  },
  data() {
    return {
      searchFields: "",
      detailRoute: "bookStore-detail",
      channel: "caupress_bookMall",
      defaultType: 2, // 默认搜索书城
      searchValue: "",
    };
  },
  created() {
    this.searchValue = this.$route.query.searchValue;
  },
  methods: {
    switchType(type) {
      if (type == 1) {
        this.defaultType = 1;
        this.channel = "caupress_teachingResource";
        this.detailRoute = "teachingServices-detail";
      } else {
        this.defaultType = 2;
        this.channel = "caupress_bookMall";
        this.detailRoute = "bookStore-detail";
      }
    },
  },
  watch: {
    $route: {
      handler: function (val, oldval) {
        if (val.name == "search") {
          if (this.searchValue != this.$route.query.searchValue) {
            this.searchValue = this.$route.query.searchValue;
          }
          // 如果搜索的选项卡位于教学服务,则默认搜索教学服务
          if (this.$route.query.searchPath == "caupress_teachingResource") {
            this.switchType(1);
          }
          switch (this.$route.query.searchType) {
            case "bookName":
              this.searchFields = "Name";
              break;
            case "isbn":
              this.searchFields = "caupress_ISBN";
              break;
            case "author":
              this.searchFields = "caupress_author";
              break;
            case "projectTitle":
              this.searchFields = "caupress_projectTitle";
              break;
          }
        }
      },
      immediate: true,
      deep: true,
    },
  },
  // 如果跳转页面不是详情,则将当前页面不缓存
  beforeRouteLeave(to, from, next) {
    if (to.name != "teachingServices-detail" && to.name != "bookStore-detail") {
      this.$store.commit("delKeepAlive", from.name);
    }
    next();
  },
};
</script>
<style lang="less" scoped>
.contentBox {
  padding-bottom: 120px;
 
  .el-row {
    margin-bottom: 10px;
  }
 
  .crumbs {
    padding: 35px 0 25px 0;
    line-height: 70px;
  }
}
</style>