CatalogEditForm.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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="105"
  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="currentCatalog.name"
  102. class="bs-el-input"
  103. />
  104. </el-form-item>
  105. <el-form-item
  106. label="排序"
  107. >
  108. <el-input-number
  109. v-model="currentCatalog.orderNum"
  110. :min="0"
  111. :max="30000"
  112. controls-position="right"
  113. class="bs-el-input-number"
  114. />
  115. </el-form-item>
  116. </el-form>
  117. <span
  118. slot="footer"
  119. class="dialog-footer"
  120. >
  121. <el-button
  122. class="bs-el-button-default"
  123. @click="catalogVisible = false"
  124. >
  125. 取消
  126. </el-button>
  127. <el-button
  128. type="primary"
  129. @click="addOrEditCatalog"
  130. >确定</el-button>
  131. </span>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script>
  136. // import { get, post } from 'data-room-ui/js/utils/http'
  137. // import Icon from 'data-room-ui/assets/images/dataSourceIcon/export'
  138. import _ from 'lodash'
  139. export default {
  140. name: 'CatalogEditForm',
  141. components: {
  142. },
  143. props: {
  144. catalogType: {
  145. type: String,
  146. default: ''
  147. },
  148. catalogList: {
  149. type: Array,
  150. default: () => {}
  151. }
  152. },
  153. data () {
  154. return {
  155. searchKey: '', // 分组查询
  156. catalogVisible: false,
  157. currentCatalog: {},
  158. formVisible: false,
  159. formRules: {
  160. name: [
  161. { required: true, message: '分组名称不能为空', trigger: 'blur' }
  162. ]
  163. }
  164. }
  165. },
  166. computed: {
  167. tableList: {
  168. get () {
  169. return _.cloneDeep(this.catalogList)
  170. },
  171. set () {
  172. }
  173. }
  174. },
  175. watch: {
  176. },
  177. mounted () {
  178. // this.getCatalogList()
  179. },
  180. methods: {
  181. reSearch () {
  182. },
  183. // 获取分组列表
  184. getCatalogList () {
  185. this.$dataRoomAxios.get(`/bigScreen/type/list/${this.catalogType}`)
  186. .then((data) => {
  187. this.tableList = data
  188. })
  189. .catch(() => {})
  190. },
  191. // 新增编辑目录(点击确定)
  192. addOrEditCatalog () {
  193. this.$refs.form.validate(async (valid) => {
  194. if (!valid) {
  195. return
  196. }
  197. if (!this.currentCatalog.id) {
  198. this.$dataRoomAxios.post('/bigScreen/type/add',
  199. {
  200. ...this.currentCatalog,
  201. type: this.catalogType
  202. }).then(data => {
  203. this.catalogVisible = false
  204. this.getCatalogList()
  205. }).catch(() => {
  206. })
  207. } else {
  208. this.$dataRoomAxios.post('/bigScreen/type/update', { ...this.currentCatalog, type: this.type || 'bigScreenCatalog' }).then(data => {
  209. this.catalogVisible = false
  210. this.getCatalogList()
  211. }).catch(() => {
  212. })
  213. }
  214. })
  215. },
  216. addCatalog () {
  217. this.currentCatalog = {
  218. name: '',
  219. id: '',
  220. code: ''
  221. }
  222. this.catalogVisible = true
  223. },
  224. editCatalog (row) {
  225. this.currentCatalog = row
  226. this.catalogVisible = true
  227. },
  228. // 删除目录
  229. catalogDel (catalog) {
  230. this.$confirm('确定删除该目录?', '提示', {
  231. confirmButtonText: '确定',
  232. cancelButtonText: '取消',
  233. type: 'warning',
  234. customClass: 'bs-el-message-box'
  235. }).then(async () => {
  236. this.$dataRoomAxios.post(`/bigScreen/type/delete/${catalog.id}`).then(() => {
  237. this.$message({
  238. type: 'success',
  239. message: '删除成功'
  240. })
  241. this.getCatalogList()
  242. }).catch(() => {
  243. this.$message({
  244. type: 'error',
  245. message: '删除失败!'
  246. })
  247. })
  248. }).catch()
  249. },
  250. // 关闭目录弹窗
  251. handleClose () {
  252. this.catalogVisible = false
  253. this.$refs.form.clearValidate()
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. @import '../assets/style/bsTheme.scss';
  260. .catalog-edit-wrap{
  261. .el-input {
  262. width: 200px;
  263. margin-right: 20px
  264. }
  265. }
  266. </style>