<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli="iconCli" :tooltit="tooltit"></toolList>
            <div class="search">
                <mySearch
                    :searchList="searchList"
                    @searchInfo="searchInfo"
                ></mySearch>
                <el-button
                    class="btn-check"
                    size="medium"
                    type="primary"
                    @click="dialogCheck(3)"
                    v-if="
                        userInfo.countyName != null || userInfo.cityName != null
                    "
                    >添加
                </el-button>
            </div>
            <div class="tabbox">
                <el-table
                    height="calc(100% - 40px)"
                    class="com-table"
                    ref="multipleTable"
                    :data="tableData"
                    tooltip-effect="dark"
                    size="small"
                    border
                    style="width: 100%"
                    v-loading="loading"
                >
                    <el-table-column prop="regionName" label="地市公司">
                    </el-table-column>
                    <el-table-column prop="regionCode" label="公司编码">
                    </el-table-column>
                    <el-table-column prop="countyName" label="区县名称">
                    </el-table-column>
                    <el-table-column prop="countyCode" label="区县编码">
                    </el-table-column>
                    <el-table-column prop="channelCode" label="渠道编码">
                    </el-table-column>
                    <el-table-column prop="channelName" label="渠道名称">
                    </el-table-column>
                    <el-table-column prop="sts" label="营业状态">
                    </el-table-column>
                    <el-table-column prop="sceneName" label="场景">
                    </el-table-column>
                    <el-table-column prop="metirialType" label="物料类别">
                    </el-table-column>
                    <el-table-column
                        prop="metirialCode"
                        label="物料编码"
                        width="100"
                        show-overflow-tooltip
                    >
                    </el-table-column>
                    <el-table-column
                        prop="metirialName"
                        label="物料名称"
                        width="100"
                        show-overflow-tooltip
                    >
                    </el-table-column>
                    <el-table-column prop="unit" label="物料单位">
                    </el-table-column>
                    <el-table-column
                        prop="size"
                        label="规格尺寸"
                        width="100"
                        show-overflow-tooltip
                    >
                    </el-table-column>
                    <el-table-column prop="length" label="长">
                    </el-table-column>
                    <el-table-column prop="width" label="宽"> </el-table-column>
                    <el-table-column prop="direction" label="横/竖">
                    </el-table-column>
                    <el-table-column prop="coefficient" label="系数">
                    </el-table-column>
                    <el-table-column
                        prop="priority"
                        label="优先级(仅灯箱需要填写)"
                    >
                    </el-table-column>
                    <el-table-column prop="quantity" label="数量">
                    </el-table-column>
                    <el-table-column prop="settlementAmount" label="结算金额">
                    </el-table-column>
                    <!-- <el-table-column prop="price" label="单价">
					</el-table-column> -->

                    <el-table-column
                        label="操作"
                        width="160px"
                        align="center"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="primary"
                                @click="dialogCheck(1, scope.row)"
                                >查看</el-button
                            >
                            <el-button
                                size="mini"
                                type="primary"
                                @click="dialogCheck(2, scope.row)"
                                v-if="
                                    userInfo.countyName != null ||
                                        userInfo.cityName != null
                                "
                                >修改</el-button
                            >
                            <el-button
                                size="mini"
                                type="danger"
                                @click="delLine(scope.row)"
                                v-if="
                                    userInfo.countyName != null ||
                                        userInfo.cityName != null
                                "
                                >删除</el-button
                            >
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    class="pageBox"
                    @current-change="currchange"
                    layout="prev, pager, next"
                    background
                    :total="total"
                >
                </el-pagination>
            </div>
        </div>

        <el-dialog
            :title="titname"
            :visible.sync="dialogStatus"
            width="50%"
            :destroy-on-close="true"
            :modal-append-to-body="false"
            :close-on-click-modal="false"
            :before-close="closedia"
        >
            <div v-loading="loadinged">
                <el-form
                    :model="infolist"
                    ref="infolist"
                    :rules="rules"
                    style="height: 50vh; overflow-y: scroll"
                >
                    <div class="info-line">
                        <el-form-item prop="regionName">
                            <span>地市公司</span>
                            <el-select
                                :popper-append-to-body="false"
                                v-model="infolist.regionCode"
                                placeholder="地市公司"
                                @change="verifcheck"
                                :disabled="disableStatus"
                            >
                                <el-option
                                    v-for="item in regionOpt"
                                    :key="item.compId"
                                    :label="item.compName"
                                    :value="item.compId"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <span>公司编码</span>
                            <el-input
                                v-model="infolist.regionCode"
                                placeholder="公司编码"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item prop="countyName">
                            <span>区县名称</span>
                            <el-select
                                :popper-append-to-body="false"
                                v-model="infolist.countyCode"
                                placeholder="区县名称"
                                @change="verifcheck(2)"
                                :disabled="disableStatus"
                            >
                                <el-option
                                    v-for="item in countyOpt"
                                    :key="item.compId"
                                    :label="item.compName"
                                    :value="item.compId"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <span>区县编码</span>
                            <el-input
                                v-model="infolist.countyCode"
                                placeholder="区县编码"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item prop="channelCode">
                            <span>渠道编码</span>
                            <el-input
                                v-model="infolist.channelCode"
                                placeholder="渠道编码"
                                :disabled="disableStatus"
                            >
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="channelName">
                            <span>渠道名称</span>
                            <el-input
                                v-model="infolist.channelName"
                                placeholder="营业厅名称、校园名称、小区名称"
                                :disabled="disableStatus"
                            >
                            </el-input>
                        </el-form-item>

                        <el-form-item prop="sts">
                            <span>营业状态</span>
                            <el-select
                                :popper-append-to-body="false"
                                v-model="infolist.sts"
                                placeholder="营业状态"
                                :disabled="disableStatus"
                            >
                                <el-option
                                    v-for="item in stsOpt"
                                    :key="item.dataName"
                                    :label="item.dataName"
                                    :value="item.dataName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="sceneName">
                            <span>场景</span>
                            <el-select
                                @change="accountcho"
                                :popper-append-to-body="false"
                                v-model="infolist.sceneName"
                                placeholder="场景"
                                :disabled="disableStatus"
                            >
                                <el-option
                                    v-for="item in sceneOpt"
                                    :key="item.dataCode"
                                    :label="item.dataName"
                                    :value="item.dataName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="metirialType">
                            <span>物料类别</span>
                            <el-select
                                :disabled="disableStatus"
                                :popper-append-to-body="false"
                                v-model="infolist.metirialType"
                                placeholder="物料类别"
                            >
                                <el-option
                                    v-for="(item, index) in metirialTypeopt"
                                    :key="index"
                                    :label="item.dataName"
                                    :value="item.dataName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <span>物料编码</span>
                            <el-input
                                v-model="infolist.metirialCode"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item prop="metirialName">
                            <span>物料名称</span>
                            <el-select
                                :disabled="disableStatus"
                                :popper-append-to-body="false"
                                v-model="infolist.metirialName"
                                placeholder="物料名称"
                                @change="materialNameChange"
                            >
                                <el-option
                                    v-for="(item, index) in materialNameopt"
                                    :key="index"
                                    :label="item.metirialName"
                                    :value="item.metirialName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <span>物料单位</span>
                            <el-input
                                v-model="infolist.unit"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>规格尺寸</span>
                            <el-input
                                v-model="infolist.size"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item
                            prop="length"
                            v-if="
                                infolist.unit == '平方米' ||
                                    infolist.unit == '延长米'
                            "
                        >
                            <span>长</span>
                            <el-input
                                type="number"
                                v-model="infolist.length"
                                placeholder="长"
                                :disabled="disableStatus"
                            >
                            </el-input>
                        </el-form-item>
                        <el-form-item
                            prop="width"
                            v-if="infolist.unit == '平方米'"
                        >
                            <span>宽</span>
                            <el-input
                                type="number"
                                v-model="infolist.width"
                                placeholder="宽"
                                :disabled="disableStatus"
                            >
                            </el-input>
                        </el-form-item>
                        <el-form-item prop="direction">
                            <span>横竖</span>
                            <el-select
                                :disabled="disableStatus"
                                :popper-append-to-body="false"
                                v-model="infolist.direction"
                                placeholder="横竖"
                            >
                                <el-option
                                    v-for="(item, index) in directionopt"
                                    :key="index"
                                    :label="item.directionName"
                                    :value="item.directionName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <span>系数</span>
                            <el-input
                                :value="coefficient"
                                placeholder="系数"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item
                            v-if="infolist.metirialType == '卡布灯箱'"
                        >
                            <span>卡布灯箱优先级</span>
                            <el-input
                                v-model="infolist.priority"
                                placeholder="卡布灯箱优先级"
                                @keyup.native="numberVertify"
                            ></el-input>
                        </el-form-item>
                        <el-form-item prop="quantity">
                            <span>数量</span>
                            <el-input
                                v-model="infolist.quantity"
                                placeholder="数量"
                                :disabled="quantityDisabled"
                            ></el-input>
                        </el-form-item>
                        <el-form-item>
                            <span>单价</span>
                            <el-input
                                v-model="infolist.price"
                                disabled
                            ></el-input>
                        </el-form-item>
                        <el-form-item prop="settlementAmount">
                            <span>结算金额</span>
                            <el-input
                                v-model="infolist.settlementAmount"
                                placeholder="结算金额"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </div>
                </el-form>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button
                        type="primary"
                        @click="dialogCli(2)"
                        v-if="titname !== '查看'"
                        >确 定</el-button
                    >
                    <el-button @click="dialogCli(1)" v-if="titname === '查看'"
                        >确 定</el-button
                    >
                    <el-button @click="dialogCli(1)">取 消</el-button>
                </div>
            </div>
        </el-dialog>

        <myMessage
            :messTit="messTit"
            @closeMessage="closeMessage"
            :centerDialogVisible="centerDialogVisible"
            v-if="centerDialogVisible"
        ></myMessage>
    </fullscreen>
</template>
<script>
import mySearch from "../../../components/search.vue";
import myMessage from "../../../components/myMessage.vue";
import toolList from "../../../components/toolList";

export default {
    components: {
        mySearch,
        myMessage,
        toolList
    },
    data() {
        //地市名称
        const regionName = (rule, value, callback) => {
            if (!this.infolist.regionName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        //区县名称
        const countyName = (rule, value, callback) => {
            if (!this.infolist.countyName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        //渠道名称
        const channelName = (rule, value, callback) => {
            if (!this.infolist.channelName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        //渠道编码
        const channelCode = (rule, value, callback) => {
            if (!this.infolist.channelCode) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        //营业状态
        const sts = (rule, value, callback) => {
            if (!this.infolist.sts) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        //场景
        const sceneName = (rule, value, callback) => {
            if (!this.infolist.sceneName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };

        const priority = (rule, value, callback) => {
            if (!this.infolist.priority) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };

        const length = (rule, value, callback) => {
            if (
                this.infolist.unit == "平方米" ||
                this.infolist.unit == "延长米"
            ) {
                if (!this.infolist.length) {
                    callback(new Error("不能为空"));
                } else {
                    callback();
                }
            }
        };
        const width = (rule, value, callback) => {
            if (this.infolist.unit == "平方米") {
                if (!this.infolist.width) {
                    callback(new Error("不能为空"));
                } else {
                    callback();
                }
            }
        };
        const direction = (rule, value, callback) => {
            if (!this.infolist.direction) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const quantity = (rule, value, callback) => {
            if (!this.infolist.quantity) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const settlementAmount = (rule, value, callback) => {
            if (!this.infolist.settlementAmount) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };

        // const advTypeDesc = (rule, value, callback) => {
        //   if (!this.infolist.advTypeDesc) {
        //     callback(new Error("不能为空"));
        //   } else {
        //     callback();
        //   }
        // };

        return {
            rules: {
                regionName: [
                    {
                        required: true,
                        trigger: "change",
                        validator: regionName
                    }
                ],
                countyName: [
                    {
                        required: true,
                        trigger: "change",
                        validator: countyName
                    }
                ],
                channelName: [
                    {
                        required: true,
                        trigger: "change",
                        validator: channelName
                    }
                ],
                channelCode: [
                    {
                        required: true,
                        trigger: "change",
                        validator: channelCode
                    }
                ],
                sts: [
                    {
                        required: true,
                        trigger: "change",
                        validator: sts
                    }
                ],
                sceneName: [
                    {
                        required: true,
                        trigger: "change",
                        validator: sceneName
                    }
                ],
                priority: [
                    {
                        required: true,
                        trigger: "change",
                        validator: priority
                    }
                ],

                // advTypeDesc: [
                //   {
                //     required: true,
                //     trigger: "change",
                //     validator: advTypeDesc,
                //   },
                // ],
                length: [
                    {
                        required: true,
                        trigger: "change",
                        validator: length
                    }
                ],
                width: [
                    {
                        required: true,
                        trigger: "change",
                        validator: width
                    }
                ],
                direction: [
                    {
                        required: true,
                        trigger: "change",
                        validator: direction
                    }
                ],
                quantity: [
                    {
                        required: true,
                        trigger: "change",
                        validator: quantity
                    }
                ],
                settlementAmount: [
                    {
                        required: true,
                        trigger: "change",
                        validator: settlementAmount
                    }
                ]
            },
            searchList: [
                {
                    type: "input",
                    tit: "地市名称",
                    value: "",
                    width: "24%"
                },
                {
                    type: "input",
                    tit: "区县名称",
                    value: "",
                    width: "24%"
                },
                {
                    type: "input",
                    tit: "渠道名称",
                    value: "",
                    width: "24%"
                },
                {
                    type: "input",
                    tit: "场景",
                    value: "",
                    width: "24%"
                }
            ],
            tooltit: "物料基础信息维护",
            fullscreen: false,
            total: 0,
            pageSize: 1,
            tableData: [],
            dialogStatus: false,
            disableStatus: false,
            titname: "",
            infolist: { quantity: 1 },
            userInfo: {},
            params: {},
            centerDialogVisible: false,
            messTit: "",
            delid: "",
            loading: false,
            loadinged: false,
            regionOpt: [],
            proviceopt: [
                {
                    id: "0",
                    name: "省公司"
                },
                {
                    id: "1",
                    name: "地市公司"
                }
            ],
            areaOpt: [
                {
                    dataName: "门面区",
                    dataCode: "A"
                },
                {
                    dataName: "主广告区",
                    dataCode: "B"
                },
                {
                    dataName: "业务办理区",
                    dataCode: "C"
                },
                {
                    dataName: "终端销售区",
                    dataCode: "D"
                },
                {
                    dataName: "和家庭体验区",
                    dataCode: "E"
                },
                {
                    dataName: "公告区",
                    dataCode: "F"
                },
                {
                    dataName: "其他区域（地贴、桌前挡板）",
                    dataCode: "G"
                },
                {
                    dataName: "各类专区（携转、全球通、关爱台席等）",
                    dataCode: "H"
                }
            ],
            stsOpt: [
                {
                    dataName: "有效",
                    dataCode: "1"
                },
                {
                    dataName: "关闭",
                    dataCode: "2"
                },
                {
                    dataName: "暂停营业",
                    dataCode: "3"
                }
            ],
            ststOpt: [
                {
                    dataName: "有效",
                    dataCode: "1"
                },
                {
                    dataName: "无效",
                    dataCode: "2"
                }
            ],
            sceneOpt: [
                {
                    dataName: "营业厅-VI改造",
                    dataCode: "1"
                },
                {
                    dataName: "营业厅-常规物料",
                    dataCode: "2"
                },
                {
                    dataName: "小区",
                    dataCode: "3"
                },
                {
                    dataName: "校园",
                    dataCode: "4"
                },
                {
                    dataName: "政企",
                    dataCode: "5"
                }
            ],
            directionopt: [
                {
                    directionId: "1",
                    directionName: "横"
                },
                {
                    directionId: "2",
                    directionName: "竖"
                }
            ],
            account: "",
            metirialOpt: [],
            countyOpt: [],
            num: 0,
            metirialTypeopt: [],
            materialNameopt: [],
            metirialInfoSingle: [],
            quantityDisabled: true
        };
    },
    computed: {
        coefficient: function() {
            if (
                this.infolist.width == undefined &&
                this.infolist.length == undefined
            ) {
                this.infolist.coefficient = "1";
                this.settlementAmount();
                return this.infolist.coefficient;
            } else if (this.infolist.width == undefined) {
                this.infolist.coefficient = this.infolist.length;
                this.settlementAmount();
                return this.infolist.coefficient;
            } else {
                this.infolist.coefficient =
                    this.infolist.length * this.infolist.width;
                this.settlementAmount();
                return this.infolist.coefficient;
            }
        }
    },
    methods: {
        // 结算金额
        settlementAmount: function() {
            this.infolist.settlementAmount =
                this.infolist.price *
                this.infolist.coefficient *
                this.infolist.quantity;

            this.infolist.settlementAmount = parseFloat(
                this.infolist.settlementAmount
            ).toFixed(2);
            if (isNaN(this.infolist.settlementAmount)) {
                this.infolist.settlementAmount = "";
            }

            // return this.infolist.settlementAmount
        },
        accountcho(v) {
            //   this.account = v;
            //   let x = v;
            //   if (v == "营业厅-VI改造" || v == "营业厅-常规物料") {
            //     x = "3";
            //   } else if (v == "校园") {
            //     x = "2";
            //   } else if (v == "小区") {
            //     x = "1";
            //   }
            this.$http({
                url: "/market/cadvSecbuyMetirial/queryPage",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    page: '{"pageNo":"' + 1 + '","pageSize":"1000"}'
                },
                data: { sceneName: v }
            }).then(res => {
                this.metirialOpt = res.data.data;
            });
        },
        // metiriacheck(v) {
        //   for (let i = 0; i < this.metirialOpt.length; i++) {
        //     if (this.metirialOpt[i].metirialCode == v) {
        //       this.infolist.quality = this.metirialOpt[i].quality;
        //       this.infolist.size = this.metirialOpt[i].size;
        //       this.infolist.unit = this.metirialOpt[i].unit;
        //       this.infolist.price = this.metirialOpt[i].price;
        //       this.infolist.metirialName = this.metirialOpt[i].metirialName;
        //       this.infolist.advance =
        //         this.infolist.price * this.infolist.conversion;
        //     }
        //   }
        // },
        materialNameChange(v) {
            this.metirialInfoSingle = this.materialNameopt.filter(item => {
                return item.metirialName == v;
            });
            this.infolist.metirialCode = this.metirialInfoSingle[0].metirialCode;
            this.infolist.size = this.metirialInfoSingle[0].size;
            this.infolist.unit = this.metirialInfoSingle[0].unit;

            if (this.metirialInfoSingle[0].coefficient == "1") {
                this.quantityDisabled = true;
                this.$set(this.infolist, "quantity", 1);
            } else {
                this.quantityDisabled = false;
                this.$set(this.infolist, "quantity", "");
            }
            this.infolist.price = this.metirialInfoSingle[0].price;
        },
        // advancecheck() {
        //   this.num = this.infolist.price * this.infolist.conversion;
        //   this.infolist.advance = this.num;
        // },
        closedia() {
            this.infolist = {};
            this.dialogStatus = false;
        },
        //搜索数据
        searchInfo(v) {
            this.params = {};
            v[0] ? (this.params.regionName = v[0]) : "";
            v[1] ? (this.params.countyName = v[1]) : "";
            v[2] ? (this.params.channelName = v[2]) : "";
            v[3] ? (this.params.sceneName = v[3]) : "";
            this.getList(this.params, this.pageSize);
        },
        //获取列表
        getList(v, n) {
            this.pageSize = n;
            let _this = this;
            this.loading = true;
            this.tableData = [];
            this.$http({
                url: "/market/cadvBusiMetirial/queryPage",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    page: '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: v
            }).then(res => {
                this.tableData = res.data.data;
                this.total = res.data.totalRecord;
                this.loading = false;
                if (
                    this.userInfo.countyName == null &&
                    this.userInfo.cityName == null
                ) {
                    this.tableData = res.data.data;
                } else if (
                    this.userInfo.cityName != null &&
                    this.userInfo.countyName == null
                ) {
                    this.tableData = res.data.data.filter(item => {
                        return item.regionName == this.userInfo.cityName;
                    });
                } else if (
                    this.userInfo.countyName != null &&
                    this.userInfo.cityName != null
                ) {
                    this.tableData = res.data.data.filter(item => {
                        return item.countyName == this.userInfo.countyName;
                    });
                }
            });
            this.loading = false;
        },
        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        //申请
        dialogCheck(v, n) {
            this.dialogStatus = true;
            this.infolist = Object.assign({}, n);
            if (v === 1) {
                this.titname = "查看";
                this.disableStatus = true;
                return;
            } else if (v === 2) {
                this.titname = "修改";
                this.disableStatus = false;
            } else if (v === 3) {
                this.titname = "添加";
                this.disableStatus = false;
                // this.infolist.unit = "延长米";
            }
            // this.infolist.opNo = this.userInfo.loginNo;
            // this.infolist.opName = this.userInfo.loginName;

            this.$http({
                url: "/sysmgr/regionComp/queryList",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                data: {
                    parentCompId: this.infolist.regionCode
                }
            }).then(res => {
                this.countyOpt = res.data;
            });
        },
        //添加
        dialogCli(v) {
            if (v === 1) {
                this.infolist = {};
                this.dialogStatus = false;
                return;
            } else {
                this.infolist.opTime = this.$formatDate(
                    new Date(),
                    "YYYY-MM-DD"
                );

                if (this.titname === "添加") {
                    this.submitInfo("/market/cadvBusiMetirial/add");
                } else if (this.titname === "修改") {
                    this.submitInfo("/market/cadvBusiMetirial/update", v);
                }
            }
        },
        submitInfo(u) {
            if (!this.infolist.length == "") {
                this.infolist.length = parseFloat(this.infolist.length).toFixed(
                    2
                );
            }
            if (!this.infolist.width == "") {
                this.infolist.width = parseFloat(this.infolist.width).toFixed(
                    2
                );
            }

            let _this = this;
            this.$refs.infolist.validate(valid => {
                if (valid) {
                    this.loadinged = true;
                    this.$http({
                        url: u,
                        method: "post",
                        headers: {
                            "Content-Type": "application/json"
                        },
                        data: this.infolist
                    }).then(res => {
                        this.loadinged = false;
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: "error"
                            });
                        } else {
                            _this.$message({
                                message: "成功",
                                type: "success"
                            });
                            _this.infolist = {};
                            _this.dialogStatus = false;
                            _this.getList({}, _this.pageSize);
                        }
                    });
                }
            });
        },
        closeMessage(v) {
            this.centerDialogVisible = false;
            let _this = this;
            if (v === 1) {
                _this
                    .$http({
                        url: "/market/cadvBusiMetirial/del",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json"
                        },
                        data: {
                            id: this.delid
                        }
                    })
                    .then(res => {
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: "error"
                            });
                        } else {
                            _this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            _this.getList(this.params, this.pageSize);
                        }
                    });
            }
        },
        //删除
        delLine(v) {
            this.centerDialogVisible = true;
            this.messTit = "即将删除此条数据, 是否删除?";
            this.delid = v.id;
        },
        //文件返回值
        uploadBack(v) {
            console.log(v);
        },
        //功能栏
        iconCli(v) {
            if (v === 1) {
                this.getList(this.params, this.pageSize);
            }
            if (v === 2) {
                this.fullscreen = !this.fullscreen;
            }
        },
        // 下拉change
        verifcheck(v) {
            if (v == 2) {
                for (let i = 0; i < this.countyOpt.length; i++) {
                    if (this.countyOpt[i].compId === this.infolist.countyCode) {
                        this.infolist.countyName = this.countyOpt[i].compName;
                    }
                }
            } else {
                for (let i = 0; i < this.regionOpt.length; i++) {
                    if (this.regionOpt[i].compId === this.infolist.regionCode) {
                        this.infolist.regionName = this.regionOpt[i].compName;
                        this.$http({
                            url: "/sysmgr/regionComp/queryList",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json"
                            },
                            data: {
                                parentCompId: this.regionOpt[i].compId
                            }
                        }).then(res => {
                            if (this.userInfo.cityName != null && this.userInfo.countyName == null) {
                                this.countyOpt = res.data;
                            } else if (this.userInfo.cityName != null && this.userInfo.countyName != null) {
                                // this.countyOpt = res.data;
                                this.countyOpt = res.data.filter(item => {
                                    return ( item.compName == this.userInfo.countyName );
                                });
                                // this.countyOpt = res.data;
                            }
                            // this.countyOpt = res.data;
                        });
                    }
                }
            }
        },
        numberVertify() {
            this.infolist.priority = this.infolist.priority.replace(
                /[^\.\d]/g,
                ""
            );
            this.infolist.priority = this.infolist.priority.replace(".", "");
        },
        getUser() {
            this.userInfo = JSON.parse(window.sessionStorage.userInfo);

            this.$http({
                url: "/sysmgr/regionComp/queryList",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                data: {
                    parentCompId: "0"
                }
            }).then(res => {
                // this.regionOpt = res.data;

                if (
                    (this.userInfo.countyName == null &&
                        this.userInfo.cityName != null) ||
                    (this.userInfo.countyName != null &&
                        this.userInfo.cityName != null)
                ) {
                    //只显示地市下拉
                    this.regionOpt = res.data.filter(item => {
                        return item.compName == this.userInfo.cityName;
                    });
                }

                // if (
                //   this.userInfo.countyName == null &&
                //   this.userInfo.cityName == null
                // ) {
                //   this.regionOpt = res.data;
                // } else if (this.userInfo.countyName == null && this.userInfo.cityName != null) {
                //   this.regionOpt = res.data.filter((item) => {
                //     return item.compName == this.userInfo.cityName;
                //   });
                // }
            });
        },
        getMetirialType() {
            this.$http({
                url: "/sysmgr/cfgDataDicts/queryMap",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                data: {
                    dictCodePks: "metirialType"
                }
            }).then(res => {
                this.metirialTypeopt = res.data.body.metirialType;
            });
        },
        getMetirialInfo() {
            this.$http({
                url: "/market/cadvSecbuyMetirial/queryList",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                data: {
                    dictCodePks: "metirialType"
                }
            }).then(res => {
                this.materialNameopt = res.data;
            });
        }
    },
    mounted() {
        this.getList({}, 1);
        this.getUser();
        this.getMetirialType();
        this.getMetirialInfo();
    },
    created() {}
};
</script>
<style scoped lang="scss">
.onetab {
    margin-bottom: 20px;
    padding: 0 20px;
}

.titbox {
    div {
        float: right;

        i {
            font-size: 22px;
            margin-left: 20px;
            cursor: pointer;
        }
    }
}

.tabbox {
    margin-top: 14px;
}

.pageBox {
    text-align: right;
    margin-top: 10px;
}

.info-line {
    width: 100%;
    display: block;
    padding-left: 20px;

    div {
        width: 50%;
        display: inline-block;
    }

    span {
        width: 100px;
        display: inline-block;
        text-align: left;

        i {
            color: red;
            display: inline-block;
            padding-right: 5px;
        }
    }

    .el-select,
    .el-input {
        width: calc(100% - 120px);
    }
}

.online {
    width: 100%;

    .el-select {
        width: calc(100% - 120px);
    }

    span {
        vertical-align: top;
    }

    .el-textarea {
        width: calc(100% - 120px);
    }
}
.search-box .box-l .box-info {
    margin-right: 20px !important;
}
</style>
