<!--业务编码-->
<template>
    <div class="BusinessCode">
        <div
            class="BusinessCode-box"
            v-show="!BCR.show"
        >
            <div
                class="box"
                :style="{'padding-bottom': dialog_code.show ? '200px' : '0px'}"
            >
                <el-form
                    class="box-top"
                    :model="filterForm.data"
                    :rules="filterForm.rules"
                    ref="filterForm"
                    inline
                >
                    <el-form-item>
                        <el-input
                            size="mini"
                            v-model.trim="filterForm.data.codeName"
                            placeholder="编码规则名"
                            style="width: 250px;"
                        ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-input
                            size="mini"
                            v-model.trim="filterForm.data.describe"
                            placeholder="备注"
                            style="width: 250px;"
                        ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-search"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="getTableData(1)"
                        >查询</el-button>
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-refresh"
                            v-privilege="activeMenu + 'QUERY'"
                            @click="tableDataCancel();"
                        >重置</el-button>
                        <el-button
                            class="button"
                            type="primary"
                            size="mini"
                            icon="el-icon-plus"
                            v-privilege="activeMenu + 'ADD'"
                            @click="code_handle({str:'add',row:''})"
                        >新增</el-button>
                    </el-form-item>
                </el-form>
                <div class="box-bottom">
                    <el-table
                        ref="singleTable"
                        :data="tableData"
                        v-loading="tableLoading"
                        style="width: 100%;"
                        height="100%"
                        border
                        size="mini"
                        highlight-current-row
                        @current-change="handleCurrentChange"
                    >
                        <el-table-column
                            prop="codeName"
                            label="编码规则名"
                            min-width="200px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            label="是否允许断号"
                            align="center"
                            width="100"
                            sortable
                            :show-overflow-tooltip="true"
                        >
                            <template slot-scope="scope">
                                <span>{{ scope.row.broken === '1' ? '是' : scope.row.broken === '0' ? '否' : '' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="是否新增显示"
                            align="center"
                            width="100"
                            sortable
                            :show-overflow-tooltip="true"
                        >
                            <template slot-scope="scope">
                                <span>{{ scope.row.newShow === '1' ? '是' : scope.row.newShow === '0' ? '否' : '' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            prop="describe"
                            label="备注"
                            min-width="240px"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            prop="crtUserCode"
                            label="创建人"
                            align="center"
                            width="100"
                            :show-overflow-tooltip="true"
                        ></el-table-column>
                        <el-table-column
                            prop="crtDate"
                            label="创建时间"
                            align="center"
                            width="150"
                        ></el-table-column>
                        <el-table-column
                            label="状态"
                            align="center"
                            width="70"
                            fixed="right"
                        >
                            <template slot-scope="scope">
                                <span :class="{chartreuse: scope.row.state === '1', red: scope.row.state === '0'}">{{ scope.row.state === '1' ? '启用' : scope.row.state === '0' ? '停用' : '' }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            label="操作"
                            align="center"
                            width="240"
                            fixed="right"
                        >
                            <template slot-scope="scope">
                                <div @click.stop>
                                    <el-button
                                        type="primary"
                                        size="mini"
                                        v-privilege="activeMenu + 'PUT'"
                                        @click="code_handle({str:'bmgz', row:scope.row})"
                                    >编码规则</el-button>
                                    <el-button
                                        type="danger"
                                        size="mini"
                                        v-privilege="activeMenu + 'DELETE'"
                                        @click="code_handle({str:'del', row:scope.row})"
                                    >删除</el-button>
                                    <el-button
                                        v-if="scope.row.state !== '1'"
                                        type="primary"
                                        size="mini"
                                        v-privilege="activeMenu + 'STARTANDSTOP'"
                                        @click="code_handle({str:'open', row:scope.row})"
                                    >启用</el-button>
                                    <el-button
                                        v-else
                                        size="mini"
                                        v-privilege="activeMenu + 'STARTANDSTOP'"
                                        @click="code_handle({str:'shut', row:scope.row})"
                                    >停用</el-button>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total"
                        :page-sizes="[10, 20, 30, 40, 100, 200]"
                        :page-size="pageSize"
                        :current-page.sync="pageNum"
                        @size-change="tableSizeChange"
                        @current-change="getTableData()"
                        style="text-align: right;margin-top: 10px;"
                    >
                    </el-pagination>
                </div>
            </div>
            <div
                class="box_edit"
                v-show="dialog_code.show"
                :style="{height: dialog_code.show ? '200px' : '0px'}"
            >
                <div style="padding: 0 20px;">
                    <div class="edit-title">
                        <span class="span-text">编辑区-{{ dialog_code.state }}</span>
                    </div>
                    <el-form
                        size="mini"
                        :model="dialog_code.form.data"
                        :rules="dialog_code.form.rules"
                        ref="dialog_code_form"
                        label-width="100px"
                    >
                        <div class="edit-box">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item
                                        label="业务编码名"
                                        prop="codeName"
                                    >
                                        <!-- <el-autocomplete
                                            size="mini"
                                            class="BusinessCode-width-100"
                                            ref="dialog_code_form_codeName"
                                            v-model.trim="dialog_code.form.data.codeName"
                                            :fetch-suggestions="querySearch"
                                            @select="handleSelect"
                                            placeholder="编码名格式为：表面.字段名"
                                        ></el-autocomplete> -->
                                        <div>
                                            <el-input
                                                size="mini"
                                                class="BusinessCode-width-100 input-but"
                                                v-model.trim="dialog_code.form.data.codeName"
                                                placeholder="编码名格式为：表面.字段名"
                                                readonly
                                            >
                                                <el-button
                                                    slot="append"
                                                    type="primary"
                                                    @click="chooseCodeName();"
                                                >选择</el-button>
                                            </el-input>
                                        </div>
                                    </el-form-item>
                                </el-col>
                                <!-- <el-col :span="4">
                                    <el-form-item
                                        label="状态"
                                        prop="state"
                                    >
                                        <el-select
                                            size="mini"
                                            class="BusinessCode-width-100"
                                            v-model="dialog_code.form.data.state"
                                        >
                                            <el-option
                                                label="启用"
                                                value="1"
                                            ></el-option>
                                            <el-option
                                                label="停用"
                                                value="0"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col> -->
                                <el-col :span="6">
                                    <el-form-item
                                        label="是否允许断号"
                                        prop="broken"
                                    >
                                        <el-select
                                            size="mini"
                                            class="BusinessCode-width-100"
                                            v-model="dialog_code.form.data.broken"
                                        >
                                            <el-option
                                                label="是"
                                                value="1"
                                            ></el-option>
                                            <el-option
                                                label="否"
                                                value="0"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6">
                                    <el-form-item
                                        label="是否新增显示"
                                        prop="newShow"
                                    >
                                        <el-select
                                            size="mini"
                                            class="BusinessCode-width-100"
                                            v-model="dialog_code.form.data.newShow"
                                        >
                                            <el-option
                                                label="是"
                                                value="1"
                                            ></el-option>
                                            <el-option
                                                label="否"
                                                value="0"
                                            ></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item
                                        label="备注"
                                        prop="describe"
                                    >
                                        <el-input
                                            size="mini"
                                            type="textarea"
                                            :rows="1"
                                            class="BusinessCode-width-100"
                                            v-model.trim="dialog_code.form.data.describe"
                                        ></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <div class="edit-but">
                                <el-button
                                    @click="cancelBut();"
                                    :loading="loading"
                                    size="mini"
                                >取 消</el-button>
                                <el-button
                                    type="primary"
                                    @click="formSubmit_dialog_code()"
                                    :loading="loading"
                                    size="mini"
                                >保 存</el-button>
                            </div>
                        </div>
                    </el-form>
                </div>
            </div>
        </div>
        <el-dialog
            title="选择业务编码名"
            :visible.sync="dialog_codeName.show"
            width="400px"
            :close-on-click-modal="false"
        >
            <el-form
                ref="codeNameForm"
                label-width="80px"
                :model="dialog_codeName"
                :rules="dialog_codeName.rules"
                size="mini"
            >
                <el-form-item
                    label="表名："
                    prop="tableName"
                >
                    <el-select
                        size="mini"
                        class="BusinessCode-width-100"
                        v-model="dialog_codeName.tableName"
                        :disabled="dialog_code.state === '修改' && !dialog_codeName.nameEdit"
                        @change="changeTableName()"
                        filterable
                    >
                        <el-option
                            v-for="(item, index) of dialog_codeName.data"
                            :key="index"
                            :label="item.value"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item
                    label="字段名："
                    prop="fieldsName"
                >
                    <el-select
                        size="mini"
                        class="BusinessCode-width-100"
                        v-model="dialog_codeName.fieldsName"
                        filterable
                    >
                        <el-option
                            v-for="(item, index) of dialog_codeName.showFields"
                            :key="index"
                            :label="item.value"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button @click="dialog_codeName.show = false">取 消</el-button>
                <el-button
                    type="primary"
                    @click="selectCodeName()"
                >确 定</el-button>
            </span>
        </el-dialog>
        <BusinessCodeRules
            v-if="BCR.show"
            :builder="BCR.data"
            v-on:exit="exitBCR"
        ></BusinessCodeRules>
    </div>
</template>

<script>
import { checkComplexText } from '@/utils/validator.js'
import BusinessCodeRules from '@/views/systemConfig/components/businessCode/children/businessCodeRules.vue'
import store from '@/store/index.js';
export default {
    name: 'BusinessCode',
    components: {
        BusinessCodeRules
    },
    data () {
        const checkCodeName = (rule, value, callback) => {
            if (value) {
                let st = /^[a-zA-Z0-9_.]*$/;
                if (!st.test(value)) {
                    return callback(new Error('只能输入英文字母、数字、下划线(_)、点(.)的组合'));
                }
                if (rule.max && value.length > rule.max) {
                    return callback(new Error('最多输入' + rule.max + '个字符'));
                }
                if (rule.min && value.length < rule.min) {
                    return callback(new Error('最少输入' + rule.min + '个字符'));
                }
            }
            callback();
        };
        return {
            store,
            activeMenu: '',
            userInfo: {
                data: {}, // 用户基础信息
                admin: false // 身份是否为管理员
            },
            BCR: {
                show: false,
                data: {}
            },
            loading: false,
            tableLoading: false,
            filterForm: {
                data: {
                    codeName: '',
                    describe: ''
                },
                rules: {

                }
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            tableData: [],
            codeNameHint: [],
            codeNameProps: {
                label: 'value',
                value: 'value',
                children: 'fields'
            },
            dialog_code: {
                state: '',
                show: false,
                form: {
                    data: {
                        id: '',
                        codeName: '',
                        broken: '1',
                        newShow: '1',
                        describe: '',
                        state: '1'
                    },
                    rules: {
                        codeName: [
                            { required: true, message: '该项不能为空', trigger: 'change' },
                            { validator: checkCodeName, max: 36, trigger: 'change' }
                        ],
                        broken: [
                            { required: true, message: '该项不能为空', trigger: 'change' }
                        ],
                        newShow: [
                            { required: true, message: '该项不能为空', trigger: 'change' }
                        ],
                        describe: [
                            { validator: checkComplexText, max: 500, trigger: 'change' }
                        ],
                        state: [
                            { required: true, message: '该项不能为空', trigger: 'change' }
                        ]
                    }
                }
            },
            dialog_codeName: {
                show: false,
                nameEdit: false,
                tableName: '',
                fieldsName: '',
                rules: {
                    tableName: [
                        { required: true, message: '该项不能为空', trigger: 'change' }
                    ],
                    fieldsName: [
                        { required: true, message: '该项不能为空', trigger: 'change' }
                    ]
                },
                data: {},
                showFields: []
            }
        };
    },
    created () {
        this.activeMenu = window.localStorage.getItem('activeMenu');
    },
    mounted () {
        let that = this;
        that.store.dispatch('getUserInfo').then((res) => {
            that.userInfo.data = res.data;
            that.getUserRoles(that.getTableData);
        });
    },
    methods: {
        getUserRoles (foo) {
            let that = this;
            // 获取用户信息
            that.tableLoading = true;
            that.axios.get('pass/v1/sysuserroles/?userCode=' + that.userInfo.data.userCode)
                .then(function (res) {
                    if (res.code === '0') {
                        for (let item of res.data.list) {
                            if (item.roleId === '1') { // 判断用户身份是否是管理员（管理员身份id是1）
                                that.userInfo.admin = true;
                            }
                        }
                        if (foo) {
                            foo();
                        }
                    } else {
                        that.$message.error(res.message);
                    }
                    that.tableLoading = false;
                }).catch(function () {
                    that.tableLoading = false;
                });
        },
        getTableData (pageNum) {
            let that = this,
                params = {
                    builderType: that.filterForm.data.codeName,
                    remark: that.filterForm.data.describe
                };
            that.pageNum = pageNum || that.pageNum;
            that.tableLoading = true;
            let url = 'pass/v1/syscodebuilders/?pageNum=' + that.pageNum + '&pageSize=' + that.pageSize;
            if (!that.userInfo.admin) {
                url += '&userCode=' + that.userInfo.data.userCode;
            }
            that.axios.get(url, {
                params: params
            })
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        that.total = res.data.total;
                        res.data.list.forEach(item => {
                            arr.push({
                                id: item.builderId,
                                codeName: item.builderType, // 编码规则名
                                broken: item.isBreakCode, // 是否允许断号
                                newShow: item.isAddView, // 是否新增显示
                                describe: item.remark, // 备注
                                state: item.status, // 状态
                                crtUserCode: item.crtUserCode,
                                crtDate: item.crtDate
                            });
                        });
                        that.tableData = arr;
                    } else {
                        that.$message.error(res.message);
                    }
                    that.tableLoading = false;
                }).catch(function () {
                    that.tableLoading = false;
                });
        },
        // 改变表格显示条数
        tableSizeChange (val) {
            let that = this;
            that.pageSize = val;
            that.getTableData(1);
        },
        // 重置搜索
        tableDataCancel () {
            let that = this;
            that.filterForm.data.codeName = '';
            that.filterForm.data.describe = '';
            that.getTableData(1);
        },
        // 取消
        cancelBut () {
            let that = this;
            that.$refs['singleTable'].setCurrentRow();
            that.dialog_code.show = false;
        },
        // 选中行
        handleCurrentChange (row) {
            let that = this;
            if (row && !that.loading) {
                that.code_handle({ str: 'edit', row: row });
            }
        },
        // 各种按钮点击的效果
        code_handle (command) {
            let that = this,
                str = command.str, row = command.row;
            switch (str) {
                case 'add':
                    that.dialog_code.state = '新增';
                    that.dialog_code.show = true;
                    setTimeout(() => {
                        that.$refs['dialog_code_form'].resetFields();
                    }, 100);
                    break;
                case 'edit':
                    that.dialog_code.state = '修改';
                    that.dialog_code.show = true;
                    that.dialog_code.form.data = {
                        id: row.id,
                        codeName: row.codeName, // 编码规则名
                        broken: row.broken, // 是否允许断号
                        newShow: row.newShow, // 是否新增显示
                        describe: row.describe, // 备注
                        state: row.state // 状态
                    }
                    setTimeout(() => {
                        that.$refs['dialog_code_form'].validate((valid) => { });
                    }, 100);
                    break;
                case 'del':
                    that.cancelBut();
                    that.$confirm('此操作将删除该条编码规则, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        state: 'warning'
                    }).then(() => {
                        that.axios.delete('pass/v1/syscodebuilders/' + row.id)
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.$message({
                                        message: '删除成功',
                                        type: 'success'
                                    });
                                    that.getTableData();
                                } else {
                                    that.$message.error(res.message);
                                }
                            }).catch(function () {
                            });
                    }).catch(() => {
                    });
                    break;
                case 'bmgz':
                    this.BCR.data = {
                        id: row.id,
                        codeName: row.codeName
                    };
                    this.BCR.show = true;
                    break;
                case 'open':
                    that.axios.put('pass/v1/syscodebuilders/' + row.id, {
                        status: '1'
                    })
                        .then(function (res) {
                            if (res.code === '0') {
                                row.state = res.data.status;
                                that.$message({
                                    message: '规则已启用',
                                    type: 'success'
                                });
                            } else {
                                that.$message.error(res.message);
                            }
                        }).catch(function () {
                        });
                    break;
                case 'shut':
                    that.axios.put('pass/v1/syscodebuilders/' + row.id, {
                        status: '0'
                    })
                        .then(function (res) {
                            if (res.code === '0') {
                                row.state = res.data.status;
                                that.$message({
                                    message: '规则已停用',
                                    type: 'success'
                                });
                            } else {
                                that.$message.error(res.message);
                            }
                        }).catch(function () {
                        });
                    break;
            }
        },
        // 新增或修改业务编码定义
        formSubmit_dialog_code () {
            let that = this,
                obj = {
                    builderType: that.dialog_code.form.data.codeName, // 编码规则名
                    isBreakCode: that.dialog_code.form.data.broken, // 是否允许断号
                    isAddView: that.dialog_code.form.data.newShow, // 是否新增显示
                    remark: that.dialog_code.form.data.describe // 备注
                    // status: that.dialog_code.form.data.state
                };
            that.$refs['dialog_code_form'].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    if (that.dialog_code.state === '新增') {
                        let formData = new FormData();
                        for (let key in obj) {
                            formData.append(key, obj[key]);
                        }
                        if (typeof obj.status === 'undefined') {
                            formData.append('status', '1');
                        }
                        that.axios.post('pass/v1/syscodebuilders/', formData, {
                            headers: {
                                'Content-Type': 'multipart/form-data'
                            }
                        })
                            .then(function (res) {
                                if (res.code === '0') {
                                    that.tableData.unshift({
                                        id: res.data.builderId,
                                        codeName: res.data.builderType,
                                        broken: res.data.isBreakCode,
                                        newShow: res.data.isAddView,
                                        describe: res.data.remark,
                                        state: res.data.status,
                                        crtUserCode: res.data.crtUserCode,
                                        crtDate: res.data.crtDate
                                    })
                                    // 表格滚动至顶部
                                    let container = that.$el.querySelector('.el-table__body-wrapper');
                                    that.$refs['singleTable'].setCurrentRow(that.tableData[0]);
                                    container.scrollTop = 0;
                                    that.$message({
                                        message: '新增成功',
                                        type: 'success'
                                    });
                                    that.dialog_code.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    } else if (that.dialog_code.state === '修改') {
                        that.axios.put('pass/v1/syscodebuilders/' + that.dialog_code.form.data.id, obj)
                            .then(function (res) {
                                if (res.code === '0') {
                                    for (let i = 0; i < that.tableData.length; i++) {
                                        if (that.dialog_code.form.data.id === that.tableData[i].id) {
                                            that.tableData[i].codeName = res.data.builderType;
                                            that.tableData[i].broken = res.data.isBreakCode;
                                            that.tableData[i].newShow = res.data.isAddView;
                                            that.tableData[i].describe = res.data.remark;
                                            that.tableData[i].state = res.data.status;
                                            break;
                                        }
                                    }
                                    that.$message({
                                        message: '修改成功',
                                        type: 'success'
                                    });
                                    that.dialog_code.show = false;
                                } else {
                                    that.$message.error(res.message);
                                }
                                that.loading = false;
                            }).catch(function () {
                                that.loading = false;
                            });
                    }
                } else {
                    return false;
                }
            });
        },
        chooseCodeName () {
            let that = this;
            that.dialog_codeName.nameEdit = false;
            that.getDataTableName(() => {
                if (that.dialog_code.form.data.codeName !== '') {
                    if (/^[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+$/.test(that.dialog_code.form.data.codeName)) {
                        let arr = that.dialog_code.form.data.codeName.split('.');
                        that.dialog_codeName.tableName = arr[0];
                        that.changeTableName(arr[1]);
                    } else {
                        that.dialog_codeName.nameEdit = true;
                        that.dialog_codeName.tableName = '';
                        that.dialog_codeName.fieldsName = '';
                        that.dialog_codeName.showFields = [];
                        setTimeout(() => {
                            that.$refs['codeNameForm'].clearValidate();
                        }, 100);
                    }
                } else {
                    that.dialog_codeName.nameEdit = true;
                    that.dialog_codeName.tableName = '';
                    that.dialog_codeName.fieldsName = '';
                    that.dialog_codeName.showFields = [];
                    setTimeout(() => {
                        that.$refs['codeNameForm'].clearValidate();
                    }, 100);
                }
            });
            that.dialog_codeName.show = true;
        },
        changeTableName (fieldsName) {
            let that = this;
            for (let i = 0; i < that.dialog_codeName.data.length; i++) {
                if (that.dialog_codeName.data[i].value === that.dialog_codeName.tableName) {
                    that.getDataFields(that.dialog_codeName.data[i]);
                    that.dialog_codeName.fieldsName = fieldsName || '';
                    break;
                }
            }
        },
        selectCodeName () {
            let that = this;
            that.$refs['codeNameForm'].validate((valid) => {
                if (valid) {
                    that.dialog_code.form.data.codeName = that.dialog_codeName.tableName + '.' + that.dialog_codeName.fieldsName;
                    that.dialog_codeName.show = false;
                }
            });
        },
        getDataTableName (foo) {
            let that = this;
            that.axios.get('pass/v1/mdtables/queryAllByBlurTableName')
                .then(function (res) {
                    if (res.code === '0') {
                        let arr = [];
                        for (let item of res.data) {
                            arr.push({
                                value: item.tableName,
                                tableId: item.tableId,
                                fields: []
                            })
                        }
                        that.dialog_codeName.data = arr;
                        if (foo) {
                            foo();
                        }
                    } else {
                        that.$message.error(res.message);
                    }
                }).catch(function () {
                });
        },
        getDataFields (tableObj) {
            let that = this;
            if (tableObj.fields.length === 0) {
                // 获取表中字段名
                that.axios.get('pass/v1/mdfields/getAllByTableId', {
                    params: {
                        tableId: tableObj.tableId
                    }
                })
                    .then(function (res) {
                        if (res.code === '0') {
                            let arr = [];
                            res.data.forEach(item => {
                                arr.push({
                                    value: item.fieldName
                                });
                            });
                            tableObj.fields = arr;
                            that.dialog_codeName.showFields = tableObj.fields
                        } else {
                            that.$message.error(res.message);
                        }
                    }).catch(function () {
                    });
            } else {
                that.dialog_codeName.showFields = tableObj.fields
            }
        },
        // codeNameHandleItemChange (val) {
        //     let that = this;
        //     for (let i = 0; i < that.codeNameHint.length; i++) {
        //         if (that.codeNameHint[i].value === val[0]) {
        //             console.log(that.codeNameHint[i]);
        //             if (that.codeNameHint[i].fields.length === 0) {
        //                 // 获取表中字段名
        //                 that.axios.get('pass/v1/mdfields/getAllByTableId', {
        //                     params: {
        //                         tableId: that.codeNameHint[i].tableId
        //                     }
        //                 })
        //                     .then(function (res) {
        //                         if (res.code === '0') {
        //                             let arr = [];
        //                             console.log(res.data)
        //                             res.data.forEach(item => {
        //                                 arr.push({
        //                                     value: item.fieldName
        //                                 });
        //                             });
        //                             that.codeNameHint[i].fields = arr;
        //                         } else {
        //                             that.$message.error(res.message);
        //                         }
        //                     }).catch(function () {
        //                     });
        //             }
        //             break;
        //         }
        //     }
        // },
        // querySearch (queryString, cb) {
        //     let that = this,
        //         restaurants = [];
        //     let fooStep1 = () => {
        //         let fooStep2 = () => {
        //             // 筛选出符合项
        //             let createFilter = (queryString) => {
        //                 return (restaurant) => {
        //                     return (restaurant.value.indexOf(queryString) === 0);
        //                 };
        //             }
        //             let results = queryString ? restaurants.filter(createFilter(queryString)) : restaurants;
        //             cb(results); // 输出’输入建议‘
        //         };
        //         // 判断输入表名还是输入字段
        //         let reg = new RegExp(/^[^.]+\./);
        //         if (reg.test(queryString)) {
        //             let tableIndex = 0,
        //                 tableName = queryString.match(reg)[0].replace(/\./, '');
        //             let fooStep3 = () => {
        //                 // 将表名与字段名用‘.’连接
        //                 that.codeNameHint[tableIndex].fields.forEach(element => {
        //                     restaurants.push({ value: tableName + '.' + element });
        //                 });
        //                 fooStep2();
        //             }
        //             // 寻找对应的数据
        //             that.codeNameHint.forEach((item, index) => {
        //                 if (tableName === item.value) {
        //                     tableIndex = index;
        //                 }
        //             });
        //             if (that.codeNameHint[tableIndex].fields.length === 0) {
        //                 // 获取表中字段名
        //                 that.axios.get('pass/v1/mdfields/getAllByTableId', {
        //                     params: {
        //                         tableId: that.codeNameHint[tableIndex].tableId
        //                     }
        //                 })
        //                     .then(function (res) {
        //                         if (res.code === '0') {
        //                             let arr = [];
        //                             res.data.forEach(item => {
        //                                 arr.push(item.fieldName);
        //                             });
        //                             that.codeNameHint[tableIndex].fields = arr;
        //                             fooStep3();
        //                         } else {
        //                             that.$message.error(res.message);
        //                         }
        //                     }).catch(function () {
        //                     });
        //             } else {
        //                 fooStep3();
        //             }
        //         } else {
        //             restaurants = that.codeNameHint;
        //             fooStep2();
        //         }
        //     }
        //     if (that.codeNameHint.length === 0) {
        //         // 获取表名称
        //         that.axios.get('pass/v1/mdtables/queryAllByBlurTableName')
        //             .then(function (res) {
        //                 if (res.code === '0') {
        //                     let arr = [];
        //                     res.data.forEach(item => {
        //                         arr.push({
        //                             value: item.tableName,
        //                             tableId: item.tableId,
        //                             fields: []
        //                         })
        //                     });
        //                     that.codeNameHint = arr;
        //                     fooStep1();
        //                 } else {
        //                     that.$message.error(res.message);
        //                 }
        //             }).catch(function () {
        //             });
        //     } else {
        //         fooStep1();
        //     }
        // },
        // handleSelect () {
        //     // // 点击输入提示自动补'.',触发进一步的输入提示
        //     // let that = this,
        //     //     reg = new RegExp(/^[^.]+\./);
        //     // // 判断输入表名还是输入字段
        //     // if (!reg.test(that.dialog_code.form.data.codeName)) {
        //     //     that.dialog_code.form.data.codeName = that.dialog_code.form.data.codeName + '.';
        //     //     setTimeout(() => {
        //     //         that.$refs['dialog_code_form_codeName'].focus();
        //     //     }, 100);
        //     // }
        // },
        exitBCR (tj) {
            let that = this;
            that.BCR.show = tj || false;
        }
    }
}
</script>

<style lang="less">
.BusinessCode {
    height: 100%;
    .BusinessCode-box {
        padding: 15px;
        height: 100%;
        position: relative;
        .box {
            position: relative;
            height: 100%;
            padding-top: 45px;
            .box-top {
                position: absolute;
                top: 0;
                left: 0;
            }
            .box-bottom {
                height: 100%;
                padding-bottom: 40px;
            }
        }
        .box_edit {
            position: absolute;
            width: 100%;
            bottom: 0;
            left: 0;
            border-top: 1px solid #e4e7ed;
            -webkit-box-shadow: 0 -5px 5px -5px #e0e0e0;
            box-shadow: 0 -5px 5px -5px #e0e0e0;
            .edit-title {
                text-align: left;
                .span-text {
                    display: inline-block;
                    height: 26px;
                    line-height: 26px;
                    font-size: 14px;
                    padding: 0 10px;
                    border-left: 3px solid #70baf2;
                    margin-bottom: 5px;
                }
            }
            .edit-box {
                position: relative;
                // padding-right: 160px;
                .edit-but {
                    // position: absolute;
                    // width: 160px;
                    top: 0;
                    right: 0;
                    text-align: right;
                }
            }
        }
        .red {
            color: red;
        }
        .chartreuse {
            color: #1a9f17;
        }
    }
    .height-100 {
        height: 100%;
    }
    .BusinessCode-width-100 {
        width: 100%;
    }
    .dialog_codeName {
        height: 300px;
    }
    .input-but {
        .el-input-group__append {
            background-color: #409eff;
            color: #fff;
        }
    }
    .is-success {
        .input-but {
            .el-input-group__append {
                border-color: #67c23a;
            }
        }
    }
    .is-error {
        .input-but {
            .el-input-group__append {
                border-color: #f56c6c;
            }
        }
    }
    .el-input-number-text-left {
        .el-input__inner {
            text-align: left;
        }
    }
}
</style>
