<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
                    tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="woName" label="名称">
                    </el-table-column>
                    <el-table-column prop="supplierCode" label="统计周期">
                        <template slot-scope="scope">
                            {{scope.row.startTime}}-{{scope.row.endTime}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="initiatorName" label="发起人">
                    </el-table-column>
                    <el-table-column prop="stsDesc" label="状态">
                    </el-table-column>
                    <el-table-column prop="fillTime" label="最后一次提交时间">
                    </el-table-column>
                    <el-table-column label="操作" width="160px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(1,scope.row)">查看</el-button>
                            <el-button size="mini" v-if="scope.row.sts != 1" type="primary" @click="dialogCheck(2,scope.row)">编辑</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination>
            </div>
        </div>

        <el-dialog title="员工信息" :visible.sync="dialogStatus" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia" :fullscreen="true">
            <div>

                <el-table class="com-table" ref="multipleTable" :data="infodata" tooltip-effect="dark" size="small"
                    border style="width: 100%">

                    <el-table-column prop="memberRelation" label="成员关系">
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.memberRelation" :disabled="disableStatus">
                                <el-option v-for="items in relationopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="memberName" label="成员姓名">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.memberName" :disabled="disableStatus"></el-input>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column prop="bornDate" label="成员出生日期" width="250" >
                        <template slot-scope="scope">
                            <el-date-picker v-model="scope.row.bornDate" type="date"
                                disabled>
                                </el-date-picker>
                        </template>
                    </el-table-column> -->
                    <el-table-column prop="memberSex" label="成员性别">
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.memberSex" :disabled="disableStatus">
                                <el-option v-for="items in sexopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="idCard" label="成员身份证号">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.idCard" :disabled="disableStatus" @change="sfzyz(scope.row)"></el-input>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column prop="memberEdu" label="成员学历" width="200">eduBack
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.memberEdu" disabled>
                                <el-option v-for="items in eduBackopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="partyGroup" label="成员政治面貌" width="200">
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.partyGroup" disabled>
                                <el-option v-for="items in partyGroupopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="memberNation" label="成员民族信息" width="200">
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.memberNation" disabled>
                                <el-option v-for="items in nationopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="workUnit" label="成员工作单位" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.workUnit" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="workDuty" label="成员职位职务" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.workDuty" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="emerContact" label="是否为紧急联系人" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.emerContact" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="memberTel" label="成员联系电话" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.memberTel" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="interiorStaff" label="是否移动系统内工作" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.interiorStaff" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="staffName" label="系统内员工职务" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.staffName" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isMove" label="是否移居海外" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.isMove" disabled></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column prop="immiType" label="移居类型" width="200">
                        <template slot-scope="scope">
                            <el-select clearable v-model="scope.row.immiType" disabled>
                                <el-option v-for="items in immiTypeopt" :key="items.dataCode" :label="items.dataName"
                                    :value="items.dataCode">
                                </el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column prop="memberAddress" label="成员联系地址" width="200">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.memberAddress" disabled></el-input>
                        </template>
                    </el-table-column> -->
                    <el-table-column label="操作" align="center" v-if="!disableStatus">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="choline(1,scope)" v-if="!scope.row.id">添加
                            </el-button>
                            <el-button size="mini" type="primary" @click="choline(3,scope)" v-if="scope.row.id">修改
                            </el-button>
                            <el-button size="mini" type="danger" @click="choline(2,scope)" v-if="scope.row.id">删除
                            </el-button>
                        </template>
                    </el-table-column>

                </el-table>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button type="primary" @click="dialogCli(2)">确 定</el-button>
                    <!-- <el-button @click="dialogCli(1)">取 消</el-button> -->
                </div>
            </div>
        </el-dialog>

        <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
            v-if="centerDialogVisible"></myMessage>
    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'

    export default {
        components: {
            mySearch,
            myMessage,
            toolList
        },
        data() {
            const supplierName = (rule, value, callback) => {
                if (!this.infolist.supplierName) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                rules: {
                    supplierName: [{
                        required: true,
                        trigger: 'blur',
                        validator: supplierName
                    }],
                },
                searchList: [{
                    type: 'input',
                    tit: '名称',
                    value: '',
                    width: '98%',
                }],
                tooltit: '员工信息',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {},
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                infodata: [{}],
                nationopt: [],
                relationopt: [],
                sexopt: [],
                eduBackopt: [],
                partyGroupopt: [],
                immiTypeopt: [],
                fillId: '',
            }
        },
        methods: {
            sfzyz(v){
                let card = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
                if(!card.test(v.idCard)){
                    this.$message({
                        message: '请填写正确的身份证号！',
                        type: 'error'
                    });
                    v.idCard='';
                }
            },
            choline(v, n) {
                let _this = this;
                n.row.fillId = this.fillId;
                // console.log(n.row);
                let url = '';
                if (v == 1) {
                    url = "/market/cMemberFillDetail/add"
                    // _this.infodata.push({});
                } else if (v == 3) {
                    url = "/market/cMemberFillDetail/update"
                } else if (v == 2) {
                    url = "/market/cMemberFillDetail/del"
                }
                if(!n.row.memberRelation){
                    this.$message({
                        message: '请填写成员关系',
                        type: 'error'
                    });
                    return
                }
                
                if(!n.row.memberName){
                    this.$message({
                        message: '请填写成员姓名',
                        type: 'error'
                    });
                    return
                }
                // if(!n.row.bornDate){
                //     this.$message({
                //         message: '请填写成员出生日期',
                //         type: 'error'
                //     });
                //     return
                // }
                
                if(!n.row.memberSex){
                    this.$message({
                        message: '请填写成员性别',
                        type: 'error'
                    });
                    return
                }
                if(!n.row.idCard){
                    this.$message({
                        message: '请填写成员身份证号',
                        type: 'error'
                    });
                    return
                }
                // if(!n.row.partyGroup){
                //     this.$message({
                //         message: '请填写成员政治面貌',
                //         type: 'error'
                //     });
                //     return
                // }
                // if(!n.row.workUnit){
                //     this.$message({
                //         message: '请填写成员工作单位',
                //         type: 'error'
                //     });
                //     return
                // }
                // if(!n.row.memberTel){
                //     this.$message({
                //         message: '请填写成员联系电话',
                //         type: 'error'
                //     });
                //     return
                // }
                // if(!n.row.memberAddress){
                //     this.$message({
                //         message: '请填写成员联系地址',
                //         type: 'error'
                //     });
                //     return
                // }
                // if(!n.row.interiorStaff){
                //     this.$message({
                //         message: '请填写是否移动系统内工作',
                //         type: 'error'
                //     });
                //     return
                // }
                // if(!n.row.staffName){
                //     this.$message({
                //         message: '请填写系统内员工职务',
                //         type: 'error'
                //     });
                //     return
                // }
                this.$http({
                    url: url,
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: n.row,
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: res.data.desc,
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '成功',
                            type: 'success'
                        });
                        _this.$http({
                            url: "/market/cMemberFillDetail/queryPage",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                            },
                            data: {
                                fillId: _this.fillId
                            },
                        }).then((res) => {
                            _this.infodata = res.data.data;
                            _this.infodata.push({});
                        });
                    }
                });
            },
            jumpfw() {
                this.$router.push({
                    path: "/reportProgress",
                });
                this.setabList("填报进度跟踪", "/reportProgress");
            },
            jumpjd() {
                this.$router.push({
                    path: "/speedOfProgress",
                });
                this.setabList("进度跟踪", "/speedOfProgress");
            },
            setabList(n, p) {
                let params = {
                    children: "",
                    name: n,
                    rountPath: p,
                    target: "_self",
                };
                for (let i = 0; i < this.$store.state.tabList.length; i++) {
                    if (this.$store.state.tabList[i].name === params.name) {
                        this.$store.state.tabList[i] = params;
                    }
                }
                let set = new Set([...this.$store.state.tabList, params]);
                set.add(params);
                this.$store.commit("setDefaultActive", params.rountPath);
                this.$store.commit("setTabList", Array.from(set));
            },
            closedia() {
                this.infolist = {};
                this.dialogStatus = false;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.woName = v[0] : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.tableData = [];
                this.$http({
                    url: "/market/cMemberFill/queryMkMemberFillPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data.data;
                    this.total = res.data.totalRecord;
                    this.loading = false;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            //申请
            dialogCheck(v, n) {
                this.dialogStatus = true;
                if (v === 1) {
                    this.titname = '查看';
                    this.disableStatus = true;
                } else if (v === 2) {
                    this.titname = '修改';
                    this.disableStatus = false;
                }
                this.fillId = n.id;
                this.$http({
                    url: "/market/cMemberFillDetail/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    },
                    data: {
                        fillId: n.id
                    },
                }).then((res) => {
                    this.infodata = res.data.data;
                    this.infodata.push({fillId: this.fillId});
                });
            },
            //添加
            dialogCli(v) {
                if(this.disableStatus){
                    this.infolist = {};
                    this.dialogStatus = false;
                }else{

                    let _this = this;
                    let infodata1 = JSON.parse(JSON.stringify(this.infodata))
                    let infodataLast = infodata1[infodata1.length-1]
                    if(Object.keys(infodataLast).length >= 2){
                        if(!infodataLast.memberRelation && !infodataLast.memberName && !infodataLast.memberSex && !infodataLast.idCard){
                            this.loadinged = true;
                        this.$http({
                            url: "/market/cMemberFillDetail/saveFillDetailSummaryNew",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                            },
                            data: infodata1,
                        }).then((res) => {
                            // this.infolist = {};
                            // this.dialogStatus = false;
                            this.loadinged = false;
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }
                        });
                        }else if(!infodataLast.memberRelation || !infodataLast.memberName || !infodataLast.memberSex || !infodataLast.idCard){
                            if(!infodataLast.memberRelation){
                            this.$message({
                                message: '请填写成员关系',
                                type: 'error'
                            });
                            return false
                        }
                        
                        if(!infodataLast.memberName){
                            this.$message({
                                message: '请填写成员姓名',
                                type: 'error'
                            });
                            return false
                        }
                        
                        if(!infodataLast.memberSex){
                            this.$message({
                                message: '请填写成员性别',
                                type: 'error'
                            });
                            return false
                        }
                        if(!infodataLast.idCard){
                            this.$message({
                                message: '请填写成员身份证号',
                                type: 'error'
                            });
                            return false
                        }
                        this.loadinged = true;
                        this.$http({
                            url: "/market/cMemberFillDetail/saveFillDetailSummaryNew",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                            },
                            data: infodata1,
                        }).then((res) => {
                            // this.infolist = {};
                            // this.dialogStatus = false;
                            this.loadinged = false;
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }
                        });
                        }
                        
                    }else if(Object.keys(infodataLast).length == 1){
                        this.loadinged = true;
                        this.$http({
                            url: "/market/cMemberFillDetail/saveFillDetailSummaryNew",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                            },
                            data: infodata1,
                        }).then((res) => {
                            // this.infolist = {};
                            // this.dialogStatus = false;
                            this.loadinged = false;
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }
                        });
                    }


                    // let isInfodataNull = infodataLast.filter((item)=>{
                    //     console.log(item.length);
                    //     return item.length
                    // })
                    // console.log(isInfodataNull);  
                // this.infodata.forEach((item,index)=>{
                    // if(!infodataLast.memberRelation){
                    //     this.$message({
                    //         message: '请填写成员关系',
                    //         type: 'error'
                    //     });
                    //     return false
                    // }
                    
                    // if(!infodataLast.memberName){
                    //     this.$message({
                    //         message: '请填写成员姓名',
                    //         type: 'error'
                    //     });
                    //     return false
                    // }
                    
                    // if(!infodataLast.memberSex){
                    //     this.$message({
                    //         message: '请填写成员性别',
                    //         type: 'error'
                    //     });
                    //     return false
                    // }
                    // if(!infodataLast.idCard){
                    //     this.$message({
                    //         message: '请填写成员身份证号',
                    //         type: 'error'
                    //     });
                    //     return false
                    // }
                // })
                    // this.$http({
                    //     url: "/market/cMemberFillDetail/saveFillDetailSummaryNew",
                    //     method: "post",
                    //     headers: {
                    //         "Content-Type": "application/json",
                    //         "page": '{"pageNo":"' + 1 + '","pageSize":"100"}'
                    //     },
                    //     data: infodata1,
                    // }).then((res) => {
                    //     this.infolist = {};
                    //     this.dialogStatus = false;
                    // });
                    // console.log(infodata1)
                
                }
                
            },
            submitInfo(u) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.loadinged = true;
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: this.infolist,
                        }).then((res) => {
                            this.loadinged = false;
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.infolist = {};
                                _this.dialogStatus = false;
                                _this.getList({}, _this.pageSize);
                            }

                        });
                    }
                })
            },
            closeMessage(v) {
                this.centerDialogVisible = false;
                let _this = this;
                if (v === 1) {
                    _this.$http({
                        url: "/market/cAdvPubSupplier/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            id: this.delid
                        },
                    }).then((res) => {
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: 'error'
                            });
                        } else {
                            _this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            _this.getList(this.params, this.pageSize);
                        }
                    });
                }
            },
            //删除
            delLine(v) {
                this.centerDialogVisible = true;
                this.messTit = '即将删除此条数据, 是否删除?';
                this.delid = v.id;
            },
            //文件返回值
            uploadBack(v) {
                console.log(v)
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.$http({
                    url: "/sysmgr/cfgDataDicts/queryMap",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        dictCodePks: 'nation,relation,sex,eduBack,partyGroup,immiType'
                    },
                }).then((res) => {
                    this.nationopt = res.data.body.nation;
                    this.relationopt = res.data.body.relation;
                    this.sexopt = res.data.body.sex;
                    this.eduBackopt = res.data.body.eduBack;
                    this.partyGroupopt = res.data.body.partyGroup;
                    this.immiTypeopt = res.data.body.immiType;
                });
            }
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 80px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 100px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 100px);
        }
    }
</style>
