<template>
    <layout-form>
        <el-form :model="form" :loading="loading" :rules="rules" size='small' style="width:100%" label-width='120px' ref="form">
            <el-row>
                <Field label="名称" prop="name" v-model="form.name" placeholder="请输入名称" :disabled="pageInfo.type === 'view'" />
                <Field label="代码" prop="code" v-model="form.code" placeholder="请输入代码" :disabled="pageInfo.type !== 'add'" />
                <Field label="标签" prop="tags" v-model="form.tags">
                    <el-select v-model="form.tags" filterable clearable multiple :disabled="pageInfo.type === 'view'" placeholder="请选择标签">
                        <el-option v-for="($label, $value) in dict.tags" :key="$value" :label="$label" :value="$value"></el-option>
                    </el-select>
                </Field>
                <Field label="性质" prop="nature" v-model="form.nature" placeholder="请输入性质" :enumData='dict.nature' type="select" :disabled="pageInfo.type === 'view'" />
                <Field label="信用代码" prop="nature" v-model="form.creditCode" placeholder="性质为非个人：统一信用代码；性质为个人：身份证号" :disabled="pageInfo.type === 'view'" />
                <!-- <Field label="行业类别" prop="trade" v-model="form.trade" placeholder="请输入行业类别。参看国家标准：http://www.stats.gov.cn/tjsj/tjbz/hyflbz/201905/P020190716349644060705.pdf"  :disabled="pageInfo.type === 'view'"/> -->
                <Field label="结算方式" prop="settlementType" v-model="form.settlementType" placeholder="请输入结算方式" :enumData='dict.settlementType' type="select" :disabled="pageInfo.type === 'view'" />
                <Field label="联系人" prop="contactsUser" v-model="form.contactsUser" placeholder="请输入联系人" :disabled="pageInfo.type === 'view'" />
                <Field label="联系手机" prop="contactsMobile" v-model="form.contactsMobile" placeholder="请输入联系手机" :disabled="pageInfo.type === 'view'" />
                <Field label="联系座机" prop="contactsPhone" v-model="form.contactsPhone" placeholder="请输入联系座机" :disabled="pageInfo.type === 'view'" />
                <Field label="联系邮箱" prop="contactsEmail" v-model="form.contactsEmail" placeholder="请输入联系邮箱" :disabled="pageInfo.type === 'view'" />
                <Field label="联系地址" prop="contactsAddress" v-model="form.contactsAddress" placeholder="请输入联系地址" :disabled="pageInfo.type === 'view'" />
                <Field label="网站" prop="contactsWebsite" v-model="form.contactsWebsite" placeholder="请输入网站" :disabled="pageInfo.type === 'view'" />
                <Field label="备注" prop="remark" span="24" v-model="form.remark" type="textarea" placeholder="请输入备注" :disabled="pageInfo.type === 'view'" />
            </el-row>
            <form-buttons @submit='submitForm' :noSaveBtn="pageInfo.type === 'view'" />
        </el-form>
    </layout-form>
</template>

<script>
import form from "@/assets/mixins/form";
import valid from "@/assets/utils/vaild";
export default {
    mixins: [form],
    methods: {
        beforeRender(data) {
            if (data.entity.tags) {
                let status = data.entity.tags.split(",");
                data.entity.tags = status;
            } else {
                data.entity.tags = [];
            }
            return data;
        },
    },
    data() {
        return {
            toString: ["partnerType", "nature", "settlementType"],
            rules: {
                name: [
                    {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur",
                    },
                    {
                        max: 50,
                        message: "最多只能录入50个字符",
                        trigger: "blur",
                    },
                ],
              code: [
                {
                  required: true,
                  message: "请输入代码",
                  trigger: "blur",
                },
              ],
                tags: [
                    {
                        required: true,
                        message: "请选择标签",
                        trigger: "blur",
                    },
                ],
                nature: [
                    {
                        required: true,
                        message: "请输入信用代码",
                        trigger: "blur",
                    },
                ],
                creditCode: [
                    {
                        required: true,
                        message: "请选择性质",
                        trigger: "blur",
                    },
                ],
                /*	trade:[{type: 'integer', trigger: 'blur'}],*/
                settlementType: [
                    {
                        required: true,
                        message: "请输入结算方式",
                        trigger: "blur",
                    },
                ],
                contactsUser: [
                    {
                        required: true,
                        message: "请输入联系人",
                        trigger: "blur",
                    },
                    {
                        max: 50,
                        message: "最多只能录入50个字符",
                        trigger: "blur",
                    },
                ],
                contactsMobile: [
                    {
                        required: true,
                        message: "请输入联系手机",
                        trigger: "blur",
                    },
                    { validator: this.phone, trigger: "blur" },
                    {
                        max: 50,
                        message: "最多只能录入50个字符",
                        trigger: "blur",
                    },
                ],
                contactsPhone: [
                    {
                        required: true,
                        message: "请输入联系座机",
                        trigger: "blur",
                    },
                    {
                        max: 50,
                        message: "最多只能录入50个字符",
                        trigger: "blur",
                    },
                ],
                contactsEmail: [
                    { type: "email", trigger: "blur" },
                    {
                        max: 50,
                        message: "最多只能录入50个字符",
                        trigger: "blur",
                    },
                ],
                contactsAddress: [
                    {
                        max: 100,
                        message: "最多只能录入100个字符",
                        trigger: "blur",
                    },
                ],
                contactsWebsite: [
                    {
                        max: 100,
                        message: "最多只能录入100个字符",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
};
</script>