sysDictionaryDetail.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 v-model="searchInfo.label" placeholder="搜索条件" />
  7. </el-form-item>
  8. <el-form-item label="字典值">
  9. <el-input v-model="searchInfo.value" placeholder="搜索条件" />
  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" />
  14. <el-option key="false" label="否" value="false" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button size="mini" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button size="mini" type="primary" icon="el-icon-plus" @click="openDialog">新增字典项</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. <el-table
  26. ref="multipleTable"
  27. :data="tableData"
  28. border
  29. stripe
  30. style="width: 100%"
  31. tooltip-effect="dark"
  32. >
  33. <el-table-column type="selection" width="55" />
  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" />
  38. <el-table-column label="字典值" prop="value" width="120" />
  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" />
  43. <el-table-column label="按钮组">
  44. <template slot-scope="scope">
  45. <el-button size="small" type="primary" @click="updateSysDictionaryDetail(scope.row)">变更</el-button>
  46. <el-popover v-model="scope.row.visible" placement="top" width="160">
  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 slot="reference" type="danger" icon="el-icon-delete" size="mini">删除</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. layout="total, sizes, prev, pager, next, jumper"
  64. @current-change="handleCurrentChange"
  65. @size-change="handleSizeChange"
  66. />
  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. />
  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. />
  86. </el-form-item>
  87. <el-form-item label="启用状态" prop="status" required>
  88. <el-switch v-model="formData.status" active-text="开启" inactive-text="停用" />
  89. </el-form-item>
  90. <el-form-item label="排序标记" prop="sort">
  91. <el-input-number v-model.number="formData.sort" placeholder="排序标记" />
  92. </el-form-item>
  93. </el-form>
  94. <div slot="footer" class="dialog-footer">
  95. <el-button @click="closeDialog">取 消</el-button>
  96. <el-button type="primary" @click="enterDialog">确 定</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. filters: {
  114. formatDate: function(time) {
  115. if (time !== null && time !== '') {
  116. var date = new Date(time)
  117. return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
  118. } else {
  119. return ''
  120. }
  121. },
  122. formatBoolean: function(bool) {
  123. if (bool !== null) {
  124. return bool ? '是' : '否'
  125. } else {
  126. return ''
  127. }
  128. }
  129. },
  130. mixins: [infoList],
  131. data() {
  132. return {
  133. listApi: getSysDictionaryDetailList,
  134. dialogFormVisible: false,
  135. type: '',
  136. formData: {
  137. label: null,
  138. value: null,
  139. status: true,
  140. sort: null
  141. },
  142. rules: {
  143. label: [
  144. {
  145. required: true,
  146. message: '请输入展示值',
  147. trigger: 'blur'
  148. }
  149. ],
  150. value: [
  151. {
  152. required: true,
  153. message: '请输入字典值',
  154. trigger: 'blur'
  155. }
  156. ],
  157. sort: [
  158. {
  159. required: true,
  160. message: '排序标记',
  161. trigger: 'blur'
  162. }
  163. ]
  164. }
  165. }
  166. },
  167. created() {
  168. this.searchInfo.sysDictionaryID = Number(this.$route.params.id)
  169. this.getTableData()
  170. },
  171. methods: {
  172. // 条件搜索前端看此方法
  173. onSubmit() {
  174. this.page = 1
  175. this.pageSize = 10
  176. if (this.searchInfo.status === '') {
  177. this.searchInfo.status = null
  178. }
  179. this.getTableData()
  180. },
  181. async updateSysDictionaryDetail(row) {
  182. const res = await findSysDictionaryDetail({ ID: row.ID })
  183. this.type = 'update'
  184. if (res.code === 0) {
  185. this.formData = res.data.resysDictionaryDetail
  186. this.dialogFormVisible = true
  187. }
  188. },
  189. closeDialog() {
  190. this.dialogFormVisible = false
  191. this.formData = {
  192. label: null,
  193. value: null,
  194. status: true,
  195. sort: null,
  196. sysDictionaryID: ''
  197. }
  198. },
  199. async deleteSysDictionaryDetail(row) {
  200. row.visible = false
  201. const res = await deleteSysDictionaryDetail({ ID: row.ID })
  202. if (res.code === 0) {
  203. this.$message({
  204. type: 'success',
  205. message: '删除成功'
  206. })
  207. if (this.tableData.length === 1 && this.page > 1) {
  208. this.page--
  209. }
  210. this.getTableData()
  211. }
  212. },
  213. async enterDialog() {
  214. this.formData.sysDictionaryID = Number(this.$route.params.id)
  215. this.$refs['elForm'].validate(async valid => {
  216. if (!valid) return
  217. let res
  218. switch (this.type) {
  219. case 'create':
  220. res = await createSysDictionaryDetail(this.formData)
  221. break
  222. case 'update':
  223. res = await updateSysDictionaryDetail(this.formData)
  224. break
  225. default:
  226. res = await createSysDictionaryDetail(this.formData)
  227. break
  228. }
  229. if (res.code === 0) {
  230. this.$message({
  231. type: 'success',
  232. message: '创建/更改成功'
  233. })
  234. this.closeDialog()
  235. this.getTableData()
  236. }
  237. })
  238. },
  239. openDialog() {
  240. this.type = 'create'
  241. this.dialogFormVisible = true
  242. }
  243. }
  244. }
  245. </script>
  246. <style>
  247. </style>