CatalogEditForm.vue 6.7 KB

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