material-tree.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!-- 选择物料 -->
  2. <template>
  3. <view>
  4. <uni-nav-bar title="选择物料" @clickLeft="$utils.back()" :status-bar="true" background-color="#3F92F9" color="#FFF">
  5. <view slot="left">
  6. <u-icon name="arrow-leftward" color="#FFF" size="35"></u-icon>
  7. </view>
  8. </uni-nav-bar>
  9. <view class="container">
  10. <scroll-view
  11. scroll-y="true"
  12. style="height: calc(100vh - 150rpx);padding-bottom: 50rpx;">
  13. <xiaolu-tree
  14. v-slot:default="{item}"
  15. :checkList="checkList"
  16. v-if="tree.length>0"
  17. :max="max" :props="prop"
  18. @sendValue="confirm"
  19. :parent="true"
  20. :isCheck="true"
  21. :trees="tree">
  22. <!-- 内容插槽 -->
  23. <view>
  24. <view class="content-item">
  25. <view class="word">{{item.name}}</view>
  26. </view>
  27. </view>
  28. </xiaolu-tree>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import XiaoluTree from '@/components/xiaolu-tree/tree.vue';
  35. import dataList from './data.js'
  36. export default {
  37. components: {
  38. XiaoluTree
  39. },
  40. data() {
  41. return {
  42. tree: [],
  43. checkList: [],
  44. backList: this.checkList,
  45. prop:{},
  46. max: 5,
  47. aprop: {
  48. label: 'name',
  49. children: 'children',
  50. multiple:true
  51. },
  52. bprop: {
  53. label: 'name',
  54. children: 'children',
  55. multiple:true,
  56. checkStrictly:true
  57. },
  58. cprop: {//单选模式(任意一项)
  59. label: 'name',
  60. children: 'children',
  61. multiple:false,
  62. nodes:false
  63. },
  64. dprop: {//单选模式选user
  65. label: 'name',
  66. children: 'children',
  67. multiple:false,
  68. nodes:true
  69. }
  70. }
  71. },
  72. onLoad(option) {
  73. this.$http.GetZTreeChildren().then(res => {
  74. if(res.code === 0) {
  75. this.tree = res.result
  76. this.handleArray(this.tree)
  77. }
  78. })
  79. // this.tree=dataList;//树形数据赋值
  80. // #ifdef H5
  81. // let obj = option.arr.replace("\"([^\"]*)\"", "$1");
  82. // let checkList = JSON.parse(obj);
  83. // // #endif
  84. // // #ifdef MP-QQ||MP-WEIXIN||APP-NVUE||APP-PLUS
  85. // let checkList = JSON.parse(option.arr);
  86. // // #endif
  87. this.checkList = []
  88. // this.checkList = checkList;
  89. if(option.type==0){
  90. this.prop=this.aprop;//多选
  91. }else if(option.type==1){
  92. this.prop=this.bprop;//多选
  93. }else if(option.type==2){
  94. this.prop=this.cprop;//单选任意一项
  95. }else{
  96. this.prop=this.dprop;//单选user
  97. }
  98. },
  99. methods: {
  100. handleArray(array) {
  101. array.forEach(item => {
  102. if(item.children && item.children.length > 0) {
  103. this.handleArray(item.children)
  104. } else {
  105. item.isEnd = true
  106. }
  107. })
  108. },
  109. //获取选中的值
  110. confirm(val,back) {
  111. // this.checkList = val;
  112. if(back){
  113. this.backConfirm(val)
  114. return
  115. }
  116. this.backList = val;
  117. },
  118. // 返回上一页传参
  119. backConfirm(val) {
  120. uni.$emit('materialcfm', val)
  121. uni.navigateBack();
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .box_sizing {
  128. -webkit-box-sizing: border-box;
  129. -moz-box-sizing: border-box;
  130. box-sizing: border-box;
  131. }
  132. .btn {
  133. position: fixed;
  134. bottom: 0;
  135. padding: 10px;
  136. background-color: #fff;
  137. width: 100%;
  138. .sureBtn {
  139. background-color: #0095F2;
  140. color: #fff;
  141. }
  142. }
  143. .content-item{
  144. display: flex;
  145. position: relative;
  146. align-items: center;
  147. .person {
  148. height: 36rpx;
  149. min-width: 64rpx;
  150. border-radius: 50%;
  151. border: 1rpx solid rgba(0, 149, 235, 0.15);
  152. background-color: rgba(0, 149, 235, 0.1);
  153. margin-left: 0px;
  154. color: #0095F2;
  155. line-height: 36rpx;
  156. font-size: 22rpx;
  157. text-align: center;
  158. margin-left: 20rpx;
  159. }
  160. .word {
  161. margin-left: 16rpx;
  162. font-size: 28rpx;
  163. color: #5b5757;
  164. width: 500rpx;
  165. word-break: break-all;
  166. }
  167. }
  168. </style>