<!--
<template>
    <div class="addDataModel">
        <el-dialog
                title="收购资格企业新增"
                :visible.sync="addData.dialogVisible"
                width="1000px"
                center
                :close-on-click-modal="false"
        >
            <el-form :label-width="labelwidthStyle" :rules="rules" ref="addFormData" :model="addFormData">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="营业执照注册号：" prop="tyshxydm">
&lt;!&ndash;                            <el-input v-model="addFormData.yyzzzch"></el-input>&ndash;&gt;
                            <el-autocomplete v-model="addFormData.tyshxydm" style="width: 325px;" :label="addFormData.tyshxydm" @select="changeTyshxydm"
                                             :fetch-suggestions="querySearch" placeholder="营业执照注册号"
                                             :trigger-on-focus="false" clearable></el-autocomplete>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="市场主体名称：" prop="scztmc">
                            <el-input v-model="addFormData.scztmc" clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="组织机构代码：" prop="zzjgdm">
                            <el-input v-model="addFormData.zzjgdm" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="许可文件名称：" prop="xkwjmc">
                            <el-input v-model="addFormData.xkwjmc" disabled clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="许可文件编号：" prop="xkwjbh1">
                            <el-input v-model="addFormData.xkwjbh1" style="width: 100%;"  clearable v-show="!fzjgdm"></el-input>
                            <span v-show="fzjgdm">{{fzjgdm}}</span>
                            <el-input v-model="addFormData.xkwjbh1" style="display: inline-block;width: 280px" clearable  v-show="fzjgdm"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="许可内容：" prop="xknr">
                            <el-input v-model="addFormData.xknr" disabled clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="有效期自：" prop="yxqq1">
                            <el-date-picker v-model="addFormData.yxqq1" type="date" value-format="yyyy-MM-dd" style="width: 100%;" :picker-options="selectStartTime" clearable></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="有效期至：" prop="yxqz1">
                            <el-date-picker v-model="addFormData.yxqz1" type="date" value-format="yyyy-MM-dd" style="width: 100%;"  :picker-options="selectEndTime" clearable></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="许可机关：" prop="xkjgbmmc">
&lt;!&ndash;                            <el-input v-model="addFormData.xkjgbmmc" clearable></el-input>&ndash;&gt;
                            <el-select
                                    placeholder="请选择"
                                    v-model="addFormData.xkjgbmmc"
                                    clearable
                                    :disabled="sslsxzglbm != 'LS001007'"
                            >
                                <el-option
                                        v-for="item in xkjgList"
                                        :key="item.fzdwbm"
                                        :label="item.fzdw"
                                        :value="item.fzdw"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：" prop="yxzt">
                            <el-radio-group  v-model="addFormData.yxzt" disabled>
                                <el-radio :label="'1'">是</el-radio>
                                <el-radio :label="'0'">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="btnSave(1,'addFormData')" class="iconfont icontijiao"> 提交</el-button>
                <el-button type="primary" @click="btnSave(0,'addFormData')" class="iconfont iconquxiao"> 取消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { fileApi } from "@/api";
    import {getCompanyInfo} from "@/api/jcxxwh/qyjcxx";
    import {searchTyshxydm, addSgzg, xzqhList, getDetail} from '@/api/grainCoManage/acquisitionQualification/index';
    export default {
        props: {
            addData: Object,
        },
        data() {
            let self = this
            return {
                labelwidthStyle: "150px",
                list: [],
                fzjgdm: null,
                addFormData:{
                    scztmc: null,
                    zzjgdm: null,
                    xkwjmc: null,
                    xkwjbh1: null,
                    xknr: null,
                    yxqq1: null,
                    yxqz1: null,
                    yxzt: null,
                    xkjgbmmc: null,
                },
                rules:{
                    tyshxydm: [{ required: true, message: '请输入营业执照注册号', trigger: 'blur' }],
                    scztmc: [{ required: true, message: '请输入市场主体名称', trigger: 'blur' }],
                    zzjgdm: [{ required: true, message: '请输入组织机构代码', trigger: 'blur' }],
                    xkwjmc: [{ required: true, message: '请输入许可文件名称', trigger: 'blur' }],
                    xkwjbh1: [
                        { required: true, message: '请输入许可文件编号', trigger: 'blur' },
                        { min: 1, max: 15, message: '长度在 1 到 15 个字符', trigger: 'change' }
                    ],
                    xknr: [{ required: true, message: '请输入许可内容', trigger: 'blur' }],
                    yxqq1: [{ required: true, message: '请选择有效期始', trigger: 'change' }],
                    yxqz1: [{ required: true, message: '请选择有效期止', trigger: 'change' }],
                    xkjgbmmc: [{ required: true, message: '请选择许可机关', trigger: 'blur' }],
                    yxzt: [{ required: true, message: '请选择有效状态', trigger: 'change' }],
                },
                fileList:[],
                actionUrl: fileApi + "/file/upload",
                //用来选择 开始与结束的时间段
                selectStartTime:{
                    disabledDate(time){
                        if(!self.addFormData.yxqz1) return false;
                        return new Date(time).getTime() >= new Date(self.addFormData.yxqz1).getTime();
                    }
                },
                selectEndTime:{
                    disabledDate(time){
                        if(!self.addFormData.yxqq1) return false;
                        return new Date(time).getTime() <= new Date(self.addFormData.yxqq1).getTime();
                    }
                },
                fzjgdmList: [
                    {
                        value: '001',
                        code: 'LS001'
                    }
                ],
                sslsxzglbm: null,
                xkjgList: [],
            };
        },
        watch: {
            "addFormData.tyshxydm" (newVal, oldVal){
                if(!newVal){
                    this.addFormData.zzjgdm = null
                    this.addFormData.scztmc = null
                    this.fzjgdm = null
                    this.xkjgList = []
                    this.addFormData.xkjgbmmc = null
                    this.sslsxzglbm = null
                }
            }
        },
        created() {
            // if(this.addData.code){
            //     this.getInfo(this.addData.code)
            // }
            this.initData()
        },
        methods: {
            changeTyshxydm(val){
                if(val && val.tyshxydm){
                    this.addFormData.tyshxydm = val.tyshxydm
                    this.addFormData.zzjgdm = val.zzjgdm
                    this.addFormData.scztmc = val.qymc
                    this.sslsxzglbm = val.sslsxzglbm
                    if(val.xzqhList && val.xzqhList.length){
                        this.fzjgdm = "津" + val.xzqhList[0].fzdwbm
                        this.addFormData.xkjgbmmc = val.xzqhList[0].fzdw
                        this.xkjgList = val.xzqhList
                    }
                }else{
                    this.addFormData.zzjgdm = null
                    this.addFormData.scztmc = null
                    this.fzjgdm = null
                    this.xkjgList = []
                    this.addFormData.xkjgbmmc = null
                    this.sslsxzglbm = null
                }
            },
            querySearch(queryString, cb) {
                let data = {
                    tyshxydm: queryString,
                };
                searchTyshxydm(data).then(res => {
                    if(res.data){
                        for (let i of res.data) {
                            // i.value = i.qymc;
                            i.value = i.tyshxydm;
                            i.label = i.tyshxydm;
                        }
                        let restaurants = res.data;
                        if (restaurants.length === 0) {
                            restaurants = [];
                            this.$message.error("该企业不存在！")
                        }
                        cb(restaurants);
                    }else{
                        cb([]);
                    }
                })
            },
            initData(){
                this.addFormData.xkwjmc = "粮食收购许可证"
                this.addFormData.xknr = "粮食收购"
                this.addFormData.yxzt = "1"
            },
            btnSave(type,formName){
                if(type){
                    this.$refs[formName].validate((valid,dom) => {
                        if (valid) {
                            this.addFormData.xkwjbh = this.fzjgdm + this.addFormData.xkwjbh1
                            this.addFormData.yyzzzch = this.addFormData.tyshxydm
                            this.addFormData.yxqz = this.addFormData.yxqz1.replace(new RegExp("-",'g'),"")
                            this.addFormData.yxqq = this.addFormData.yxqq1.replace(new RegExp("-",'g'),"")
                            let params = this.addFormData
                            console.log(params,'提交参数')
                            addSgzg(params).then(res => {
                                if(res.infoCode == 200){
                                    this.$message.success('提交成功')
                                }else{
                                    this.$message.error('该企业存在有效期内数据，请核实后提交')
                                }

                                this.addData.dialogVisible = false
                                this.$emit("getList")
                            }).catch(res=>{
                                this.$message.error(res.msg)
                                this.addData.dialogVisible = false
                            })

                        } else {

                        }
                    });
                }else{
                    this.addData.dialogVisible = false
                }
            },
            getInfo(code){
                let params = {
                    "sgzgid": code
                }
                getDetail(params).then(res => {
                    if (!res) return;
                    this.addFormData = res.data;
                    this.addFormData.yxqq = this.addFormData.yxqq + ''
                    this.addFormData.yxqq1 = this.addFormData.yxqq.substring(0,4) + '-' + this.addFormData.yxqq.substring(4,6) + '-' + this.addFormData.yxqq.substring(6,8)
                    this.addFormData.yxqz = this.addFormData.yxqz + ''
                    this.addFormData.yxqz1 = this.addFormData.yxqz.substring(0,4) + '-' + this.addFormData.yxqz.substring(4,6) + '-' + this.addFormData.yxqz.substring(6,8)
                }).catch()
            },
            formatDateTimes (date) {
                let y = date.getFullYear();
                let m = date.getMonth() + 1;
                m = m < 10 ? ('0' + m) : m;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h=h < 10 ? ('0' + h) : h;
                let minute = date.getMinutes();
                minute = minute < 10 ? ('0' + minute) : minute;
                let second=date.getSeconds();
                second=second < 10 ? ('0' + second) : second;
                return y + '-' + m + '-' + d + ' ' + h +':'+minute + ':'+second;
            },
            //转时间方法
            formatDateTime (date) {
                let y = date.getFullYear();
                let m = date.getMonth() + 1;
                m = m < 10 ? ('0' + m) : m;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h=h < 10 ? ('0' + h) : h;
                let minute = date.getMinutes();
                minute = minute < 10 ? ('0' + minute) : minute;
                let second=date.getSeconds();
                second=second < 10 ? ('0' + second) : second;
                return y + '-' + m + '-' + d;
            },
        },
    };
</script>

<style scoped="scoped">
    .rowBottom{
        margin-bottom: 10px;
    }
</style>
-->
