index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
  4. <el-form-item label="问题描述" prop="description">
  5. <el-input
  6. v-model="queryParams.description"
  7. placeholder="请输入问题描述"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item prop="createTime">
  13. <el-date-picker
  14. v-model="queryParams.createTime"
  15. value-format="yyyy-MM-dd"
  16. type="date"
  17. placeholder="选择日期">
  18. </el-date-picker>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  22. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-row :gutter="10" class="mb8">
  26. <el-col :span="1.5">
  27. <el-button
  28. type="danger"
  29. icon="el-icon-delete"
  30. size="mini"
  31. :disabled="multiple"
  32. @click="handleDelete"
  33. >删除</el-button>
  34. </el-col>
  35. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  36. </el-row>
  37. <el-table v-loading="loading" :data="issueList" @selection-change="handleSelectionChange">
  38. <el-table-column type="selection" width="55" align="center" />
  39. <el-table-column label="序号" width="50">
  40. <template slot-scope="scope">
  41. {{(scope.$index + 1) + ((queryParams.pageNum - 1) * queryParams.pageSize)}}
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="问题名称" align="center" prop="title" />
  45. <el-table-column label="问题描述" align="center" prop="description" />
  46. <el-table-column label="上报人" align="center" prop="person" />
  47. <el-table-column label="问题状态" align="center">
  48. <template slot-scope="scope">
  49. <span v-if="scope.row.status == 1" style="color: #42b983">●已解决</span>
  50. <span v-if="scope.row.status == 0" style="color: #C03639">●待解决</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="创建时间" align="center" prop="createTime" />
  54. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
  55. <template slot-scope="scope">
  56. <el-button
  57. size="mini"
  58. type="text"
  59. icon="el-icon-edit"
  60. @click="handleUpdate(scope.row)"
  61. >查看</el-button>
  62. <el-button
  63. size="mini"
  64. type="text"
  65. icon="el-icon-delete"
  66. @click="handleDelete(scope.row)"
  67. >删除</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination
  72. v-show="total>0"
  73. :total="total"
  74. :page.sync="queryParams.pageNum"
  75. :limit.sync="queryParams.pageSize"
  76. @pagination="getList"
  77. />
  78. <!-- 添加或修改上报问题对话框 -->
  79. <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="800px" append-to-body>
  80. <el-form ref="form" :model="form" label-width="80px">
  81. <el-form-item label="所属项目" prop="projectId">
  82. <el-input v-model="form.projectName" readonly/>
  83. </el-form-item>
  84. <el-form-item label="问题名称" prop="title">
  85. <el-input v-model="form.title" readonly/>
  86. </el-form-item>
  87. <el-form-item label="上报人" prop="person">
  88. <el-input v-model="form.person" readonly/>
  89. </el-form-item>
  90. <el-form-item label="问题描述" prop="description">
  91. <el-input type="textarea" v-model="form.description" readonly/>
  92. </el-form-item>
  93. <el-form-item label="整改要求" prop="need">
  94. <el-input type="textarea" v-model="form.need" readonly/>
  95. </el-form-item>
  96. <el-form-item label="附件" prop="imagePath">
  97. <el-button @click="downloadSth(form.imagePath)" v-if="form.imagePath != null" type="info">下载附件</el-button>
  98. </el-form-item>
  99. </el-form>
  100. <div slot="footer" class="dialog-footer">
  101. <!-- <el-button type="primary" @click="submitForm">确 定</el-button>-->
  102. <!-- <el-button @click="cancel">取 消</el-button>-->
  103. </div>
  104. </el-dialog>
  105. </div>
  106. </template>
  107. <script>
  108. import { addIssue, delIssue, downloadFile, getIssue, listIssue, updateIssue } from '@/api/zcustom/issue'
  109. import { listProject } from '@/api/zcustom/project'
  110. export default {
  111. name: "Issue",
  112. data() {
  113. return {
  114. // 根路径
  115. baseURL: process.env.VUE_APP_BASE_API,
  116. // 遮罩层
  117. loading: true,
  118. // 选中数组
  119. ids: [],
  120. // 非单个禁用
  121. single: true,
  122. // 非多个禁用
  123. multiple: true,
  124. // 显示搜索条件
  125. showSearch: true,
  126. // 总条数
  127. total: 0,
  128. // 上报问题表格数据
  129. issueList: [],
  130. projectList: [],
  131. // 弹出层标题
  132. title: "",
  133. // 是否显示弹出层
  134. open: false,
  135. // 查询参数
  136. queryParams: {
  137. pageNum: 1,
  138. pageSize: 10,
  139. description: null,
  140. projectId: null,
  141. status: null,
  142. createTime: null
  143. },
  144. // 表单参数
  145. form: {},
  146. // 表单校验
  147. rules: {
  148. description: [
  149. { required: true, message: "问题描述不能为空", trigger: "blur" }
  150. ],
  151. need: [
  152. { required: true, message: "整改要求不能为空", trigger: "blur" }
  153. ],
  154. title: [
  155. { required: true, message: "问题名称不能为空", trigger: "blur" }
  156. ],
  157. projectId: [
  158. { required: true, message: "所属项目不能为空", trigger: "blur" }
  159. ],
  160. }
  161. };
  162. },
  163. created() {
  164. this.getList();
  165. this.getPrjList()
  166. },
  167. methods: {
  168. /** 查询上报问题列表 */
  169. getList() {
  170. this.loading = true;
  171. listIssue(this.queryParams).then(response => {
  172. console.log(response)
  173. this.issueList = response.data;
  174. this.total = response.data.length;
  175. this.loading = false;
  176. });
  177. },
  178. getPrjList() {
  179. listProject().then(response => {
  180. this.projectList = response.data.records;
  181. });
  182. },
  183. // 取消按钮
  184. cancel() {
  185. this.open = false;
  186. this.reset();
  187. },
  188. // 表单重置
  189. reset() {
  190. this.form = {
  191. id: null,
  192. description: null,
  193. projectId: null,
  194. projectName: null,
  195. status: "0",
  196. delFlag: null,
  197. };
  198. this.resetForm("form");
  199. },
  200. /** 搜索按钮操作 */
  201. handleQuery() {
  202. this.queryParams.pageNum = 1;
  203. this.getList();
  204. },
  205. /** 重置按钮操作 */
  206. resetQuery() {
  207. this.resetForm("queryForm");
  208. this.handleQuery();
  209. },
  210. // 多选框选中数据
  211. handleSelectionChange(selection) {
  212. this.ids = selection.map(item => item.id)
  213. this.single = selection.length!==1
  214. this.multiple = !selection.length
  215. },
  216. /** 新增按钮操作 */
  217. handleAdd() {
  218. this.reset();
  219. this.open = true;
  220. this.title = "添加上报问题";
  221. },
  222. /** 修改按钮操作 */
  223. handleUpdate(row) {
  224. this.reset();
  225. const id = row.id || this.ids
  226. getIssue(id).then(response => {
  227. this.form = response.data;
  228. this.open = true;
  229. this.title = "问题详情";
  230. });
  231. },
  232. /** 提交按钮 */
  233. submitForm() {
  234. this.$refs["form"].validate(valid => {
  235. if (valid) {
  236. if (this.form.id != null) {
  237. updateIssue(this.form).then(response => {
  238. this.$modal.msgSuccess("修改成功");
  239. this.open = false;
  240. this.getList();
  241. });
  242. } else {
  243. addIssue(this.form).then(response => {
  244. this.$modal.msgSuccess("新增成功");
  245. this.open = false;
  246. this.getList();
  247. });
  248. }
  249. }
  250. });
  251. },
  252. /** 删除按钮操作 */
  253. handleDelete(row) {
  254. const ids = row.id || this.ids;
  255. this.$modal.confirm('是否确认删除?').then(function() {
  256. return delIssue(ids);
  257. }).then(() => {
  258. this.getList();
  259. this.$modal.msgSuccess("删除成功");
  260. }).catch(() => {});
  261. },
  262. downloadSth(imagePath){
  263. return downloadFile(imagePath).then(response => {
  264. // 解析返回的文件流并触发下载
  265. const blob = new Blob([response], { type: 'application/octet-stream' });
  266. const url = window.URL.createObjectURL(blob);
  267. const link = document.createElement('a');
  268. link.href = url;
  269. // 设置下载文件名(从文件路径中提取文件名)
  270. const fileName = imagePath.split('/').pop();
  271. link.download = fileName; // 设置下载的文件名
  272. link.click(); // 触发点击事件,下载文件
  273. window.URL.revokeObjectURL(url); // 释放 URL 对象,防止内存泄漏
  274. }).catch(error => {
  275. console.error('文件下载失败:', error);
  276. });
  277. }
  278. }
  279. };
  280. </script>