You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.8 KiB

5 years ago
5 years ago
  1. <template>
  2. <section style="margin-top: 10px;margin-right: 10px;">
  3. <el-input v-model="categoryFilterText" v-if="showFilter=='true'" placeholder="分类名称、编号过滤" auto-complete="off"></el-input>
  4. <el-tree
  5. class="filter-tree"
  6. :data="categoryTreeData"
  7. :props="defaultCategoryTreeProps"
  8. :filter-node-method="filterCategoryNode"
  9. :show-checkbox="showCheckbox"
  10. :default-expand-all="defaultExpandAll"
  11. :expand-on-click-node="expandOnClickNode"
  12. :indent="indent"
  13. :node-key="nodeKey_"
  14. :default-expanded-keys="defaultExpandedKeys"
  15. :default-checked-keys="defaultCheckedKeys"
  16. auto-expand-parent
  17. @check-change="handleCheckChange"
  18. @current-change="handleCurrentChange"
  19. @node-click="handleNodeClick"
  20. check-strictly
  21. :accordion="true"
  22. highlight-current
  23. :render-content="renderContent"
  24. ref="categoryTree"
  25. :style="treeStyle">
  26. </el-tree>
  27. </section>
  28. </template>
  29. <script>
  30. import util from '../../common/js/util'
  31. import { getImageCategoryTrees } from '@/api/mdp/arc/imageCategory';
  32. import { mapGetters } from 'vuex';
  33. export default {
  34. watch: {
  35. categoryFilterText(val) {
  36. this.$refs.categoryTree.filter(val);
  37. },
  38. // locationId(locationId) {
  39. // this.getCategoryTreeData(false);
  40. // },branchId
  41. branchId(branchId) {
  42. this.getCategoryTreeData(false);
  43. },
  44. checkedKeys(val){
  45. this.$refs.categoryTree.setCheckedKeys(val);
  46. },
  47. refresh(val){
  48. this.getCategoryTreeData(refresh);
  49. },
  50. /* currentKey(val){
  51. //console.log("111111111111111111111111111");
  52. //console.log(val);
  53. this.categoryTreeData=[];
  54. // this.$refs.categoryTreeTag.getCategoryTreeData();
  55. this.getCategoryTreeData();
  56. //this.$refs.categoryTree.setCheckedKeys([val]);
  57. this.$refs.categoryTree.setCurrentKey(val);
  58. }, */
  59. },
  60. computed:{
  61. defaultExpandedKeys(){
  62. return this.defaultCheckedKeys;
  63. },
  64. defaultCheckedKeys(){
  65. if(!!this.currentKey){
  66. return [this.currentKey];
  67. }
  68. /* if(!!this.checkedKeys&&this.checkedKeys.length>0){
  69. return this.checkedKeys
  70. }; */
  71. if(!!this.checkedKeys&&this.checkedKeys.length>0){
  72. var flag=this.checkedKeys.some(y=>{
  73. if(!y){
  74. return true;
  75. }
  76. });
  77. if(!flag){
  78. return this.checkedKeys
  79. }
  80. }
  81. return ["0"];
  82. },
  83. nodeKey_(){
  84. return this.nodeKey?this.nodeKey:'id'
  85. },
  86. ...mapGetters([
  87. 'userInfo'
  88. ])
  89. },
  90. props: ['visible','currentKey','nodeKey','showCount','countTips','showFilter','rootKey','multiple','checkedKeys','refresh','defaultExpandAll','expandOnClickNode','showCheckbox','indent','treeStyle','locationId'],
  91. data() {
  92. return {
  93. categoryFilterText: '',
  94. categoryTreeData:[],
  95. defaultCategoryTreeProps:{
  96. id:this.nodeKey_,
  97. label:'categoryName',
  98. children: 'children'
  99. },
  100. listLoading: false
  101. }
  102. },
  103. methods: {
  104. handleCheckChange(data, checked, indeterminate) {
  105. let checkedKeys=this.$refs.categoryTree.getCheckedKeys();
  106. if( !this.multiple || this.multiple==false||this.multiple=='false'){
  107. if(checked==true){
  108. if(checkedKeys.length>1){
  109. this.$refs.categoryTree.setCheckedKeys([data[this.nodeKey_]]);
  110. this.$emit('check-change',data,checked,indeterminate);
  111. }else{
  112. this.$emit('check-change',data,checked,indeterminate);
  113. }
  114. }else{
  115. if(checkedKeys.length==0){
  116. this.$emit('check-change',data,checked,indeterminate);
  117. }
  118. }
  119. }else{
  120. this.$emit('check-change',data,checked,indeterminate);
  121. }
  122. },
  123. handleCurrentChange(data, node) {
  124. this.$emit('current-change',data, node);
  125. },
  126. handleNodeClick(data, node, comp) {
  127. this.$emit('node-click',data, node, comp);
  128. },
  129. //获取分类树列表
  130. getCategoryTreeData(refresh) {
  131. console.log("进来这里");
  132. let id='';
  133. if(this.rootKey!='' && this.rootKey!=null){
  134. id=this.rootKey;
  135. }
  136. let params = {
  137. id: id,
  138. branchId:this.userInfo.branchId
  139. };
  140. console.log("进来这里第二部");
  141. // if(this.branchId!=''&&this.branchId!=undefined){
  142. // params.branchId=this.branchId
  143. // }else{
  144. // this.categoryTreeData=[];
  145. // return ;
  146. // }
  147. if(refresh==true){
  148. params.refresh=1;
  149. }
  150. this.listLoading = true;
  151. this.categoryTreeData=[];
  152. getImageCategoryTrees(params).then((res) => {
  153. var tips=res.data.tips;
  154. console.log("进来这里第三部");
  155. if(tips.isOk==true){
  156. console.log("进来这里第四部");
  157. var data = res.data.data;
  158. data.disabled=true;
  159. console.log("数据");
  160. console.log(data);
  161. this.categoryTreeData=[res.data.data];
  162. this.$refs.categoryTree.setCurrentKey(this.currentKey);
  163. }else{
  164. this.$message({showClose: true, message: tips.msg, type: 'error'});
  165. }
  166. this.listLoading = false;
  167. }).catch(() => {
  168. this.listLoading = false;
  169. });
  170. },
  171. filterCategoryNode(value, data) {
  172. if (!value) return true;
  173. return data.categoryName.indexOf(value) !== -1;
  174. },
  175. renderContent(h, { node, data, store }) {
  176. var countMsg='';
  177. if(this.countTips){
  178. countMsg=this.countTips;
  179. }
  180. if(this.showCount==true || this.showCount=='true'){
  181. return h('span',node.label) ;
  182. }else{
  183. return h('span',node.label+"("+(data.isPub=='1'?'公共分类':'')+countMsg+")") ;
  184. }
  185. }
  186. },
  187. mounted() {
  188. this.getCategoryTreeData();
  189. }
  190. }
  191. </script>
  192. <style scoped>
  193. </style>