column.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="app-container">
  3. <el-form :inline="true">
  4. <el-form-item label="文档名称">
  5. <el-input
  6. v-model="queryParams.deptName"
  7. placeholder="请输入文档名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button
  15. class="filter-item"
  16. type="primary"
  17. icon="el-icon-search"
  18. size="mini"
  19. @click="handleQuery"
  20. >搜索</el-button>
  21. <el-button
  22. class="filter-item"
  23. type="primary"
  24. icon="el-icon-plus"
  25. size="mini"
  26. @click="handleAdd"
  27. v-hasPermi="['system:dept:add']"
  28. >新增</el-button>
  29. </el-form-item>
  30. </el-form>
  31. <el-table
  32. v-loading="loading"
  33. :data="deptList"
  34. row-key="deptId"
  35. default-expand-all
  36. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  37. >
  38. <el-table-column prop="deptName" label="文档名称" width="260"></el-table-column>
  39. <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  40. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  41. <template slot-scope="scope">
  42. <span>{{ parseTime(scope.row.createTime) }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  46. <template slot-scope="scope">
  47. <el-button
  48. size="mini"
  49. type="text"
  50. icon="el-icon-edit"
  51. @click="handleUpdate(scope.row)"
  52. v-hasPermi="['system:dept:edit']"
  53. >修改</el-button>
  54. <el-button
  55. size="mini"
  56. type="text"
  57. icon="el-icon-plus"
  58. @click="handleAdd(scope.row)"
  59. v-hasPermi="['system:dept:add']"
  60. >新增</el-button>
  61. <el-button
  62. v-if="scope.row.parentId != 0"
  63. size="mini"
  64. type="text"
  65. icon="el-icon-delete"
  66. @click="handleDelete(scope.row)"
  67. v-hasPermi="['system:dept:remove']"
  68. >删除</el-button>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <!-- 添加或修改文档对话框 -->
  73. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  74. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  75. <el-row>
  76. <el-col :span="24" v-if="form.parentId !== 0">
  77. <el-form-item label="上级" prop="parentId">
  78. <treeselect v-model="form.parentId" :options="docmenuOptions" :normalizer="normalizer" :show-count="true" placeholder="选择上级" />
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="12">
  82. <el-form-item label="文档名称" prop="deptName">
  83. <el-input v-model="form.deptName" placeholder="请输入文档名称" />
  84. </el-form-item>
  85. </el-col>
  86. <el-col :span="12">
  87. <el-form-item label="显示排序" prop="orderNum">
  88. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. </el-form>
  93. <div slot="footer" class="dialog-footer">
  94. <el-button type="primary" @click="submitForm">确 定</el-button>
  95. <el-button @click="cancel">取 消</el-button>
  96. </div>
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script>
  101. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/information/docmenu";
  102. import Treeselect from "@riophae/vue-treeselect";
  103. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  104. export default {
  105. name: "Dept",
  106. components: { Treeselect },
  107. data() {
  108. return {
  109. // 遮罩层
  110. loading: true,
  111. // 表格树数据
  112. deptList: [],
  113. // 文档树选项
  114. docmenuOptions: [],
  115. // 弹出层标题
  116. title: "",
  117. // 是否显示弹出层
  118. open: false,
  119. // 状态数据字典
  120. statusOptions: [],
  121. // 查询参数
  122. queryParams: {
  123. deptName: undefined,
  124. status: undefined
  125. },
  126. // 表单参数
  127. form: {},
  128. // 表单校验
  129. rules: {
  130. parentId: [
  131. //{ required: true, message: "上级不能为空", trigger: "blur" }
  132. ],
  133. deptName: [
  134. { required: true, message: "文档名称不能为空", trigger: "blur" }
  135. ],
  136. orderNum: [
  137. { required: true, message: "菜单顺序不能为空", trigger: "blur" }
  138. ]
  139. }
  140. };
  141. },
  142. created() {
  143. this.getList();
  144. this.getDicts("sys_normal_disable").then(response => {
  145. this.statusOptions = response.data;
  146. });
  147. },
  148. methods: {
  149. /** 查询文档列表 */
  150. getList() {
  151. this.loading = true;
  152. listDept(this.queryParams).then(response => {
  153. this.deptList = this.handleTree(response.data, "deptId");
  154. this.loading = false;
  155. });
  156. },
  157. /** 转换文档数据结构 */
  158. normalizer(node) {
  159. if (node.children && !node.children.length) {
  160. delete node.children;
  161. }
  162. return {
  163. id: node.deptId,
  164. label: node.deptName,
  165. children: node.children
  166. };
  167. },
  168. // 字典状态字典翻译
  169. statusFormat(row, column) {
  170. return this.selectDictLabel(this.statusOptions, row.status);
  171. },
  172. // 取消按钮
  173. cancel() {
  174. this.open = false;
  175. this.reset();
  176. },
  177. // 表单重置
  178. reset() {
  179. this.form = {
  180. deptId: undefined,
  181. parentId: undefined,
  182. deptName: undefined,
  183. orderNum: undefined,
  184. leader: undefined,
  185. phone: undefined,
  186. email: undefined,
  187. status: "0"
  188. };
  189. this.resetForm("form");
  190. },
  191. /** 搜索按钮操作 */
  192. handleQuery() {
  193. this.getList();
  194. },
  195. /** 查询菜单下拉树结构 */
  196. getTreeselect() {
  197. listDept().then(response => {
  198. this.docmenuOptions = [];
  199. const menu = { menuId: 0, menuName: '主类目', children: [] };
  200. menu.children = this.handleTree(response.data, "deptId");
  201. this.docmenuOptions.push(menu);
  202. });
  203. },
  204. /** 新增按钮操作 */
  205. handleAdd(row) {
  206. this.reset();
  207. this.getTreeselect();
  208. if (row != undefined) {
  209. this.form.parentId = row.deptId;
  210. }
  211. this.open = true;
  212. this.title = "添加文档";
  213. listDept().then(response => {
  214. this.docmenuOptions = this.handleTree(response.data, "deptId");
  215. });
  216. },
  217. /** 修改按钮操作 */
  218. handleUpdate(row) {
  219. this.reset();
  220. this.getTreeselect();
  221. getDept(row.deptId).then(response => {
  222. this.form = response.data;
  223. this.open = true;
  224. this.title = "修改文档";
  225. });
  226. listDeptExcludeChild(row.deptId).then(response => {
  227. this.docmenuOptions = this.handleTree(response.data, "deptId");
  228. });
  229. },
  230. /** 提交按钮 */
  231. submitForm: function() {
  232. this.$refs["form"].validate(valid => {
  233. if (valid) {
  234. if (this.form.deptId != undefined) {
  235. updateDept(this.form).then(response => {
  236. if (response.code === 200) {
  237. this.msgSuccess("修改成功");
  238. this.open = false;
  239. this.getList();
  240. }
  241. });
  242. } else {
  243. addDept(this.form).then(response => {
  244. if (response.code === 200) {
  245. this.msgSuccess("新增成功");
  246. this.open = false;
  247. this.getList();
  248. }
  249. });
  250. }
  251. }
  252. });
  253. },
  254. /** 删除按钮操作 */
  255. handleDelete(row) {
  256. this.$confirm('是否确认删除名称为"' + row.deptName + '"的数据项?', "警告", {
  257. confirmButtonText: "确定",
  258. cancelButtonText: "取消",
  259. type: "warning"
  260. }).then(function() {
  261. return delDept(row.deptId);
  262. }).then(() => {
  263. this.getList();
  264. this.msgSuccess("删除成功");
  265. }).catch(function() {});
  266. }
  267. }
  268. };
  269. </script>