CatalogEditForm.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. class="bs-el-table"
  45. height="100%"
  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="105"
  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="groupForm.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="groupForm"
  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="groupForm.name"
  106. class="bs-el-input"
  107. clearable
  108. />
  109. </el-form-item>
  110. <el-form-item
  111. label="排序"
  112. >
  113. <el-input-number
  114. v-model="groupForm.orderNum"
  115. :min="0"
  116. :max="30000"
  117. controls-position="right"
  118. class="bs-el-input-number"
  119. />
  120. </el-form-item>
  121. </el-form>
  122. <span
  123. slot="footer"
  124. class="dialog-footer"
  125. >
  126. <el-button
  127. class="bs-el-button-default"
  128. @click="catalogVisible = false"
  129. >
  130. 取消
  131. </el-button>
  132. <el-button
  133. type="primary"
  134. @click="addOrEditCatalog"
  135. >
  136. 确定
  137. </el-button>
  138. </span>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import { cloneDeep } from 'lodash'
  144. export default {
  145. name: 'CatalogEditForm',
  146. components: {
  147. },
  148. props: {
  149. catalogType: {
  150. type: String,
  151. default: ''
  152. }
  153. },
  154. data () {
  155. return {
  156. dataList: [], // 模糊查询时用来给数据备份
  157. tableList: [],
  158. randomKey: '',
  159. searchKey: '', // 分组查询
  160. catalogVisible: false,
  161. currentCatalog: {},
  162. formVisible: false,
  163. formRules: {
  164. name: [
  165. { required: true, message: '分组名称不能为空', trigger: 'blur' }
  166. ]
  167. },
  168. groupForm: {
  169. code: '',
  170. name: '',
  171. orderNum: 0
  172. }
  173. }
  174. },
  175. computed: {
  176. },
  177. watch: {
  178. catalogType () {
  179. this.getCatalogList()
  180. }
  181. },
  182. mounted () {
  183. this.getCatalogList()
  184. },
  185. methods: {
  186. reSearch () {
  187. const arr = this.dataList
  188. this.tableList = arr?.filter((item) => item.name?.indexOf(this.searchKey) !== -1)
  189. },
  190. // 获取分组列表
  191. getCatalogList () {
  192. this.$dataRoomAxios.get(`/bigScreen/type/list/${this.catalogType}`)
  193. .then((data) => {
  194. this.tableList = data
  195. this.dataList = data
  196. this.$emit('updateCatalogList', data)
  197. })
  198. .catch(() => {})
  199. },
  200. // 新增编辑目录(点击确定)
  201. addOrEditCatalog () {
  202. this.$refs.form.validate(async (valid) => {
  203. if (!valid) {
  204. return
  205. }
  206. this.currentCatalog = {
  207. ...this.currentCatalog,
  208. ...this.groupForm
  209. }
  210. if (!this.currentCatalog.id) {
  211. this.$dataRoomAxios.post('/bigScreen/type/add',
  212. {
  213. ...this.currentCatalog,
  214. type: this.catalogType
  215. }).then(data => {
  216. this.catalogVisible = false
  217. this.getCatalogList()
  218. }).catch(() => {
  219. })
  220. } else {
  221. this.$dataRoomAxios.post('/bigScreen/type/update', { ...this.currentCatalog, type: this.catalogType }).then(data => {
  222. this.catalogVisible = false
  223. this.getCatalogList()
  224. }).catch(() => {
  225. })
  226. }
  227. })
  228. },
  229. addCatalog () {
  230. this.currentCatalog = {
  231. name: '',
  232. id: '',
  233. code: ''
  234. }
  235. this.catalogVisible = true
  236. },
  237. editCatalog (row) {
  238. this.groupForm = cloneDeep(row)
  239. this.catalogVisible = true
  240. },
  241. // 删除目录
  242. catalogDel (catalog) {
  243. this.$confirm('确定删除该分组?', '提示', {
  244. confirmButtonText: '确定',
  245. cancelButtonText: '取消',
  246. type: 'warning',
  247. customClass: 'bs-el-message-box'
  248. }).then(async () => {
  249. this.$dataRoomAxios.post(`/bigScreen/type/delete/${catalog.id}`).then(() => {
  250. this.$message({
  251. type: 'success',
  252. message: '删除成功'
  253. })
  254. this.getCatalogList()
  255. }).catch(() => {
  256. this.$message({
  257. type: 'error',
  258. message: '删除失败!'
  259. })
  260. })
  261. }).catch()
  262. },
  263. // 关闭分组弹窗
  264. handleClose () {
  265. this.catalogVisible = false
  266. this.$refs.form.clearValidate()
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="scss" scoped>
  272. @import '../assets/style/bsTheme.scss';
  273. .catalog-edit-wrap{
  274. ::v-deep .el-dialog__body{
  275. min-height: 500px !important;
  276. }
  277. .el-input {
  278. width: 200px;
  279. margin-right: 20px;
  280. }
  281. .top-search-wrap {
  282. display: flex;
  283. align-items: center;
  284. justify-content: flex-start;
  285. margin-bottom: 12px;
  286. .el-input {
  287. width: 200px;
  288. margin-right: 20px;
  289. ::v-deep.el-input__inner {
  290. background-color: #151A26 !important;
  291. }
  292. }
  293. }
  294. }
  295. </style>