danpicker.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <!-- 树形层级选择器-->
  2. <!-- 1、支持单选、多选 -->
  3. <template>
  4. <view class="xmmain">
  5. <view class="tree-cover" :class="{'show':showDialog}" @tap="_cancel"></view>
  6. <view class="tree-dialog" :class="{'show':showDialog}">
  7. <view class="tree-bar">
  8. <view class="tree-bar-cancel" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_cancel">取消
  9. </view>
  10. <view class="tree-bar-title" :style="{'color':titleColor}">{{title}}</view>
  11. <view class="tree-bar-confirm" :style="{'color':confirmColor}" hover-class="hover-c" @tap="_confirm">
  12. {{multiple?'确定':''}}
  13. </view>
  14. </view>
  15. <view class="tree-view">
  16. <scroll-view class="tree-list" :scroll-y="true">
  17. <uni-data-checkbox selectedTextColor='#343434' :map="map" :multiple="multiple" v-model="bgvalue" :localdata="localdata" @change="checkboxChangeadr"></uni-data-checkbox>
  18. </scroll-view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. emits: ['select-change'],
  26. name: "ba-tree-picker",
  27. props: {
  28. map:{
  29. type: Object,
  30. default: {},
  31. },
  32. mvalue:{
  33. type: Array,
  34. default: function() {
  35. return []
  36. }
  37. },
  38. valueKey: {
  39. type: String,
  40. default: 'id'
  41. },
  42. textKey: {
  43. type: String,
  44. default: 'name'
  45. },
  46. childrenKey: {
  47. type: String,
  48. default: 'children'
  49. },
  50. localdata: {
  51. type: Array,
  52. default: function() {
  53. return []
  54. }
  55. },
  56. localTreeList: { //在已经格式化好的数据
  57. type: Array,
  58. default: function() {
  59. return []
  60. }
  61. },
  62. selectedData: {
  63. type: Array,
  64. default: function() {
  65. return []
  66. }
  67. },
  68. title: {
  69. type: String,
  70. default: ''
  71. },
  72. deptType:{
  73. type: String,
  74. default: ''
  75. },
  76. multiple: { // 是否可以多选
  77. type: Boolean,
  78. default: true
  79. },
  80. selectParent: { //是否可以选父级
  81. type: Boolean,
  82. default: true
  83. },
  84. confirmColor: { // 确定按钮颜色
  85. type: String,
  86. default: '' // #FE5706
  87. },
  88. cancelColor: { // 取消按钮颜色
  89. type: String,
  90. default: '' // #757575
  91. },
  92. titleColor: { // 标题颜色
  93. type: String,
  94. default: '' //
  95. },
  96. switchColor: { // 节点切换图标颜色
  97. type: String,
  98. default: '' // #666
  99. },
  100. border: { // 是否有分割线
  101. type: Boolean,
  102. default: false
  103. },
  104. },
  105. data() {
  106. return {
  107. showDialog: false,
  108. treeList: [],
  109. checkArr:[],
  110. bgvalue:[1,2]
  111. }
  112. },
  113. computed: {},
  114. methods: {
  115. checkboxChangeadr(e){
  116. this.checkArr=e.detail.data;
  117. },
  118. _show() {
  119. this.showDialog = true
  120. },
  121. _hide() {
  122. this.showDialog = false
  123. },
  124. _cancel() {
  125. this._hide()
  126. this.$emit("cancel", '');
  127. },
  128. _confirm() { //多选
  129. this._hide()
  130. if(this.checkArr.length>0){
  131. this.$emit("select-change", this.checkArr);
  132. }
  133. // this.$emit("select-change", selectedList, selectedNames);
  134. },
  135. },
  136. watch: {
  137. mvalue(data){
  138. console.log(data,1)
  139. this.bgvalue=data
  140. }
  141. },
  142. mounted() {
  143. this.bgvalue=this.mvalue;
  144. // this._initTree();
  145. }
  146. }
  147. </script>
  148. <style scoped>
  149. .xmmain /deep/ .uni-data-checklist .checklist-group{display: block;}
  150. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box{padding: 28rpx 0;margin: 0;}
  151. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box .checklist-text{color: #343434;font-size: 34rpx;font-weight: bold;}
  152. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box .checkbox__inner{margin-right: 32rpx;}
  153. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box.is--default.is-checked .checkbox__inner{border-color: #FF440B; background-color: #FF440B;}
  154. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box.is--default.is-checked .checklist-text{color: #343434;}
  155. .xmbtn{height: 100rpx;display: flex;align-items: center;justify-content: center;
  156. &.btn1{width: 200rpx;}
  157. &.btn2{background-color: $uni-color-fa;}
  158. }
  159. .tree-cover {
  160. position: fixed;
  161. top: 0rpx;
  162. right: 0rpx;
  163. bottom: 0rpx;
  164. left: 0rpx;
  165. z-index: 100;
  166. background-color: rgba(0, 0, 0, .4);
  167. opacity: 0;
  168. transition: all 0.3s ease;
  169. visibility: hidden;
  170. }
  171. .tree-cover.show {
  172. visibility: visible;
  173. opacity: 1;
  174. }
  175. .tree-dialog {
  176. position: fixed;
  177. top: 0rpx;
  178. right: 0rpx;
  179. bottom: 0rpx;
  180. left: 0rpx;
  181. background-color: #fff;
  182. border-top-left-radius: 10px;
  183. border-top-right-radius: 10px;
  184. /* #ifndef APP-NVUE */
  185. display: flex;
  186. /* #endif */
  187. flex-direction: column;
  188. z-index: 100002;
  189. top: 20%;
  190. transition: all 0.3s ease;
  191. transform: translateY(100%);
  192. }
  193. .tree-dialog.show {
  194. transform: translateY(0);
  195. }
  196. .tree-bar {
  197. /* background-color: #fff; */
  198. height: 90rpx;
  199. padding-left: 25rpx;
  200. padding-right: 25rpx;
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. box-sizing: border-box;
  205. border-bottom-width: 1rpx !important;
  206. border-bottom-style: solid;
  207. border-bottom-color: #f5f5f5;
  208. font-size: 32rpx;
  209. color: #757575;
  210. line-height: 1;
  211. }
  212. .tree-bar-confirm {
  213. color: #FE5706;
  214. padding: 15rpx;
  215. }
  216. .tree-bar-title {}
  217. .tree-bar-cancel {
  218. color: #757575;
  219. padding: 15rpx;
  220. }
  221. .tree-view {
  222. flex: 1;
  223. padding: 20rpx 36rpx;
  224. /* #ifndef APP-NVUE */
  225. display: flex;
  226. /* #endif */
  227. flex-direction: column;
  228. overflow: hidden;
  229. height: 100%;
  230. }
  231. .tree-list {
  232. flex: 1;
  233. height: 100%;
  234. overflow: hidden;
  235. }
  236. .tree-item {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. line-height: 1;
  241. height: 0;
  242. opacity: 0;
  243. transition: 0.2s;
  244. overflow: hidden;
  245. }
  246. .tree-item.show {
  247. height: 90rpx;
  248. opacity: 1;
  249. }
  250. .tree-item.showchild:before {
  251. transform: rotate(90deg);
  252. }
  253. .tree-item.last:before {
  254. opacity: 0;
  255. }
  256. .switch-on {
  257. width: 0;
  258. height: 0;
  259. border-left: 16rpx solid transparent;
  260. border-right: 16rpx solid transparent;
  261. border-top: 20rpx solid #666;
  262. }
  263. .switch-off {
  264. width: 0;
  265. height: 0;
  266. border-bottom: 16rpx solid transparent;
  267. border-top: 16rpx solid transparent;
  268. border-left: 20rpx solid #666;
  269. }
  270. .item-last-dot {
  271. position: absolute;
  272. width: 12rpx;
  273. height: 12rpx;
  274. border-radius: 100%;
  275. background: #666;
  276. }
  277. .item-icon {
  278. width: 26rpx;
  279. height: 30rpx;
  280. margin-right: 8rpx;
  281. padding-right: 20rpx;
  282. padding-left: 20rpx;
  283. }
  284. .item-label {
  285. flex: 1;
  286. display: flex;
  287. align-items: center;
  288. height: 100%;
  289. line-height: 1.2;
  290. }
  291. .item-name {
  292. flex: 1;
  293. overflow: hidden;
  294. text-overflow: ellipsis;
  295. white-space: nowrap;
  296. /* width: 450rpx; */
  297. font-size: 34rpx;
  298. font-weight: bold;
  299. line-height: 1;
  300. }
  301. .item-check {
  302. width: 40px;
  303. height: 40px;
  304. display: flex;
  305. justify-content: center;
  306. align-items: center;
  307. }
  308. .item-check-yes,
  309. .item-check-no {
  310. width: 32rpx;
  311. height: 32rpx;
  312. border-top-left-radius: 20%;
  313. border-top-right-radius: 20%;
  314. border-bottom-right-radius: 20%;
  315. border-bottom-left-radius: 20%;
  316. border-top-width: 1rpx;
  317. border-left-width: 1rpx;
  318. border-bottom-width: 1rpx;
  319. border-right-width: 1rpx;
  320. border-style: solid;
  321. border-color: #FE5706;
  322. border-radius: 8rpx;
  323. display: flex;
  324. justify-content: center;
  325. align-items: center;
  326. box-sizing: border-box;
  327. /* background-color: #FE5706; */
  328. }
  329. .item-check-yes{
  330. border: none;
  331. background-color: #FE5706;
  332. }
  333. .item-check-yes-part {
  334. width: 24rpx;
  335. height: 6rpx;
  336. border-top-left-radius: 20%;
  337. border-top-right-radius: 20%;
  338. border-bottom-right-radius: 20%;
  339. border-bottom-left-radius: 20%;
  340. background-color: #ffffff;
  341. }
  342. .item-check-yes-all {
  343. margin-bottom: 5px;
  344. border: 2px solid #ffffff;
  345. border-left: 0;
  346. border-top: 0;
  347. height: 12px;
  348. width: 6px;
  349. transform-origin: center;
  350. /* #ifndef APP-NVUE */
  351. transition: all 0.3s;
  352. /* #endif */
  353. transform: rotate(45deg);
  354. /* border: none;
  355. background-color: #FE5706; */
  356. }
  357. .item-check .radio {
  358. border-top-left-radius: 50%;
  359. border-top-right-radius: 50%;
  360. border-bottom-right-radius: 50%;
  361. border-bottom-left-radius: 50%;
  362. }
  363. .item-check .radio .item-check-yes-b {
  364. border-top-left-radius: 50%;
  365. border-top-right-radius: 50%;
  366. border-bottom-right-radius: 50%;
  367. border-bottom-left-radius: 50%;
  368. }
  369. .hover-c {
  370. opacity: 0.6;
  371. }
  372. .itemBorder {
  373. border-bottom: 1px solid #e5e5e5;
  374. }
  375. </style>