albumClassifyList.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <rx-layout>
  3. <div slot="center" style>
  4. <rx-fit>
  5. <div slot="toolheader" border="false" foldbtn="false">
  6. <breadcrumb firstLevel="专辑管理" lastLevel="专辑分类" />
  7. <div class="mainContent">
  8. <div class="body">
  9. <div class="content">
  10. <a-form ref="searchForm" layout="inline" style="display:flex;">
  11. <div style="width:80%;display:flex;flex-wrap:wrap;">
  12. <a-form-item
  13. style="width:300px;margin: 5px 40px 5px 0;"
  14. label="分类名称"
  15. name="name">
  16. <a-input v-model="queryParam.name" placeholder="请输入"/>
  17. </a-form-item>
  18. </div>
  19. <div style="width:20%;display:flex;justify-content:flex-end;margin-top: 8px;">
  20. <a-button @click="handleResetClick(true)">重置</a-button>
  21. <a-button type="primary" @click="handleSearchClick">查询</a-button>
  22. </div>
  23. </a-form>
  24. <rx-button alias="albumClassifyListAdd" :butn-icon="'none'" @click="handleAddClassClick">新增分类</rx-button>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <rx-grid
  30. ref="albumClassifyRef"
  31. class="table-style"
  32. style="background: #fff"
  33. :columns="columns"
  34. :url="api.query"
  35. :queryParam="queryParam"
  36. data-field="result.data"
  37. :defaultPageSize="10"
  38. :pageSizeOptions="['10','20','30','40']"
  39. idField="pkId"
  40. >
  41. <template slot="name" slot-scope="{text}">
  42. <div style="white-space: pre-line">{{ text }}</div>
  43. </template>
  44. <template slot="action" slot-scope="{text,record,index}">
  45. <rx-button class="clearBtn" alias="albumClassifyListEdit" :butn-icon="'none'" v-if="record.isSys != 1" @click="handleUpdateClassifyClick(record)">编辑</rx-button>
  46. <rx-button class="clearBtn" alias="albumClassifyListLook" :butn-icon="'none'" @click="handleJumpKnowledgeManage(record)">查看专辑</rx-button>
  47. <template v-if="isShowButton">
  48. <rx-button v-if="index != (getDataLength(record) - 1)" class="clearBtn" alias="albumClassifyListRise" :butn-icon="'none'" @click="handleActionClick(record,2)">下降</rx-button>
  49. <rx-button v-if="index != 0" class="clearBtn" alias="albumClassifyListRise" :butn-icon="'none'" @click="handleActionClick(record,1)">上升</rx-button>
  50. </template>
  51. <rx-button class="clearBtn" alias="albumClassifyListDel" :butn-icon="'none'" v-if="record.isSys != 1" @click="handleDeleteClick(record)">删除</rx-button>
  52. </template>
  53. </rx-grid>
  54. </rx-fit>
  55. <a-modal v-model="classifyShow"
  56. :title="title"
  57. centered
  58. okText="保存"
  59. @ok="handleOk"
  60. :confirmLoading="saveLoading"
  61. @cancel="handleCancel">
  62. <a-form ref="classRef" :model="classForm" layout="inline" :label-col="{ span: 4 }">
  63. <a-form-item label="分类名称" prop="name">
  64. <a-input v-model="classForm.name" :maxLength="10" placeholder="请输入" />
  65. </a-form-item>
  66. <a-form-item label="上级分类" prop="parent" v-if="chooseLevel != 1">
  67. <a-cascader v-model="classForm.parent"
  68. ref="cascader"
  69. style="width: 100%;"
  70. :options="classifyLevelList"
  71. :fieldNames="{ label: 'name', value: 'pkId', children: 'children' }"
  72. placeholder="请选择上级分类,创建一级分类无需选择" />
  73. </a-form-item>
  74. <a-form-item label="排序" prop="sort">
  75. <div style="width:40%">
  76. <a-input-number v-model="classForm.sort" :min="1" />
  77. </div>
  78. </a-form-item>
  79. </a-form>
  80. </a-modal>
  81. </div>
  82. </rx-layout>
  83. </template>
  84. <script>
  85. import breadcrumb from '../components/breadcrumb.vue'
  86. import api from '@/api/knowledge/album/classify'
  87. import mixin from "../aMixin/mixin"
  88. const albumClassifyMixin = new mixin('albumClassify')
  89. export default {
  90. components: {
  91. breadcrumb
  92. },
  93. mixins: [ albumClassifyMixin ],
  94. data() {
  95. return {
  96. api,
  97. saveLoading: false,
  98. title: '',
  99. classifyShow: false,
  100. queryParam: {
  101. name: ''
  102. },
  103. columns:[
  104. {
  105. title: 'ID',
  106. dataIndex: 'pkId',
  107. align: 'center'
  108. },
  109. {
  110. title: '分类名称',
  111. dataIndex: 'name',
  112. // align: 'center',
  113. scopedSlots: {customRender: 'name'}
  114. },
  115. {
  116. title: '操作人',
  117. dataIndex: 'operator',
  118. align: 'center'
  119. },
  120. {
  121. title: '操作时间',
  122. dataIndex: 'updateTime',
  123. align: 'center'
  124. },
  125. {
  126. title: '操作',
  127. dataIndex: 'action',
  128. // align: 'center',
  129. scopedSlots: {customRender: 'action'},
  130. width: 250
  131. }
  132. ],
  133. classForm: {
  134. pkId: '',
  135. name: '',
  136. parent: [],
  137. sort: 0
  138. },
  139. // 编辑时不同等级的分类数据
  140. classifyLevelList: [],
  141. // 显示上升下降按钮
  142. isShowButton: true,
  143. // 选中的分类等级
  144. chooseLevel: 0,
  145. }
  146. },
  147. computed: {
  148. getDataLength() {
  149. return function(record) {
  150. if(record.grade == 1) {
  151. return this.$refs.albumClassifyRef.getData().length
  152. } else {
  153. let levelTwo = this.$refs.albumClassifyRef.getData().find(item => item.pkId == record.parent)
  154. if(levelTwo.children) {
  155. return levelTwo.children.length
  156. } else {
  157. return 0
  158. }
  159. }
  160. }
  161. }
  162. },
  163. created() {
  164. this.init()
  165. },
  166. methods: {
  167. async init() {
  168. let res = await api.listOflevel({level: 1})
  169. this.classifyLevelList = JSON.parse(JSON.stringify(res.data))
  170. },
  171. // 格式化数据 disabled 编辑三分类时,只有一级分类没有二级分类,则不可选一级分类
  172. getData(data,disabled = false) {
  173. data.forEach((element) => {
  174. if(element.children && element.children.length > 0 && element.level == 2) {
  175. this.getData(element.children)
  176. } else {
  177. if(disabled && element.level == 2) {
  178. element.disabled = true
  179. }
  180. delete element.children
  181. }
  182. })
  183. return data
  184. },
  185. // 搜索
  186. handleSearchClick() {
  187. this.isShowButton = this.queryParam.name ? false : true
  188. this.reloadTable()
  189. },
  190. handleAddClassClick() {
  191. this.title ='新增分类'
  192. this.chooseLevel = 0
  193. this.init()
  194. this.classifyShow = true
  195. },
  196. // 编辑页面显示
  197. async handleUpdateClassifyClick(record) {
  198. this.title = '编辑分类'
  199. this.chooseLevel = record.grade
  200. let res = await this.api.info({pkId: record.pkId})
  201. let gategoryId
  202. if(res.data.grade == 1) {
  203. gategoryId = []
  204. } else {
  205. gategoryId = [res.data.parent]
  206. }
  207. this.classForm = {
  208. pkId: record.pkId,
  209. name: record.name,
  210. parent: gategoryId,
  211. sort: record.sort
  212. }
  213. this.classifyShow = true
  214. },
  215. async handleOk() {
  216. if(!this.classForm.name) {
  217. this.$message.error("请输入分类名称");
  218. return
  219. }
  220. if(this.chooseLevel == 2 && !this.classForm.parent.length) {
  221. this.$message.error("请选择上级分类");
  222. return
  223. }
  224. this.saveLoading = true
  225. let parentId = this.classForm.parent[0] ? this.classForm.parent[0] : ''
  226. let res
  227. if(this.title == '新增分类') {
  228. res = await this.api.save({...this.classForm, parent: parentId})
  229. } else {
  230. res = await this.api.edit({...this.classForm, parent: parentId})
  231. }
  232. if(res.code == 200) {
  233. this.reloadTable()
  234. this.handleCancel()
  235. this.saveLoading = false
  236. }
  237. },
  238. handleCancel() {
  239. this.classifyShow = false
  240. this.classForm = Object.assign({},this.$options.data().classForm)
  241. },
  242. handleJumpKnowledgeManage(record) {
  243. this.$router.push({
  244. path: '/knowledge/albumList',
  245. query: {pkId: record.pkId}
  246. })
  247. },
  248. // 重新加载表格
  249. reloadTable() {
  250. this.$refs.albumClassifyRef.loadData()
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="less" scoped>
  256. @gary: #f8f8f8;
  257. @white: #fff;
  258. .rx-fit {
  259. padding: 40px!important;
  260. background: @gary;
  261. .fit-header {
  262. .mainContent {
  263. width: 100%;
  264. .body {
  265. background: @white;
  266. padding: 10px 20px;
  267. .content {
  268. background: @white;
  269. button:first-child {
  270. margin-right: 20px;
  271. }
  272. >button {
  273. margin: 10px;
  274. margin-left: 0;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. .table-style {
  281. padding: 20px;
  282. .clearBtn {
  283. background: none;
  284. color: #3294F7;
  285. text-shadow: none;
  286. padding: 0px 6px;
  287. border: none;
  288. box-shadow: none;
  289. }
  290. }
  291. }
  292. .show-other{
  293. width: 100%;
  294. animation:show-other-search 0.8s;
  295. }
  296. @keyframes show-other-search{
  297. 0%{opacity:0;}
  298. 50%{opacity:0.8;}
  299. 100%{opacity: 1;}
  300. }
  301. </style>
  302. <style scoped>
  303. /deep/ .ant-table-row-expand-icon{
  304. position: relative;
  305. z-index: 100;
  306. }
  307. /deep/.ant-btn > .anticon + span {
  308. margin-left: 0;
  309. }
  310. /deep/.ant-table-thead > tr > th {
  311. text-align: center;
  312. height: 54px;
  313. }
  314. /deep/ .ant-table-tbody > tr > td {
  315. height: 54px;
  316. }
  317. /deep/ .ant-form{
  318. padding: 0;
  319. }
  320. /deep/ .gridContent{
  321. border: none;
  322. }
  323. /deep/ .gridContent .ant-table-content .ant-table-tbody>tr>td:nth-child(2) {
  324. padding-left: 60px!important;
  325. }
  326. </style>