<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
                <el-col :span="24" v-if="form.parentId !== 0">
                    <el-form-item label="上级站点" prop="parentId">
                        <treeselect
                                v-model="form.parentId"
                                :options="siteOptions"
                                :normalizer="normalizer"
                                placeholder="选择上级站点信息"
                        />
                    </el-form-item>
                </el-col>


                            <Field label="站点名" prop="siteName" v-model="form.siteName" placeholder="请输入站点名"/>

                            <Field label="父级id" prop="parentId" v-model="form.parentId" placeholder="请输入父级id"/>

                            <Field label="祖级列表，逗号分隔" prop="ancestors" v-model="form.ancestors" placeholder="请输入祖级列表，逗号分隔"/>

                            <Field label="地址" prop="address" v-model="form.address" placeholder="请输入地址"/>

                            <Field label="电话" prop="mobile" v-model="form.mobile" placeholder="请输入电话"/>

                            <Field label="单位介绍" prop="introduce" v-model="form.introduce" type="textarea" placeholder="请输入单位介绍"/>

                            <Field label="周一 1上班 0不上" prop="workday1" v-model="form.workday1" type="select" :enumData="dict.workday1" placeholder="请选择周一 1上班 0不上"/>

                            <Field label="周二 1上班 0不上" prop="workday2" v-model="form.workday2" type="select" :enumData="dict.workday2" placeholder="请选择周二 1上班 0不上"/>

                            <Field label="周三 1上班 0不上" prop="workday3" v-model="form.workday3" type="select" :enumData="dict.workday3" placeholder="请选择周三 1上班 0不上"/>

                            <Field label="周四 1上班 0不上" prop="workday4" v-model="form.workday4" type="select" :enumData="dict.workday4" placeholder="请选择周四 1上班 0不上"/>

                            <Field label="周五 1上班 0不上" prop="workday5" v-model="form.workday5" type="select" :enumData="dict.workday5" placeholder="请选择周五 1上班 0不上"/>

                            <Field label="周六 1上班 0不上" prop="workday6" v-model="form.workday6" type="select" :enumData="dict.workday6" placeholder="请选择周六 1上班 0不上"/>

                            <Field label="周日 1上班 0不上" prop="workday7" v-model="form.workday7" type="select" :enumData="dict.workday7" placeholder="请选择周日 1上班 0不上"/>

                            <Field label="站点编号" prop="number" v-model="form.number" placeholder="请输入站点编号"/>

                            <Field label="中心介绍" prop="summary" v-model="form.summary" type="textarea" placeholder="请输入中心介绍"/>

                            <Field label="排序字段" prop="orderNum" v-model="form.orderNum" placeholder="请输入排序字段"/>

                            <Field label="站点状态 ，0，停用，1，正常 默认1" prop="status" v-model="form.status" type="select" :enumData="dict.status" placeholder="请选择站点状态 ，0，停用，1，正常 默认1"/>

            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import form from "@/assets/mixins/form";
    import Treeselect from "@riophae/vue-treeselect";
    import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    export default {
        mixins: [form],
        components: {
            Treeselect,
        },
        data() {
            return {
                siteOptions: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "站点信息",
                // 是否显示弹出层
                open: false,
                toString:[
                    "workday1",
                    "workday2",
                    "workday3",
                    "workday4",
                    "workday5",
                    "workday6",
                    "workday7",
                    "status",
                ],
                // 表单校验
                rules: {
                    siteName: [
                        {required: true, trigger: "blur" },
                    ],
                    ancestors: [
                        { trigger: "blur" },
                    ],
                    address: [
                        {required: true, trigger: "blur" },
                    ],
                    mobile: [
                        {required: true, trigger: "blur" },
                    ],
                    introduce: [
                        {required: true, trigger: "blur" },
                    ],
                    workday1: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday2: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday3: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday4: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday5: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday6: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    workday7: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    number: [
                        {required: true, trigger: "blur" },
                    ],
                    summary: [
                        {required: true, trigger: "blur" },
                    ],
                    orderNum: [
                        { type: 'integer',trigger: "blur" },
                    ],
                    status: [
                        { type: 'integer',trigger: "blur" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row, siteOptions) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl =this.pageInfo.editUrl;;
                this.getData();
                this.siteOptions = siteOptions;
                this.open = true;
                this.title = "修改站点信息";
            },
            /** 新增 */
            add(row, siteOptions) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl = this.pageInfo.addUrl;
                this.getData();
                this.siteOptions = siteOptions;
                this.open = true;
                this.title = "新增站点信息";
            },
            /** 查看*/
            view(row, siteOptions) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl =this.pageInfo.viewUrl;;
                this.getData();
                this.siteOptions = siteOptions;
                this.open = true;
                this.title = "站点信息详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },

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

            /** 转换站点信息数据结构 */
            normalizer(node) {
                if (node.children && !node.children.length) {
                    delete node.children;
                }
                return {
                    id: node.id,
                    label: node.siteName,
                    children: node.children,
                };
            },
            // 表单重置
            reset() {
                this.form = {
                    siteName : null,
                    parentId : null,
                    ancestors : "",
                    address : null,
                    mobile : null,
                    introduce : null,
                    number : null,
                    summary : null,
                    orderNum : 0,
                    status : 1,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
