<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="exportTempletelist" v-if="userInfo.duty <= 9" >下载导入模板
                </el-button>
                <el-button
                    class="btn-check"
                    size="medium"
                    type="primary"
                    @click="dialogCheck(3)" v-if="userInfo.loginNoStr == 'jiangshuai'"
                    >添加
                </el-button>
                
                <myUpload style="display:inline-block;" :fileInfo="fileInfot" v-if="userInfo.loginNoStr == 'jiangshuai'"
                          :fileList="fileInfot.fileList" @uploadBack='uploadBack'></myUpload>
            </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="sceneName" label="使用场景">
                    </el-table-column>
                    <el-table-column prop="proviceFlagName" label="下单模式">
                    </el-table-column>
                    <el-table-column
                        prop="metirialCode"
                        label="物料编码"
                        show-overflow-tooltip
                    >
                    </el-table-column>
                    <el-table-column prop="metirialName" label="物料名称">
                    </el-table-column>

                    <el-table-column prop="unit" label="物料单位">
                    </el-table-column>
                    <el-table-column prop="price" label="不含税单价(元)">
                    </el-table-column>
                    <!-- <el-table-column prop="proviceFlagName" label="申请权限">
					</el-table-column> -->

                    <el-table-column label="操作" width="160px" align="center">
                        <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.loginNoStr == 'jiangshuai'"
                                >修改</el-button
                            >
                            
                             <!-- v-if="userInfo.loginNo=='jiangshuai'" -->
                            <el-button
                                size="mini"
                                type="danger"
                                @click="delLine(scope.row)" v-if="userInfo.loginNoStr == 'jiangshuai'"
                                >删除</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="sceneName">
                            <!-- :disabled="disableStatus" -->
                            <span>使用场景</span>
                            <el-select
                                
                                :popper-append-to-body="false"
                                multiple
                                v-model="infolist.sceneName"
                                placeholder="使用场景"
                                @change="usePlance"
                            >
                                <el-option
                                    v-for="item in sceneopt"
                                    :key="item.dataName"
                                    :label="item.dataName"
                                    :value="item.dataName"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                         <!-- :disabled="disableStatus" -->
                        <el-form-item prop="proviceFlagName">
                            <span>下单模式</span>
                            <el-select
                               
                                :popper-append-to-body="false"
                                v-model="infolist.proviceFlagName"
                                placeholder="下单模式"
                            >
                                <el-option
                                    v-for="item in proviceopt"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.name"
                                >
                                </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 prop="isAsic">-->
<!--                            <span>基础数据</span>-->
<!--                            <el-select-->
<!--                                :disabled="disableStatus"-->
<!--                                :popper-append-to-body="false"-->
<!--                                v-model="infolist.isAsic"-->
<!--                                placeholder="基础数据"-->
<!--                            >-->
<!--                                <el-option-->
<!--                                    v-for="item in isAsicopt"-->
<!--                                    :key="item.id"-->
<!--                                    :label="item.name"-->
<!--                                    :value="item.name"-->
<!--                                >-->
<!--                                </el-option>-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->

                        <!-- <el-form-item prop="metirialType">
							<span>细分类型</span>
							<el-input v-model="infolist.metirialType" placeholder="细分类型" :disabled="disableStatus">
							</el-input>
						</el-form-item> -->
                        <!-- :disabled="metirialCodeDisableStatus" -->
                        <el-form-item prop="metirialCode">
                            <span>物料编码</span>
                            <el-input
                                v-model="infolist.metirialCode"
                                placeholder="物料编码"
                                
                            >
                            </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="物料名称">
								<el-option v-for="item in nameopt" :key="item.dataCode" :label="item.dataName"
									:value="item.dataName">
								</el-option>
							</el-select> -->
                            <!-- :disabled="disableStatus" -->
                            <el-input
                                v-model="infolist.metirialName"
                                placeholder="物料名称"
                                
                            >
                            </el-input>
                        </el-form-item>
<!--                        <el-form-item prop="supplierCode">-->
<!--                            <span>供应商</span>-->
<!--                            <el-select-->
<!--                                :disabled="disableStatus"-->
<!--                                :popper-append-to-body="false"-->
<!--                                v-model="infolist.supplierCode"-->
<!--                                placeholder="供应商"-->
<!--                                @change="verifall"-->
<!--                            >-->
<!--                                <el-option-->
<!--                                    v-for="item in suppOpt"-->
<!--                                    :key="item.code"-->
<!--                                    :label="item.name"-->
<!--                                    :value="item.code"-->
<!--                                >-->
<!--                                </el-option>-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->
<!--                        <el-form-item prop="size">-->
<!--                            <span>规格尺寸</span>-->
<!--                            <el-input-->
<!--                                v-model="infolist.size"-->
<!--                                placeholder="规格尺寸"-->
<!--                                :disabled="disableStatus"-->
<!--                            ></el-input>-->
<!--                        </el-form-item>-->
<!--                        <el-form-item prop="coefficient">-->
<!--                            <span>勾选后系数</span>-->
<!--                            <el-select-->
<!--                                :disabled="disableStatus"-->
<!--                                :popper-append-to-body="false"-->
<!--                                v-model="infolist.coefficient"-->
<!--                                placeholder="勾选后系数"-->
<!--                            >-->
<!--                                <el-option-->
<!--                                    v-for="item in coefficientopt"-->
<!--                                    :key="item.id"-->
<!--                                    :label="item.name"-->
<!--                                    :value="item.id"-->
<!--                                >-->
<!--                                </el-option>-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->
<!-- :disabled="disableStatus" -->
                        <el-form-item prop="unit">
                            <span>物料单位</span>
                            <!-- <el-input v-model="infolist.unit" placeholder="单位" :disabled="disableStatus"></el-input> -->
                            <el-select
                                
                                :popper-append-to-body="false"
                                v-model="infolist.unit"
                                placeholder="物料单位"
                            >
                                <el-option
                                    v-for="item in unitopt"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.name"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <!-- :disabled="disableStatus" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')" -->
                        <el-form-item prop="price">
                            <span>不含税单价(元)</span>
                            <el-input
                                 
                                oninput="value = value.replace(/^(-)(\d+).(\d\d).$/,’$1$2.$3’)"
                                type="number"
                                v-model="infolist.price"
                                placeholder="不含税单价(元)"
                                
                            ></el-input>
                        </el-form-item>
                        <!-- <el-form-item>
							<span>税率</span>
							<el-input v-model="infolist.tax" placeholder="税率" :disabled="disableStatus"></el-input>
						</el-form-item> -->
                        <!-- <el-form-item>
							<span>安装</span>
							<el-input v-model="infolist.install" placeholder="是否需要安装" :disabled="disableStatus"></el-input>
						</el-form-item> -->
                    </div>
                    <!-- <el-form-item class="info-line online" prop="quality">
						<span>物料材质</span>
						<el-input v-model="infolist.quality" placeholder="物料材质" :disabled="disableStatus"
							type="textarea" :rows="4"></el-input>
					</el-form-item> -->
                </el-form>

                <div slot="footer" class="dialog-footer myfooter">
                    <el-button
                        type="primary"
                        @click="dialogCli(2)"
                        v-if="titname === '修改'"
                        >确 定</el-button
                    >
                    <el-button
                        type="primary"
                        @click="xintianjia()"
                        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";
import myUpload from "../../../components/upload.vue";

export default {
    components: {
        mySearch,
        myMessage,
        toolList,
        myUpload
    },
    data() {
        // const sceneName = (rule, value, callback) => {
        //     if (!this.infolist.sceneName) {
                
        //             callback(new Error("使用场景不能为空"));
                
                
        //     } else {
        //         callback();
        //     }
        // };
         let sceneName = (rule, value, callback) => {
            if (!this.isFirstLoad) {
                // console.log(value);
                if(value == ''|| value == undefined){
                    callback(new Error("使用场景不能为空"));
                }else{
                    callback();
                }
                    
                
                
            } else {
                this.isFirstLoad = false;
                
            }
        };
        const metirialName = (rule, value, callback) => {
            if (!this.infolist.metirialName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const metirialType = (rule, value, callback) => {
            if (!this.infolist.metirialType) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const isAsic = (rule, value, callback) => {
            if (!this.infolist.isAsic) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const metirialCode = (rule, value, callback) => {
            if (!this.infolist.metirialCode) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const proviceFlag = (rule, value, callback) => {
            if (!this.infolist.proviceFlag) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        const proviceFlagName = (rule, value, callback) => {
            if (!this.infolist.proviceFlagName) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };

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

        const price = (rule, value, callback) => {
            if (!this.infolist.price) {
                callback(new Error("单价不能为空"));
            } else if (parseFloat(this.infolist.price) > 999999.99) {
                callback(new Error("数量过大"));
            } else if (parseFloat(this.infolist.price) <= 0){
                callback(new Error("请输入正数"));
            }else {
                callback();
            }
        };
        const quality = (rule, value, callback) => {
            if (!this.infolist.quality) {
                callback(new Error("不能为空"));
            } else {
                callback();
            }
        };
        return {
            isFirstLoad : true,
            rules: {
             
                metirialName: [
                    {
                        required: true,
                        trigger: "blur",
                        message: "物料名称不能为空"
                    }
                ],
                 sceneName: [
                    {
                        required: true,
                        trigger: "change",
                        type: 'array',
                        validator: sceneName
                        // message: "使用场景不能为空"
                    }
                ],
                //  sceneName: [
                //     {
                //         required: true,
                //         trigger: "change",
                //         validator: function (rule, value, callback) {
                //         if (value.length === 0) {
                //             callback(new Error('请选择高风险问题1'))
                //         } else {
                //             callback()
                //         }
                //         },
                //         // validator: sceneName
                //         // message: "使用场景不能为空"
                //     }
                // ],
                
               

                metirialCode: [
                    {
                        required: true,
                        trigger: "blur",
                        message: "物料编码不能为空"
                    }
                ],
                proviceFlagName: [
                    {
                        required: true,
                        trigger: "change",
                        message: "下单模式不能为空"
                    }
                ],
                // proviceFlagName: [
                //     {
                //         required: true,
                //         trigger: "change",
                //         validator: proviceFlagName
                //     }
                // ],

                // supplierCode: [
                //     {
                //         required: true,
                //         trigger: "change",
                //         validator: supplierCode
                //     }
                // ],
                // size: [
                //     {
                //         required: true,
                //         trigger: "blur",
                //         validator: size
                //     }
                // ],
                // coefficient: [
                //     {
                //         required: true,
                //         trigger: "blur",
                //         validator: coefficient
                //     }
                // ],

                unit: [
                    {
                        required: true,
                        trigger: "change",
                        message: "物料单位不能为空"
                    }
                ],
                // price: [
                //     {
                //         required: true,
                //         trigger: "blur",
                //         message: "物料单价不能为空"
                //     }
                // ],
                 price: [
                    {
                        required: true,
                        trigger: "change",
                        validator: price
                    }
                ],
           
            },
            searchList: [
                {
                    type: "sel",
                    tit: "使用场景",
                    value: "",
                    width: "31%",
                    options: [
                        {
                            dataCode: "营业厅-VI改造-自有渠道",
                            dataName: "营业厅-VI改造-自有渠道"
                        },
                        {
                            dataCode: "营业厅-常规物料-自有渠道",
                            dataName: "营业厅-常规物料-自有渠道"
                        },
                        {
                            dataCode: "营业厅-VI改造-合作渠道",
                            dataName: "营业厅-VI改造-合作渠道"
                        },
                        {
                            dataCode: "营业厅-常规物料-合作渠道",
                            dataName: "营业厅-常规物料-合作渠道"
                        },
                        {
                            dataCode: "小区",
                            dataName: "小区"
                        },
                        {
                            dataCode: "校园",
                            dataName: "校园"
                        },
                        {
                            dataCode: "政企",
                            dataName: "政企"
                        }
                    ]
                },
                {
                    type: "sel",
                    tit: "下单模式",
                    value: "",
                    width: "31%",
                    options: [
                        {
                            dataCode: "省公司",
                            dataName: "省公司"
                        },
                        {
                            dataCode: "地市",
                            dataName: "地市"
                        },

                        {
                            dataCode: "省+地市",
                            dataName: "省+地市"
                        },
                        {
                            dataCode: "省+市",
                            dataName: "省+市"
                        }
                    ]
                },
                { type: "input", tit: "物料名称", value: "", width: "31%" },
                { type: "input", tit: "物料编码", value: "", width: "31%" }
            ],
            fileInfot: {
                type: 'btn',
                typename: '导入',
                btntype: 'primary',
                limit: 1,
                url: '/market/cadvSecbuyMetirial/import',
                fileList: [],
                woNo: "",
            },
            tooltit: "宣传物料及印刷品类型建档",
            fullscreen: false,
            total: 0,
            pageSize: 1,
            tableData: [],
            dialogStatus: false,
            disableStatus: false,//是否禁用弹窗
            titname: "",
            infolist: {
                'infolist.sceneName':[]
            },
            userInfo: {},
            params: {},
            centerDialogVisible: false,
            messTit: "",
            delid: "",
            loading: false,
            loadinged: false,
            //下单模式
            proviceopt: [
                {
                    id: "0",
                    name: "省公司"
                },
                {
                    id: "1",
                    name: "地市"
                },
                {
                    id: "2",
                    name: "省+地市"
                },{
                    id: "3",
                    name: "省+市"
                }
            ],
            //使用场景
            sceneopt: [
                {
                    dataCode: "1",
                    dataName: "小区"
                },
                {
                    dataCode: "2",
                    dataName: "校园"
                },
                {
                    dataCode: "3",
                    dataName: "营业厅-VI改造-自有渠道"
                },
                {
                    dataCode: "4",
                    dataName: "营业厅-常规物料-自有渠道"
                },
                {
                    dataCode: "5",
                    dataName:'营业厅-VI改造-合作渠道'
                },
                {
                    dataCode: "6",
                  dataName: '营业厅-常规物料-合作渠道'
                },
                {
                    dataCode: "7",
                    dataName: "政企"
                }
            ],
            // 基础数据
            isAsicopt: [
                {
                    id: "0",
                    name: "是"
                },
                {
                    id: "1",
                    name: "否"
                }
            ],
            coefficientopt: [
                {
                    id: "0",
                    name: "按需录入"
                },
                {
                    id: "1",
                    name: "1"
                }
            ],
            //单位
            unitopt: [
                {
                    id: "0",
                    name: "平方米"
                },
                {
                    id: "1",
                    name: "个"
                },
                {
                    id: "2",
                    name: "延长米"
                },
                {
                    id: "3",
                    name: "套"
                },
                {
                    id: "4",
                    name: "组"
                },{
                    id: "5",
                    name: "延米"
                },{
                    id:'6',
                    name:'张'
                }
            ],
            //物料名称
            nameopt: [],
            //供应商
            suppOpt: [],
            usePlanceArr: [],
            metirialTypeopt: [],
            metirialCodeDisableStatus: false,//物料编码是否禁用
            // scene:[]
        };
    },
    methods: {
        //处理所需数据
        verifall(v) {
            // for (let j = 0; j < this.suppOpt.length; j++) {
            //     if (this.suppOpt[j].code == v) {
            //         this.infolist.supplierName = this.suppOpt[j].name;
            //     }
            // }
        },
        exportTempletelist() {
            let data = this.params;
            // console.log(data);
            // return
            this.$http({
                url: "/market/cadvSecbuyMetirial/excelExportTemplete",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                responseType: "blob",
                data: data,
            }).then((response) => {
                if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    let blob = new Blob([response.data], {
                        type: 'application/vnd.ms-excel'
                    })
                    window.navigator.msSaveOrOpenBlob(blob,
                        new Date().getTime() + '.xlsx')
                } else {
                    /* 火狐谷歌的文件下载方式 */
                    var blob = new Blob([response.data])
                    var downloadElement = document.createElement('a')
                    var href = window.URL.createObjectURL(blob)
                    downloadElement.href = href
                    downloadElement.download = new Date().getTime() + '.xlsx'
                    document.body.appendChild(downloadElement)
                    downloadElement.click()
                    document.body.removeChild(downloadElement)
                    window.URL.revokeObjectURL(href)
                }
            });
        },

        usePlance(v) {
            this.usePlanceArr = v;

            // 	let value = ''
            // 	if(v == '1'){
            // 		value = 'house';
            // 	}else if(v == '2'){
            // 		value = 'school';
            // 	}else if(v == '3'){
            // 		value = 'serviceHall';
            // 	}
            // 	this.$http({
            // 	    url: "/market/cfgDataDict/queryList",
            // 	    method: "post",
            // 	    headers: {
            // 	        "Content-Type": "application/json",
            // 	    },
            // 	    data: {
            // 	        dictCode: value
            // 	    },
            // 	}).then((res) => {
            // 	    this.nameopt = res.data;
            // 	});
        },
        closedia() {
            this.infolist = {};
            this.dialogStatus = false;
        },
        //搜索数据
        searchInfo(v) {
            this.params = {};
            v[0] ? (this.params.sceneName = v[0]) : "";
            v[1] ? (this.params.proviceFlagName = v[1]) : "";
            v[2] ? (this.params.metirialName = v[2]) : "";
            v[3] ?(this.params.metirialCode = v[3]) :"";
            this.getList(this.params, this.pageSize);
        },
        uploadBack(v) {
            let that = this;
            // console.log(v);
            // console.log(v.data.desc);
            // if(v.data.desc != "导入成功"){
            //     let timer = setTimeout(() => {
            //        this.$message.error("物料编码已存在，请更改物料编码"); 
            //     },800)
                
            // }
            if(v.data.result==0){
                that.getList({}, 1);
                that.getUser();
                that.getMetirialType();
                that.getMetirialInfo();
            }
        },
        getMetirialInfo() {
            this.$http({
                url: "/market/cadvSecbuyMetirial/queryList",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                data: {
                    dictCodePks: "metirialType"
                }
            }).then(res => {
                this.materialNameopt = res.data;
            });
        },
        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;
            });
        },
        //获取列表
        getList(v, n) {
            this.pageSize = n;
            let _this = this;
            this.loading = true;
            this.tableData = [];
            this.$http({
                url: "/market/cadvSecbuyMetirial/queryPage",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    page: '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: v
            }).then(res => {
                res.data.data.forEach(item => {
                    for (let i = 0; i < this.sceneopt.length; i++) {
                        if (this.sceneopt[i].dataCode == item.sceneName) {
                            item.sceneName = this.sceneopt[i].dataName;
                        }
                    }
                });
                this.tableData = res.data.data;
                this.total = res.data.totalRecord;
                this.loading = false;
            });
        },

        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        //申请
        dialogCheck(v, n) {
            this.dialogStatus = true;
            this.infolist.sceneName = [],
            this.isFirstLoad = true;
            this.infolist = Object.assign({}, n);
            if (v === 1) {
                this.titname = "查看";
                this.disableStatus = true;
                this.metirialCodeDisableStatus = true;
                this.infolist.sceneName = this.infolist.sceneName.split("/");
                return;
            } else if (v === 2) {
                this.titname = "修改";
                this.disableStatus = false;
                this.metirialCodeDisableStatus = true;
                this.infolist.sceneName = this.infolist.sceneName.split("/");
                // this.usePlance(n.scene);
            } else if (v === 3) {
                this.titname = "添加";
                this.disableStatus = false;
            }
            this.infolist.opNo = this.userInfo.loginNo;
            this.infolist.opName = this.userInfo.loginName;
        },
        
        // 添加1
         xintianjia(e) {
            this.$refs.infolist.validate((valid) => {
         
          if (valid) {
            this.infolist.price = parseFloat(this.infolist.price).toFixed(2);
            let scene = "";
                    this.infolist.sceneName.forEach((item, index) => {
                        scene += item;
                        if (index != this.infolist.sceneName.length - 1) {
                            scene += "/";
                        }
            });
            this.infolist.sceneName = scene;
            this.$http({
                url: "/market/cadvSecbuyMetirial/add",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    
                },
               data: this.infolist,
            }).then((res) => {
        
                // if(res.data.desc == "添加成功"){
                //     this.infolist = {};
                //      this.$message.success("成功");
                //      this.dialogStatus = false;
                //      this.getList({}, this.pageSize);
                // }
                if (res.data.result === 1) {
                            this.infolist.sceneName = this.infolist.sceneName.split(
                                "/"
                            );
                            this.$message({
                                message: res.data.desc,
                                type: "error"
                            });
                        } else if (res.data.result === -1) {
                            this.infolist.sceneName = this.infolist.sceneName.split(
                                "/"
                            );
                            this.$message({
                                message: res.data.desc,
                                type: "fail"
                            });
                        } else {
                            this.$message({
                                message: "成功",
                                type: "success"
                            });
                            this.infolist = {};
                            this.dialogStatus = false;
                            this.getList({}, this.pageSize);
                        }
            });
        
         
        }
        })
        },
        //添加
        dialogCli(v) {
            if (v === 1) {
                this.infolist = {};
                this.dialogStatus = false;
                return;
            } else {
                this.infolist.opTime = this.$formatDate(
                    new Date(),
                    "YYYY-MM-DD"
                );
                this.infolist.sts = "0";
                this.infolist.stsDesc = "在用";
                // this.infolist.proviceFlagName = this.infolist.proviceFlag
                // this.infolist.proviceFlagName = this.infolist.proviceFlag == "0"?'省公司':'地市公司';
                if (this.infolist.proviceFlag == 0) {
                    this.infolist.proviceFlagName = "省公司";
                } else if (this.infolist.proviceFlag == 1) {
                    this.infolist.proviceFlagName = "地市公司";
                } else if (this.infolist.proviceFlag == 2) {
                    this.infolist.proviceFlagName = "省+地市";
                }

                if (this.titname === "添加") {
                    this.submitInfo("/market/cadvSecbuyMetirial/add");
                } else if (this.titname === "修改") {
                    this.submitInfo("/market/cadvSecbuyMetirial/update", v);
                }
            }
        },
        submitInfo(u) {
            this.infolist.price = parseFloat(this.infolist.price).toFixed(2);
            let _this = this;
            this.$refs.infolist.validate(valid => {
                if (valid) {
                    this.loadinged = true;
                    let scene = "";
                    this.infolist.sceneName.forEach((item, index) => {
                        scene += item;
                        if (index != this.infolist.sceneName.length - 1) {
                            scene += "/";
                        }
                    });
                    this.infolist.sceneName = scene;
                    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.infolist.sceneName = this.infolist.sceneName.split(
                                "/"
                            );
                            _this.$message({
                                message: res.data.desc,
                                type: "error"
                            });
                        } else if (res.data.result === -1) {
                            this.infolist.sceneName = this.infolist.sceneName.split(
                                "/"
                            );
                            _this.$message({
                                message: res.data.desc,
                                type: "fail"
                            });
                        } 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/cadvSecbuyMetirial/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 if (res.data.result === -1) {
                            _this.$message({
                                message: res.data.desc,
                                type: "fail"
                            });
                        } else {
                            _this.$message({
                                message: "删除成功",
                                type: "success"
                            });
                            _this.getList(this.params, this.pageSize);
                        }
                    });
            }
        },
        //删除
        delLine(v) {
            this.centerDialogVisible = true;
            this.messTit = "即将删除此条数据, 是否删除?";
            this.delid = v.id;
        },
        //文件返回值

        //功能栏
        iconCli(v) {
            if (v === 1) {
                this.getList(this.params, this.pageSize);
            }
            if (v === 2) {
                this.fullscreen = !this.fullscreen;
            }
        },
        getUser() {
            this.userInfo = JSON.parse(window.sessionStorage.userInfo);
            this.$http({
                url: "/market/cadvSupplier/queryValidSupplierList",
                method: "post",
                headers: {
                    "Content-Type": "application/json"
                },
                // data: { buyTypeCode: "2" }
                data: {}
            }).then(res => {
                this.suppOpt = res.data;
            });
        }
    },
    mounted() {
        this.getList({}, 1);
        this.getUser();

        // this.$http({
        //     url: "/sysmgr/cfgDataDicts/queryMap",
        //     method: "post",
        //     headers: {
        //         "Content-Type": "application/json"
        //     },
        //     data: {
        //         dictCodePks: "metirialType"
        //     }
        // }).then(res => {
        //     this.metirialTypeopt = res.data.body.metirialType;
        //     // this.stypeList = res.data.body.materType;
        // });
    },
    created() {
        // if (this.multiples) this.infolist.sceneName = []
        this.$set(this.infolist, 'this.infolist.sceneName', [])
    }
};
</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: 15px;
}

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

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

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

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

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

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

.online {
    width: 100%;

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

    span {
        vertical-align: top;
    }

    .el-textarea {
        width: calc(100% - 100px);
    }
}
</style>
