
<template>
    <layout-form>
        <el-form :model="form" :loading="loading" :rules="rules" size='small' label-width='100px' ref="form">
            <el-row>
                <Field label="事件码" prop="code" v-model="form.code" :disabled="pageInfo.type !== 'add'" />
                <Field label="事件名称" prop="name" v-model="form.name" :disabled="pageInfo.type === 'view'" />
                <Field label="是否启用" prop="enabled" v-model="form.enabled" :enumData='dict.enabled' type='select' :disabled="pageInfo.type === 'view'" />
                <Field label="事件前状态" prop="beforeFlowStatus" v-model="form.beforeFlowStatus">
                    <el-select v-model="form.beforeFlowStatus" filterable clearable multiple :disabled="pageInfo.type === 'view'" placeholder="请选择事件前状态">
                        <el-option v-for="($label, $value) in dict.beforeFlowStatus" :key="$value" :label="$label" :value="$value"></el-option>
                    </el-select>
                </Field>
                <!--<Field label="事件前状态" prop="beforeFlowStatus" v-model="form.beforeFlowStatus" multiple :enumData='dict.beforeFlowStatus' type='select' />-->
                <Field label="事件后状态" prop="afterFlowStatus" v-model="form.afterFlowStatus" :disabled="pageInfo.type === 'view'" :enumData='dict.afterFlowStatus' type='select' />
                <Field label="执行脚本" prop="script" v-model="form.script"  :disabled="pageInfo.type === 'view'" type='select'  :enumData='dict.script' />
              <Field label="排序号" prop="orderNo" v-model="form.orderNo"  :disabled="pageInfo.type === 'view'" >
                <el-input-number v-model="form.orderNo" :step="1"  :min="0"></el-input-number>
              </Field>

            </el-row>
            <form-buttons @submit='submitForm' v-if="pageInfo.type != 'view'" />
            <el-button @click="$router.go(-1)" size='small' icon='el-icon-circle-close-outline' v-if="pageInfo.type == 'view'">返回</el-button>
        </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.beforeFlowStatus) {
                let status = data.entity.beforeFlowStatus.split(",");
                data.entity.beforeFlowStatus = status;
            } else {
                data.entity.beforeFlowStatus = [];
            }
            return data;
        },
    },
    data() {
        return {
            beforeFlowStatusSelect: [],
            toString: ["enabled", "afterFlowStatus"],
            rules: {
                code: [
                    { required: true, message: "请输入CODE", trigger: "blur" },
                    { validator: valid.integer, trigger: "blur" },
                ],
                name: [
                    {
                        required: true,
                        message: "请输入事件名称",
                        trigger: "blur",
                    },
                ],
                enabled: [
                    {
                        required: true,
                        message: "请选择是否启用",
                        trigger: "blur",
                    },
                ],
                beforeFlowStatus: [
                    {
                        required: true,
                        message: "请选择事件前资产流转状态",
                        trigger: "blur",
                    },
                ],
                afterFlowStatus: [
                    {
                        required: true,
                        message: "请选择事件后资产流转状态",
                        trigger: "blur",
                    },
                ],
                 script: [{ required: true, message: '请选择事件执行事务脚本', trigger: 'blur' },],
              orderNo: [
                {
                  required: true,
                  message: "请输入排序号",
                  trigger: "blur",
                },
              ],
            },
        };
    },
};
</script>
