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. this.bgvalue=data
  139. }
  140. },
  141. mounted() {
  142. this.bgvalue=this.mvalue;
  143. // this._initTree();
  144. }
  145. }
  146. </script>
  147. <style >
  148. .xmbtn{height: 100rpx;display: flex;align-items: center;justify-content: center;}
  149. .xmbtn.btn1{width: 200rpx;}
  150. .xmbtn.btn2{background-color: $uni-color-fa;}
  151. .tree-cover {
  152. position: fixed;
  153. top: 0rpx;
  154. right: 0rpx;
  155. bottom: 0rpx;
  156. left: 0rpx;
  157. z-index: 100;
  158. background-color: rgba(0, 0, 0, .4);
  159. opacity: 0;
  160. transition: all 0.3s ease;
  161. visibility: hidden;
  162. }
  163. .tree-cover.show {
  164. visibility: visible;
  165. opacity: 1;
  166. }
  167. .tree-dialog {
  168. position: fixed;
  169. top: 0rpx;
  170. right: 0rpx;
  171. bottom: 0rpx;
  172. left: 0rpx;
  173. background-color: #fff;
  174. border-top-left-radius: 10px;
  175. border-top-right-radius: 10px;
  176. /* #ifndef APP-NVUE */
  177. display: flex;
  178. /* #endif */
  179. flex-direction: column;
  180. z-index: 100002;
  181. top: 20%;
  182. transition: all 0.3s ease;
  183. transform: translateY(100%);
  184. }
  185. .tree-dialog.show {
  186. transform: translateY(0);
  187. }
  188. .tree-bar {
  189. /* background-color: #fff; */
  190. height: 90rpx;
  191. padding-left: 25rpx;
  192. padding-right: 25rpx;
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. box-sizing: border-box;
  197. border-bottom-width: 1rpx !important;
  198. border-bottom-style: solid;
  199. border-bottom-color: #f5f5f5;
  200. font-size: 32rpx;
  201. color: #757575;
  202. line-height: 1;
  203. }
  204. .tree-bar-confirm {
  205. color: #FE5706;
  206. padding: 15rpx;
  207. }
  208. .tree-bar-title {}
  209. .tree-bar-cancel {
  210. color: #757575;
  211. padding: 15rpx;
  212. }
  213. .tree-view {
  214. flex: 1;
  215. padding: 20rpx 36rpx;
  216. /* #ifndef APP-NVUE */
  217. display: flex;
  218. /* #endif */
  219. flex-direction: column;
  220. overflow: hidden;
  221. height: 100%;
  222. }
  223. .tree-list {
  224. flex: 1;
  225. height: 100%;
  226. overflow: hidden;
  227. }
  228. .tree-item {
  229. display: flex;
  230. justify-content: space-between;
  231. align-items: center;
  232. line-height: 1;
  233. height: 0;
  234. opacity: 0;
  235. transition: 0.2s;
  236. overflow: hidden;
  237. }
  238. .tree-item.show {
  239. height: 90rpx;
  240. opacity: 1;
  241. }
  242. .tree-item.showchild:before {
  243. transform: rotate(90deg);
  244. }
  245. .tree-item.last:before {
  246. opacity: 0;
  247. }
  248. .switch-on {
  249. width: 0;
  250. height: 0;
  251. border-left: 16rpx solid transparent;
  252. border-right: 16rpx solid transparent;
  253. border-top: 20rpx solid #666;
  254. }
  255. .switch-off {
  256. width: 0;
  257. height: 0;
  258. border-bottom: 16rpx solid transparent;
  259. border-top: 16rpx solid transparent;
  260. border-left: 20rpx solid #666;
  261. }
  262. .item-last-dot {
  263. position: absolute;
  264. width: 12rpx;
  265. height: 12rpx;
  266. border-radius: 100%;
  267. background: #666;
  268. }
  269. .item-icon {
  270. width: 26rpx;
  271. height: 30rpx;
  272. margin-right: 8rpx;
  273. padding-right: 20rpx;
  274. padding-left: 20rpx;
  275. }
  276. .item-label {
  277. flex: 1;
  278. display: flex;
  279. align-items: center;
  280. height: 100%;
  281. line-height: 1.2;
  282. }
  283. .item-name {
  284. flex: 1;
  285. overflow: hidden;
  286. text-overflow: ellipsis;
  287. white-space: nowrap;
  288. /* width: 450rpx; */
  289. font-size: 34rpx;
  290. font-weight: bold;
  291. line-height: 1;
  292. }
  293. .item-check {
  294. width: 40px;
  295. height: 40px;
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. }
  300. .item-check-yes,
  301. .item-check-no {
  302. width: 32rpx;
  303. height: 32rpx;
  304. border-top-left-radius: 20%;
  305. border-top-right-radius: 20%;
  306. border-bottom-right-radius: 20%;
  307. border-bottom-left-radius: 20%;
  308. border-top-width: 1rpx;
  309. border-left-width: 1rpx;
  310. border-bottom-width: 1rpx;
  311. border-right-width: 1rpx;
  312. border-style: solid;
  313. border-color: #FE5706;
  314. border-radius: 8rpx;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. box-sizing: border-box;
  319. /* background-color: #FE5706; */
  320. }
  321. .item-check-yes{
  322. border: none;
  323. background-color: #FE5706;
  324. }
  325. .item-check-yes-part {
  326. width: 24rpx;
  327. height: 6rpx;
  328. border-top-left-radius: 20%;
  329. border-top-right-radius: 20%;
  330. border-bottom-right-radius: 20%;
  331. border-bottom-left-radius: 20%;
  332. background-color: #ffffff;
  333. }
  334. .item-check-yes-all {
  335. margin-bottom: 5px;
  336. border: 2px solid #ffffff;
  337. border-left: 0;
  338. border-top: 0;
  339. height: 12px;
  340. width: 6px;
  341. transform-origin: center;
  342. /* #ifndef APP-NVUE */
  343. transition: all 0.3s;
  344. /* #endif */
  345. transform: rotate(45deg);
  346. /* border: none;
  347. background-color: #FE5706; */
  348. }
  349. .item-check .radio {
  350. border-top-left-radius: 50%;
  351. border-top-right-radius: 50%;
  352. border-bottom-right-radius: 50%;
  353. border-bottom-left-radius: 50%;
  354. }
  355. .item-check .radio .item-check-yes-b {
  356. border-top-left-radius: 50%;
  357. border-top-right-radius: 50%;
  358. border-bottom-right-radius: 50%;
  359. border-bottom-left-radius: 50%;
  360. }
  361. .hover-c {
  362. opacity: 0.6;
  363. }
  364. .itemBorder {
  365. border-bottom: 1px solid #e5e5e5;
  366. }
  367. .xmmain /deep/ .uni-data-checklist .checklist-group{display: block;}
  368. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box{padding: 28rpx 0;margin: 0;}
  369. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box .checklist-text{color: #343434;font-size: 32rpx;font-weight: bold;}
  370. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box .checkbox__inner{margin-right: 32rpx;}
  371. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box.is--default.is-checked .checkbox__inner{border-color: #FF440B; background-color: #FF440B;}
  372. .xmmain /deep/ .uni-data-checklist .checklist-group .checklist-box.is--default.is-checked .checklist-text{color: #343434;}
  373. </style>