template.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="投诉分类" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入投诉分类"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. plain
  23. icon="el-icon-plus"
  24. size="mini"
  25. @click="handleAdd"
  26. v-hasPermi="['his:template:add']"
  27. >新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button
  31. type="warning"
  32. plain
  33. icon="el-icon-download"
  34. size="mini"
  35. :loading="exportLoading"
  36. @click="handleExport"
  37. v-hasPermi="['his:template:export']"
  38. >导出</el-button>
  39. </el-col>
  40. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  41. </el-row>
  42. <el-table
  43. height="500"
  44. border
  45. v-loading="loading"
  46. :data="templateList"
  47. row-key="id"
  48. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  49. >
  50. <el-table-column label="ID" align="left" prop="id" />
  51. <el-table-column label="投诉分类" align="left" prop="name" />
  52. <el-table-column label="排序" sortable align="center" prop="sort" />
  53. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  54. <template slot-scope="scope">
  55. <el-button
  56. v-if="isLeafNode(scope.row)"
  57. size="mini"
  58. type="text"
  59. icon="el-icon-edit"
  60. @click="handleDesc(scope.row)"
  61. v-hasPermi="['his:template:edit']"
  62. >填写字段</el-button>
  63. <el-button
  64. size="mini"
  65. type="text"
  66. icon="el-icon-edit"
  67. @click="handleUpdate(scope.row)"
  68. v-hasPermi="['his:template:edit']"
  69. >修改</el-button>
  70. <el-button
  71. size="mini"
  72. type="text"
  73. icon="el-icon-delete"
  74. @click="handleDelete(scope.row)"
  75. v-hasPermi="['his:template:remove']"
  76. >删除</el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  81. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  82. <el-form-item label="上级" prop="parentId">
  83. <treeselect
  84. v-model="form.parentId"
  85. :options="categoryOptions"
  86. :show-count="true"
  87. :normalizer="normalizer"
  88. :disable-branch-nodes="false"
  89. :searchable="true"
  90. :clearable="true"
  91. placeholder="请选择上级分类"
  92. />
  93. </el-form-item>
  94. <el-form-item label="投诉分类" prop="name">
  95. <el-input v-model="form.name" placeholder="请输入标签名称" />
  96. </el-form-item>
  97. <el-form-item label="排序" prop="sort">
  98. <el-input-number v-model="form.sort" placeholder="请输入排序" />
  99. </el-form-item>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button type="primary" @click="submitForm">确 定</el-button>
  103. <el-button @click="cancel">取 消</el-button>
  104. </div>
  105. </el-dialog>
  106. <el-dialog title="选择填写字段" :visible.sync="descOpen" width="600px" append-to-body>
  107. <!-- 添加表头说明 -->
  108. <div class="field-header">
  109. <div class="field-name-header">字段名称</div>
  110. <div class="field-required-header">是否必填</div>
  111. </div>
  112. <el-checkbox-group v-model="descForm">
  113. <div v-for="(item, index) in fields" :key="index" class="field-item">
  114. <div class="field-checkbox-wrapper">
  115. <el-checkbox :label="item.label" name="desc" v-model="item.checked"></el-checkbox>
  116. </div>
  117. <div class="field-switch-wrapper">
  118. <el-switch
  119. v-model="item.isRequire"
  120. active-value="1"
  121. inactive-value="0"
  122. :disabled="!item.checked"
  123. class="require-switch"
  124. ></el-switch>
  125. </div>
  126. </div>
  127. </el-checkbox-group>
  128. <div slot="footer" class="dialog-footer">
  129. <el-button type="primary" @click="submitDescForm">确 定</el-button>
  130. <el-button @click="descCancel">取 消</el-button>
  131. </div>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script>
  136. import { treeListTemplate, listTemplate, getTemplate, delTemplate, addTemplate, updateTemplate, exportTemplate } from "@/api/his/complaint";
  137. import Treeselect from "@riophae/vue-treeselect";
  138. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  139. export default {
  140. name: "Template",
  141. components: {
  142. Treeselect
  143. },
  144. data() {
  145. return {
  146. descId: null,
  147. fields: [
  148. { label: "详细内容", checked: false, isRequire: 0, desc: "content",type:"文本框" },
  149. { label: "联系方式", checked: false, isRequire: 0, desc: "phone",type:"文本框"},
  150. { label: "上传图片", checked: false, isRequire: 0, desc: "urls",type:"图片" },
  151. { label: "交易截图", checked: false, isRequire: 0, desc: "tradeImage",type:"图片" },
  152. { label: "被投诉人账号信息", checked: false, isRequire: 0, desc: "account",type:"文本框" },
  153. ],
  154. descOpen: false,
  155. categoryOptions: [],
  156. loading: true,
  157. exportLoading: false,
  158. ids: [],
  159. single: true,
  160. multiple: true,
  161. showSearch: true,
  162. total: 0,
  163. templateList: [],
  164. title: "",
  165. open: false,
  166. queryParams: {
  167. name: null,
  168. isDel: null
  169. },
  170. form: {},
  171. rules: {
  172. parentId: [
  173. { required: true, message: "上级编码不能为空", trigger: "blur" }
  174. ],
  175. sort: [
  176. { required: true, message: "同级下排序不能为空", trigger: "blur" }
  177. ],
  178. name: [
  179. { required: true, message: "投诉分类不能为空", trigger: "blur" }
  180. ],
  181. }
  182. };
  183. },
  184. computed: {
  185. descForm: {
  186. get() {
  187. return this.fields.filter(item => item.checked).map(item => item.label);
  188. },
  189. set(value) {
  190. this.fields.forEach(item => {
  191. item.checked = value.includes(item.label);
  192. });
  193. },
  194. },
  195. },
  196. created() {
  197. this.getList();
  198. },
  199. methods: {
  200. /**
  201. * 判断是否为叶子节点(最后一级)
  202. */
  203. isLeafNode(row) {
  204. return !row.children || row.children.length === 0;
  205. },
  206. submitDescForm() {
  207. const result = this.fields
  208. .filter(item => item.checked)
  209. .map(item => ({
  210. name: item.label,
  211. isRequire: item.isRequire,
  212. desc: item.desc,
  213. type: item.type,
  214. }));
  215. console.log("提交的数据:", result);
  216. const param = { id: this.descId, description: JSON.stringify(result) }
  217. updateTemplate(param).then(response => {
  218. this.msgSuccess("修改成功");
  219. this.descOpen = false;
  220. this.getList();
  221. });
  222. },
  223. /** 转换标签数据结构 */
  224. normalizer(node) {
  225. if (node.children && !node.children.length) {
  226. delete node.children;
  227. }
  228. return {
  229. id: node.id,
  230. label: node.name,
  231. children: node.children
  232. };
  233. },
  234. /** 查询部门下拉树结构 */
  235. getTreeselect() {
  236. treeListTemplate().then(response => {
  237. const rootOption = { id: 0, name: '根目录', children: response.data || [] };
  238. this.categoryOptions = [rootOption];
  239. });
  240. },
  241. /** 查询投诉模板列表 */
  242. getList() {
  243. this.loading = true;
  244. treeListTemplate(this.queryParams).then(response => {
  245. this.templateList = response.data;
  246. this.total = response.data.length;
  247. this.loading = false;
  248. });
  249. },
  250. cancel() {
  251. this.open = false;
  252. this.reset();
  253. },
  254. descCancel() {
  255. this.descOpen = false;
  256. this.descReset();
  257. },
  258. descReset() {
  259. this.descForm = [];
  260. },
  261. reset() {
  262. this.form = {
  263. id: null,
  264. parentId: 0,
  265. sort: null,
  266. name: null,
  267. updateTime: null,
  268. createTime: null,
  269. isDel: null
  270. };
  271. this.resetForm("form");
  272. },
  273. handleQuery() {
  274. this.getList();
  275. },
  276. resetQuery() {
  277. this.resetForm("queryForm");
  278. this.handleQuery();
  279. },
  280. handleSelectionChange(selection) {
  281. this.ids = selection.map(item => item.id)
  282. this.single = selection.length !== 1
  283. this.multiple = !selection.length
  284. },
  285. /** 新增按钮操作 */
  286. handleAdd() {
  287. this.reset();
  288. this.getTreeselect();
  289. this.open = true;
  290. this.title = "添加投诉模板";
  291. },
  292. handleDesc(row) {
  293. if (!this.isLeafNode(row)) {
  294. this.msgWarning("只有最后一级分类才能配置填写字段");
  295. return;
  296. }
  297. this.descOpen = true;
  298. this.descId = row.id
  299. if (row.description) {
  300. const description = JSON.parse(row.description);
  301. this.fields.forEach(field => {
  302. // 修复:添加 return 语句或者直接使用箭头函数的简写形式
  303. const found = description.find(item => item.name === field.label);
  304. if (found) {
  305. field.checked = true;
  306. field.isRequire = found.isRequire;
  307. } else {
  308. field.checked = false;
  309. field.isRequire = 0;
  310. }
  311. });
  312. } else {
  313. // 重置所有字段
  314. this.fields.forEach(field => {
  315. field.checked = false;
  316. field.isRequire = 0;
  317. });
  318. }
  319. // 添加调试信息,查看最终的 fields 状态
  320. console.log("最终 fields 状态:", JSON.stringify(this.fields));
  321. },
  322. /** 修改按钮操作 */
  323. handleUpdate(row) {
  324. this.reset();
  325. this.getTreeselect();
  326. const id = row.id || this.ids
  327. getTemplate(id).then(response => {
  328. this.form = response.data;
  329. if (this.form.parentId === null || this.form.parentId === undefined) {
  330. this.form.parentId = 0;
  331. }
  332. this.open = true;
  333. this.title = "修改投诉模板";
  334. });
  335. },
  336. submitForm() {
  337. this.$refs["form"].validate(valid => {
  338. if (valid) {
  339. if (this.form.id != null) {
  340. updateTemplate(this.form).then(response => {
  341. this.msgSuccess("修改成功");
  342. this.open = false;
  343. this.getList();
  344. });
  345. } else {
  346. addTemplate(this.form).then(response => {
  347. this.msgSuccess("新增成功");
  348. this.open = false;
  349. this.getList();
  350. });
  351. }
  352. }
  353. });
  354. },
  355. handleDelete(row) {
  356. const ids = row.id || this.ids;
  357. this.$confirm('是否确认删除投诉模板编号为"' + ids + '"的数据项?', "警告", {
  358. confirmButtonText: "确定",
  359. cancelButtonText: "取消",
  360. type: "warning"
  361. }).then(function() {
  362. return delTemplate(ids);
  363. }).then(() => {
  364. this.getList();
  365. this.msgSuccess("删除成功");
  366. }).catch(() => {});
  367. },
  368. handleExport() {
  369. const queryParams = this.queryParams;
  370. this.$confirm('是否确认导出所有投诉模板数据项?', "警告", {
  371. confirmButtonText: "确定",
  372. cancelButtonText: "取消",
  373. type: "warning"
  374. }).then(() => {
  375. this.exportLoading = true;
  376. return exportTemplate(queryParams);
  377. }).then(response => {
  378. this.download(response.msg);
  379. this.exportLoading = false;
  380. }).catch(() => {});
  381. }
  382. }
  383. };
  384. </script>
  385. <style scoped>
  386. /* 表头样式 */
  387. .field-header {
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. margin-bottom: 15px;
  392. padding: 10px 0;
  393. border-bottom: 1px solid #e4e7ed;
  394. font-weight: bold;
  395. color: #606266;
  396. }
  397. .field-name-header {
  398. flex: 1;
  399. text-align: left;
  400. padding-left: 20px;
  401. }
  402. .field-required-header {
  403. width: 120px;
  404. text-align: center;
  405. }
  406. /* 字段项样式 */
  407. .field-item {
  408. display: flex;
  409. align-items: center;
  410. justify-content: space-between;
  411. margin-bottom: 15px;
  412. padding: 8px 0;
  413. border-bottom: 1px solid #f0f0f0;
  414. }
  415. .field-checkbox-wrapper {
  416. flex: 1;
  417. display: flex;
  418. align-items: center;
  419. }
  420. .field-checkbox-wrapper .el-checkbox {
  421. margin-right: 20px;
  422. }
  423. .field-switch-wrapper {
  424. width: 120px;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. }
  429. .require-switch {
  430. margin: 0;
  431. }
  432. /* 对话框内容区域样式调整 */
  433. .el-dialog__body {
  434. padding: 20px;
  435. }
  436. </style>