CatalogEditForm.vue 6.2 KB

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