<template>
    <div v-loading="fullscreenLoading">
        <div class="groupedit">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <div class="required-box">
                    <el-form-item label-width="120px" label="销售报价号:">
                        <el-input :readonly="true" el-input v-model="ruleForm.quotenum"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="本团成单人:" :prop="nongroupty?'person':''">
                        <el-select @change="personchange" filterable v-model="ruleForm.person" placeholder="请选择本团成单人     ">
                            <el-option v-for="(item, index) in personarr" :key="index" :label="item.cnName"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label-width="120px" label="客户级别:" :prop="nongroupty?'grades':''">
                        <el-select @change="rankchange" v-model="ruleForm.grades" placeholder="请选择客户级别">
                            <el-option v-for="(item, index) in gradearr" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label-width="120px" label="团组类型:" :prop="nongroupty?'OP':''">
                        <el-select @change="optypechange" class="op-type" v-model="ruleForm.OP" placeholder="请选择团组类型">
                            <el-option v-for="(item, index) in OPtype" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label-width="120px" label="客户名称:" :prop="nongroupty?'customername':''">
                        <el-autocomplete
                        style="width: 100%;"
                        class="inline-input"
                        v-model="ruleForm.customername"
                        :fetch-suggestions="querySearch"
                        placeholder="请输入内容"
                        @select="handleSelect"
                        ></el-autocomplete>
                        <!-- <el-input el-input v-model="ruleForm.customername"></el-input> -->
                    </el-form-item>
                    <el-form-item label-width="120px" label="客户单位:" :prop="nongroupty?'customerunits':''">
                        <el-autocomplete
                        style="width: 100%;"
                        class="inline-input"
                        v-model="ruleForm.customerunits"
                        :fetch-suggestions="querySearchdw"
                        placeholder="请输入内容"
                        @select="splicingname"
                        ></el-autocomplete>
                        <!-- <el-input el-input v-model="ruleForm.customerunits"></el-input> -->
                    </el-form-item>
                    <el-form-item label-width="120px" label="城市:" :prop="nongroupty?'cityId':''">
                        <el-select filterable @change="optypechange" class="op-type" v-model="ruleForm.cityId" placeholder="请选择城市">
                            <el-option v-for="(item, index) in cityData" :key="index" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label-width="120px" label="出访国家:" prop="countriesvisited">
                        <el-input @blur="splicingname" el-input v-model="ruleForm.countriesvisited" placeholder="按照“国家1、国家2、国家3”录入"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="出访时间:" :prop="nongroupty?'visitingtime':''">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.visitingtime"
                            style="width: 100%;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label-width="120px" label="出访天数:" :prop="nongroupty?'numdays':''">
                        <el-input @blur="splicingname" el-input v-model="ruleForm.numdays"></el-input>
                    </el-form-item>
                    <el-form-item style="position: relative;" label-width="120px" label="出访人数:" prop="numperson">
                        <el-input el-input v-model="ruleForm.numperson"></el-input>
                        <!-- 客户名单 -->
                        <el-popover
                        placement="bottom"
                        width="662"
                        trigger="hover">
                            <el-table max-height="600" border :data="rollcallarr">
                                <el-table-column width="100" property="date" label="姓名">
                                    <template slot-scope="scope">
                                        {{ scope.row.lastName}}{{scope.row.firstName}}
                                    </template>
                                </el-table-column>
                                <el-table-column width="200" property="birthDay" label="拼音">
                                    <template slot-scope="scope">
                                        {{ pinyingxing(scope.row.lastName) }}/{{  pinyingxing(scope.row.firstName) }}
                                    </template>
                                </el-table-column>
                                <el-table-column width="50" property="sex" label="性别">
                                    <template slot-scope="scope">
                                        {{ scope.row.sex==0?'男':'女'}}
                                    </template>
                                </el-table-column>
                                <el-table-column width="110" property="birthDay" label="生日">
                                    <template slot-scope="scope">
                                        {{ fgarr(scope.row.birthDay) }}
                                    </template>
                                </el-table-column>
                                <el-table-column width="200"  label="身份证号码">
                                    <template slot-scope="scope">
                                        {{ scope.row.idCardNo==""?'-':scope.row.idCardNo }}
                                    </template>
                                </el-table-column>
                            </el-table>
                            <span v-if="editid!=undefined" slot="reference" style="cursor: pointer;position: absolute;right: -65px;color: red;">客户名单</span>
                        </el-popover>
                    </el-form-item>
                    <el-form-item label-width="120px" label="团组名称:" prop="groupname">
                        <el-input el-input v-model="ruleForm.groupname"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="合同时间:">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.contracttime"
                            style="width: 100%;"></el-date-picker>
                    </el-form-item>
                    <!-- <el-form-item label-width="120px" label="合同时间:" :prop="bidbr?'contracttime':''">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.contracttime"
                            style="width: 100%;"></el-date-picker>
                    </el-form-item> -->
                    
                </div>
                <div style="display: flex;">
                    <el-form-item style="width: 35%;" label-width="120px" label="是否用于投标:">
                        <el-radio-group v-model="ruleForm.radioval" @change="agreeChange">
                            <el-radio label="0">否</el-radio>
                            <el-radio label="1">是</el-radio>
                        </el-radio-group>
                        <!-- <el-radio v-model="ruleForm.radioval" label='0'>否</el-radio>
                        <el-radio v-model="ruleForm.radioval" label='1'>是</el-radio> -->
                    </el-form-item>
                    <div  class="advance-box">
                        <!-- <el-form-item label-width="120px" label="于出访时间前" :prop="bidbr?'occasion':''">
                            <el-input style="width: 100px;" el-input v-model="ruleForm.occasion"></el-input>
                        </el-form-item>
                        <el-form-item label-width="98px" label="日支付款项:" :prop="bidbr?'payments':''">
                            <el-input el-input v-model="ruleForm.payments"></el-input>
                        </el-form-item> -->
                        <el-form-item label-width="120px" label="于出访时间前">
                            <el-input style="width: 100px;" el-input v-model="ruleForm.occasion"></el-input>
                        </el-form-item>
                        <el-form-item label-width="98px" label="日支付款项:">
                            <el-input el-input v-model="ruleForm.payments"></el-input>
                        </el-form-item>
                        <span style="margin-bottom: 22px;display: inline-block;color: #606266;font-size: 14px;">（预付款,请输入RMB）</span>
                    </div>
                </div>
                <div style="display: flex;align-items: center;">
                    <el-form-item style="width:16%" label-width="120px" label="OP提成等级" :prop="bidbr&&nongroupty?'opRoyaltyLv':''">
                        <el-select @change="commissionlevel" v-model="ruleForm.opRoyaltyLv" placeholder="OP提成等级" clearable filterable
                            style="width: 100%;">
                            <el-option v-for="item in opRoyaltyLvList" :key="item.id" :label="item.name + '元'"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item style="width:50%" label-width="98px" label="等级说明:" :prop="bidbr&&nongroupty?'opRoyaltyRemark':''">
                        <el-select style="width:100%" class="op-type" v-model="ruleForm.opRoyaltyRemark" placeholder="请选择团组类型">
                            <el-option v-for="(item, index) in commissionleve" :key="index" :label="item"
                                :value="item"></el-option>
                        </el-select>
                        <!-- <el-input type="textarea" v-model="ruleForm.opRoyaltyRemark" style="width: 500px;"></el-input> -->
                    </el-form-item>
                    <span style="margin-bottom: 22px;display: inline-block;color: #606266;font-size: 14px;"
                        @click="dialogVisible = true">（点击查看等级说明）</span>
                </div>
                <el-form>
                    <el-form-item label-width="120px" label="出访目的:">
                        <el-input type="textarea" v-model="ruleForm.purposevisit"></el-input>
                    </el-form-item>
                    <el-form-item class="items" label-width="120px" label="基础需求:">
                        <el-input type="textarea" v-model="ruleForm.otherneeds"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="特殊需求:">
                        <el-input type="textarea" v-model="ruleForm.specialneeds"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="公务需求:">
                        <el-input type="textarea" v-model="ruleForm.Officialneeds"></el-input>
                    </el-form-item>
                </el-form>
                <el-form class="approval-box">
                    <el-form-item label-width="160px" label="出国任务审批部门名称:">
                        <el-input el-input v-model="ruleForm.approvalname"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="批件文号:">
                        <el-input el-input v-model="ruleForm.approvalnumber1"></el-input>
                    </el-form-item>
                    <el-form-item label-width="130px" label="政治审查部门名称:">
                        <el-input el-input v-model="ruleForm.censorshipdepartment"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="批件文号:">
                        <el-input el-input v-model="ruleForm.approvalnumber2"></el-input>
                    </el-form-item>
                </el-form>
                <el-form>
                    <el-form-item label-width="120px" label="备注:">
                        <el-input type="textarea" v-model="ruleForm.remark"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="微信号:">
                        <el-input type="textarea" v-model="ruleForm.Wechat"></el-input>
                    </el-form-item>
                    <el-form-item label-width="120px" label="手机号:">
                        <el-input type="textarea" v-model="ruleForm.phonenumber"></el-input>
                    </el-form-item>
                </el-form>
                <el-form-item style="text-align: right;">
                    <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
                    <el-button @click="resetForm('ruleForm')">重 置</el-button>
                    <el-button @click="clickback()">返 回</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-dialog title="等级说明" :visible.sync="dialogVisible" width="30%"
            :close-on-click-modal="false">
            <span>
                1)普通团组：￥300/团；<br><br>
 
                2)VIP团（地市州书记 市长 成都副市级别 副书记级别 成都正厅级干部）：￥500/团；<br><br>

                3)VVIP团（四川省副部级 副省级 省长 ）：￥1000/团；<br><br>

                4)非全程接待或非标准团组，接待5天内（含5天）的团组：￥100/团；<br><br>

                5)非全程接待或非标准团组，但负责全程机票，接待5天以上的团组：￥200/团；<br><br>

                6)非全程接待或非标准团组且不负责全程机票，接待5天以上的团组：￥100/团<br><br>

                7)非全程接待或非标准团组且不负责全程机票，只负责地接的，人数为10人以上的的团组:300/团；<br><br>

                8)人数为5人以内（含5人）的标准团组：￥200/团；<br><br>

                9)人数为5人以内（含5人）并且非全程接待5天内（含5天）的团组：￥100/团；<br><br>

                10)人数为5人以内（含5人），非全程接待5天以上并且负责全程机票的团组：￥200/团；<br><br>

                11)人数为5人以内（含5人）并且非全程接待5天以上，但不负责全程机票的团组：￥100.00/团；<br><br>
            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { el } from '@fullcalendar/core/internal-common';
import { all } from 'q';
import { pinyin } from 'pinyin-pro';
export default {
    // beforeRouteLeave(to, from, next) {
    //     console.log(to);
    //     console.log(from);
    //     if(to.name=='OPgroup'){
    //         to.meta.keepAlive = true;
    //     }
    //     next()
    // },
    data() {
        return {
            editid: '',
            token: '',
            userid: '',
            ruleForm: {
                quotenum: '',
                groupname: '',
                customername: '',
                customerunits: '',
                countriesvisited: '',
                visitingtime: '',
                contracttime: '',
                numdays: '',
                cityId:'',
                numperson: '',
                occasion: '',
                payments: '',
                purposevisit: '',
                specialneeds: '',
                otherneeds: '',
                Officialneeds:'',
                approvalname: '',
                approvalnumber1: '',
                approvalnumber2: '',
                censorshipdepartment: '',
                remark: '',
                phonenumber: '',
                Wechat: '',
                OP: '',
                grades: '',
                person: '',
                opRoyaltyLv: '',
                opRoyaltyRemark: '',
                radioval:'0',
            },
            commissionleve:[
               '无'
            ],
            personarr: [],
            cityData:[],
            gradearr: [],
            OPtype: [],
            rules: {
                groupname: [
                    { required: true, message: '请输入团组名称', trigger: 'blur' },
                ],
                customername: [
                    { required: true, message: '请输入客户名称', trigger: 'change' },
                ],
                customerunits: [
                    { required: true, message: '请输入客户单位', trigger: 'change' },
                ],
                countriesvisited: [
                    { required: true, message: '请输入出访国家', trigger: 'blur' },
                ],
                person: [
                    { required: true, message: '请选择成团人', trigger: 'change' }
                ],
                cityId: [
                    { required: true, message: '请选择城市', trigger: 'change' }
                ],
                grades: [
                    { required: true, message: '请选择级别', trigger: 'change' }
                ],
                OP: [
                    { required: true, message: '请选择类型', trigger: 'change' }
                ],
                visitingtime: [
                    { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                ],
                contracttime: [
                    { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
                ],
                numdays: [
                    { required: true, message: '请输入出访天数', trigger: 'blur' },
                    { pattern: "^\\d+$", message: "请输入正整数", trigger: "blur" }
                ],
                numperson: [
                    { required: true, message: '请输入出访人数', trigger: 'blur' },
                    { pattern: "^\\d+$", message: "请输入正整数", trigger: "blur" }
                ],
                occasion: [
                    { required: true, message: '请输入出天数', trigger: 'blur' },
                    { pattern: "^\\d+$", message: "请输入正整数", trigger: "blur" }
                ],
                payments: [
                    { required: true, message: '请输入出款额', trigger: 'blur' },
                    { pattern: "^\\d+(\\.\\d+)?$", message: "请输入正浮点数或整数", trigger: "blur" }
                ],
                opRoyaltyLv: [
                    { required: true, message: '请选择op提成等级', trigger: 'change' }
                ],
                opRoyaltyRemark: [
                    { required: true, message: '请填写等级描述', trigger: 'change' }
                ],
            },
            fullscreenLoading: false,
            dialogVisible: false,
            opRoyaltyLvList: [],
            restaurants: [],
            restaurantss:[],
            customerunitslist:[],
            bidbr:true,
            rollcallarr:[],
            nongroupty:true,
            depname:'',
            //xiao nao fa yu bu jian quan de xu qiu
            companyName:'',
        };
    },
    methods: {
        //拼音
        pinyingxing(val){
            return pinyin(val, { toneType: 'none' }).toUpperCase();
        },
        //fenge
        fgarr(val){
            val=val+""
            return val.split(' ')[0]
        },
        querySearch(queryString, cb) {
            var restaurants = this.restaurants;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        querySearchdw(queryString, cb) {
            var restaurants = this.customerunitslist;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString) {
            return (restaurant) => {
                return restaurant.value.replace("  ", "").toLowerCase().match(queryString.toLowerCase());
            };
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.addGroupInfo()
                } else {
                    return false;
                }
            });
        },
        //拼接团名
        splicingname(){
            if(this.ruleForm.radioval==1){
                this.ruleForm.groupname='投标-'+this.ruleForm.customerunits+'赴'+this.ruleForm.countriesvisited+this.ruleForm.numdays+'日';
            }else{
                this.ruleForm.groupname=this.ruleForm.customerunits+'赴'+this.ruleForm.countriesvisited+this.ruleForm.numdays+'日'
            }
        },
        //清空
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        //返回
        clickback() {
            // this.$router.back(-1)
            this.$router.go(-1);
        },
        //匹配
        filteredItems() {
            if (this.companyName=='') return this.cityData;

            const searchChars = this.companyName.toLowerCase();

            return this.cityData.filter(item => {
                // 将对象的所有字符串属性拼接起来
                const searchContent = item.name.toLowerCase();
                // 检查搜索字符串中的每个字符是否出现在对象内容中
                for (let i = 0; i < searchChars.length; i++) {
                    if (searchContent.includes(searchChars[i])) {
                        return true;
                    }
                }
                return false;
            }).map(item => {
                // 添加匹配字符信息
                const matchedChars = [];
                const searchContent = Object.values(item)
                    .filter(value => typeof value === 'string')
                    .join(' ')
                    .toLowerCase();

                for (let i = 0; i < searchChars.length; i++) {
                    if (searchContent.includes(searchChars[i])) {
                        matchedChars.push(searchChars[i]);
                    }
                }

                return {
                    ...item,
                    matchedChars: [...new Set(matchedChars)] // 去重
                };
            });
        },
        //获取下拉列表
        getdown() {
            var url = "/api/Groups/GroupEditBasicSource"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.restaurantss=res.data.data.clientData;
                    that.restaurants= that.restaurantss.map((terminal) => {
                        return {
                            value: terminal.contact +'   '+ terminal.client +'   '+terminal.telephone+'   '+terminal.wechat,
                        };
                    });
                    that.customerunitslist= that.restaurantss.map((terminal) => {
                        return {
                            value:terminal.client,
                        };
                    });
                    that.personarr = res.data.data.userData;
                    that.gradearr = res.data.data.teamLevData;
                    that.OPtype = res.data.data.teamTypeData;
                    that.cityData = res.data.data.cityData;
                    if (that.ruleForm.cityId=='') {
                        if(that.companyName=='泛美(贵阳) 会展服务有限公司'){
                            that.ruleForm.cityId=3332
                        }else{
                            that.ruleForm.cityId=that.filteredItems()[0].id;
                        }
                    }
                    if(that.editid==undefined) {
                        that.ruleForm.OP=that.OPtype[0].id;
                    }
                }
            })
            var url = "/api/System/QuerySetData"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    dataType: 70,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.opRoyaltyLvList = res.data.data;
                }
            })
        },
        //personchange
        personchange(val){
            if (val==330) {
                this.ruleForm.person=21;
            }
        },
        //新增获取销售号
        getSalesQuoteNo() {
            if (this.editid == undefined) {
                var url = "/api/Groups/GetGroupSalesQuoteNo"
                var that = this
                if (this.editid == undefined) {
                    this.$axios({
                        method: 'post',
                        url: url,
                        headers: {
                            Authorization: 'Bearer ' + this.token
                        },
                    }).then(function (res) {
                        if (res.data.code == 200) {
                            that.ruleForm.quotenum = res.data.data.salesQuoteNo;
                        }
                    })
                }
            }

        },
        //提成等级值改变
        commissionlevel(val){
            var tctext
            for(var tc=0;tc<this.opRoyaltyLvList.length;tc++){
                if(this.opRoyaltyLvList[tc].id==val){
                    tctext=this.opRoyaltyLvList[tc].remark.split('&')
                }
            }
            this.ruleForm.opRoyaltyRemark='';
            this.commissionleve=tctext;
            this.ruleForm.opRoyaltyRemark=tctext[0]
        },
        //处理时间
        disposeTime(val) {
            if(val==null||val==""){
                return ""
            }
            var date = new Date(val);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let time = y + '-' + m + '-' + d;
            return time
        },
        //agreeChange
        optypechange(val){
            if(val==248){
                this.nongroupty=false;
                this.ruleForm.OP=248;
                this.ruleForm.cityId=3505;
                this.ruleForm.customername="暂无";
                this.ruleForm.customerunits="暂无";
                this.ruleForm.grades=770;
                this.ruleForm.numdays="1";
                this.ruleForm.opRoyaltyLv=995;
                this.ruleForm.opRoyaltyRemark="无";
                this.ruleForm.person=21;
                this.ruleForm.visitingtime=new Date();
            }else{
                this.nongroupty=true;
                // this.initializeinfo();
            }

            if (val==1348) {
                this.bidbr=false;
                this.ruleForm.groupname='沟通中-'+this.ruleForm.groupname;
            }else{
                if(this.ruleForm.radioval!=1){
                    this.bidbr=true;
                }
                this.ruleForm.groupname=this.ruleForm.groupname.split("沟通中-").join("");
            }
        },
        //是否用于投标
        agreeChange(val){
            if(val==1){
                this.bidbr=false;
                this.ruleForm.groupname='投标-'+this.ruleForm.groupname;
            }else{
                if(this.ruleForm.OP!=1348){
                    this.bidbr=true;
                }
                this.ruleForm.groupname=this.ruleForm.groupname.split("投标-").join("");
            }
        },
        //编辑获取原数据
        getGroupInfo() {
            var url = "/api/Groups/GetGroupInfo"
            var that = this
            var datagroup
            if (this.editid != undefined) {
                this.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer ' + this.token
                    },
                    data: {
                        portType: 1,
                        id: that.editid
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        datagroup = res.data.data;
                        that.ruleForm.quotenum = datagroup.salesQuoteNo;
                        that.ruleForm.cityId = datagroup.cityId;
                        that.ruleForm.groupname = datagroup.teamName;
                        that.ruleForm.customername = datagroup.clientName;
                        that.ruleForm.customerunits = datagroup.clientUnit;
                        that.ruleForm.countriesvisited = datagroup.visitCountry.replaceAll("|", "、");
                        that.ruleForm.visitingtime = new Date(datagroup.visitDate.split(' ')[0]);
                        that.ruleForm.numdays = datagroup.visitDays + "";
                        that.ruleForm.numperson = datagroup.visitPNumber + "";
                        that.ruleForm.contracttime =datagroup.tontractTime==null?"":new Date(datagroup.tontractTime.split(' ')[0]);
                        that.ruleForm.payments = datagroup.paymentMoney + '';
                        that.ruleForm.occasion =datagroup.payDay + '';
                        that.ruleForm.purposevisit = datagroup.visitPurpose;
                        that.ruleForm.specialneeds = datagroup.specialNeeds;
                        that.ruleForm.otherneeds = datagroup.otherNeeds;
                        that.ruleForm.Officialneeds = datagroup.officialneeds;//公务需求
                        that.ruleForm.approvalname = datagroup.cgrwspbmmc;
                        that.ruleForm.approvalnumber1 = datagroup.cgrwspwh;
                        that.ruleForm.censorshipdepartment = datagroup.zzscbmmc;
                        that.ruleForm.approvalnumber2 = datagroup.zzscspwh;
                        that.ruleForm.remark = datagroup.remark;
                        that.ruleForm.Wechat = datagroup.weChatNo;
                        that.ruleForm.phonenumber = datagroup.tellPhone;
                        that.ruleForm.OP = datagroup.teamDid;
                        that.ruleForm.grades = datagroup.teamLevSId;
                        that.ruleForm.person = datagroup.jietuanOperator;
                        that.ruleForm.opRoyaltyLv = parseInt(datagroup.opRoyaltyLv)==0?'':parseInt(datagroup.opRoyaltyLv);
                        that.ruleForm.opRoyaltyRemark = datagroup.opRoyaltyRemark;
                        that.ruleForm.radioval = datagroup.isBid==0?'0':'1';
                        if(that.ruleForm.radioval==1){
                            that.bidbr=false;
                        }
                        if (that.ruleForm.OP==248) {
                            that.nongroupty=false;
                        }
                    }
                })
            }
        },
        //新增编辑
        addGroupInfo() {
            var url = "/api/Groups/GroupOperation";
            var that = this;
            that.fullscreenLoading = true;
            var status
            if (this.editid != undefined) {
                status = 2
            } else {
                status = 1
            }
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + this.token
                },
                data: {
                    portType: 1,
                    status: status,//添加1//修改2//删除3
                    id: that.editid,
                    userId: that.userid,
                    cityId:that.ruleForm.cityId,
                    salesQuoteNo: that.ruleForm.quotenum,
                    jietuanOperator:parseInt(that.ruleForm.person),//
                    teamLevSId: parseInt(that.ruleForm.grades),//
                    teamDid: parseInt(that.ruleForm.OP),//
                    teamName: that.ruleForm.groupname,
                    clientName: that.ruleForm.customername,
                    clientUnit: that.ruleForm.customerunits,
                    visitCountry: that.ruleForm.countriesvisited.replaceAll("、", "|"),
                    visitDate: that.disposeTime(that.ruleForm.visitingtime),
                    visitDays: parseInt(that.ruleForm.numdays),
                    visitPNumber: parseInt(that.ruleForm.numperson),
                    tontractTime: that.disposeTime(that.ruleForm.contracttime),
                    payDay: that.ruleForm.occasion==""?0:parseInt(that.ruleForm.occasion),
                    paymentMoney: that.ruleForm.payments==""?0:parseInt(that.ruleForm.payments),
                    visitPurpose: that.ruleForm.purposevisit,
                    specialNeeds: that.ruleForm.specialneeds,
                    otherNeeds: that.ruleForm.otherneeds,
                    officialneeds:that.ruleForm.Officialneeds,//公务需求
                    cgrwspbmmc: that.ruleForm.approvalname,
                    cgrwspwh: that.ruleForm.approvalnumber1,
                    zzscbmmc: that.ruleForm.censorshipdepartment,
                    zzscspwh: that.ruleForm.approvalnumber2,
                    tellPhone: that.ruleForm.phonenumber,
                    weChatNo:that.ruleForm.Wechat,
                    remark: that.ruleForm.remark,
                    opRoyaltyLv: that.ruleForm.opRoyaltyLv==""?0:that.ruleForm.opRoyaltyLv,
                    opRoyaltyRemark: that.ruleForm.opRoyaltyRemark,
                    isBid: that.ruleForm.radioval=='0'?0:1,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    if (status==2) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                            offset: 50
                        });
                        that.$confirm(res.data.msg+'是否跳转到客户名单?', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                        type: 'warning'
                        }).then(() => {
                            that.$router.push({path: '/home/PickupList?id=' +that.editid +''});
                        }).catch(() => {
                            that.$router.go(-1);
                        });
                    }else{
                        that.$router.go(-1);
                    }
                    that.fullscreenLoading = false;
                } else {
                    that.$message({
                        message: res.data.msg,
                        type: 'warning',
                        offset: 50
                    });
                    that.fullscreenLoading = false;
                }
            })
        },
        handleSelect(item) {
            this.ruleForm.customername=item.value.split('   ')[0];
            this.ruleForm.customerunits=item.value.split('   ')[1];
            this.ruleForm.phonenumber=item.value.split('   ')[2];
            this.ruleForm.Wechat=item.value.split('   ')[3];
            this.splicingname();
        },
        rankchange(val){
            if (val==771) {
                this.ruleForm.opRoyaltyLv=999
                this.commissionlevel(this.ruleForm.opRoyaltyLv)
            }
            if(val==772){
                this.ruleForm.opRoyaltyLv=1000
                this.commissionlevel( this.ruleForm.opRoyaltyLv)
            }
            if(val==770){
                this.ruleForm.opRoyaltyLv=998
                this.commissionlevel( this.ruleForm.opRoyaltyLv)
            }
        },
        //数据初始化
        initializeinfo(){
            this.ruleForm={
                groupname: '',
                customername: '',
                customerunits: '',
                countriesvisited: '',
                visitingtime: '',
                contracttime: '',
                numdays: '',
                cityId:'',
                numperson: '',
                occasion: '',
                payments: '',
                purposevisit: '',
                specialneeds: '',
                otherneeds: '',
                Officialneeds:'',
                approvalname: '',
                approvalnumber1: '',
                approvalnumber2: '',
                censorshipdepartment: '',
                remark: '',
                phonenumber: '',
                Wechat: '',
                grades: '',
                person: '',
                opRoyaltyLv: '',
                opRoyaltyRemark: '',
                radioval:'0',
            }
        },
        //获取客户名单info
        PostTourClientListByDiId() {
            this.rollcallarr=[];
            if (this.editid==undefined) {
                return
            }
            var that = this
            var url = "/api/Groups/PostTourClientListByDiId"
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer ' + that.token
                },
                data: {
                    portType:1,
                    diid: that.editid,
                    pageId:104,
                    userId:233
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.rollcallarr=res.data.data;
                } else {
                    that.$message.error(res.data.msg);
                }
            })
        },
    },
    beforeRouteEnter(to, from, next) {
        next();
    },
    mounted() {
        this.editid = this.$route.query.id;
        this.token = JSON.parse(localStorage.getItem('userinif')).token;
        this.userid = JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        this.depname = JSON.parse(localStorage.getItem('userinif')).userInfo.depName;
        this.companyName = JSON.parse(localStorage.getItem('userinif')).userInfo.companyName;
        setTimeout(() => {
            this.PostTourClientListByDiId();
        }, 500);
        this.getSalesQuoteNo();
        this.getdown();
        this.getGroupInfo();
    }
}
</script>
<style>
.groupedit {
    background-color: #fff;
    border-radius: 10px;
    padding: 20px;
}

.required-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}

.required-box>div {
    width: 30%;
}

.required-box .el-select {
    width: 100%;
}

.approval-box {
    display: flex;
    justify-content: space-between;
}

.approval-box>div {
    width: 23%;
    
}

.approval-box>div:nth-child(1) {
    width: 30%;
}

.advance-box {
    display: flex;
    align-items: center;
}
.items .el-form-item__label{
    color: red;
}
</style>>
