123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <template>
- <view class="tm-treeSelect fulled-height">
- <view class="tm-treeSelect-slide ">
- <scroll-view scroll-y
- :style="{
- height:activeHeight+'px'
- }"
- >
- <tm-listitem :disabled="item['disabled']?true:false"
- :black="black_tmeme" @click="activeIndex=index"
- :disabled-color="bgColor"
- v-for="(item,index) in formaData" :key='index'
- :color="activeIndex==index?(text?' text ' + color:'white'):bgColor"
- :show-right-icon="false"
- :margin="[0,0]"
- fontSize="26"
- :class-style="activeIndex==index?`border-${color_tmeme}-l-2`:'border-grey-lighten-5-l-2'"
- round="0" shadow="0"
- >
- <tm-badges color='red' :fllowTheme="false" :offset="[12,-10]" v-if="item.dot>0&&dot" :dot="false" :label="item.dot"></tm-badges>
- <view class="mr-10">
- <text :class="[`text-${activeIndex==index?color_tmeme:fontColor}`,item['disabled']?'opacity-3':'']">{{item[rangKey]}}</text>
- </view>
- </tm-listitem>
- </scroll-view>
- </view>
- <view class="tm-treeSelect-slideitem" >
- <scroll-view scroll-y
- :style="{
- height:activeHeight+'px'
- }"
- >
- <tm-groupcheckbox v-if="formaData[activeIndex]" :max="max" @change="changeOk">
- <block v-for="(item,index) in formaData[activeIndex].children" :key='index'>
- <tm-checkbox dense
- :disabled="item['disabled']||formaData[activeIndex]['disabled']?true:false"
- :color="color_tmeme" round="2" @change="itemChange"
- :name="item"
- v-model="item.checked">
- <tm-listitem fontSize="28" :black="black_tmeme" :padding="[24,24]" :margin="[0,0]" :border-bottom="true" round="0" shadow="0"
- :title="item[rangKey]" >
- <template #default>
- <text :class="[item.checked?'text-'+color_tmeme:'']">{{item[rangKey]}}</text>
- </template>
- <template v-slot:rightIcon>
- <view style="line-height: 0;vertical-align: middle;min-width: 40rpx;" class="fulled">
- <view v-if="item.checked" class="rounded flex-center" :class="[color_tmeme,`shadow-${color_tmeme}-4`]" style="width: 34rpx;height: 34rpx;">
- <text class="iconfont icon-check text-size-xs"></text>
- </view>
-
-
- </view>
- </template>
- </tm-listitem>
- </tm-checkbox>
- </block>
-
- </tm-groupcheckbox>
- </scroll-view>
- </view>
-
- </view>
- </template>
- <script>
-
- import tmListitem from "@/tm-vuetify/components/tm-listitem/tm-listitem.vue"
- import tmGrouplist from "@/tm-vuetify/components/tm-grouplist/tm-grouplist.vue"
- import tmBadges from "@/tm-vuetify/components/tm-badges/tm-badges.vue"
- import tmGroupcheckbox from "@/tm-vuetify/components/tm-groupcheckbox/tm-groupcheckbox.vue"
- import tmCheckbox from "@/tm-vuetify/components/tm-checkbox/tm-checkbox.vue"
- export default {
- components:{tmListitem,tmGrouplist,tmBadges,tmGroupcheckbox,tmCheckbox},
- name:"tm-treeSelect",
- props:{
-
- height: {
- type: String | Number,
- default: 0
- },
-
- defaultSelected:{
- type:Array,
- default:()=>{
- return []
- }
- },
-
- list:{
- type:Array,
- default:()=>{
- return [];
- }
- },
-
- rangKey:{
- type:String,
- default:'title'
- },
-
- max:{
- type:Number,
- default:999
- },
-
- color:{
- type:String,
- default:'primary'
- },
-
- bgColor:{
- type:String,
- default:'grey-lighten-5'
- },
-
- fontColor:{
- type:String,
- default:'grey-darken-1'
- },
-
- text:{
- type:Boolean,
- default:false
- },
- black:{
- type:Boolean,
- default:null
- },
-
- dot:{
- type:Boolean,
- default:false
- },
-
- fllowTheme:{
- type:Boolean|String,
- default:true
- }
- },
- data() {
- return {
- activeHeight: 0,
- activeIndex:0,
- formaData:[]
- };
- },
- watch:{
- list:{
- deep:true,
- handler:function(){
- this.formaData = [...this.dataList];
- }
- },
- defaultSelected:{
- deep:true,
- handler:function(){
- this.clear()
- this.formaData = [...this.clear()]
- this.formaData = [...this.dataList];
- }
- }
- },
- computed:{
- black_tmeme: function() {
- if (this.black !== null) return this.black;
- return this.$tm.vx.state().tmVuetify.black;
- },
- color_tmeme:function(){
- if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
- return this.$tm.vx.state().tmVuetify.color;
- }
- return this.color;
- },
- dataList(){
- let t = this;
- let p = this.$tm.deepClone(this.list)
- for(let j=0;j<p.length;j++){
- p[j]['dot'] = 0;
- if(p[j].children){
- let ic = p[j].children;
- for(let k=0;k<ic.length;k++){
- if(!ic[k].hasOwnProperty('checked')){
- ic[k]['checked'] = false;
- }
-
- for(let i=0 ;i < t.defaultSelected.length;i++){
- let lsitem = t.defaultSelected[i];
- if(typeof lsitem === 'object'){
- if(lsitem['id'] == ic[k]['id']){
- ic[k]['checked'] = true;
- }
- }else{
- if(lsitem == ic[k]['id']){
- ic[k]['checked'] = true;
-
- }
- }
-
- }
- if(ic[k]['checked']===true){
- p[j]['dot'] +=1
- }
- }
- }
- }
- return p;
- },
- },
- mounted() {
-
- let t = this;
- this.$nextTick(async function() {
- this.activeHeight = uni.upx2px(this.height);
- if (!this.activeHeight) {
- let wsz = await this.$Querey(".tm-treeSelect",this).catch(e=>{})
- this.activeHeight = wsz[0].height||250;
- }
- this.formaData = [...this.dataList];
- });
- },
- methods: {
- clear(){
- let t = this;
- let p = this.$tm.deepClone(this.list)
- for(let j=0;j<p.length;j++){
- p[j]['dot'] = 0;
- if(p[j].children){
- let ic = p[j].children;
- for(let k=0;k<ic.length;k++){
- if(!ic[k].hasOwnProperty('checked')){
- ic[k]['checked'] = false;
- }else{
- ic[k]['checked'] = false;
- }
- }
- }
- }
- return p;
- },
-
- changeOk(e) {
-
- let p = [];
- function ts(obj){
- if(Array.isArray(obj)){
- obj.forEach(item=>{
- if(item.children){
- ts(item.children);
- }else{
- if(item.checked===true){
- p.push(item)
- }
- }
-
- })
- }
-
-
- }
-
- ts(this.dataList);
- this.$emit('change',{
- all:p,
- index:this.activeIndex,
- children:e
- });
- if(this.formaData.length>0){
- this.$set(this.formaData[this.activeIndex],'dot',e.length)
- }
-
- },
- // 单个数组点击切换产生的选项。
- itemChange(e){
- let t = this;
-
- this.$emit('children-change',e)
-
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .tm-treeSelect{
- height: 100%;
- display: flex;
- justify-content: flex-start;
- .tm-treeSelect-slide{
- width: 190upx;
- }
- .tm-treeSelect-slideitem{
- width: calc(100% - 190upx);
- }
- }
- </style>
|