<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="公司名称" prop="companyName" v-model="form.companyName" placeholder="请输入公司名称"/>
                            <Field label="公司编码" prop="companyCode" v-model="form.companyCode" placeholder="请输入公司编码"/>
                            <Field label="注册号" prop="registrationNumber" v-model="form.registrationNumber" placeholder="请输入注册号"/>
                            <Field label="法定代表人" prop="legalRepresentative" v-model="form.legalRepresentative" placeholder="请输入法定代表人"/>
                            <Field label="注册资本" prop="registeredCapital" v-model="form.registeredCapital" placeholder="请输入注册资本"/>
                            <Field label="公司类型" prop="companyType" v-model="form.companyType" placeholder="请输入公司类型"/>
                            <Field label="经营范围" prop="businessScope" v-model="form.businessScope" placeholder="请输入经营范围"/>
                            <Field label="经营地址" prop="businessAdress" v-model="form.businessAdress" placeholder="请输入经营地址"/>
                            <Field label="所在地" prop="location" v-model="form.location" placeholder="请输入所在地"/>
                            <Field label="所属区域编码" prop="areaCode" v-model="form.areaCode" placeholder="请输入所属区域编码"/>
                            <Field label="所属区域名称" prop="areaName" v-model="form.areaName" placeholder="请输入所属区域名称"/>
                            <Field label="联系电话" prop="contactPhone" v-model="form.contactPhone" placeholder="请输入联系电话"/>
                            <Field label="电子邮件地址" prop="email" v-model="form.email" placeholder="请输入电子邮件地址"/>
                            <Field label="公司网站" prop="website" v-model="form.website" placeholder="请输入公司网站"/>
                            <Field label="税务登记号" prop="taxRegistrationNumber" v-model="form.taxRegistrationNumber" placeholder="请输入税务登记号"/>
                            <Field label="社会信用代码" prop="socialCreditCode" v-model="form.socialCreditCode" placeholder="请输入社会信用代码"/>
                            <Field label="商标信息" prop="trademarkInfo" v-model="form.trademarkInfo" placeholder="请输入商标信息"/>
                            <Field label="网站历史备案信息" prop="websiteRegistrationInfo" v-model="form.websiteRegistrationInfo" placeholder="请输入网站历史备案信息"/>
                            <Field label="员工总数" prop="totalEmployees" v-model="form.totalEmployees" type="select" :enumData="dict.totalEmployees" placeholder="请选择员工总数"/>
                            <Field label="软件著作权数量" prop="softNum" v-model="form.softNum" type="select" :enumData="dict.softNum" placeholder="请选择软件著作权数量"/>
                            <Field label="专利数量" prop="patentNum" v-model="form.patentNum" type="select" :enumData="dict.patentNum" placeholder="请选择专利数量"/>
                            <Field label="历史发展" prop="hisDevelop" v-model="form.hisDevelop" type="textarea" placeholder="请输入历史发展"/>
                            <Field label="经度" prop="lon" v-model="form.lon" placeholder="请输入经度"/>
                            <Field label="纬度" prop="lati" v-model="form.lati" placeholder="请输入纬度"/>
                            <Field label="企业logo" prop="logoPath" v-model="form.logoPath" placeholder="请输入企业logo"/>
                            <Field label="企业视频" prop="companyVideoPath" v-model="form.companyVideoPath" type="textarea" placeholder="请输入企业视频"/>
                            <Field label="企业宣传图片" prop="companyPicPath" v-model="form.companyPicPath" type="textarea" placeholder="请输入企业宣传图片"/>
                            <Field label="公司介绍" prop="companyIntroduction" v-model="form.companyIntroduction" type="textarea" placeholder="请输入公司介绍"/>
                            <Field label="公司文化" prop="companyCulture" v-model="form.companyCulture" type="textarea" placeholder="请输入公司文化"/>
                            <Field label="排序" prop="sort" v-model="form.sort" placeholder="请输入排序"/>
                            <Field label="成立日期" prop="establishDate" v-model="form.establishDate" type="date" />
                            <Field label="备注" prop="remark" v-model="form.remark" placeholder="请输入备注"/>

            </el-row>
                <el-divider content-position="center">公司标注信息</el-divider>
                <br/>
                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddCompanyLabels">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteCompanyLabels">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="companyLabelsList" :row-class-name="rowCompanyLabelsIndex" @selection-change="handleCompanyLabelsSelectionChange" ref="companyLabels">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="标签Id" prop="labelId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.labelId" placeholder="请输入标签Id" />
                                </template>
                            </el-table-column>
                            <el-table-column label="标签名称" prop="labelName">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.labelName" placeholder="请输入标签名称" />
                                </template>
                            </el-table-column>
                            <el-table-column label="备注" prop="remark">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.remark" placeholder="请输入备注" />
                                </template>
                            </el-table-column>
                            <el-table-column label="创建用户" prop="createUserId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.createUserId" placeholder="请输入创建用户" />
                                </template>
                            </el-table-column>
                            <el-table-column label="创建时间" prop="createTime">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.createTime" placeholder="请输入创建时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="更新用户" prop="updateUserId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.updateUserId" placeholder="请输入更新用户" />
                                </template>
                            </el-table-column>
                            <el-table-column label="更新时间" prop="updateTime">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.updateTime" placeholder="请输入更新时间" />
                                </template>
                            </el-table-column>
                </el-table>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" v-if="pageInfo.type !== 'view'" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    import dialogShow from "./dialogshow";
    export default {
        mixins: [form],
        components: {
            dialogShow ,
        },
        data() {
            return {
                // 子表选中数据
                checkedCompanyLabels: [],
                // 公司标注表格数据
                companyLabelsList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "公司",
                // 是否显示弹出层
                open: false,
                toString:[
                    "totalEmployees",
                    "softNum",
                    "patentNum",
                ],
                // 表单校验
                rules: {
                    companyName: [
                        {required: true,message: "请输入公司名称", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    areaCode: [
                        {required: true,message: "请输入所属区域编码", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    areaName: [
                        {required: true,message: "请输入所属区域名称", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    contactPhone: [
                        {required: true,message: "请输入联系电话", trigger: "blur" },
                        {max: 32,message: "最多只能录入32个字符",trigger: "blur",},
                    ],
                    lon: [
                        {required: true,message: "请输入经度", trigger: "blur" },
                        {max: 32,message: "最多只能录入32个字符",trigger: "blur",},
                    ],
                    lati: [
                        {required: true,message: "请输入纬度", trigger: "blur" },
                        {max: 32,message: "最多只能录入32个字符",trigger: "blur",},
                    ],
                    logoPath: [
                        {required: true,message: "请输入企业logo", trigger: "blur" },
                        {max: 128,message: "最多只能录入128个字符",trigger: "blur",},
                    ],
                    establishDate: [
                        {required: true,message: "请选择成立日期" },
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 公司标注序号 */
            rowCompanyLabelsIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 公司标注添加按钮操作 */
            handleAddCompanyLabels() {
                let obj = {};
                obj.labelId = "";
                obj.labelName = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.companyLabelsList.push(obj);
            },
            /** 公司标注删除按钮操作 */
            handleDeleteCompanyLabels() {
                if (this.checkedCompanyLabels.length == 0) {
                    this.$alert("请先选择要删除的公司标注数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.companyLabelsList.splice(this.checkedCompanyLabels[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleCompanyLabelsSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.companyLabels.clearSelection();
                    this.$refs.companyLabels.toggleRowSelection(selection.pop());
                } else {
                    this.checkedCompanyLabels = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.companyLabelsList) {
                    this.companyLabelsList = data.entity.companyLabelsList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="company/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改公司";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "company/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增公司";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="company/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "公司详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    companyName : "",
                    companyCode : "",
                    registrationNumber : "",
                    legalRepresentative : "",
                    registeredCapital : "",
                    companyType : "",
                    businessScope : "",
                    businessAdress : "",
                    location : "",
                    areaCode : "",
                    areaName : "",
                    contactPhone : "",
                    email : "",
                    website : "",
                    taxRegistrationNumber : "",
                    socialCreditCode : "",
                    trademarkInfo : "",
                    websiteRegistrationInfo : "",
                    totalEmployees : null,
                    softNum : null,
                    patentNum : null,
                    hisDevelop : "",
                    lon : "",
                    lati : "",
                    logoPath : "",
                    companyVideoPath : "",
                    companyPicPath : "",
                    companyIntroduction : "",
                    companyCulture : "",
                    sort : 0,
                    establishDate : null,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
