xiangpei
2024-05-22 e81ae1ff5e83f6c8a315c3f6b99221308b7ceb44
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" :inline="true">
      <el-form-item label="问答内容:">
        <el-input v-model="queryParam.question" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <div style="display: flex">
          <el-button type="primary" @click="submitForm">查询</el-button>
          <router-link :to="{ path: '/edit' }" class="link-left">
            <el-button type="primary">添加</el-button>
          </router-link>
        </div>
      </el-form-item>
    </el-form>
 
    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="question" label="问题" />
      <el-table-column prop="answer" label="回答" />
      <el-table-column prop="attachment" label="附件" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-for="item in getUrl(scope.row.attachment)" :key="item.url">
            <el-link :underline="false" type="primary" :href="'/api/upload/download?url=' + item.url +'&fileName=' + item.name" >{{ item.name }}</el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" width="70px">
        <template slot-scope="{row}">
          <el-tag :type="row.status !== '启用' ? 'danger' : 'success'">
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column width="270px" label="操作" align="center">
        <template slot-scope="{row}">
          <el-button size="mini" @click="changeStatus(row)" class="link-left">
            {{ row.status !== '启用' ? '启用' : '禁用' }}
          </el-button>
          <router-link :to="{ path: '/edit', query: { id: row.id } }" class="link-left">
            <el-button size="mini">编辑</el-button>
          </router-link>
          <el-popconfirm title="确认删除" @confirm="deleteUser(row)">
            <el-button slot="reference" size="mini" type="danger" class="link-left">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
      @pagination="search" />
  </div>
</template>
 
<script>
import { mapGetters, mapState } from 'vuex'
import Pagination from '@/components/Pagination'
import questionAnswerApi from '@/api/questionAnswer'
 
export default {
  components: { Pagination },
  data() {
    return {
      queryParam: {
        question: '',
        role: 1,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created() {
    this.search()
  },
  methods: {
    getUrl(urlJson) {
      return urlJson ? JSON.parse(urlJson) : [];
    },
    search() {
      this.listLoading = true
      questionAnswerApi.pageList(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
      })
    },
    changeStatus(row) {
      let _this = this
      questionAnswerApi.updateStatus(row.id).then(re => {
        if (re.code === 1) {
          _this.search();
          _this.$message.success(re.message)
        } else {
          _this.$message.error(re.message)
        }
      })
    },
    deleteUser(row) {
      questionAnswerApi.delete(row.id).then(re => {
        if (re.code === 1) {
          this.search()
          this.$message.success(re.message)
        } else {
          this.$message.error(re.message)
        }
      })
    },
    submitForm() {
      this.queryParam.pageIndex = 1
      this.search()
    },
    statusFormatter(status) {
      return this.enumFormat(this.statusEnum, status)
    },
    statusTagFormatter(status) {
      return this.enumFormat(this.statusTag, status)
    },
    statusBtnFormatter(status) {
      return this.enumFormat(this.statusBtn, status)
    }
 
  },
  computed: {
    ...mapGetters('enumItem', [
      'enumFormat'
    ]),
    ...mapState('enumItem', {
      sexEnum: state => state.user.sexEnum,
      statusEnum: state => state.user.statusEnum,
      statusTag: state => state.user.statusTag,
      statusBtn: state => state.user.statusBtn,
      levelEnum: state => state.user.levelEnum
    })
  }
}
</script>
<style lang="scss" scoped>
.upload-demo {
  margin-left: 5px;
}
</style>