index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <div class="app-container" style="padding: 0px;">
  3. <span>
  4. <div class="head-container">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入章节名称"
  8. clearable
  9. size="small"
  10. prefix-icon="el-icon-search"
  11. style="margin-bottom: 20px"
  12. />
  13. </div>
  14. <div class="head-container">
  15. <el-table
  16. ref="chapterList"
  17. v-loading="loading"
  18. :data="chapterList"
  19. style="margin-bottom: 20px"
  20. border
  21. class="menuTable"
  22. @row-click="handleNodeClick"
  23. :show-header="false">
  24. <el-table-column align="center" prop="code" width="50" :show-overflow-tooltip="true"/>
  25. <el-table-column align="center" prop="name"/>
  26. </el-table>
  27. </div>
  28. </span>
  29. </div>
  30. </template>
  31. <script>
  32. import { listChapter, getChapter, delChapter, addChapter, updateChapter } from "@/api/rc/chapter";
  33. import { listDept } from "@/api/system/dept";
  34. export default {
  35. name: "Chapter",
  36. data() {
  37. return {
  38. // 遮罩层
  39. loading: true,
  40. // 选中数组
  41. ids: [],
  42. // 非单个禁用
  43. single: true,
  44. // 非多个禁用
  45. multiple: true,
  46. // 显示搜索条件
  47. showSearch: true,
  48. // 总条数
  49. total: 0,
  50. // 章节表格数据
  51. chapterList: [],
  52. // 弹出层标题
  53. title: "",
  54. // 是否显示弹出层
  55. open: false,
  56. // 查询参数
  57. queryParams: {
  58. pageNum: 1,
  59. pageSize: 10,
  60. auditId: null,
  61. code: null,
  62. name: null,
  63. deptId: null
  64. },
  65. // 表单参数
  66. form: {},
  67. // 表单校验
  68. rules: {
  69. },
  70. // 装置列表
  71. deptOptions: [],
  72. };
  73. },
  74. created() {
  75. // this.getList();
  76. this.getDeptList();
  77. },
  78. methods: {
  79. // 节点单击事件
  80. handleNodeClick(row) {
  81. this.$emit('questionnaire', row.id);
  82. },
  83. /** 查询章节列表 */
  84. getList(auditId) {
  85. this.loading = true;
  86. if (auditId != null) {
  87. this.queryParams.auditId = auditId;
  88. }
  89. listChapter(this.queryParams).then(response => {
  90. this.chapterList = response.data;
  91. this.total = response.total;
  92. this.loading = false;
  93. });
  94. },
  95. /** 查询装置列表 */
  96. getDeptList() {
  97. listDept().then(response => {
  98. let data = response.data;
  99. for (let i = 0; i < data.length; i++) {
  100. // 非顶级节点
  101. if (data[i].parentId !== 0) {
  102. // 插入装置列表
  103. this.deptOptions.push({"dictLabel": data[i].deptName, "dictValue": data[i].deptId});
  104. }
  105. }
  106. });
  107. },
  108. // 取消按钮
  109. cancel() {
  110. this.open = false;
  111. this.reset();
  112. },
  113. // 表单重置
  114. reset() {
  115. this.form = {
  116. id: null,
  117. auditId: null,
  118. code: null,
  119. name: null,
  120. deptId: null
  121. };
  122. this.resetForm("form");
  123. },
  124. /** 搜索按钮操作 */
  125. handleQuery() {
  126. this.queryParams.pageNum = 1;
  127. this.getList();
  128. },
  129. /** 重置按钮操作 */
  130. resetQuery() {
  131. this.resetForm("queryForm");
  132. this.handleQuery();
  133. },
  134. // 多选框选中数据
  135. handleSelectionChange(selection) {
  136. this.ids = selection.map(item => item.id)
  137. this.single = selection.length!==1
  138. this.multiple = !selection.length
  139. },
  140. /** 新增按钮操作 */
  141. handleAdd() {
  142. this.reset();
  143. this.open = true;
  144. this.title = "添加章节";
  145. },
  146. /** 修改按钮操作 */
  147. handleUpdate(row) {
  148. this.reset();
  149. const id = row.id || this.ids
  150. getChapter(id).then(response => {
  151. // 字符串转数组
  152. if (response.data.deptId != null && response.data.deptId != "") {
  153. response.data.deptId = response.data.deptId.split(",").map(Number);
  154. } else {
  155. response.data.deptId = [];
  156. }
  157. this.form = response.data;
  158. this.open = true;
  159. this.title = "修改章节";
  160. });
  161. },
  162. /** 提交按钮 */
  163. submitForm() {
  164. this.$refs["form"].validate(valid => {
  165. if (valid) {
  166. // 数组转字符串
  167. if (this.form.deptId != null) {
  168. this.form.deptId = this.form.deptId.toString();
  169. }
  170. if (this.form.id != null) {
  171. updateChapter(this.form).then(response => {
  172. this.$modal.msgSuccess("修改成功");
  173. this.open = false;
  174. this.getList();
  175. });
  176. } else {
  177. addChapter(this.form).then(response => {
  178. this.$modal.msgSuccess("新增成功");
  179. this.open = false;
  180. this.getList();
  181. });
  182. }
  183. }
  184. });
  185. },
  186. /** 删除按钮操作 */
  187. handleDelete(row) {
  188. const ids = row.id || this.ids;
  189. this.$modal.confirm('是否确认删除章节编号为"' + ids + '"的数据项?').then(function() {
  190. return delChapter(ids);
  191. }).then(() => {
  192. this.getList();
  193. this.$modal.msgSuccess("删除成功");
  194. }).catch(() => {});
  195. },
  196. /** 导出按钮操作 */
  197. handleExport() {
  198. this.download('rc/chapter/export', {
  199. ...this.queryParams
  200. }, `chapter_${new Date().getTime()}.xlsx`)
  201. }
  202. }
  203. };
  204. </script>
  205. <style scoped>
  206. .menuTable {
  207. cursor: pointer; /*鼠标悬停变小手*/
  208. }
  209. </style>