sysDictionaryDetail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. <el-form-item label="展示值">
  6. <el-input placeholder="搜索条件" v-model="searchInfo.label"></el-input>
  7. </el-form-item>
  8. <el-form-item label="字典值">
  9. <el-input placeholder="搜索条件" v-model="searchInfo.value"></el-input>
  10. </el-form-item>
  11. <el-form-item label="启用状态" prop="status">
  12. <el-select v-model="searchInfo.status" placeholder="请选择">
  13. <el-option key="true" label="是" value="true"></el-option>
  14. <el-option key="false" label="否" value="false"></el-option>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button @click="onSubmit" type="primary">查询</el-button>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button @click="openDialog" type="primary">新增字典项</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. <el-table
  26. :data="tableData"
  27. border
  28. ref="multipleTable"
  29. stripe
  30. style="width: 100%"
  31. tooltip-effect="dark"
  32. >
  33. <el-table-column type="selection" width="55"></el-table-column>
  34. <el-table-column label="日期" width="180">
  35. <template slot-scope="scope">{{scope.row.CreatedAt|formatDate}}</template>
  36. </el-table-column>
  37. <el-table-column label="展示值" prop="label" width="120"></el-table-column>
  38. <el-table-column label="字典值" prop="value" width="120"></el-table-column>
  39. <el-table-column label="启用状态" prop="status" width="120">
  40. <template slot-scope="scope">{{scope.row.status|formatBoolean}}</template>
  41. </el-table-column>
  42. <el-table-column label="排序标记" prop="sort" width="120"></el-table-column>
  43. <el-table-column label="按钮组">
  44. <template slot-scope="scope">
  45. <el-button @click="updateSysDictionaryDetail(scope.row)" size="small" type="primary">变更</el-button>
  46. <el-popover placement="top" width="160" v-model="scope.row.visible">
  47. <p>确定要删除吗?</p>
  48. <div style="text-align: right; margin: 0">
  49. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  50. <el-button type="primary" size="mini" @click="deleteSysDictionaryDetail(scope.row)">确定</el-button>
  51. </div>
  52. <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
  53. </el-popover>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <el-pagination
  58. :current-page="page"
  59. :page-size="pageSize"
  60. :page-sizes="[10, 30, 50, 100]"
  61. :style="{float:'right',padding:'20px'}"
  62. :total="total"
  63. @current-change="handleCurrentChange"
  64. @size-change="handleSizeChange"
  65. layout="total, sizes, prev, pager, next, jumper"
  66. ></el-pagination>
  67. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  68. <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="110px">
  69. <el-form-item label="展示值" prop="label">
  70. <el-input
  71. v-model="formData.label"
  72. placeholder="请输入展示值"
  73. clearable
  74. :style="{width: '100%'}"
  75. ></el-input>
  76. </el-form-item>
  77. <el-form-item label="字典值" prop="value">
  78. <el-input-number
  79. v-model.number="formData.value"
  80. step-strictly
  81. :step="1"
  82. placeholder="请输入字典值"
  83. clearable
  84. :style="{width: '100%'}"
  85. ></el-input-number>
  86. </el-form-item>
  87. <el-form-item label="启用状态" prop="status" required>
  88. <el-switch v-model="formData.status" active-text="开启" inactive-text="停用"></el-switch>
  89. </el-form-item>
  90. <el-form-item label="排序标记" prop="sort">
  91. <el-input-number v-model.number="formData.sort" placeholder="排序标记"></el-input-number>
  92. </el-form-item>
  93. </el-form>
  94. <div class="dialog-footer" slot="footer">
  95. <el-button @click="closeDialog">取 消</el-button>
  96. <el-button @click="enterDialog" type="primary">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script>
  102. import {
  103. createSysDictionaryDetail,
  104. deleteSysDictionaryDetail,
  105. updateSysDictionaryDetail,
  106. findSysDictionaryDetail,
  107. getSysDictionaryDetailList
  108. } from "@/api/sysDictionaryDetail"; // 此处请自行替换地址
  109. import { formatTimeToStr } from "@/utils/date";
  110. import infoList from "@/mixins/infoList";
  111. export default {
  112. name: "SysDictionaryDetail",
  113. mixins: [infoList],
  114. data() {
  115. return {
  116. listApi: getSysDictionaryDetailList,
  117. dialogFormVisible: false,
  118. visible: false,
  119. type: "",
  120. formData: {
  121. label: null,
  122. value: null,
  123. status: true,
  124. sort: null
  125. },
  126. rules: {
  127. label: [
  128. {
  129. required: true,
  130. message: "请输入展示值",
  131. trigger: "blur"
  132. }
  133. ],
  134. value: [
  135. {
  136. required: true,
  137. message: "请输入字典值",
  138. trigger: "blur"
  139. }
  140. ],
  141. sort: [
  142. {
  143. required: true,
  144. message: "排序标记",
  145. trigger: "blur"
  146. }
  147. ]
  148. }
  149. };
  150. },
  151. filters: {
  152. formatDate: function(time) {
  153. if (time != null && time != "") {
  154. var date = new Date(time);
  155. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  156. } else {
  157. return "";
  158. }
  159. },
  160. formatBoolean: function(bool) {
  161. if (bool != null) {
  162. return bool ? "是" : "否";
  163. } else {
  164. return "";
  165. }
  166. }
  167. },
  168. methods: {
  169. //条件搜索前端看此方法
  170. onSubmit() {
  171. this.page = 1;
  172. this.pageSize = 10;
  173. if (this.searchInfo.status == "") {
  174. this.searchInfo.status = null;
  175. }
  176. this.getTableData();
  177. },
  178. async updateSysDictionaryDetail(row) {
  179. const res = await findSysDictionaryDetail({ ID: row.ID });
  180. this.type = "update";
  181. if (res.code == 0) {
  182. this.formData = res.data.resysDictionaryDetail;
  183. this.dialogFormVisible = true;
  184. }
  185. },
  186. closeDialog() {
  187. this.dialogFormVisible = false;
  188. this.formData = {
  189. label: null,
  190. value: null,
  191. status: true,
  192. sort: null,
  193. sysDictionaryID: ""
  194. };
  195. },
  196. async deleteSysDictionaryDetail(row) {
  197. this.visible = false;
  198. const res = await deleteSysDictionaryDetail({ ID: row.ID });
  199. if (res.code == 0) {
  200. this.$message({
  201. type: "success",
  202. message: "删除成功"
  203. });
  204. if (this.tableData.length == 1) {
  205. this.page--;
  206. }
  207. this.getTableData();
  208. }
  209. },
  210. async enterDialog() {
  211. this.formData.sysDictionaryID = Number(this.$route.params.id);
  212. this.$refs["elForm"].validate(async valid => {
  213. if (!valid) return;
  214. let res;
  215. switch (this.type) {
  216. case "create":
  217. res = await createSysDictionaryDetail(this.formData);
  218. break;
  219. case "update":
  220. res = await updateSysDictionaryDetail(this.formData);
  221. break;
  222. default:
  223. res = await createSysDictionaryDetail(this.formData);
  224. break;
  225. }
  226. if (res.code == 0) {
  227. this.$message({
  228. type: "success",
  229. message: "创建/更改成功"
  230. });
  231. this.closeDialog();
  232. this.getTableData();
  233. }
  234. });
  235. },
  236. openDialog() {
  237. this.type = "create";
  238. this.dialogFormVisible = true;
  239. }
  240. },
  241. created() {
  242. this.searchInfo.sysDictionaryID = this.$route.params.id;
  243. this.getTableData();
  244. }
  245. };
  246. </script>
  247. <style>
  248. </style>