CatalogEditForm.vue 6.7 KB

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