tree.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view>
  3. <tree :checkList="checkList" :props="prop" @sendValue="confirm" :isCheck="true" :trees="tree" />
  4. <view class="btn box_sizing">
  5. <button class="sureBtn" type="primary" @click="backConfirm">确认</button>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. import {getMaterialTree} from '@/common/api/commonApi.js';
  11. export default {
  12. data() {
  13. return {
  14. tree: [],
  15. checkList: [],
  16. prop: {
  17. label: 'name',
  18. children: 'children',
  19. multiple:false,
  20. nodes:true
  21. }
  22. }
  23. },
  24. onLoad(o) {
  25. // var that = this
  26. this.$util.persistLogin(this);
  27. },
  28. created:function(){
  29. let classCode=this.$util.getQuery("classCode");
  30. this.getMaterialTree(classCode);
  31. },
  32. updated:function(){
  33. },
  34. mounted:function(){
  35. },
  36. methods: {
  37. //检查默认选中,要是字段钟本身包含了checked字段就不需要这个
  38. checks() {
  39. var that = this;
  40. for (var i = 0, len = that.tree.length; i < len; i++) {
  41. for (var j = 0, lens = that.checkList.length; j < lens; j++) {
  42. if (that.checkList[j].id === that.tree[i].id) {
  43. that.$set(that.tree[i], 'checked', true)
  44. break
  45. } else {
  46. that.$set(that.tree[i], 'checked', false)
  47. }
  48. }
  49. }
  50. },
  51. //获取选中的
  52. confirm(val) {
  53. this.checkList = val
  54. console.log(this.checkList,588)
  55. },
  56. backConfirm() {
  57. var pages = getCurrentPages();
  58. var currPage = pages[pages.length - 1]; //当前页面
  59. //var prevPage = pages[pages.length - 2]; //上一个页面
  60. //h5写法
  61. //prevPage.query = this.checkList;
  62. console.info('prevPage.query ',this.checkList);
  63. uni.$emit("intype",this.checkList);
  64. //return;
  65. //小程序写法
  66. //prevPage.$vm.query =this.checkList;
  67. uni.navigateBack();
  68. },
  69. getMaterialTree(classCode){
  70. let that=this;
  71. return new Promise((resolve,reject)=>{
  72. getMaterialTree(classCode).then(
  73. (res)=>{
  74. console.info(JSON.stringify(res));
  75. //that.tree=res;
  76. res.forEach((item,index,array)=>{
  77. that.$set(that.tree,index,item);
  78. });
  79. console.info(that.tree);
  80. resolve('suc');
  81. }).catch((err)=>{
  82. reject(err);
  83. });
  84. })
  85. },
  86. }
  87. }
  88. </script>
  89. <style lang="scss">
  90. .box_sizing {
  91. -webkit-box-sizing: border-box;
  92. -moz-box-sizing: border-box;
  93. box-sizing: border-box;
  94. }
  95. .btn {
  96. position: fixed;
  97. bottom: 0;
  98. padding: 10px;
  99. background-color: #fff;
  100. width: 100%;
  101. .sureBtn {
  102. background-color: #007AFF;
  103. color: #fff;
  104. }
  105. }
  106. .btn1 {
  107. position: fixed;
  108. bottom: 600px;
  109. padding: 10px;
  110. background-color: #fff;
  111. width: 100%;
  112. }
  113. .btn2 {
  114. position: fixed;
  115. bottom: 150px;
  116. padding: 10px;
  117. background-color: #fff;
  118. width: 100%;
  119. }
  120. </style>