dict-edit.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <!-- 字典编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="800px"
  5. :maxable="true"
  6. :visible="visible"
  7. :close-on-click-modal="true"
  8. :title="isUpdate ? '修改字典' : '添加字典'"
  9. @update:visible="updateVisible"
  10. >
  11. <div class="divider">
  12. <div class="title">
  13. <div class="ele-bg-primary"></div>
  14. <span>基本信息</span>
  15. </div>
  16. <div class="ele-bg-primary" style="width: 100%; height: 2px"></div>
  17. </div>
  18. <el-form
  19. ref="form"
  20. :model="form"
  21. :rules="rules"
  22. label-width="85px"
  23. style="margin-bottom: 10px"
  24. >
  25. <el-row>
  26. <el-col :span="12">
  27. <el-form-item label="字典名称:" prop="name">
  28. <el-input
  29. clearable
  30. :disabled="isUpdate"
  31. :maxlength="20"
  32. v-model="form.name"
  33. placeholder="请输入字典名称"
  34. />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="12">
  38. <el-form-item label="字典值:" prop="code">
  39. <el-input
  40. clearable
  41. :maxlength="20"
  42. v-model="form.code"
  43. placeholder="请输入字典值"
  44. />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="12">
  48. <el-form-item label="应用类型:" prop="appType">
  49. <el-radio-group v-model="form.appType">
  50. <el-radio :label="1">业务字典</el-radio>
  51. <el-radio :label="2">数据字典</el-radio>
  52. </el-radio-group>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="12">
  56. <el-form-item label="是否启用:" prop="enable">
  57. <el-radio-group v-model="form.enable">
  58. <el-radio :label="1">是</el-radio>
  59. <el-radio :label="0">否</el-radio>
  60. </el-radio-group>
  61. </el-form-item>
  62. </el-col>
  63. <!-- <el-col :span="12">
  64. <el-form-item label="排序号:" prop="sortNumber">
  65. <el-input-number
  66. :min="0"
  67. :max="9999"
  68. v-model="form.sortNumber"
  69. controls-position="right"
  70. placeholder="请输入排序号"
  71. class="ele-fluid ele-text-left"
  72. />
  73. </el-form-item>
  74. </el-col> -->
  75. <el-col :span="24">
  76. <el-form-item label="备注:">
  77. <el-input
  78. :rows="4"
  79. type="textarea"
  80. :maxlength="200"
  81. v-model="form.remark"
  82. placeholder="请输入备注"
  83. />
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. </el-form>
  88. <div class="divider">
  89. <div class="title">
  90. <div class="ele-bg-primary"></div>
  91. <span>字典项配置</span>
  92. </div>
  93. <div class="ele-bg-primary" style="width: 100%; height: 2px"></div>
  94. </div>
  95. <div style="margin: 5px 0">
  96. <el-button
  97. size="small"
  98. type="primary"
  99. icon="el-icon-plus"
  100. class="ele-btn-icon"
  101. @click="pushArr"
  102. >
  103. 添加
  104. </el-button>
  105. <el-button
  106. size="small"
  107. type="danger"
  108. icon="el-icon-delete"
  109. class="ele-btn-icon"
  110. @click="removeArr"
  111. >
  112. 删除
  113. </el-button>
  114. </div>
  115. <el-table
  116. :data="form.dictStaticSubmitPOList"
  117. border
  118. style="width: 100%"
  119. @selection-change="handleSelectionChange"
  120. >
  121. <el-table-column type="selection" align="center"> </el-table-column>
  122. <el-table-column prop="code" label="字典项编码">
  123. <template slot-scope="scope">
  124. <el-input v-model="scope.row.code" placeholder=""></el-input>
  125. </template>
  126. </el-table-column>
  127. <el-table-column prop="name" label="字典项名称">
  128. <template slot-scope="scope">
  129. <el-input v-model="scope.row.name" placeholder=""></el-input>
  130. </template>
  131. </el-table-column>
  132. <el-table-column prop="sort" label="排序">
  133. <template slot-scope="scope">
  134. <el-input
  135. v-model="scope.row.sort"
  136. @input="
  137. scope.row.sort = String(scope.row.sort).replace(/[^\d]/g, '')
  138. "
  139. ></el-input>
  140. </template>
  141. </el-table-column>
  142. <el-table-column prop="enable" label="启用">
  143. <template slot-scope="scope">
  144. <el-radio-group v-model="scope.row.enable">
  145. <el-radio :label="1">是</el-radio>
  146. <el-radio :label="0">否</el-radio>
  147. </el-radio-group>
  148. </template>
  149. </el-table-column>
  150. </el-table>
  151. <template v-slot:footer>
  152. <el-button @click="updateVisible(false)">取消</el-button>
  153. <el-button type="primary" :loading="loading" @click="save">
  154. 保存
  155. </el-button>
  156. </template>
  157. </ele-modal>
  158. </template>
  159. <script>
  160. import { addDictionary, updateDictionary } from '@/api/system/dictionary';
  161. import {
  162. pageDictionaryData,
  163. removeDictionaryData,
  164. removeDictionaryDataBatch
  165. } from '@/api/system/dictionary-data';
  166. export default {
  167. props: {
  168. // 弹窗是否打开
  169. visible: Boolean,
  170. // 修改回显的数据
  171. id: String
  172. },
  173. data() {
  174. const defaultForm = {
  175. name: '',
  176. code: '',
  177. appType: 1,
  178. enable: 1,
  179. remark: '',
  180. dictStaticSubmitPOList: []
  181. };
  182. return {
  183. defaultForm,
  184. // 表单数据
  185. form: { ...defaultForm },
  186. // form: {
  187. // name: '',
  188. // code: '',
  189. // appType: 1,
  190. // enable: 1,
  191. // remark: ''
  192. // },
  193. // 表单验证规则
  194. rules: {
  195. name: [
  196. {
  197. required: true,
  198. message: '请输入字典名称',
  199. trigger: 'blur'
  200. }
  201. ],
  202. code: [
  203. {
  204. required: true,
  205. message: '请输入字典值',
  206. trigger: 'blur'
  207. }
  208. ],
  209. appType: [
  210. {
  211. required: true,
  212. message: '请选择应用类型',
  213. trigger: 'blur'
  214. }
  215. ],
  216. enable: [
  217. {
  218. required: true,
  219. message: '请选择是否启用',
  220. trigger: 'blur'
  221. }
  222. ],
  223. sort: [
  224. {
  225. required: true,
  226. message: '请输入排序号',
  227. trigger: 'blur'
  228. }
  229. ]
  230. },
  231. // 表格列配置
  232. columns: [
  233. {
  234. columnKey: 'selection',
  235. type: 'selection',
  236. width: 45,
  237. align: 'center'
  238. },
  239. {
  240. columnKey: 'index',
  241. type: 'index',
  242. width: 45,
  243. align: 'center',
  244. showOverflowTooltip: true
  245. },
  246. {
  247. prop: 'code',
  248. label: '字典编码',
  249. showOverflowTooltip: true
  250. },
  251. {
  252. prop: 'name',
  253. label: '字典名称',
  254. showOverflowTooltip: true
  255. },
  256. // {
  257. // prop: 'appType',
  258. // label: '字典类型',
  259. // showOverflowTooltip: true,
  260. // minWidth: 110
  261. // },
  262. {
  263. prop: 'appType',
  264. label: '应用类型',
  265. showOverflowTooltip: true
  266. },
  267. {
  268. prop: 'remark',
  269. label: '描述',
  270. showOverflowTooltip: true
  271. },
  272. {
  273. prop: 'createTime',
  274. label: '创建时间',
  275. showOverflowTooltip: true,
  276. minWidth: 110,
  277. formatter: (_row, _column, cellValue) => {
  278. return this.$util.toDateString(cellValue);
  279. }
  280. },
  281. {
  282. columnKey: 'action',
  283. label: '操作',
  284. width: 130,
  285. align: 'center',
  286. resizable: false,
  287. slot: 'action',
  288. showOverflowTooltip: true
  289. }
  290. ],
  291. // 表格选中数据
  292. selection: [],
  293. datasource: {
  294. list: []
  295. },
  296. // 提交状态
  297. loading: false,
  298. // 是否是修改
  299. isUpdate: false
  300. };
  301. },
  302. created() {},
  303. methods: {
  304. pushArr() {},
  305. removeArr() {},
  306. handleSelectionChange() {},
  307. /* 保存编辑 */
  308. save() {
  309. this.$refs.form.validate((valid) => {
  310. if (!valid) {
  311. return false;
  312. }
  313. this.loading = true;
  314. const saveOrUpdate = this.isUpdate ? updateDictionary : addDictionary;
  315. saveOrUpdate(this.form)
  316. .then((msg) => {
  317. this.loading = false;
  318. this.$message.success(msg);
  319. this.updateVisible(false);
  320. this.$emit('done');
  321. })
  322. .catch((e) => {
  323. this.loading = false;
  324. this.$message.error(e.message);
  325. });
  326. });
  327. },
  328. /* 更新visible */
  329. updateVisible(value) {
  330. this.$emit('update:visible', value);
  331. },
  332. async getDetail() {
  333. const res = await pageDictionaryData(this.id);
  334. this.form = res.data.dictInfoVO;
  335. this.form.dictStaticSubmitPOList = res.data.dictStaticVOList;
  336. // this.datasource.list = this.from.dictStaticSubmitPOList;
  337. }
  338. },
  339. watch: {
  340. visible(visible) {
  341. if (visible) {
  342. if (this.id) {
  343. // this.$util.assignObject(this.form, this.data);
  344. this.isUpdate = true;
  345. this.getDetail();
  346. } else {
  347. this.isUpdate = false;
  348. }
  349. } else {
  350. this.$refs.form.clearValidate();
  351. this.form = { ...this.defaultForm };
  352. }
  353. }
  354. }
  355. };
  356. </script>
  357. <style lang="scss" scoped>
  358. .divider {
  359. margin-bottom: 20px;
  360. .title {
  361. display: flex;
  362. align-items: center;
  363. margin-bottom: 10px;
  364. div {
  365. width: 8px;
  366. height: 20px;
  367. margin-right: 10px;
  368. }
  369. span {
  370. font-size: 20px;
  371. }
  372. }
  373. }
  374. </style>