CatalogEditForm.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. <div class="top-search-wrap">
  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. </div>
  40. <el-table
  41. :key="randomKey"
  42. class="bs-el-table"
  43. height="100%"
  44. :data="tableList"
  45. >
  46. <el-empty />
  47. <el-table-column
  48. show-overflow-tooltip
  49. label="名称"
  50. prop="name"
  51. align="center"
  52. />
  53. <el-table-column
  54. show-overflow-tooltip
  55. label="排序"
  56. prop="orderNum"
  57. align="center"
  58. />
  59. <el-table-column
  60. label="操作"
  61. width="105"
  62. align="center"
  63. >
  64. <template slot-scope="scope">
  65. <el-button
  66. type="text"
  67. @click="editCatalog(scope.row)"
  68. >
  69. 编辑
  70. </el-button>
  71. <el-button
  72. type="text"
  73. @click="catalogDel(scope.row)"
  74. >
  75. 删除
  76. </el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </el-form>
  81. </el-dialog>
  82. <!-- 新增或编辑目录弹窗 -->
  83. <el-dialog
  84. :title="currentCatalog.code ? '编辑分组':'新建分组'"
  85. :visible.sync="catalogVisible"
  86. custom-class="bs-el-dialog"
  87. width="30%"
  88. class="bs-dialog-wrap bs-el-dialog"
  89. @close="handleClose"
  90. >
  91. <el-form
  92. ref="form"
  93. :model="currentCatalog"
  94. label-width="80px"
  95. :rules="formRules"
  96. >
  97. <el-form-item
  98. label="分组名称"
  99. prop="name"
  100. >
  101. <el-input
  102. v-model="currentCatalog.name"
  103. class="bs-el-input"
  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. >确定</el-button>
  132. </span>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script>
  137. import { get, post } from 'packages/js/utils/http'
  138. export default {
  139. name: 'CatalogEditForm',
  140. components: {
  141. },
  142. props: {
  143. catalogType: {
  144. type: String,
  145. default: ''
  146. }
  147. },
  148. data () {
  149. return {
  150. dataList: [], // 模糊查询时用来给数据备份
  151. tableList: [],
  152. randomKey: '',
  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. },
  166. watch: {
  167. catalogType () {
  168. this.getCatalogList()
  169. }
  170. },
  171. mounted () {
  172. this.getCatalogList()
  173. },
  174. methods: {
  175. reSearch () {
  176. const arr = this.dataList
  177. this.tableList = arr?.filter((item) => item.name?.indexOf(this.searchKey) !== -1)
  178. },
  179. // 获取分组列表
  180. getCatalogList () {
  181. get(`/bigScreen/type/list/${this.catalogType}`)
  182. .then((data) => {
  183. this.tableList = data
  184. this.dataList = data
  185. this.$emit('updateCatalogList', 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.catalogType }).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. .top-search-wrap {
  267. display: flex;
  268. align-items: center;
  269. justify-content: flex-start;
  270. margin-bottom: 12px;
  271. .el-input {
  272. width: 200px;
  273. margin-right: 20px;
  274. /deep/.el-input__inner {
  275. background-color: #151A26 !important;
  276. }
  277. }
  278. }
  279. }
  280. </style>