123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <view class="tm-groupcheckbox " :class="[customClass]">
- <slot></slot>
- </view>
- </template>
- <script>
-
- export default {
- name:'tm-groupcheckbox',
- props:{
-
- max:{
- type:Number,
- default:9999
- },
-
- name:{
- type:String,
- default:''
- },
- customClass:{
- type:String,
- default:''
- }
- },
- data() {
- return {
-
- };
- },
- mounted() {
- this.$nextTick(function(){
-
- this.$emit('change',this.getVal())
- })
- },
- methods: {
- change(e) {
-
- this.$emit('change',e)
- },
-
-
- getVal(){
- let box = [];
- function findchild(p,index){
- let preat = p;
- if(preat.$options?.name==='tm-checkbox'){
-
- if(preat.changValue){
- box.push({index:index,value:preat.name,checked:preat.changValue})
- }
- }else{
- if(preat.$children.length>0){
- preat.$children.forEach(item=>{
- findchild(item,index++);
- })
- }
- }
- };
- findchild(this,0);
- return box;
- },
-
-
- reverseVal(){
- function findchild(p,index){
- let preat = p;
- if(preat.$options?.name==='tm-checkbox'){
-
- preat.changValue = !preat.changValue;
- }else{
- if(preat.$children.length>0){
- preat.$children.forEach(item=>{
- findchild(item,index++);
- })
- }
- }
- };
- findchild(this,0);
-
- },
-
- clear(){
- function findchild(p,index){
- let preat = p;
- if(preat.$options?.name==='tm-checkbox'){
-
- preat.changValue = false;
- }else{
- if(preat.$children.length>0){
- preat.$children.forEach(item=>{
- findchild(item,index++);
- })
- }
- }
- };
- findchild(this,0);
- },
-
- error(){
- uni.showToast({
- title:"超过选择限制",icon:'none'
- })
- this.$emit('error',"超过选择限制")
- }
- },
- }
- </script>
- <style lang="scss">
- </style>
|