CatalogEditForm.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div>
  3. <el-dialog
  4. :close-on-click-modal="false"
  5. title="分组管理"
  6. :visible.sync="formVisible"
  7. :append-to-body="true"
  8. custom-class="bs-el-dialog"
  9. destroy-on-close
  10. class="bs-dialog-wrap bs-el-dialog catalog-edit-wrap"
  11. >
  12. <el-form
  13. v-if="formVisible"
  14. ref="dataForm"
  15. label-position="right"
  16. label-width="100px"
  17. class="bs-el-form"
  18. >
  19. <div class="top-search-wrap">
  20. <el-input
  21. v-model="searchKey"
  22. class="bs-el-input"
  23. placeholder="请输入分组名称"
  24. prefix-icon="el-icon-search"
  25. clearable
  26. @clear="reSearch"
  27. @keyup.enter.native="reSearch"
  28. />
  29. <el-button
  30. type="primary"
  31. @click="reSearch"
  32. >
  33. 搜索
  34. </el-button>
  35. <el-button
  36. type="primary"
  37. @click="addCatalog"
  38. >
  39. 新增
  40. </el-button>
  41. </div>
  42. <el-table
  43. :key="randomKey"
  44. max-height="400"
  45. class="bs-el-table"
  46. :data="tableList"
  47. >
  48. <el-empty />
  49. <el-table-column
  50. show-overflow-tooltip
  51. label="分组名称"
  52. prop="name"
  53. align="center"
  54. />
  55. <el-table-column
  56. show-overflow-tooltip
  57. label="排序"
  58. prop="orderNum"
  59. align="center"
  60. />
  61. <el-table-column
  62. label="操作"
  63. width="150"
  64. align="center"
  65. >
  66. <template slot-scope="scope">
  67. <el-button
  68. type="text"
  69. @click="editCatalog(scope.row)"
  70. >
  71. 编辑
  72. </el-button>
  73. <el-button
  74. type="text"
  75. @click="catalogDel(scope.row)"
  76. >
  77. 删除
  78. </el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. </el-form>
  83. </el-dialog>
  84. <!-- 新增或编辑目录弹窗 -->
  85. <el-dialog
  86. :title="currentCatalog.code ? '编辑分组' : '新建分组'"
  87. :visible.sync="catalogVisible"
  88. custom-class="bs-el-dialog"
  89. width="30%"
  90. class="bs-dialog-wrap bs-el-dialog"
  91. @close="handleClose"
  92. >
  93. <el-form
  94. ref="form"
  95. :model="currentCatalog"
  96. label-width="80px"
  97. :rules="formRules"
  98. class="bs-el-form"
  99. >
  100. <el-form-item
  101. label="分组名称"
  102. prop="name"
  103. >
  104. <el-input
  105. v-model.trim="currentCatalog.name"
  106. class="bs-el-input"
  107. clearable
  108. />
  109. </el-form-item>
  110. <el-form-item label="排序">
  111. <el-input-number
  112. v-model="currentCatalog.orderNum"
  113. :min="0"
  114. :max="30000"
  115. controls-position="right"
  116. class="bs-el-input-number"
  117. />
  118. </el-form-item>
  119. </el-form>
  120. <span
  121. slot="footer"
  122. class="dialog-footer"
  123. >
  124. <el-button
  125. class="bs-el-button-default"
  126. @click="catalogVisible = false"
  127. >
  128. 取消
  129. </el-button>
  130. <el-button
  131. type="primary"
  132. @click="addOrEditCatalog"
  133. >
  134. 确定
  135. </el-button>
  136. </span>
  137. </el-dialog>
  138. </div>
  139. </template>
  140. <script>
  141. import cloneDeep from 'lodash/cloneDeep'
  142. export default {
  143. name: 'CatalogEditForm',
  144. components: {
  145. },
  146. props: {
  147. catalogType: {
  148. type: String,
  149. default: ''
  150. }
  151. },
  152. data () {
  153. // 检验分组名称是否重复
  154. const validateName = (rule, value, callback) => {
  155. this.$dataRoomAxios.post('/bigScreen/type/nameRepeat', {
  156. name: value,
  157. type: this.catalogType
  158. }, true).then((r) => {
  159. if (r.data) {
  160. callback(new Error('分组名称已存在'))
  161. } else {
  162. callback()
  163. }
  164. })
  165. }
  166. return {
  167. dataList: [], // 模糊查询时用来给数据备份
  168. tableList: [],
  169. randomKey: '',
  170. searchKey: '', // 分组查询
  171. catalogVisible: false,
  172. currentCatalog: {},
  173. formVisible: false,
  174. formRules: {
  175. name: [
  176. { required: true, message: '分组名称不能为空', trigger: 'blur' },
  177. { validator: validateName, trigger: 'blur' }
  178. ]
  179. }
  180. }
  181. },
  182. computed: {
  183. },
  184. watch: {
  185. catalogType () {
  186. this.getCatalogList()
  187. }
  188. },
  189. mounted () {
  190. this.getCatalogList()
  191. },
  192. methods: {
  193. reSearch () {
  194. const arr = this.dataList
  195. this.tableList = arr?.filter((item) => item.name?.indexOf(this.searchKey) !== -1)
  196. },
  197. // 获取分组列表
  198. getCatalogList () {
  199. this.$dataRoomAxios.get(`/bigScreen/type/list/${this.catalogType}`)
  200. .then((data) => {
  201. this.tableList = data
  202. this.dataList = data
  203. this.$emit('updateCatalogList', data)
  204. })
  205. .catch(() => { })
  206. },
  207. // 新增编辑目录(点击确定)
  208. addOrEditCatalog () {
  209. this.$refs.form.validate(async (valid) => {
  210. if (!valid) {
  211. return
  212. }
  213. if (!this.currentCatalog.id) {
  214. this.$dataRoomAxios.post('/bigScreen/type/add',
  215. {
  216. ...this.currentCatalog,
  217. type: this.catalogType
  218. }).then(data => {
  219. this.catalogVisible = false
  220. this.getCatalogList()
  221. }).catch(() => {
  222. })
  223. } else {
  224. this.$dataRoomAxios.post('/bigScreen/type/update', { ...this.currentCatalog, type: this.catalogType }).then(data => {
  225. this.catalogVisible = false
  226. this.getCatalogList()
  227. }).catch(() => {
  228. })
  229. }
  230. })
  231. },
  232. addCatalog () {
  233. this.currentCatalog = {
  234. name: '',
  235. id: '',
  236. code: '',
  237. orderNum: 0
  238. }
  239. this.catalogVisible = true
  240. },
  241. editCatalog (row) {
  242. this.currentCatalog = cloneDeep(row)
  243. this.catalogVisible = true
  244. },
  245. // 删除目录
  246. catalogDel (catalog) {
  247. this.$confirm('确定删除该分组?', '提示', {
  248. confirmButtonText: '确定',
  249. cancelButtonText: '取消',
  250. type: 'warning',
  251. customClass: 'bs-el-message-box'
  252. }).then(async () => {
  253. this.$dataRoomAxios.post(`/bigScreen/type/delete/${catalog.id}`).then(() => {
  254. this.$message({
  255. type: 'success',
  256. message: '删除成功'
  257. })
  258. this.getCatalogList()
  259. }).catch(() => {
  260. this.$message({
  261. type: 'error',
  262. message: '删除失败!'
  263. })
  264. })
  265. }).catch()
  266. },
  267. // 关闭分组弹窗
  268. handleClose () {
  269. this.catalogVisible = false
  270. this.$refs.form.clearValidate()
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. @import '../assets/style/bsTheme.scss';
  277. .catalog-edit-wrap{
  278. ::v-deep .el-dialog__body{
  279. min-height: 300px !important;
  280. }
  281. .el-input {
  282. width: 200px;
  283. margin-right: 20px;
  284. }
  285. .top-search-wrap {
  286. display: flex;
  287. align-items: center;
  288. justify-content: flex-start;
  289. margin-bottom: 12px;
  290. .el-input {
  291. width: 200px;
  292. margin-right: 20px;
  293. ::v-deep.el-input__inner {
  294. background-color: #151A26 !important;
  295. }
  296. }
  297. }
  298. }
  299. </style>