index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. >
  10. <el-form-item label="单位编号" prop="unitId">
  11. <el-input
  12. v-model="queryParams.unitId"
  13. placeholder="请输入单位编号"
  14. clearable
  15. oninput="value=value.replace(/[^\d.]/g,'')"
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item label="单位名称" prop="unitName">
  20. <el-input
  21. v-model="queryParams.unitName"
  22. placeholder="请输入单位名称"
  23. clearable
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="状态" prop="status">
  28. <el-select
  29. v-model="queryParams.status"
  30. placeholder="状态"
  31. clearable
  32. style="width: 240px"
  33. >
  34. <el-option
  35. v-for="dict in dict.type.sys_normal_disable"
  36. :key="dict.value"
  37. :label="dict.label"
  38. :value="dict.value"
  39. />
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button
  44. v-no-more-click
  45. type="primary"
  46. icon="el-icon-search"
  47. size="mini"
  48. @click="handleQuery"
  49. >搜索
  50. </el-button>
  51. <el-button
  52. v-no-more-click
  53. icon="el-icon-refresh"
  54. size="mini"
  55. @click="resetQuery"
  56. >重置</el-button
  57. >
  58. </el-form-item>
  59. </el-form>
  60. <el-row :gutter="10" class="mb8">
  61. <el-col :span="1.5">
  62. <el-button
  63. v-no-more-click
  64. type="primary"
  65. plain
  66. icon="el-icon-plus"
  67. size="mini"
  68. @click="handleAdd"
  69. v-hasPermi="['iscs:unit:add']"
  70. >新增
  71. </el-button>
  72. </el-col>
  73. <!-- <el-col :span="1.5">-->
  74. <!-- <el-button v-no-more-click-->
  75. <!-- type="info"-->
  76. <!-- plain-->
  77. <!-- icon="el-icon-sort"-->
  78. <!-- size="mini"-->
  79. <!-- @click="toggleExpandAll"-->
  80. <!-- >展开/折叠-->
  81. <!-- </el-button>-->
  82. <!-- </el-col>-->
  83. <right-toolbar
  84. :showSearch.sync="showSearch"
  85. @queryTable="getList"
  86. ></right-toolbar>
  87. </el-row>
  88. <el-table
  89. v-if="refreshTable"
  90. v-loading="loading"
  91. :data="deptList"
  92. row-key="unitId"
  93. :default-expand-all="isExpandAll"
  94. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  95. >
  96. <el-table-column
  97. prop="unitId"
  98. label="单位编号"
  99. width="130"
  100. ></el-table-column>
  101. <el-table-column
  102. prop="unitName"
  103. label="单位名称"
  104. width="260"
  105. ></el-table-column>
  106. <el-table-column
  107. prop="unitType"
  108. label="单位类型"
  109. width="260"
  110. ></el-table-column>
  111. <el-table-column
  112. prop="orderNum"
  113. label="排序"
  114. width="200"
  115. ></el-table-column>
  116. <el-table-column prop="remark" label="备注" width="260"></el-table-column>
  117. <el-table-column prop="status" label="状态" width="150">
  118. <template slot-scope="scope">
  119. <el-switch
  120. v-model="scope.row.status"
  121. active-value="0"
  122. inactive-value="1"
  123. @change="handleStatusChange(scope.row)"
  124. ></el-switch>
  125. </template>
  126. </el-table-column>
  127. <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="200">-->
  128. <!-- <template slot-scope="scope">-->
  129. <!-- <span>{{ scope.row.createTime }}</span>-->
  130. <!-- </template>-->
  131. <!-- </el-table-column>-->
  132. <el-table-column
  133. label="操作"
  134. align="center"
  135. class-name="small-padding fixed-width"
  136. >
  137. <template slot-scope="scope">
  138. <el-button
  139. v-no-more-click
  140. size="mini"
  141. type="text"
  142. icon="el-icon-edit"
  143. @click="handleUpdate(scope.row)"
  144. v-hasPermi="['iscs:unit:edit']"
  145. >修改
  146. </el-button>
  147. <!-- <el-button v-no-more-click-->
  148. <!-- size="mini"-->
  149. <!-- type="text"-->
  150. <!-- icon="el-icon-plus"-->
  151. <!-- @click="handleAdd(scope.row)"-->
  152. <!-- v-hasPermi="['iscs:unit:add']"-->
  153. <!-- >新增-->
  154. <!-- </el-button>-->
  155. <!-- v-if="scope.row.parentId != 0"-->
  156. <el-button
  157. v-no-more-click
  158. size="mini"
  159. type="text"
  160. icon="el-icon-delete"
  161. @click="handleDelete(scope.row)"
  162. v-hasPermi="['iscs:unit:remove']"
  163. >删除
  164. </el-button>
  165. </template>
  166. </el-table-column>
  167. </el-table>
  168. <pagination
  169. v-show="total > 0"
  170. :total="total"
  171. :page.sync="queryParams.current"
  172. :limit.sync="queryParams.size"
  173. @pagination="getList"
  174. />
  175. <!-- 添加或修改单位对话框 -->
  176. <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body>
  177. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  178. <!-- <el-form-item label="上级" prop="parentId" v-if="form.parentId !== 0">-->
  179. <!-- <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级"/>-->
  180. <!-- </el-form-item>-->
  181. <el-form-item label="单位名称" prop="unitName">
  182. <el-input v-model="form.unitName" placeholder="请输入单位名称" />
  183. </el-form-item>
  184. <el-form-item label="单位类型" prop="unitType">
  185. <el-radio-group v-model="form.unitType">
  186. <el-radio label="内部">内部</el-radio>
  187. <el-radio label="外部">外部</el-radio>
  188. </el-radio-group>
  189. </el-form-item>
  190. <el-form-item label="排序" prop="orderNum">
  191. <el-input-number type="number" v-model="form.orderNum" />
  192. </el-form-item>
  193. <el-form-item label="备注" prop="remark">
  194. <el-input v-model="form.remark" placeholder="请输入备注" />
  195. </el-form-item>
  196. <el-form-item label="状态" prop="status">
  197. <el-radio-group v-model="form.status">
  198. <el-radio
  199. v-for="dict in dict.type.sys_normal_disable"
  200. :key="dict.value"
  201. :label="dict.value"
  202. >{{ dict.label }}</el-radio
  203. >
  204. </el-radio-group>
  205. </el-form-item>
  206. </el-form>
  207. <div slot="footer" class="dialog-footer">
  208. <el-button v-no-more-click type="primary" @click="submitForm"
  209. >确 定</el-button
  210. >
  211. <el-button v-no-more-click @click="cancel">取 消</el-button>
  212. </div>
  213. </el-dialog>
  214. </div>
  215. </template>
  216. <script>
  217. import {
  218. listUnit,
  219. getUnitInfo,
  220. addUnit,
  221. updateUnit,
  222. delUnit,
  223. } from "@/api/system/unit";
  224. import Treeselect from "@riophae/vue-treeselect";
  225. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  226. import { genCode } from "@/api/system/autocode/rule";
  227. import { updateMarsDeptStatus } from "@/api/system/marsdept";
  228. export default {
  229. name: "Dept",
  230. dicts: ["sys_normal_disable"],
  231. components: { Treeselect },
  232. data() {
  233. return {
  234. // 遮罩层
  235. loading: true,
  236. //自动生成编码
  237. autoGenFlag: false,
  238. // 显示搜索条件
  239. showSearch: true,
  240. total: 0, //
  241. // 表格树数据
  242. deptList: [],
  243. // 单位树选项
  244. deptOptions: [],
  245. // 弹出层标题
  246. title: "",
  247. // 是否显示弹出层
  248. open: false,
  249. // 是否展开,默认全部展开
  250. isExpandAll: true,
  251. // 重新渲染表格状态
  252. refreshTable: true,
  253. // 查询参数
  254. queryParams: {
  255. current: 1,
  256. size: 10,
  257. unitName: undefined,
  258. userId: undefined,
  259. unitId: undefined,
  260. status: undefined,
  261. },
  262. // 表单参数
  263. form: {},
  264. // 表单校验
  265. rules: {
  266. // parentId: [
  267. // { required: true, message: '上级不能为空', trigger: 'blur' }
  268. // ],
  269. unitName: [
  270. { required: true, message: "单位名称不能为空", trigger: "blur" },
  271. ],
  272. },
  273. };
  274. },
  275. created() {
  276. this.getList();
  277. },
  278. methods: {
  279. // 用户状态修改
  280. handleStatusChange(row) {
  281. let text = row.status === "0" ? "启用" : "停用";
  282. this.$modal
  283. .confirm('确认要"' + text + '""' + row.unitName + '"岗位吗?')
  284. .then(function () {
  285. const data = {
  286. unitId: row.unitId,
  287. unitName: row.unitName,
  288. unitType: row.unitType,
  289. orderNum: row.orderNum,
  290. status: row.status,
  291. };
  292. return updateUnit(data);
  293. })
  294. .then(() => {
  295. this.$modal.msgSuccess(text + "成功");
  296. })
  297. .catch(function () {
  298. row.status = row.status === "0" ? "1" : "0";
  299. });
  300. },
  301. /** 查询单位列表 */
  302. getList() {
  303. this.loading = true;
  304. listUnit(this.queryParams).then((response) => {
  305. debugger;
  306. this.deptList = this.handleTree(
  307. response.data.records,
  308. "unitId",
  309. "parentId"
  310. );
  311. console.log(this.deptList, "单位列表");
  312. this.loading = false;
  313. this.total = response.data.total;
  314. });
  315. },
  316. /** 转换单位数据结构 */
  317. normalizer(node) {
  318. if (node.children && !node.children.length) {
  319. delete node.children;
  320. }
  321. return {
  322. id: node.unitId,
  323. label: node.unitName,
  324. children: node.children,
  325. };
  326. },
  327. // 取消按钮
  328. cancel() {
  329. this.open = false;
  330. this.reset();
  331. },
  332. // 表单重置
  333. reset() {
  334. this.form = {
  335. unitId: undefined,
  336. parentId: undefined,
  337. unitName: undefined,
  338. };
  339. this.autoGenFlag = false;
  340. this.resetForm("form");
  341. },
  342. /** 搜索按钮操作 */
  343. handleQuery() {
  344. this.getList();
  345. },
  346. /** 重置按钮操作 */
  347. resetQuery() {
  348. this.resetForm("queryForm");
  349. this.handleQuery();
  350. },
  351. /** 新增按钮操作 */
  352. handleAdd(row) {
  353. this.reset();
  354. if (row != null && row.unitId) {
  355. this.form.parentId = row.unitId;
  356. } else {
  357. this.form.parentId = 0;
  358. }
  359. this.open = true;
  360. this.title = "新增单位";
  361. listUnit(this.queryParams).then((response) => {
  362. this.deptOptions = this.handleTree(
  363. response.data.records,
  364. "unitId",
  365. "parentId"
  366. );
  367. });
  368. },
  369. /** 展开/折叠操作 */
  370. toggleExpandAll() {
  371. this.refreshTable = false;
  372. this.isExpandAll = !this.isExpandAll;
  373. this.$nextTick(() => {
  374. this.refreshTable = true;
  375. });
  376. },
  377. /** 修改按钮操作 */
  378. handleUpdate(row) {
  379. this.reset();
  380. getUnitInfo(row.unitId).then((response) => {
  381. this.form = response.data;
  382. if (this.form.parentId == 0) {
  383. this.form.parentId = undefined;
  384. }
  385. this.open = true;
  386. this.title = "修改单位";
  387. });
  388. },
  389. /** 提交按钮 */
  390. submitForm: function () {
  391. this.$refs["form"].validate((valid) => {
  392. if (valid) {
  393. if (this.form.unitId != undefined) {
  394. updateUnit(this.form).then((response) => {
  395. this.$modal.msgSuccess("修改成功");
  396. this.open = false;
  397. this.getList();
  398. });
  399. } else {
  400. addUnit(this.form).then((response) => {
  401. this.$modal.msgSuccess("新增成功");
  402. this.open = false;
  403. this.getList();
  404. });
  405. }
  406. }
  407. });
  408. },
  409. /** 删除按钮操作 */
  410. // .confirm('是否确认删除名称为"' + row.unitName + '"的数据项?')
  411. handleDelete(row) {
  412. this.$modal
  413. .confirm("是否确认删除所选数据项?")
  414. .then(function () {
  415. return delUnit(row.unitId);
  416. })
  417. .then(() => {
  418. this.getList();
  419. this.$modal.msgSuccess("删除成功");
  420. })
  421. .catch(() => {});
  422. },
  423. },
  424. };
  425. </script>