<template>
    <div class="paymentstatement-all">
        <el-dialog width="60%" title="日常付款类型筛选" :visible.sync="dialogFormVisible">
            <div class="paymentstatement-dialog-ul">
                <div v-for="(item,index) in DailypaymentTypelist" :key="index" class="paymentstatement-dialog-li">
                    <div>
                        <div class="modulename">{{item.name}}</div>
                        <div class="paymentstatement-dialog-type">
                            <el-checkbox v-model='items.isChecked' v-for="(items,index) in item.subData" :key="index" :label="items.name"></el-checkbox>
                        </div>
                    </div>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
              <el-button size="small" @click="checkidall">全 选</el-button>
              <el-button size="small" @click="checkidclear">清 空</el-button>
              <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
              <el-button size="small" type="primary" @click="checkidarr">确 定</el-button>
            </div>
        </el-dialog>
        <div class="paymentstatement-haed">
            <el-date-picker style="width:350px" v-model="value2" type="daterange" align="left"
                unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                :picker-options="pickerOptions">
            </el-date-picker>
            <el-button @click="dialogFormVisible = true" type="primary">更改筛选器</el-button>
        </div>
    </div>
</template>
<script>
export default {
    data () {
        return {
            token:'',
            dialogFormVisible:true,
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                    const end = new Date();
                    const start = new Date();
                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                    picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            value2:'',
            DailypaymentTypelist:[],
            typeIds:[]
        }
    },
    methods:{
        //日付类型
        DailypaymentTypeInit(){
            var url = "/api/Statistics/DailypaymentTypeInit"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: { 
                    portType: 1 ,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.DailypaymentTypelist=res.data.data
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("接口错误，请联系信息部！");
            });
        },
        //获取勾选id
        checkidarr(){
            this.typeIds=[];
            for(let i=0;i<this.DailypaymentTypelist.length;i++){
                for(let j=0;j<this.DailypaymentTypelist[i].subData.length;j++){
                    if(this.DailypaymentTypelist[i].subData[j].isChecked==true){
                        this.typeIds.push(this.DailypaymentTypelist[i].subData[j].id);
                    }
                }
            }
            this.DailypaymentTypeDataSave(this.typeIds)
        },
        //all in
        checkidall(){
            for(let i=0;i<this.DailypaymentTypelist.length;i++){
                for(let j=0;j<this.DailypaymentTypelist[i].subData.length;j++){
                    this.DailypaymentTypelist[i].subData[j].isChecked=true;
                }
            }
        },
        //清空
        checkidclear(){
            for(let i=0;i<this.DailypaymentTypelist.length;i++){
                for(let j=0;j<this.DailypaymentTypelist[i].subData.length;j++){
                    this.DailypaymentTypelist[i].subData[j].isChecked=false;
                }
            }
        },
        //保存筛选条件
        DailypaymentTypeDataSave(val){
            var url = "/api/Statistics/DailypaymentTypeDataSave"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: { 
                    portType: 1 ,
                    typeIds:val
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.dialogFormVisible=false;
                    that.$message({
                        message: res.data.msg,
                        type: 'success'
                    });
                } else {
                    that.$message.error(res.data.msg);
                }
            }).catch(function (error) {
                that.$message.error("接口错误，请联系信息部！");
            });
        },
    },
    mounted(){
        this.DailypaymentTypeInit();
    }
}
</script>
<style>
.paymentstatement-all{
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    height: 100%;
    min-height: 830px;
}
.paymentstatement-haed{
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    
}
.paymentstatement-dialog-type{
    display: flex;
    flex-wrap:wrap ;
}
.paymentstatement-dialog-type .el-checkbox{
    width: 290px;
}
.paymentstatement-dialog-li .modulename{
    font-size: 15px;
    font-weight: 600;
}
.paymentstatement-all .el-dialog__body{
    padding-top: 10px;
}
.paymentstatement-dialog-li .el-checkbox{
    margin-top: 4px;
    margin-bottom: 4px;
}
</style>