月份选择,多选,数组去重

<view class="zx-content">

<view class="zx-box" v-for="(item,idx) in dateList" @click="shedClick(idx)" :class="{'active':item.isChecked==true}" :key="idx">

<text class="zx-txt">{{item.date}}</text>

</view>

</view>

 

dateList:[

{"date":"01","isChecked":false},

{"date":"02","isChecked":false},

{"date":"03","isChecked":false},

{"date":"04","isChecked":false},

{"date":"05","isChecked":false},

{"date":"06","isChecked":false},

{"date":"07","isChecked":false},

{"date":"08","isChecked":false},

{"date":"09","isChecked":false},

{"date":"10","isChecked":false},

{"date":"11","isChecked":false},

{"date":"12","isChecked":false}

],

dt:[],

let moth =this.formatMonth(new Date());

          select(month){
                let that=this;
                for(var i=0;i<that.dateList.length;i++){
                    if(that.dateList[i].date == month){
                        that.dateList[i].isChecked = true;
                        that.dt.push(that.dateList[i].date);
                    }
                }
            },
            shedClick:function(idx){
                let that=this;
                that.dateList[idx].isChecked=that.dateList[idx].isChecked?false:true;
                that.dt = [];
                for(var i=0;i<that.dateList.length;i++){
                    if(that.dateList[i].isChecked == true){
                        that.dt.push(that.dateList[i].date);
                    }
                }
                that.dt = this.removeDuplicates(that.dt);
                // that.getShedProduceList(that.dt);
            },

formatDate:function(date) {
              var year = date.getFullYear();
              var month = this.padZero(date.getMonth() + 1); // 月份从0开始,所以需要加1
              var day = this.padZero(date.getDate());
              var hours = this.padZero(date.getHours());
              var minutes = this.padZero(date.getMinutes());
              return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
            },
            formatMonth:function(date) {
              var month = this.padZero(date.getMonth() + 1); // 月份从0开始,所以需要加1
              return month;
            },
            // 补零函数,用于保证单个数字时两位数
            padZero:function(num) {
              return num < 10 ? '0' + num : num;
            },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值