albumClassifyList.vue 11 KB

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