<template>
    <div class="two-child">
        <Modal title="创建大会员订单" v-model="bShow" class-name="order-model member-model" :mask-closable="false"
            @on-visible-change="visibleChange">
            <Form ref="member" :model="member" :label-width="121">
                <FormItem label="基本信息" class="formTitle">
                </FormItem>
                <div class="flex-endbox">
                    <FormItem label="合同性质" required>
                        <!-- 订单状态为“已完成”，不支持修改。 -->
                        <RadioGroup v-model="member.contract_nature" @on-change="contractChange">
                            <Radio label="1" style="margin-right:30px">新签合同</Radio>
                            <Radio label="2">续签合同</Radio>
                        </RadioGroup>
                    </FormItem>
                    <FormItem label="购买主体" required>
                        <RadioGroup v-model="member.buySubject" @on-change="radiosChange">
                            <Radio label="1" style="margin-right:30px">个人(如有子账号，共享额度)</Radio>
                            <Radio label="2">企业</Radio>
                        </RadioGroup>
                    </FormItem>
                </div>
                <!-- <FormItem label="订单时间" required>
                    <date-sigle ref="sigleRef2" :dateType="'datetime'" :placeholderd="'请选择订单时间'" @startDate="orderDate" :overTime="0"></date-sigle>
                </FormItem> -->
                <FormItem label="公司名称" :required="member.buySubject == '2'">
                    <Input v-model.trim="member.companyName" type="text" :maxlength="40" placeholder="请输入公司名称"></Input>
                </FormItem>
                <div class="flex-endbox">
                    <FormItem label="开通权益手机号" required :class="{ 'big-stas': colr }">
                        <Input class="ipt-inpt" v-model="member.phone" type="text" @on-change="pheHandler"
                            @on-keyup="keyHandler" :maxlength="11" placeholder="请输入手机号" :readonly="pReadon"></Input>
                        <Checkbox v-model="noPhone" @on-change="noPchange">无手机号</Checkbox>
                        <Spin fix class="order-spin" v-if="spinShow">
                            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
                        </Spin>
                        <p v-html="colr" style="color:#e13d13"></p>
                    </FormItem>
                    <FormItem label="产品类型">
                        <Select v-model="member.products" placeholder="请选择产品类型（暂不支持数据导出）" @on-change="proChange"
                            :disabled="proDis">
                            <!-- <Option v-for="item in bigPro" :value="item.v" :key="item.v">{{ item.n }}</Option> -->
                            <Option value="1">大会员</Option>
                            <Option value="2" :disabled="subaccountDis">大会员子账号</Option>
                            <Option value="3" :disabled="member.buySubject != '1' || bigStas == 0">大会员补充包</Option>
                        </Select>
                    </FormItem>
                </div>
                <FormItem label="关联订单" required v-show="member.products == '2' && contactOrderList.length > 0">
                    <div class="contactOrderTable">
                        <Table border ref="selection" :columns="contactOrderColumns" :data="contactOrderList"></Table>
                    </div>
                </FormItem>
                <!-- 选择大会员才展示 -->
                <FormItem label="会员套餐" v-if="creAuth == '1'" required>
                    <RadioGroup v-model="member.level" @on-change="radiosChangelevel">
                        <Radio :label="JSON.stringify(comVal)" :disabled="vipDis">自定义</Radio>
                        <Radio :label="JSON.stringify(item)" v-for="(item, index) in levelDown"
                            :value="JSON.stringify(item)" :key="index" :disabled="vipDis || downDis">{{ item.s_name }}
                        </Radio>
                    </RadioGroup>
                </FormItem>
                <!-- <FormItem label="会员套餐" v-if="creAuth == '1'" required>
                    <Select v-model="member.level" placeholder="请选择会员套餐" @on-change="leChange" @on-select="leSelect">
                        <Option :value="JSON.stringify(comVal)">自定义</Option>
                        <Option v-for="(item,index) in levelDown" :value="JSON.stringify(item)" :key="index" :disabled="downDis">{{ item.s_name }}</Option>
                    </Select>
                </FormItem> -->
                <!-- 仅大会员商机版2.0 支持购买单省版-->
                <!-- <FormItem label="规格" v-if="combo_id.id==6"> 
                  <Radio v-model="member.single" ref="single"  style="marginRight:30px" @click.native.prevent="areaCountClick(1)" >单省版</Radio>
              </FormItem> -->
                <!-- <FormItem label="计费模式" required>
                  <Select v-model="member.billingMode" placeholder="请选择计费模式" @on-change="moneyChange">
                    <Option v-for="item in chargeStatus" :value="item.v" :key="item.v">{{ item.n }}</Option>
                  </Select>
                </FormItem> -->
                <!-- 大会员、子账号 -->
                <div v-if="nums !== '' && creAuth">
                    <!-- nums == '0' 自定义 -->
                    <!-- <FormItem required v-if="creAuth == '1' && nums == '0'">
                        <RadioGroup v-model="member.createType" class="form-radio1" @on-change="serChange">
                            <Radio label="1" :disabled="radioDis1">新建服务</Radio>
                            <Radio label="2" :disabled="radioDis2">补充服务</Radio>
                            <Radio label="3" :disabled="radioDis3">延长服务</Radio>
                        </RadioGroup>
                    </FormItem>
                    <FormItem class="table-order1 table-order2" v-if="creAuth == '1' && nums == '0'">
                        <Table class="sel-table" border ref="selection" :columns="columns3" :data="serData"
                            @on-select="curChange" @on-select-cancel="canChange" @on-selection-change="selChage"
                            @on-select-all="allChange" @on-select-all-cancel="allCancel" :summary-method="handleSummary"
                            show-summary></Table>
                    </FormItem> -->
                    <FormItem required v-if="creAuth == '1' && nums == '0'" label="服务列表">
                        <div class="servebox" v-for="(item, index) in newServedata" :key="index">
                            <div class="one-group" v-show="!item.hide">
                                <Checkbox v-model="item.choose" :disabled="item.disabled"
                                    @on-change="chooseChange($event, 'one', index)"></Checkbox><span
                                    class="serve-one">{{ item.ColumnName }}：</span>
                            </div>
                            <div class="serve-content">
                                <div class="serve-two" v-show="!two.hide" v-for="(two, two_index) in item.lists"
                                    :key="two_index">
                                    <span v-if="two.id == 1">{{ two.name }}<span
                                            v-if="member.buySubject == '2'">+企业管理</span></span>
                                    <div class="servechildrenbox" v-else>
                                        <Checkbox v-model="two.choose" :disabled="two.disabled"
                                            @on-change="chooseChange($event, 'two', index)"></Checkbox>
                                        <span style="margin-right: 10px;">{{ two.name }}</span>
                                        <Select v-model="two.id" :disabled="two.disabled || !two.choose"
                                            placeholder="请选择产品" style="width:120px;margin-right:10px;"
                                            v-if="two.list.length > 1" @on-change="chooseChange($event, 'select')">
                                            <Option v-for="(three, three_index) in two.list" :key="three_index"
                                                :value="three.id" v-show="!three.hide" :disabled="three.disabled">{{ three.s_count_year + three.dw
                                                }}</Option>
                                        </Select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div v-if="buyserveName"><span style="color: #e13d13;">注：服务到期时间：{{ serveEndtime }}，</span><span
                                style="font-weight:bold">该客户已购买：</span>{{ buyserveName }}</div>
                    </FormItem>
                    <FormItem label="购买数量" required v-if="!(creAuth == '3' && this.member.buySubject == '1')">
                        <Input v-model="member.buyCount" type="tel" maxlength="4" @on-keyup="buyHandler"
                            @on-change="payChange" placeholder="请填写购买数量"
                            :disabled="vipDis && this.member.products != 2"></Input>
                        <span v-if="member.products == '1'">(注：主账号+子账号数量之和)</span>
                    </FormItem>
                    <!-- <div v-if="creAuth !== '3'">
                        <FormItem label="付费子账号数量">
                            <Input
                                v-model="member.paySub"
                                type="tel"
                                placeholder="请填写付费子账号数量"
                                maxlength="4"
                                @on-keyup="payHandler"
                                @on-change="payChange"
                                @on-blur="payBlur"
                            ></Input>
                        </FormItem>
                        <FormItem label="免费子账号数量">
                            <Input v-model="member.freeSub" type="tel" maxlength="4" @on-keyup="freeHandler" placeholder="请填写免费子账号数量"></Input>
                        </FormItem>
                    </div> -->
                    <!-- 补充包 -->
                    <div v-if="creAuth !== '2'">
                        <FormItem class="table-order1" v-show="creAuth == '3'">
                            <Table class="prei-table" border ref="selection" :columns="columns1" :data="pacData">
                            </Table>
                        </FormItem>
                        <FormItem class="table-order1" v-show="creAuth == '3'">
                            <Table class="prei-table" border ref="selection" :columns="columns2" :data="datas2"></Table>
                        </FormItem>
                        <!-- <div class="flex-endbox"> -->
                        <FormItem label="有效周期" required v-if="creAuth == '1' && (repair != '2')">
                            <div class="you-xiao" style="display:flex">
                                <Input v-model="member.payCycle" type="tel" :maxlength="max_length"
                                    @on-keyup="cycleHandler" @on-change="peChange" :placeholder="placed"
                                    style="width:376px"></Input>
                                <Select v-model="member.cycleType" placeholder="请选择单位" @on-change="unitChange"
                                    style="width:110px;margin-left:10px">
                                    <Option v-for="item in unitOptions" :value="item.v" :key="item.v">{{ item.n }}
                                    </Option>
                                </Select>
                                <Checkbox style="margin-left: 10px;"
                                    v-if="returnMyReceivable === false && ((member.buySubject == '1' && member.createType == '1') || member.buySubject == '2')"
                                    v-model="member.paybackOpenServer">全额回款当日自动开通</Checkbox>
                            </div>
                            <!-- 个人 延长服务 -->
                            <span style="color: #e13d13;"
                                v-if="member.buySubject == '1' && member.createType == '3'">全额回款后将自动续费开通权益，如若回款时间晚于原服务到期时间，则开始日期为回款日期。</span>
                        </FormItem>
                        <FormItem label="开始日期" v-if="creAuth == '1' && repair == '1' && showOrderStatus">
                            <date-sigle ref="sigleRef1" :dateType="'date'" :placeholderd="'请选择开始日期'"
                                @startDate="startDate" :disabledDateCallback="disabledDateForVIPCallback"
                                :dateDis="!showOrderStatus || this.pReadon" class="no-pass"
                                :beginDis="noPass"></date-sigle>
                            <Checkbox v-model="noPass" @on-change="noTchange"
                                :disabled="!showOrderStatus || this.pReadon">暂不开通</Checkbox>
                            <Checkbox
                                v-if="returnMyReceivable === true && ((member.buySubject == '1' && member.createType == '1') || member.buySubject == '2')"
                                v-model="member.paybackOpenServer" :disabled="!noPass">全额回款当日自动开通</Checkbox>
                        </FormItem>
                        <!-- </div> -->
                    </div>
                    <div class="flex-endbox">
                        <FormItem label="合同金额" required class="d-felx">
                            <Input v-model="member.payMoney" type="text" @on-keyup="keyupSale('1')" :maxlength="9"
                                placeholder="请填写合同金额" :disabled="shiDis"></Input>
                            <span class="money-unit">元</span>
                        </FormItem>
                        <!-- <div v-if="creAuth == '1'">
                        <FormItem label="大会员订单金额" :label-width="194">
                            <span class="sum-jin">{{tipFunc(member.bigMoney)}}</span>
                        </FormItem>
                        <FormItem label="大会员子账号订单金额" :label-width="194">
                            <span class="sum-jin">{{tipFunc(member.subMoney)}}</span>
                        </FormItem>
                        <FormItem label="大会员补充包订单金额" :label-width="194">
                            <span class="sum-jin">{{tipFunc(member.supplyMoney)}}</span>
                        </FormItem>
                    </div> -->
                        <!-- 中标企业预测 -->
                        <FormItem label="标准售价" :label-width="creAuth !== '1' ? 110 : 194" v-if="creAuth !== '1'">
                            <span class="sum-jin">{{ tipFunc(member.orderMoney) }}元</span>
                            <span>（折扣率：<span style="color: #36a3f7">{{ member.payMoney && member.orderMoney ?
            ((member.payMoney / member.orderMoney) * 100).toFixed(2)
            + '%' : '--' }}</span>）</span>
                        </FormItem>
                        <FormItem label="标准售价" :label-width="194" v-else>
                            <span class="sum-jin">{{ tipFunc(member.orderMoney) }}元</span>
                            <span>（折扣率：<span style="color: #36a3f7">{{ member.payMoney && member.orderMoney ?
            ((member.payMoney / member.orderMoney) * 100).toFixed(2)
            + '%' : '--' }}</span>）</span>
                        </FormItem>
                        <!-- <FormItem label="大会员应付金额" :label-width="121" required v-show="creAuth == '1'">
                        <Input
                            v-model="member.bigPayMoney"
                            type="text"
                            @on-keyup="keyupSale('2')"
                            :maxlength="9"
                            placeholder="请输入大会员应付金额"
                            :disabled="bigDis"
                        ></Input>
                    </FormItem>
                    <FormItem label="子账号应付金额" required v-show="creAuth == '1'">
                        <Input
                            v-model="member.subPayMoney"
                            type="text"
                            @on-keyup="keyupSale('3')"
                            :maxlength="9"
                            placeholder="请输入子账号应付金额"
                            :disabled="subDis"
                        ></Input>
                    </FormItem>
                    <FormItem label="补充包应付金额" required v-show="creAuth == '1'">
                        <Input
                            v-model="member.supplyPayMoney"
                            type="text"
                            @on-keyup="keyupSale('4')"
                            :maxlength="9"
                            placeholder="请输入补充包应付金额"
                            :disabled="supplyDis"
                        ></Input>
                    </FormItem> -->
                    </div>
                    <div class="flex-endbox">
                        <FormItem label="佣金金额" class="d-felx" required>
                            <Input v-model="member.commission" type="text" @on-keyup="keyupSale('5')" :maxlength="9"
                                placeholder="请输入佣金金额"></Input>
                            <span class="money-unit">元</span>
                        </FormItem>
                        <FormItem label="手续费" class="d-felx" required>
                            <Input v-model="member.proceduresMoney" type="text" @on-keyup="keyupSale('6')"
                                :maxlength="9" placeholder="请输入手续费"></Input>
                            <span class="money-unit">元</span>
                        </FormItem>
                    </div>
                    <FormItem label="协议信息" class="formTitle">
                    </FormItem>
                    <div class="flex-endbox">
                        <FormItem label="协议状态" required>
                            <RadioGroup v-model="member.agreementStatus" @on-change="agreementStatusChange">
                                <Radio :label="item.v" v-for="(item, index) in agreeStatus" :value="item.v"
                                    :key="index">{{
            item.n }}</Radio>
                            </RadioGroup>
                        </FormItem>
                        <FormItem label="签约主体" required>
                            <v-cascader ref="casRef2" :initVal="'h01'" placeholderType="签约主体" reqType="签约主体"
                                @levelChange="paybackChange" v-if="bShow"></v-cascader>
                        </FormItem>
                    </div>
                    <div class="flex-endbox">
                        <FormItem label="协议签订时间" v-show="member.agreementStatus == '1'">
                            <date-sigle ref="sigleRef" :dateType="'date'" :placeholderd="'请选择协议签订时间'"
                                @startDate="agreeDate" :overTime="0"></date-sigle>
                        </FormItem>
                        <FormItem label="协议编号" v-show="member.agreementStatus == '1' && !showOnlineContractForm">
                            <Input v-model="member.agreementNumber" type="text" placeholder="请输入协议编号"></Input>
                        </FormItem>
                    </div>
                    <!-- v-show="!showOnlineContractForm || showXieYi" -->
                    <div class="showmore">
                        <div class="flex-endbox">
                            <FormItem label="协议归档状态" v-show="member.agreementStatus == '1'">
                                <RadioGroup v-model="member.contract_archive_status">
                                    <Radio label="0">未归档</Radio>
                                    <Radio label="1">已归档</Radio>
                                </RadioGroup>
                            </FormItem>
                            <FormItem label="归档时间"
                                v-show="member.agreementStatus == '1' && member.contract_archive_status == '1'">
                                <date-sigle ref="sigleRef4" :dateType="'date'" :placeholderd="'请选择归档时间'"
                                    @startDate="guiDate" :overTime="0"></date-sigle>
                            </FormItem>
                        </div>
                        <div class="flex-endbox">
                            <FormItem label="归档份数"
                                v-show="member.agreementStatus == '1' && member.contract_archive_status == '1'">
                                <Input v-model="member.contract_archive_num" type="tel" maxlength="4"
                                    @on-keyup="payHandler" placeholder="请输入归档份数"></Input>
                            </FormItem>
                            <FormItem label="归档协议" class="chuan-pay" v-show="member.contract_archive_status == '1'">
                                <b-upload ref="uploadRef" @fileData="contractFile" :placeholdered="'请上传归档协议'"
                                    :accepted="'.doc,.pdf,.docx,.rar,.zip,.jpg,.png,.jpeg'"
                                    :formated="['doc', 'pdf', 'docx', 'rar', 'zip', 'jpg', 'png', 'jpeg']"
                                    :multipled="false" @onRemove="onRemoveUpload"></b-upload>
                            </FormItem>
                        </div>
                    </div>
                    <OnlineContractForm ref="onlineContractFormRef" v-if="showOnlineContractForm"
                        :showMore="showXieYi && showOnlineContractForm" :buySubject="member.buySubject"
                        :orderEntName="member.companyName" :e_contract_type.sync="member.e_contract_type"
                        :e_contract_userA_type.sync="member.e_contract_userA_type"
                        :e_contract_userA_name.sync="member.e_contract_userA_name"
                        :e_contract_userA_contacts_name.sync="member.e_contract_userA_contacts_name"
                        :e_contract_userA_contacts_tel.sync="member.e_contract_userA_contacts_tel"
                        :e_contract_userA_contacts_address.sync="member.e_contract_userA_contacts_address"
                        :e_contract_userB_contacts_name.sync="member.e_contract_userB_contacts_name"
                        :e_contract_remark.sync="member.e_contract_remark" />
                    <div style="display: flex;justify-content: center;" v-show="!showXieYi && showOnlineContractForm">
                        <div @click="showXieYi = !showXieYi" style="color: #36a3f7;cursor: pointer; font-size: 14px;">
                            <span>更多信息</span>
                            <i class="el-icon-arrow-down"></i>
                        </div>
                    </div>
                    <FormItem label="回款计划" class="formTitle"></FormItem>
                    <FormItem label="回款次数" required>
                        <Input v-model.trim="member.paybackNum" type="text" @on-keyup="keyupformat('paybackNum')"
                            style="width: 80px"></Input><span style="margin-left: 5px;">次</span>
                    </FormItem>
                    <!-- 回款列表 -->
                    <FormItem label="" v-show="member.paybackNum > 1">
                        <Table border :columns="paybackTable" :data="paybackTableData">
                            <template slot-scope="{ row }" slot="code">
                                <strong>{{ row.code }}</strong>
                            </template>
                            <template slot-scope="{ row, index }" slot="time">
                                <strong v-if="row.code == '合计'">-</strong>
                                <date-sigle :ref="'paybackTime' + index" :dateType="'date'"
                                    :dataV="paybackTableData[index].time" :placeholderd="'请选择'"
                                    @startDate="paybackTableChange(row, index, 'time', $event)" :overTime="0"
                                    v-else></date-sigle>
                            </template>
                            <template slot-scope="{ row, index }" slot="money">
                                <strong v-if="row.code == '合计'">{{ member.payMoney || '-' }}</strong>
                                <Input v-model="paybackTableData[index].money"
                                    @on-keyup="paybackTableChange(row, index, 'money')" type="number"
                                    @mousewheel.native.prevent @DOMMouseScroll.native.prevent placeholder="请输入"
                                    :disabled="index + 1 == member.paybackNum" v-else></Input>
                            </template>
                        </Table>
                    </FormItem>
                    <!-- 回款工作日 -->
                    <FormItem label=" " class="d-felx" :label-width="55" required v-show="member.paybackNum == 1">
                        <span v-if="member.agreementStatus == '1'">自协议签订之日起</span>
                        <span v-else>自订单创建之日起</span>
                        <Input v-model.trim="member.paybackWorkDayNum" type="text"
                            @on-keyup="keyupformat('paybackWorkDayNum')"
                            style="width: 80px;margin-left:10px;margin-right: 10px;"></Input>
                        <span> 个工作日回款,预计回款时间：<span style="color: #36a3f7">{{ member.paybackExpectDate ||
            '--' }}</span></span>
                    </FormItem>
                    <FormItem label="业绩归属" class="formTitle">
                    </FormItem>
                    <div class="flex-endbox">
                        <FormItem label="业绩归属部门" required>
                            <!-- <Cascader v-model="member.saleCodeModel" :data="saleDep" trigger="hover" @on-visible-change="saleDepClick" @on-change="saleDepChange"></Cascader> -->
                            <cascaderMulti class="truecascader" v-model="member.saleCodeModel" :data="saleDep" multiple
                                @on-change="saleDepChange"></cascaderMulti>
                        </FormItem>
                        <FormItem label="业绩统计时间">
                            <date-sigle ref="sigleRef3" :dateType="'date'" :dataV="member.sale_time"
                                :placeholderd="'请选择业绩统计时间'" @startDate="saleDate" :overTime="0"></date-sigle>
                        </FormItem>
                    </div>
                    <FormItem label="销售人员">
                        <sale-select ref="saleRef" @salePerson="salePerson"
                            :setDefaultPerson="this.$store.getters.getAdminUser.username"></sale-select>
                    </FormItem>
                    <FormItem class="table-order1" v-show="saleTableData.length > 2">
                        <Table border :columns="saleTable" :data="saleTableData">
                            <template slot-scope="{ row }" slot="name">
                                <strong>{{ row.name }}</strong>
                            </template>
                            <template slot-scope="{ row, index }" slot="money">
                                <Input v-model="saleTableData[index].money" @on-keyup="saleTableChange(index)"
                                    type="number"></Input>
                            </template>
                        </Table>
                    </FormItem>
                    <FormItem label="销售渠道" required>
                        <v-cascader ref="casRef" type="1" quType="1" placeholderType="请选择销售渠道" reqType="销售渠道"
                            @levelChange="salesChange"></v-cascader>
                    </FormItem>
                    <FormItem label="其他信息" class="formTitle">
                    </FormItem>
                    <div class="flex-endbox">
                        <FormItem label="约定支付方式" required>
                            <Select v-model="member.payType" placeholder="请选择约定支付方式">
                                <Option v-for="item in payTypes" :value="item.v" :key="item.v">{{ item.n }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="下单渠道" required>
                            <v-cascader ref="casRef1" :initVal="'d01'" placeholderType="请选择下单渠道" reqType="下单渠道"
                                @levelChange="channelChange" v-if="bShow"></v-cascader>
                        </FormItem>
                    </div>
                    <!-- 修改为默认展示 -->
                    <div v-show="!showOrderOther">
                        <FormItem label="订单备注">
                            <Input v-model="member.remark" type="text" :maxlength="40" placeholder="请输入订单备注"></Input>
                        </FormItem>
                        <FormItem label="订单状态" :required="showOrderStatus" v-if="showOrderStatus">
                            <Select v-model="member.order_status" placeholder="请选择订单状态">
                                <Option value="0">未完成</Option>
                                <Option value="1">已完成</Option>
                            </Select>
                        </FormItem>
                    </div>
                    <!-- <div style="display: flex;justify-content: center;" v-show="!showOrderOther">
                     <div @click="showOrderOther = !showOrderOther" style="color: #36a3f7;cursor: pointer; font-size: 14px;">
                        <span>更多信息</span>
                       <i class="el-icon-arrow-down"></i>
                     </div>
                   </div> -->
                </div>
            </Form>
            <div slot="footer">
                <Button type="primary" size="large" @click="ordConfirm({ save: '1' })" :disabled="isDisable">提交</Button>
                <Button type="primary" class="button-grey" size="large" @click="ordConfirm({ save: '2' })"
                    :disabled="isDisable" v-if="!showOrderStatus">暂存</Button>
                <Button size="large" @click="ordCancel()">取消</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
import { dateFormatter } from '@/assets/js/date'
import dateSigle from '@/components/dateSigle'
import vCascader from '@/components/cascader'
import bUpload from '@/components/uploadFile.vue'
import OnlineContractForm from '@/components/OnlineContractForm'
import saleSelect from './salesSelect.vue'
import { getDateSub } from '@/assets/js/date'
import { debounce } from '@/helper.js'
import serveNames from '@/assets/js/serveName.js'
export default {
    name: 'CreateBigOrderModal',
    components: {
        OnlineContractForm,
        vCascader,
        dateSigle,
        bUpload,
        saleSelect
    },
    props: {
        showOrderStatus: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        subaccountDis() {
            if (this.member.buySubject == '1' && (this.bigStas == 1 || this.bigStas == 2)) {
                return false
            } else if (this.member.buySubject == '2' && this.contactOrderList.length > 0) {
                return false
            } else {
                return true
            }
        },
        proDis: function () {
            if (this.member.phone == '') {
                return true
            } else {
                if (this.noPhone) {
                    return false
                } else {
                    if (!(/^1[03456789]\d{9}$/.test(this.member.phone))) {
                        return true
                    } else {
                        return false
                    }
                }
            }
        },
        vipDis() {
            if (this.member.contract_nature == '2' && this.member.buySubject == '1') { // 个人续签合同
                return true

            } else if (this.member.contract_nature == '1' && this.member.buySubject == '1' && (this.bigStas == 2 || this.bigStas == 1)) { // 有大会员权限
                // this.member.level = JSON.stringify(this.comVal)
                return true
            } else if (!this.member.buySubject || !this.member.phone) {
                return true
            } else {
                return false
            }
        },
        showOnlineContractForm() {
            const paybackCompanyCheck = this.member.paybackCompany == 'h01' // 签约主体为：北京剑鱼信息技术有限公司/h01
            const contractStatusCheck = this.member.agreementStatus == '1' // 协议状态为签协议
            // 展示条件：
            // 1. 产品类型是超级订阅（且付费类型为“购买”、“续费”）才展示。
            // 2. 产品类型是“大会员”且会员套餐为“商机版2.0”、“专家版2.0”（且服务类型为“新购服务”、“延长服务”）
            // memberLevelMap.id：6'商机版2.0'、7'专家版2.0'
            const memberLevel = this.member.level
            if (!memberLevel || memberLevel == 'undefined') return false
            const memberLevelMap = JSON.parse(memberLevel)
            // console.log(memberLevelMap)
            // createType '1'新建  '2'补充  '3'延期
            const createType = this.nums == 0 ? this.member.createType : '1'
            // 这里的单省版 是商机版2.0单省版
            const bigmemberCheck = (memberLevelMap.id == 6 || memberLevelMap.id == 7 || memberLevelMap.s_name.indexOf('单省版') > -1) && (createType == '1' || createType == '3')
            const productTypeCheck = bigmemberCheck
            return paybackCompanyCheck && contractStatusCheck && productTypeCheck
        },
        vipval() { //收集多个参数变动 合同性质 购买主体 是否会员 产品 
            return this.member.contract_nature + this.member.buySubject + this.bigStas + this.member.products + this.member.phone
        },
        priceChange() {
            return this.member.level + this.member.payCycle + this.member.cycleType + this.member.buySubject + String(this.form_serve.ids) + this.member.buyCount + this.member.phone + this.member.beginTime + this.member.createType

        },
        returnMyReceivable: function () {
            let rout = this.$route
            if (rout.path && rout.path.includes('myorderList')) {// 我的订单
                return false
            } else {
                return true
            }
        },
    },
    watch: {
        vipval() { // 监听变化多参数变动
        },
        priceChange() {
            this.$nextTick(() => {
                try {
                    this.orderPriceCount()
                } catch (e) {
                    // console.log(e)
                }
            })
        }
    },
    created() {
    },
    mounted() {
        // this.getNewservedata()
    },
    methods: {
        contractChange() {
            this.createdTypeChange()
        },
        orderPriceCount() { // 获取价格
            let obj = {}
            if (this.member.products == '1') {
                obj = {
                    productType: '大会员',
                    createType: this.member.buySubject == '2' ? '1' : this.member.createType || '',
                    level: JSON.parse(this.member.level).id || 5,
                    payCycle: this.member.payCycle || '',
                    cycleType: this.member.cycleType == '0' ? 2 : 3 || '',
                    startTime: this.member.createType == 2 || this.member.createType == 3 ? '' : this.member.beginTime || '',
                    products: this.member.products + '', // 产品类型
                    comboId: JSON.parse(this.member.level).id || 5,
                    buySubject: this.member.buySubject,
                    buyCount: this.member.buyCount,
                    phone: this.member.phone
                }
                if (this.member.level && JSON.parse(this.member.level).i_ispreinstall == 0) {
                    this.getserveIdAndname()
                    obj.serversId = String(this.form_serve.ids)
                    obj.level = 5
                    obj.comboId = 5
                }
            }
            if (this.member.products == '3') { // 补充包
                obj = {
                    products: this.member.products + '', // 产品类型
                    productType: '大会员',
                    buyCount: this.member.buyCount,
                    phone: this.member.phone,
                    buySubject: this.member.buySubject,
                    createType: 1

                }
                let serveData = []
                this.datas2.forEach(v => {
                    serveData.push({
                        id: v.id,
                        name: v.name,
                        price: v.price,
                        count: v.count * v.s_pkcount
                    })
                })
                obj.serversArr = serveData
            }
            if (this.member.products == '2') { //子账号
                obj = {
                    productType: '大会员',
                    products: this.member.products + '', // 产品类型
                    buyCount: this.member.buyCount,
                    phone: this.member.phone,
                    buySubject: this.member.buySubject,
                    createType: 1
                }
                if (this.member.buySubject == '2') {
                    obj.orderCode = this.member.contactOrderCode
                }
            }
            if (this.member.products == '1' && obj.phone && obj.buyCount && obj.buySubject) {
                if (this.member.createType == '1' && (!obj.payCycle || !obj.cycleType)) {
                    return
                }
                this.getpriceAjax(obj)
            } else if (this.member.products == '2' && obj.phone && obj.buyCount && obj.buySubject) {
                if (this.member.buySubject == '2' && !obj.orderCode) {
                    this.$Notice.warning({ title: '请选择关联订单' })
                    return
                }
                this.getpriceAjax(obj)
            } else if (this.member.products == '3' && obj.phone && obj.buySubject && obj.serversArr && obj.serversArr.length > 0) {
                this.getpriceAjax(obj)
            }
        },
        createdTypeChange() {  // 套餐自动勾选逻辑
            this.buyserveName = ''
            this.serveEndtime = ''
            try {
                if (!this.member.phone || !this.member.buySubject || !this.member.contract_nature) {
                    return
                }
                this.newServedata = JSON.parse(JSON.stringify(this.initnewServedata))  // 初始化服务列表数据
                if (this.member.contract_nature == '1' && this.member.buySubject == '1' && (this.bigStas == 2 || this.bigStas == 1)) {  // 合同性质为“新签合同”，且开通权益手机号已有大会员权限，则会员套餐默认为“自定义版”，不支持修改。
                    this.radiosChangelevel(JSON.stringify(this.comVal)) // 补充 勾选自定义
                    this.member.level = JSON.stringify(this.comVal)
                    if (this.nums == 0) {
                        clearTimeout(timer)
                        let timer = setTimeout(() => {
                            if (this.member.phone) {
                                this.currentServer(this.member.phone, (res) => {
                                    let ids = res.data.list
                                    this.currentServerid = res.data.list
                                    let time = dateFormatter(res.data.serviceEndTime, 'yyyy-MM-dd')
                                    this.echoServe(ids, 'hide', ids)
                                    this.Purchasedservices(time)
                                    this.getserveIdAndname()
                                })
                            }
                        }, 200);
                    }
                }
                if (this.member.contract_nature == '2' && this.member.buySubject == '1') { // 个人续签合同  延长
                    if (this.i_member_status) {
                        this.levelDown.forEach(ele => {
                            if (this.areaCount > 0) {// 单省版
                                if (ele && ele.s_name.indexOf('单省版') > -1) {
                                    this.radiosChangelevel(JSON.stringify(ele))
                                    this.member.level = JSON.stringify(ele)
                                }
                            } else {
                                if (ele && ele.id == this.i_member_status) {
                                    this.radiosChangelevel(JSON.stringify(ele))
                                    this.member.level = JSON.stringify(ele)
                                }
                            }
                        })
                        if (this.i_member_status == 5) { // 自定义
                            this.radiosChangelevel(JSON.stringify(this.comVal))
                            this.member.level = JSON.stringify(this.comVal)
                            clearTimeout(timer)
                            let timer = setTimeout(() => {
                                if (this.member.phone) {
                                    this.currentServer(this.member.phone, (res) => {
                                        let ids = res.data.list
                                        this.currentServerid = res.data.list
                                        this.echoServe(ids, 'allDis')
                                        this.getserveIdAndname()
                                    })
                                }
                            }, 200);

                        }
                    } else {
                        this.member.level = ''
                    }
                }
                this.modifycreateType()

            } catch (e) {
                // console.log(e)
            }
        },
        getpriceAjax(obj) {
            if (this.pricetimer) {
                clearTimeout(this.pricetimer)
            }
            this.pricetimer = setTimeout(() => {
                this.$request('/order/orderPriceCount').data(obj).success((res) => {
                    // if(!res.data.price){
                    //     return
                    // }
                    this.member.orderMoney = res.data.price
                }).post()
            }, 200);

        },
        getNewservedata() {// 获取新服务列表   
            this.$request('/order/getServerNew').data({ sType: 2 }).success((res) => { // 获取自定义套餐所有服务选项
                let data = res.data.lists
                // 处理为符合前端结构数据 
                data.forEach(ele => {
                    if (ele.Children.length > 0) {
                        for (const key in serveNames) { // 服务名称替换
                            ele.Children.forEach(item => {
                                if (item.s_new_name == key) {
                                    item.s_new_name = serveNames[key]
                                }
                            })
                        }
                        ele.maps = groupByProperty(ele.Children, 's_new_name') // 相同名称分组
                    }
                })
                // data.forEach(ele => {
                //     for (const key in  ele.maps) {
                //         if(ele.maps[key].length>1){
                //             if(key.indexOf('数据导出') == -1){
                //                 ele.maps[key].unshift({'s_new_name':ele.maps[key][0].s_new_name,id:'',s_count_year:10})
                //             }
                //         }  
                //     }     
                // })
                data.forEach(ele => {
                    ele.lists = []
                    for (const key in ele.maps) {
                        let obj = {}
                        if (key.includes('市场分析定制报告') || key.includes('企业分析') || key.includes('业主分析')) {
                            obj.name = key + ',报告下载:'
                        } else {
                            obj.name = key
                        }
                        obj.list = ele.maps[key]
                        if (obj.list.length == 1) {
                            obj.id = ele.maps[key][0].id
                        }
                        if (obj.list.length > 1) {
                            obj.list.forEach(e => {
                                if (e.s_new_name.indexOf('数据导出') > -1) {
                                    e.dw = '条/天'
                                    if (e.s_count_year == 200) {
                                        obj.id = e.id
                                    }
                                } else if (e.s_new_name.includes('市场分析定制报告') || e.s_new_name.includes('企业分析') || e.s_new_name.includes('业主分析')) {
                                    if (!e.s_count_year || e.s_count_year == 500) { // 企业分析count500是基础产品与一份下载包重合因此隐藏，其他两种的基础产品count是null
                                        e.hide = true
                                    }
                                    // i_isserver 1 套餐下载包
                                    if(e.i_isserver == 1){ // 隐藏套餐下载包
                                        e.dw = '份/年' // 单位
                                        e.disabled = true
                                        e.hide = true
                                    }else{
                                        e.dw = '份' // 单位
                                    }
                                    
                                    if (e.s_count_year == 1 && e.i_isserver != 1) { // 默认1份  非套餐的选项
                                        obj.id = e.id // 勾选层级的ID赋值为规格为1的产品ID
                                    }
                                } else {
                                    e.dw = '个'
                                    if (e.s_count_year == 100) {
                                        obj.id = e.id
                                    }
                                }
                            })
                        }
                        ele.lists.push(obj)
                    }
                })
                // 初始勾选处理
                data.forEach(ele => {
                    if (ele.ColumnName == '基础服务') { // 基础服务默认勾选且不可修改
                        ele.choose = true
                        ele.disabled = true
                    } else {
                        ele.choose = false
                        ele.disabled = false
                    }
                    ele.lists.forEach(e => {
                        if (e.id == 1) {
                            e.choose = true
                            e.disabled = true

                        } else {
                            e.choose = false
                            e.disabled = false
                        }
                    })
                })
                data.forEach(ele => {
                    ele.lists.forEach(e => {
                        let newlist = e.list.sort((a, b) => a.s_count_year - b.s_count_year) // 按数量排序
                        ele.list = newlist
                    })
                })
                this.newServedata = data
                console.log(this.newServedata)
                this.initnewServedata = JSON.parse(JSON.stringify(this.newServedata))
            }).get()
            // 基础数据格式处理 下拉默认选中ID及单位处理
            function groupByProperty(arr, prop) {
                let groups = {};
                arr.forEach(item => {
                    let group = groups[item[prop]];

                    if (!group) {
                        group = groups[item[prop]] = [];
                    }

                    group.push(item);
                });

                return groups;
            }
        },
        chooseChange(e, t, index) { // 多选框选择
            console.log(e, t)
            let data = this.newServedata
            if (t == 'one') {
                data[index].lists.forEach(e => {
                    if (data[index].choose) {
                        e.choose = true
                    } else {
                        e.choose = false
                    }
                })

            } else if (t == 'two') {
                console.log(data[index])

                if (data[index].lists.every(item => item.choose === true)) {
                    data[index].choose = true
                } else {
                    data[index].choose = false
                }

            }
            this.getserveIdAndname()
        },
        getserveIdAndname(type) { // 获取服务id和name
            let key = 'choose' //已勾选服务
            if (type == 'getbuyserve') { // 已购服务（被隐藏的服务即为已购服务）
                key = 'hide'
            }
            let data = this.newServedata || []
            let ids = []
            let names = []
            data.forEach(ele => {
                ele.lists.forEach(e => {
                    if (e[key]) {
                        ids.push(e.id)
                        if (e.id == 22 || e.id == 20 || e.id == 24) {  // 项目进度监控 22=>100; 14=>500  企业情报监控20=>100 ;23=>500  业主监控 24=>100 ;25=>500
                            names.push(e.name + '(100个)')
                        } else if (e.id == 14 || e.id == 23 || e.id == 25) {
                            names.push(e.name + '(500个)')
                        } else if (e.id == 17) { //数据导出
                            names.push(e.name + '(100条/天)')

                        } else if (e.id == 18) {
                            names.push(e.name + '(200条/天)')
                        } else if (e.id == 1) {
                            if (this.member.buySubject == '2') {
                                names.push('基础服务' + '+企业管理')
                            } else {
                                names.push('基础服务')
                            }
                        } else if (e.name.includes('市场分析定制报告') || e.name.includes('企业分析') || e.name.includes('业主分析')) {
                            e.list.forEach(item => {
                                if(e.id == item.id){
                                    if (item.s_count_year) {
                                        if (item.s_new_name.includes('企业分析') && item.s_count_year == 500) {
                                            names.push(item.s_new_name)
                                        } else {
                                            names.push(item.s_new_name.replace(',报告下载:', '') + `(报告下载:${item.s_count_year}${item.dw})`)
                                        }
                                    } else {
                                        names.push(item.s_new_name)
                                    }
                                }        
                            })
                        } else {
                            names.push(e.name)
                        }
                    }

                })
            })
            let names_str = names.join(',')
            // 基础服务: 服务id需要传1 3 企业情报监控包含:企业情报监控 20 23 企业情报监控传20的时候 企业中标动态传21 企业中标动态 21 13 企业情报监控传23的时候 企业中标动态传13
            if (ids.includes(1) && !ids.includes(3)) {
                ids.push(3)
            }
            if (ids.includes(20) && !ids.includes(21)) {
                ids.push(21)
            }
            if (ids.includes(23) && !ids.includes(13)) {
                ids.push(13)
            }
            if (names_str.includes('市场分析定制报告') && !ids.includes(26)) { // 选中下载包的ID时则存在没有基础产品的ID，这里补上 基础产品和下载包是绑定的，但是有两个ID
                ids.push(26)
            }
            if (names_str.includes('企业分析') && !ids.includes(4)) {
                ids.push(4)
            }
            if (names_str.includes('业主分析') && !ids.includes(5)) {
                ids.push(5)
            }
            // console.log(ids,names)
            if (type == 'getbuyserve') {
                return { ids, names }
            } else {
                this.form_serve = { ids, names }
            }
        },
        Purchasedservices(time) {
            let { names } = this.getserveIdAndname('getbuyserve') // 获取已购服务 已购服务会在服务勾选隐藏
            this.buyserveName = names.join('、')
            this.serveEndtime = time
        },
        echoServe(ids, type, hide_id) { // 回显服务 ids:勾选ID; type: dis禁用已勾选 allDis禁用全部 hide隐藏 hide_dis 隐藏指定禁用剩下的; hide_id: 需要隐藏的id
            let data = ids
            if (!data.includes(1)) { // 1 3 基础服务默认都有
                data.push(1)
            }
            if (!data.includes(3)) {
                data.push(3)
            }
            let hide = hide_id || []
            if (!hide.includes(1)) { // 1 3 基础服务默认都有
                hide.push(1)
            }
            if (!hide.includes(3)) { // 1 3 基础服务默认都有
                hide.push(3)
            }
            let servedata = this.newServedata
            servedata.forEach(ele => {
                ele.lists.forEach(e => {
                    e.list.forEach(item => {
                        if (data.includes(item.id)) {
                            if(item.id != 4 && item.id != 5 && item.id != 26){ // 企业分析 业主分析 市场分析定制报告 这三个基础服务不选中ID  （捆绑的有下载包 选中下载包的ID）
                                e.id = item.id
                            }  
                            e.choose = true
                            if (type == 'dis') { // 禁用已勾选
                                e.disabled = true
                                item.disabled = true
                                ele.disabled = true
                            }
                        }
                        if (hide.includes(item.id)) {
                            if (type == 'hide' || type == 'hide_dis') {
                                e.hide = true
                                item.hide = true
                                ele.hide = true
                                e.disabled = true
                                item.disabled = true
                                ele.disabled = true
                            }
                        }
                        if (type == 'allDis' || type == 'hide_dis') { // 禁用全部选项
                            e.disabled = true
                            item.disabled = true
                            ele.disabled = true
                        }

                    })
                })
            })
            servedata.forEach(ele => {
                if (ele.lists.every(item => item.choose === true)) {
                    ele.choose = true
                } else {
                    ele.choose = false
                }
                if ((type == 'hide' || type == 'hide_dis') && ele.lists.every(item => item.hide === true)) {
                    ele.hide = true
                } else {
                    ele.hide = false
                }
            })
        },
        modifycreateType() {
            this.member.createType = ''
            if (this.member.contract_nature == '2' && this.member.buySubject == '1') { // 当“合同性质”为“续签合同”时，购买主体为“个人”，默认为“延长服务”
                this.member.createType = '3'
            } else if (this.bigStas == 0) { // 没有大会员权限
                this.member.createType = '1'
            } else if (this.member.contract_nature == '1' && this.member.buySubject == '1' && (this.bigStas == 2 || this.bigStas == 1)) { //当开通权益手机号已有大会员权限，购买主体为“个人”，“合同性质”为“新签合同”，默认为“补充服务”
                this.member.createType = '2'
            } else if (this.member.buySubject == '2') { // 企业走新建服务新建
                this.member.createType = '1'
            }
            this.repair = this.member.createType
        },
        initialized(conf = {}) {// 初始化
            // 排除某些字段不重置
            if (!conf) {
                conf = {}
            }
            this.member.contactOrderCode = ''
            this.member.entId = ''
            this.member.paybackWorkDayNum = ''
            this.member.paybackExpectDate = ''
            this.member.paybackOpenServer = false
            const excludeList = conf.excludeList || []
            this.member.bigMoney = 0
            this.member.subMoney = 0
            this.member.supplyMoney = 0
            this.member.orderMoney = 0
            this.member.payMoney = ''
            this.member.sums = 0
            this.member.paySub = ''
            this.member.freeSub = ''
            this.member.bigPayMoney = ''
            this.member.subPayMoney = ''
            this.member.supplyPayMoney = ''
            this.member.payCycle = ''
            this.member.contractUrl = ''
            if (!excludeList.includes('companyName')) {
                this.member.companyName = ''
            }
            this.member.remark = ''
            if (this.member.products == '2') {
                this.member.agreementStatus = '0'
            } else {
                this.member.agreementStatus = '1'
            }
            this.member.payType = ''
            this.member.agreementNumber = ''
            this.member.cycleType = '0'
            this.member.commission = '0'
            this.member.proceduresMoney = '0'
            this.member.contract_archive_status = '0'
            this.member.contract_archive_num = ''
            this.member.single = false
            this.member.areaCount = 0
            this.sumSel = []
            this.sPrice = 0
            this.strItems = []
            this.selData = []
            this.isAll = false
            this.member.beginTime = ''
            this.bigDis = true
            this.subDis = true
            this.supplyDis = true
            this.strItems1 = []
            this.strItems2 = []
            this.strItems3 = []
            this.strItems4 = []
            this.strItems5 = []
            this.optionDis1 = false
            this.optionDis2 = false
            this.optionDis3 = false
            this.optionDis4 = false
            this.optionDis5 = false
            this.optionDis6 = false
            this.combo_id = ''

            Object.keys(this.member).forEach(key => {
                if (key.startsWith('e_contract_')) {
                    // 默认重置
                    if (key !== 'e_contract_userB_contacts_name') { // 乙方联系人不重置
                        this.member[key] = this.$options.data().member[key]
                    }
                }
            })

            setTimeout(() => {
                let sigs = this.$refs.sigleRef
                let sigs1 = this.$refs.sigleRef3
                let sigs2 = this.$refs.sigleRef4
                let uploads = this.$refs.uploadRef
                if (sigs) {
                    this.$refs.sigleRef.initd()
                    this.$refs.sigleRef.dataVals = dateFormatter(new Date(), 'yyyy-MM-dd')
                    this.member.agreementTime = dateFormatter(new Date(), 'yyyy-MM-dd')
                }
                if (sigs1) {
                    this.$refs.sigleRef3.dataVals = dateFormatter(new Date(), 'yyyy-MM-dd') + ' 00:00:00'
                    this.member.sale_time = dateFormatter(new Date(), 'yyyy-MM-dd') + ' 00:00:00'
                }
                if (sigs2) {
                    this.$refs.sigleRef4.initd()
                }
                if (uploads) {
                    this.$refs.uploadRef.uploadShow = false
                    this.$refs.uploadRef.payHtml = ''
                }
            }, 200)
        },
        keyupSale(val) { // 正则格式化金额
            if (val === '1') { // 合同金额
                this.member.payMoney = this.moneyReg(this.member.payMoney)
                // 金额变动清空回款列表
                if (this.member.paybackNum > 1) {
                    this.paybackTableDataClear()
                }
            } else if (val === '2') {
                this.member.bigPayMoney = this.moneyReg(this.member.bigPayMoney)
            } else if (val === '3') {
                this.member.subPayMoney = this.moneyReg(this.member.subPayMoney)
            } else if (val === '4') {
                this.member.supplyPayMoney = this.moneyReg(this.member.supplyPayMoney)
            } else if (val === '5') {
                this.member.commission = this.moneyReg(this.member.commission)
            } else if (val === '6') {
                this.member.proceduresMoney = this.moneyReg(this.member.proceduresMoney)
            }
            this.updateSaleMoney()
        },
        paybackTableDataClear() { // 初始化回款列表
            let num = this.member.paybackNum
            let arr = []
            for (let i = 0; i <= num; i++) {
                if (i == num) {
                    arr.push({ code: '合计', time: '-', money: this.member.payMoney })
                } else {
                    arr.push({ code: i + 1, time: '', money: '' })
                }
            }
            this.paybackTableData = arr
            this.$nextTick(() => {
                this.paybackTableData.forEach((ele, index) => {
                    if (index < this.paybackTableData.length - 1) {
                        this.$refs['paybackTime' + index].initd()
                    }
                })
            })
        },
        keyupformat(val) { // 格式化输入框
            if (val === 'paybackWorkDayNum') {
                this.member.paybackWorkDayNum = this.filterNonPositiveIntegers(this.member.paybackWorkDayNum)
                this.getcollectionDate()
            } else if (val === 'paybackNum') { // 回款次数
                this.member.paybackNum = this.paybackNumReg(this.member.paybackNum)
                if (this.member.paybackNum > 1) {
                    this.paybackTableDataClear()
                } else {
                    // 切换一次重置数值
                    this.member.paybackWorkDayNum = ''
                    this.member.paybackExpectDate = ''
                }
            }
        },
        paybackTableChange(row, index, type, e) { // 回款计划表格 change
            if (type == 'money') {
                // 回款金额未录入时
                if (!this.member.payMoney) {
                    this.$Notice.warning({ title: '请先输入合同金额' })
                    this.paybackTableData[index].money = ''
                    return
                }
                let num = 0
                if (this.paybackmoneyReg(this.paybackTableData[index].money)) {
                    let money_ = this.paybackmoneyReg(this.paybackTableData[index].money)
                    this.paybackTableData[index].money = Number(money_).fixed(2)
                } else {
                    this.paybackTableData[index].money = ''
                }
                this.paybackTableData.forEach((ele, index) => {
                    if (index < this.paybackTableData.length - 2) {
                        num += Number(ele.money)
                    }
                })
                if (num && this.member.payMoney) {
                    if (Number(this.member.payMoney) - Number(num) > 0) {
                        this.paybackTableData[this.member.paybackNum - 1].money = (Number(this.member.payMoney) - Number(num)).fixed(2)
                    } else {
                        this.$Notice.warning({ title: '需小于合同金额' })
                        this.paybackTableData[index].money = ''
                        // this.paybackTableData[this.member.paybackNum -1].money = ''
                    }
                    this.paybackTableData.forEach((ele) => {
                        if (ele.code == '合计') {
                            ele.money = Number(this.member.payMoney)
                        }
                    })
                } else {
                    this.paybackTableData[this.member.paybackNum - 1].money = ''
                }
            } else if (type == 'time') {
                if (e) {
                    this.paybackTableData[index].time = e
                }
            }
            console.log(this.paybackTableData)
        },
        paybackmoneyReg(val) {
            if (val) {
                let str = this.moneyReg(val + "")
                if (str == 0 && str !== '') {
                    this.$Notice.warning({ title: '不可为0' })
                    str = ''
                } else if (Number(str) >= Number(this.member.payMoney)) {
                    this.$Notice.warning({ title: '需小于合同金额' })
                    str = ''
                }
                return str
            } else {
                return ""
            }
        },
        paybackNumReg(val) {
            let str = val.toString().replace(/-\d+|[^\d\s,]+/g, '')
            if (str !== "" && str < 1) {
                this.$Notice.warning({ title: '最小值为1' })
                str = 1
            } else if (str > 5) {
                this.$Notice.warning({ title: '最大值为5' })
                str = 5
            }
            if (str && str > 0) {
                return Number(str)
            } else {
                return ''
            }
        },
        getcollectionDate: debounce(function () {
            if (this.member.paybackNum != 1) {
                return
            }
            let start = ''
            this.member.paybackExpectDate = ''
            if (this.member.paybackWorkDayNum === 0) {
                if (this.member.agreementStatus == '1') {
                    this.member.paybackExpectDate = this.member.agreementTime
                } else {
                    this.member.paybackExpectDate = dateFormatter(new Date(), 'yyyy-MM-dd')
                }
                return
            }
            if (this.member.agreementStatus == '1') { //签协议
                start = this.member.agreementTime
            } else {//不签协议
                start = dateFormatter(new Date(), 'yyyy-MM-dd')
            }
            if (this.member.paybackWorkDayNum === '' || !start) {
                return
            }
            let obj = {
                startDay: start,
                workDayNum: Number(this.member.paybackWorkDayNum),
            }
            this.$request('getWorkDay').contentType('application/json').data(obj).success((res) => {

                if (res.data) {
                    this.member.paybackExpectDate = res.data
                }
            }).post('rewritePath')

        }, 200),
        filterNonPositiveIntegers(str) {
            let strs = str + ""
            let num = strs.replace(/-\d+|[^\d\s,]+/g, '')
            if (num && num >= 0) {
                return Number(num)
            } else {
                return ''
            }

        },
        saleTableChange(index) {
            let money = Number(this.saleTableData[index].money).fixed(2)
            this.saleTableData[index].money = money
            let moneys = 0
            this.saleTableData.forEach(v => {
                if (v.name !== '合计') {
                    moneys += v.money
                }
            })
            this.saleTableData[this.saleTableData.length - 1].money = moneys
        },
        updateSaleMoney() {
            let money = Number(this.member.payMoney) + Number(this.member.bigPayMoney) + Number(this.member.subPayMoney) + Number(this.member.supplyPayMoney) - Number(this.member.commission) - Number(this.member.proceduresMoney)
            let moneys = Number(money / (this.saleTableData.length - 1)).fixed(2)
            this.saleTableData.forEach(v => {
                if (v.name === '合计') {
                    v.money = money
                } else {
                    v.money = moneys
                }
            })
        },
        saleDepClick() {
            let url = '/order/getSalesChannelItem'
            this.$request(url).data({
                name: this.reqType
            }).success((res) => {
                if (res.data.dep) {
                    this.saleDep = res.data.dep
                }
                if (res.data.displayMap) {
                    if (res.data.displayMap.distribution_channel) {
                        this.member.salesChannel = res.data.displayMap.distribution_channel
                    }
                    if (res.data.displayMap.saleDep) {
                        this.member.saleCodeModel = res.data.displayMap.saleDep
                    }
                }
            }).post()
        },
        saleDepChange: debounce(function (val) { // 业绩归属部门
            if (val && val.length > 0) {
                let valres = this.getMinLevelData(this.saleDep, val)
                this.saleCode = valres.join(',')
                if (val.indexOf('010100') > -1 || val.indexOf('010101') > -1 || val.indexOf('010102') > -1 || val.indexOf('010103') > -1 || val.indexOf('010104') > -1 || val.indexOf('050000') > -1) {
                    this.$refs.casRef.getDictItem(() => {
                        this.$refs.casRef.setDate('x020')
                    })
                    this.$refs.casRef.values = ['x02', 'x020'] //业绩归属部门为“销售一部/电销组”或“销售三部”，销售渠道默认为“线下直销/电销”
                    this.member.salesChannel = 'x020'
                }
            } else {
                this.saleCode = ''
            }
        }, 200),
        removeElementFromArray(arr, value) {
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] === value) {
                    arr.splice(i, 1)
                    i--
                }
            }
            return arr
        },
        getMinLevelData(arrayA, arrayB) {
            const result = []
            const findItem = (arr) => {
                for (let i = 0; i < arr.length; i++) {
                    if (arrayB.includes(arr[i].value)) {
                        result.push(arr[i].value)
                    }
                    if (arr[i].children) {
                        let arra = arr[i].children
                        for (let a = 0; a < arra.length; a++) {
                            if (arrayB.includes(arra[a].value)) {
                                this.removeElementFromArray(result, arra[a].value.substring(0, 2) + '0000')
                                result.push(arra[a].value)
                            }
                            if (arra[a].children) {
                                let arrb = arra[a].children
                                for (let b = 0; b < arrb.length; b++) {
                                    if (arrayB.includes(arrb[b].value)) {
                                        if (arrayB.includes(arrb[b].value.substring(0, 4) + '00')) {
                                            this.removeElementFromArray(result, arrb[b].value.substring(0, 4) + '00')
                                        }
                                        result.push(arrb[b].value)
                                    }
                                }
                            }
                        }
                    }
                }
            }
            findItem(arrayA)
            return result.reverse()
        },
        onRemoveUpload() {
            this.member.contractUrl = ''
        },
        moneyReg(val) {
            return val.replace(/[^\d^\.]+/g, '').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
        },
        keyHandler() {
            this.member.phone = this.member.phone.replace(/[^\d]/g, '')
            if (this.member.level) {
                this.member.level = ''
                this.nums = ''
            }
        },
        noPchange(val) {
            if (val) {
                this.pReadon = true
                this.member.phone = 9 + String(Math.random()).substring(2, 12)
                this.overTime = 0
                this.pheHandler() // 手机号变动
                this.myNoTchange()
            } else {
                this.pReadon = false
                this.member.phone = ''
            }
        },
        salesChange(val) {
            //销售渠道兼容单个内容 或数组内容
            if (val instanceof Array) {
                this.member.salesChannel = String(val[1])
            } else if (typeof val === 'string') {
                this.member.salesChannel = val
            } else {
                this.member.salesChannel = String(val)
            }
        },
        channelChange(val) {
            this.member.orderChannel = String(val)
        },
        radiosChange(val) {
            this.member.buySubject = String(val)
            this.member.buyCount = ''
            this.creAuth = this.member.products

            if (val == 2) {
                this.member.products = '1'
                this.repair = '1'
            }
            this.datas2 = []
            this.member.paySub = ''
            this.member.freeSub = ''
            this.member.orderMoney = 0
            this.member.payMoney = ''
            this.nums = ''
            this.member.level = ''
            this.member.contractUrl = ''
            this.member.single = false
            this.member.areaCount = 0
            this.isAll = false
            setTimeout(() => {
                let uploads = this.$refs.uploadRef
                if (uploads) {
                    this.$refs.uploadRef.uploadShow = false
                    this.$refs.uploadRef.payHtml = ''
                }
                // 产品类型类型初始为大会员 获取套餐信息
                this.proChange(this.member.products)
            }, 200)
            this.reged()
        },
        paybackChange(val) {
            this.member.paybackCompany = String(val)
        },
        reged(type) {
            this.spinShow = true
            if (type == 'pheHandler') { //手机号变动调用此方法 不重置公司名称
                this.initialized({
                    excludeList: ['companyName']
                })
            } else {
                this.initialized()
            }
            this.$request('/order/isOpenBig').data({// 验证手机号权限
                buySubject: this.member.buySubject,
                getContactOrder: 1,
                phone: this.member.phone,
                entName: (this.member.buySubject == '2') ? this.member.companyName : ''
            }).success((res) => {
                this.bigStas = res.data.Bigstatus
                this.subStas = res.data.isSub
                this.isYears = res.data.isYear // 0 开过大会员没超过一年,1 开过大会员超过一年, 2 没开过大会员
                this.overTime = res.data.endTime
                this.i_member_status = res.data.i_member_status || ''
                this.areaCount = res.data.areaCount || 0
                this.contactOrderList = res.data.contactOrder || [] // 关联订单列表
                if (this.contactOrderList.length == 1) {
                    this.$set(this.contactOrderList[0], 'choose', true)
                    this.contactOrderchoose = this.contactOrderList[0]
                    this.member.contactOrderCode = this.contactOrderchoose.order_code
                    this.member.entId = this.contactOrderchoose.ent_id

                }
                // 补充 或延长 回显购买数量
                if (this.member.products != 2 && (this.member.contract_nature == '1' && this.member.buySubject == '1' && (this.bigStas == 2 || this.bigStas == 1)) || (this.member.contract_nature == '2' && this.member.buySubject == '1')) {
                    this.member.buyCount = res.data.buyCount || ''
                    this.initbuyCount = res.data.buyCount || ''
                }
                this.stopTime = getDateSub('', res.data.endTime)
                this.serData = []
                this.pacData = []
                this.datas2 = []
                if (res.data.isYear == 0) {
                    this.yearStas = 10
                } else if (res.data.isYear == 1) {
                    this.yearStas = 12
                }
                this.currentServer()
                setTimeout(() => {
                    this.spinShow = false
                    if (this.member.buySubject != '2') {
                        if (res.data.comingIntoEffective) {
                            this.$Modal.warning({
                                title: '警告提示',
                                content: '该用户存在即将生效的大会员订单，无法创建新订单',
                                okText: '我知道了',
                                onOk: () => {
                                    this.bShow = false
                                }
                            })
                        }
                    }
                    if (this.member.products == 1) {
                        if (this.member.buySubject != '2') {//主体为个体走原有逻辑

                            if (this.bigStas == 1) {

                                if (this.subStas == 1) {
                                    this.colr = ''
                                    this.downDis = false
                                    if (this.nums == 0) {
                                        this.getServed('')
                                        this.sumSel = []
                                        this.radioDis1 = false
                                        this.radioDis2 = true
                                        this.radioDis3 = true
                                        // this.member.createType = '1'
                                        this.repair = 1
                                        this.monthTime = 60
                                    }
                                } else {
                                    this.downDis = true
                                    if (this.nums == 0) {
                                        this.getServed('')
                                        this.sumSel = []
                                        this.radioDis1 = true
                                        this.radioDis2 = false
                                        this.radioDis3 = false
                                        // this.member.createType = '2'
                                        if (this.member.contract_nature == '1' && this.member.buySubject == '1' && (this.bigStas == 2 || this.bigStas == 1)) {
                                            this.repair = 2

                                        }
                                        this.monthTime = this.stopTime
                                    }
                                }

                            } else {
                                this.colr = ''
                                if (this.nums == 0) {
                                    this.creAuth = '1'
                                }
                                this.downDis = false
                                this.getServed('')
                                if (this.nums == 0) {
                                    this.sumSel = []
                                    this.radioDis1 = false
                                    this.radioDis2 = true
                                    this.radioDis3 = true
                                    // this.member.createType = '1'
                                    this.repair = 1
                                    this.monthTime = 60
                                }
                            }

                        } else { //企业直接按新用户购买处理
                            this.colr = ''
                            if (this.nums == 0) {
                                this.creAuth = '1'
                            }
                            this.downDis = false
                            this.getServed('')
                            if (this.nums == 0) {
                                this.sumSel = []
                                this.radioDis1 = false
                                this.radioDis2 = true
                                this.radioDis3 = true
                                // this.member.createType = '1'
                                this.repair = 1
                                this.monthTime = 60
                            }
                        }
                        this.createdTypeChange()
                    } else if (this.member.products == 2) {
                        if (this.bigStas == 0 && this.contactOrderList.length == 0) {
                            if (this.subStas == 0) {
                                this.colr = '此手机号无大会员权限'
                                this.creAuth = ''
                            }
                        } else if (this.bigStas == 2) {
                            this.colr = '此手机号已有大会员权限，无需再次创建'
                            this.creAuth = ''
                        } else {
                            if (this.subStas == 1) {
                                this.colr = '此手机号已是大会员子账号'
                                this.creAuth = ''
                            } else {
                                this.colr = ''
                                if (this.nums == 0) {
                                    this.creAuth = '2'
                                    this.getServed('')
                                    this.sumSel = []
                                }
                            }
                        }
                    } else if (this.member.products == 3) {
                        if (this.bigStas == 0) {
                            if (this.subStas == 0) {
                                this.colr = '此手机号无大会员权限'
                                this.creAuth = ''
                            }
                        } else if (this.bigStas == 2) {
                            this.colr = '此手机号已有大会员权限，无需再次创建'
                            this.creAuth = ''
                        } else {
                            if (this.subStas == 1) {
                                this.colr = '此手机号已是大会员子账号'
                                this.creAuth = ''
                            } else {
                                this.colr = ''
                                if (this.nums == 0) {
                                    this.creAuth = '3'
                                }
                                this.getServed('')
                                this.sumSel = []
                            }
                        }
                    } else {
                        this.member.products = ''
                    }
                    // this.modifycreateType()     
                }, 500)
            }).post()
        },
        disabledDateForVIPCallback(date) {
            return date && date.valueOf() < Date.now() - 86400000;
        },
        pheHandler() {// 填写手机号并验证
            this.member.phone = this.member.phone.replace(/[^\d]/g, '')
            if (this.member.phone) {
                if (this.pReadon) {
                    this.reged('pheHandler')
                } else {
                    if ((/^1[3456789]\d{9}$/.test(this.member.phone))) {
                        this.reged('pheHandler')
                    }
                }
            }
        },
        proChange(val) {// 产品类型
            // alert(val)
            if (this.member.buySubject == '2' && val == '2' && !this.member.companyName) {
                this.member.products = '1'
                this.$Notice.warning({ title: '请输入公司名称' })
                return
            }
            this.creAuth = this.member.products
            this.datas2 = []
            this.proNums = val
            this.member.paySub = ''
            this.member.freeSub = ''
            this.member.orderMoney = 0
            this.member.payMoney = ''
            this.member.level = ''
            this.member.contractUrl = ''
            this.member.single = false
            this.member.areaCount = 0
            this.isAll = false
            setTimeout(() => {
                let uploads = this.$refs.uploadRef
                if (uploads) {
                    this.$refs.uploadRef.uploadShow = false
                    this.$refs.uploadRef.payHtml = ''
                }
            }, 200)
            if (val == 1) {
                if (this.initbuyCount && this.vipDis) {
                    this.member.buyCount = this.initbuyCount
                }
                this.nums = ''
                this.$request('/order/getCombo').data().success((res) => {// 获取大会员套餐
                    this.levelDown = []
                    // let newobj = {}
                    res.data.lists.forEach(v => {
                        if (v.id !== 4) {// 试用版
                            this.levelDown.push(v)
                        }
                        // if (v.id == 6) { // 商机版2.0
                        //     newobj = JSON.parse(JSON.stringify(v))
                        //     newobj.s_name = newobj.s_name + '(单省版)'
                        //     this.levelDown.push(newobj)
                        // }
                    })

                    this.comVal = {
                        i_ispreinstall: 0,
                        i_price: '',
                        id: '',
                        l_createtime: "",
                        s_name: "自定义",
                        s_servers: ""
                    }
                    if (this.member.buySubject != '2') {//主体为个体走原有逻辑
                        if (this.bigStas == 1) {
                            if (this.subStas == 1) {
                                this.colr = ''
                            } else {
                                this.downDis = true
                            }
                        } else {
                            this.colr = ''
                            this.downDis = false
                        }

                    } else { //主体为企业直接走新购买逻辑
                        this.colr = ''
                        this.downDis = false
                    }
                    if (this.member.products == '1') {
                        this.createdTypeChange()
                    }
                }).get()
            }
            if (val == 2 || val == 3) {
                this.member.buyCount = '' // 切换套餐重置数量
                this.nums = '2'
                if (this.bigStas == 0 && this.contactOrderList.length == 0) {
                    if (this.subStas == 0) {
                        this.colr = '此手机号无大会员权限'
                        this.creAuth = ''
                    }
                } else if (this.bigStas == 2) {
                    this.colr = '此手机号已有大会员权限，无需再次创建'
                    this.creAuth = ''
                } else {
                    if (this.subStas == 1) {
                        this.colr = '此手机号已是大会员子账号'
                        this.creAuth = ''
                    } else {
                        this.colr = ''
                    }
                }
                // 选择子账号货补充包回显销售渠道
                if (this.member.salesChannel) {
                    this.$nextTick(() => {
                        this.$refs.casRef.getDictItem(() => {
                            this.$refs.casRef.setDate(this.member.salesChannel)
                        })
                    })
                }
            }
            if (val == 2) { // 选择子账号 默认为不签协议
                this.member.agreementStatus = '0'
                if (this.member.phone) {
                    if (this.pReadon) {
                        this.reged('pheHandler')
                    } else {
                        if ((/^1[3456789]\d{9}$/.test(this.member.phone))) {
                            this.reged('pheHandler')
                        }
                    }
                }
            }
            if (val == 3) {
                this.getServed('')
            }
        },
        tipFunc(val) {
            return val.toLocaleString('zh', { style: 'currency', currency: 'CNY' })
        },
        currentServer(phone_, callback) {// 获取用户当前已享有的服务
            this.$request('/order/getCurrentServer').data({
                phone: phone_ ? phone_ : this.member.phone
            }).success((res) => {
                this.currentId = res.data.list
                try {
                    if (callback) {
                        callback(res)
                    }
                } catch (e) {
                    //  console.log(e) 
                }
            }).post()
        },
        unitChange(data) {// 有效周期选择单位
            if (data == 1) {
                this.placed = '请输入有效周期（单位 天）'
                this.max_length = 4
            } else {
                this.max_length = 2
                this.placed = '请输入有效周期（单位（月），最多输入' + this.monthTime + '个月）'
            }
        },
        leChange(val) {// 会员套餐
            console.log(val)
            if (!val) return
            this.initialized({
                excludeList: ['companyName']
            })
            val = JSON.parse(val)
            this.datas2 = []
            this.sArr = []
            this.combo_id = val
            this.nums = val.i_ispreinstall // 0 
            if (this.pReadon) {
                this.myNoTchange()
            }
            if (val.i_ispreinstall == 0) {
                if (this.member.buySubject != '2') {//主体为个体走原有逻辑
                    if (this.bigStas == 1) {
                        if (this.subStas == 1) {
                            this.radioDis1 = false
                            this.radioDis2 = true
                            this.radioDis3 = true
                            // this.member.createType = '1'
                            this.repair = '1'
                            this.monthTime = 60
                            if (!this.showOrderStatus && !this.pReadon) {
                                this.myNoTchange()
                            }
                        } else {
                            this.radioDis1 = true
                            this.radioDis2 = false
                            this.radioDis3 = false
                            // this.member.createType = '2'
                            this.repair = '2'
                            this.monthTime = this.stopTime
                        }
                    } else {
                        this.radioDis1 = false
                        this.radioDis2 = true
                        this.radioDis3 = true
                        // this.member.createType = '1'
                        this.repair = '1'
                        this.monthTime = 60
                        if (!this.showOrderStatus && !this.pReadon) {
                            this.myNoTchange()
                        }
                    }

                } else {

                    this.radioDis1 = false
                    this.radioDis2 = true
                    this.radioDis3 = true
                    // this.member.createType = '1'
                    this.repair = '1'
                    this.monthTime = 60
                    if (!this.showOrderStatus && !this.pReadon) {
                        this.myNoTchange()
                    }
                }
                this.getServed('')
            } else {
                // this.member.createType = ''
                if (!this.showOrderStatus && !this.pReadon) {
                    this.myNoTchange()
                }
            }
            if (val.i_ispreinstall == 1 || val.i_ispreinstall == null) {
                this.getServed(val)
                // this.currentServer()
                this.valComs = val // 固定套餐
                this.monthTime = 60
            }
            // this.modifycreateType()
        },
        leSelect(e) {
            console.log(e)
            let val = JSON.parse(e.value)
            if (val.i_ispreinstall == 1) {
                this.datas1.splice(0, 1, {
                    name: val.s_name,
                    price: val.i_price,
                    count: ''
                })
            } else {
                this.datas1[0] = {}
            }
        },
        radiosChangelevel(val) { // 单选会员套餐控件 change
            this.leSelect({ value: val })
            this.leChange(val)
            let obj = JSON.parse(val)
            if (obj.s_name && obj.s_name.indexOf('单省版') > -1) { // 商机2.0单省版 规格和地区数字段赋值
                this.member.single = true
                this.member.areaCount = 1
            } else {
                this.member.single = false
                this.member.areaCount = 0
            }
            if (this.firstOpen) {
                this.firstOpen = false
                if (this.member.salesChannel && this.nums !== '' && this.creAuth) {
                    this.$nextTick(() => {
                        this.$refs.casRef.getDictItem(() => {
                            this.$refs.casRef.setDate(this.member.salesChannel)
                        })
                    })
                }
            }
        },
        serChange(val) {// 选择服务
            if (val == 1) {
                this.monthTime = 60
            } else if (val == 2) {
                this.monthTime = this.stopTime
            } else if (val == 3) {
                this.monthTime = 60 - this.stopTime
            }
            this.datas2 = []
            this.initialized()
            this.repair = val
            this.getServed('')
        },
        cycleTime() {
            let curTime = new Date().getTime()
            let cycTime = getDateSub(this.member.beginTime, this.overTime)
            if (this.repair == 2) {
                if (this.member.beginTime * 1000 > curTime) {
                    this.monthTime = cycTime
                    if (this.member.payCycle <= cycTime) {
                        this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
                    } else {
                        this.member.payCycle = ''
                    }
                } else {
                    this.monthTime = this.stopTime
                }
            }
        },
        peChange() {// 有效周期
            let arr2 = []
            if (this.nums == 0) {
                this.sumSel.forEach(v => {
                    // if (v.id != 1) {
                    arr2.push(v.id)
                    // }
                })
                if (arr2.length != 0) {
                    this.moneyFunc(this.valComs)// 大会员订单价格
                } else {
                    this.member.bigMoney = 0
                }
                if (this.repair == '3') {
                    this.moneyFunc(this.valComs)// 大会员订单价格
                }
            } else {
                this.moneyFunc(this.valComs)// 大会员订单价格
            }
            this.packsPrice() // 补充包价格
        },
        cycleHandler() {// 有效周期
            if (this.member.cycleType == '0') {//选择月保持原有逻辑
                if (this.nums == 0) {
                    if (this.repair == 1) {
                        if (this.member.payCycle <= 60) {
                            this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
                        } else {
                            this.member.payCycle = ''
                        }
                    } else if (this.repair == 2) {
                        if (this.member.payCycle <= this.stopTime) {
                            this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
                        } else {
                            this.member.payCycle = ''
                        }
                        this.cycleTime()
                    } else if (this.repair == 3) {
                        if (this.member.payCycle <= 60 - this.stopTime) {
                            this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
                        } else {
                            this.member.payCycle = ''
                        }
                    }
                } else {
                    if (this.member.payCycle <= 60) {
                        this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
                    } else {
                        this.member.payCycle = ''
                    }
                }

            } else {//选择天只过滤字母
                this.member.payCycle = this.member.payCycle.replace(/[^\d]+/g, '')
            }

            if (!this.member.payCycle) {
                this.member.bigMoney = 0
            }
        },
        timeReg(val) {
            return new Date(dateFormatter(val, 'yyyy-MM-dd') + ' 00:00:00').getTime() / 1000
        },
        moneyChange(num) {
            if (num == 0) {
                if (this.member.products != '1') {
                    this.shiDis = true
                    this.member.payMoney = ''
                } else {
                    this.allDis = true
                }
            } else {
                if (this.member.products != '1') {
                    this.shiDis = false
                } else {
                    this.allDis = false
                }
            }
            if (this.member.bigMoney == 0 || this.allDis) {
                this.bigDis = true
                this.member.bigPayMoney = ''
            } else {
                this.bigDis = false
            }
            if (this.member.paySub == '' || this.allDis) {
                this.subDis = true
                this.member.subPayMoney = ''
            } else {
                this.subDis = false
            }
            if (this.member.supplyMoney == 0 || this.allDis) {
                this.supplyDis = true
                this.member.supplyPayMoney = ''
            } else {
                this.supplyDis = false
            }
        },
        startDate(val) {
            if (this.pReadon) {
                this.$nextTick(() => {
                    if (this.$refs.sigleRef1 !== undefined) {
                        this.$refs.sigleRef1.dataVals = '2099-01-01'
                        this.member.beginTime = this.timeReg('2099-01-01')
                    }
                })
            } else {
                if (val) {
                    this.member.beginTime = this.timeReg(val)
                } else {
                    this.member.beginTime = ''
                }
                this.cycleTime()
            }
        },
        orderDate(val) {
            this.member.createTime = val
        },
        agreeDate(val) {
            this.member.agreementTime = val
            this.keyupformat('paybackWorkDayNum')
        },
        agreementStatusChange() {
            this.keyupformat('paybackWorkDayNum')
        },
        noTchange(val) {
            if (val) {
                this.noPass = true
                this.$refs.sigleRef1.dataVals = '2099-01-01'
                this.member.beginTime = this.timeReg('2099-01-01')
            } else {
                this.$refs.sigleRef1.dataVals = ''
                this.member.beginTime = ''
                this.member.paybackOpenServer = false // 不勾选暂不开通 回款自动开通默认不勾选
            }
        },
        myNoTchange() {
            this.$nextTick(() => {
                this.noPass = true
                if (this.$refs.sigleRef1 !== undefined) {
                    this.$refs.sigleRef1.dataVals = '2099-01-01'
                    this.member.beginTime = this.timeReg('2099-01-01')
                }
            })
        },
        payBlur() {
            if (this.member.paySub) {
                this.datas1.splice(1, 1, {
                    name: '子账号',
                    price: 2000,
                    count: this.member.paySub
                })
            }
        },
        payHandler() {// 子账号金额
            this.member.paySub = this.member.paySub.replace(/[^\d]+/g, '')
        },
        payChange() {
            if (this.member.buyCount) { // 子账号数量 为购买数量-1 主账号1个
                this.member.paySub = this.member.buyCount - 1
            }
            if (this.creAuth == 2) { // 子账号
                // this.member.orderMoney = parseInt(this.member.paySub==''?0:this.member.paySub) * 2000
            }
            // this.member.subMoney = parseInt(this.member.paySub==''?0:this.member.paySub) * 2000
            if (!this.member.paySub || this.allDis) {
                this.subDis = true
                this.member.subPayMoney = ''
            } else {
                this.subDis = false
            }
            this.allSum() // 总计
        },
        freeHandler() {
            this.member.freeSub = this.member.freeSub.replace(/[^\d]+/g, '')
        },
        buyHandler() {
            this.member.buyCount = this.member.buyCount.replace(/[^\d]+/g, '')
        },
        contractFile(val) {
            this.member.contractUrl = val
        },
        fixedNum(val) {
            return val ? Number(parseFloat(val * 100).toFixed(0)) : 0
        },
        saleDate(val) {
            this.member.sale_time = val + ' 00:00:00'
        },
        guiDate(val) {
            this.member.contract_archive_time = val + ' 00:00:00'
        },
        salePerson(val) {
            this.member.salesPerson = val
            let saleNameArr = []
            val.forEach(v => {
                let vjson = JSON.parse(v)
                saleNameArr.push({ name: vjson.username, money: 0 })
            })
            saleNameArr.push({ name: '合计' })
            this.saleTableData = saleNameArr
            this.updateSaleMoney()
        },
        urlReq(url, obj) {
            this.isDisable = true
            this.$request(url).data(
                obj
            ).success(() => {
                this.bShow = false
                if (obj.save === '1') {
                    this.$Message.success({ content: '提交成功' })
                } else if (obj.save === '2') {
                    this.$Message.success({ content: '暂存成功' })
                }
                // this.$Message.success({content: '提交成功'})
                this.$parent.reload()
                setTimeout(() => {
                    this.isDisable = false
                }, 1000)
            }).error(() => {
                this.isDisable = false
            }).post()
        },
        ordConfirm(params) { //提交
            console.log(params)
            if (!this.member.salesChannel || this.member.salesChannel == undefined || this.member.salesChannel == 'undefined') {
                this.$Notice.warning({ title: '请选择销售渠道' })
                return
            }
            if (this.member.buySubject == '') {
                this.$Notice.warning({ title: '请选择购买主体' })
                return
            }
            if (!this.saleCode) {
                this.$Notice.warning({ title: '请选择业绩归属部门' })
                return
            }
            if (!this.member.payType) {
                this.$Notice.warning({ title: '请选择约定支付方式' })
                return
            }
            if (this.member.phone == '') {
                this.$Notice.warning({ title: '请输入手机号' })
                return
            }
            if (this.member.phone && !this.noPhone && !/^1[3456789]\d{9}$/.test(this.member.phone)) {
                this.$Notice.warning({ title: '手机号格式不正确' })
                return
            }
            if (this.member.products == '') {
                this.$Notice.warning({ title: '请选择产品类型' })
                return
            }
            if (!this.member.paybackCompany) {
                this.$Notice.warning({ title: '请选择签约主体' })
                return
            }
            // if(this.member.billingMode  !== 0 && this.member.billingMode  !== 1){
            //   this.$Notice.warning({title: '请选择计费模式'})
            //   return
            // }
            if (this.showOnlineContractForm) {
                // 如购买主体或甲方类型为“企业”，则公司名称必填
                const entMark = this.member.buySubject == '2' || this.member.e_contract_userA_type == 2
                if (entMark && !this.member.companyName) {
                    this.$Notice.warning({ title: '公司名称必填' })
                    return
                }
                if (!this.member.e_contract_type) {
                    this.$Notice.warning({ title: '电子协议类型必填' })
                    return
                }
                // if (!this.member.e_contract_userA_type) {
                //     this.$Notice.warning({title: '协议甲方类型必填'})
                //     return
                // }
                // if (!this.member.e_contract_userA_name) {
                //     this.$Notice.warning({title: '协议甲方必填'})
                //     return
                // }
                // if (!this.member.e_contract_userA_contacts_name) {
                //     this.$Notice.warning({title: '协议甲方联系人必填'})
                //     return
                // }
                // if (!this.member.e_contract_userA_contacts_tel) {
                //     this.$Notice.warning({title: '协议甲方联系方式必填'})
                //     return
                // }
                // if (!this.member.e_contract_userA_contacts_address) {
                //     this.$Notice.warning({title: '协议甲方联系地址必填'})
                //     return
                // }
                if (!this.member.e_contract_userB_contacts_name) {
                    this.$Notice.warning({ title: '协议乙方联系人必填' })
                    return
                }
            }
            if (this.member.buySubject == '2') {
                if (this.member.buyCount == '') {
                    this.$Notice.warning({ title: '请输入购买数量' })
                    return
                }
                if (this.member.buyCount <= 0) {
                    this.$Notice.warning({ title: '请输入大于0的数量' })
                    return
                }
            }

            if (this.member.paybackNum == '') {
                this.$Notice.warning({ title: '请输入回款次数' })
                return
            }
            console.log(this.paybackTableData)
            if (this.member.paybackNum > 1 && !this.paybackTableData.every(item => item.time && item.money)) {
                this.$Notice.warning({ title: '请填写完整回款计划' })
                return
            }
            if (this.member.paybackNum == 1 && !this.member.paybackExpectDate) {
                this.$Notice.warning({ title: '请输入回款计划工作日' })
                return
            }
            if (this.saleTableData) {
                let isOk = true
                this.saleTableData.forEach(v => {
                    if (v.name === '合计') {
                        // let money = Number(this.member.payMoney)+Number(this.member.bigPayMoney)+Number(this.member.subPayMoney)+Number(this.member.supplyPayMoney)-Number(this.member.commission)-Number(this.member.proceduresMoney)
                        let money
                        if (this.member.payMoney) {
                            money = Number(this.member.payMoney) - Number(this.member.commission) - Number(this.member.proceduresMoney)
                        } else {
                            money = Number(this.member.bigPayMoney) + Number(this.member.subPayMoney) + Number(this.member.supplyPayMoney) - Number(this.member.commission) - Number(this.member.proceduresMoney)
                        }
                        if (Number(v.money) > money) {
                            this.$Notice.warning({ title: '业绩金额大于合同金额' })
                            isOk = false
                        }
                    }
                })
                if (!isOk) {
                    return
                }
            }
            let serveData = []
            this.datas2.forEach(v => {
                serveData.push({
                    id: v.id,
                    name: v.name,
                    price: v.price,
                    count: v.count * v.s_pkcount
                })
            })
            // 服务列表参数处理
            let saleNameArr = []
            let saleIdArr = []
            this.member.salesPerson.forEach(v => {
                let vjson = JSON.parse(v)
                saleNameArr.push(vjson.username)
                saleIdArr.push(vjson.id)
            })
            let saleName = saleNameArr.join(',')
            let saleId = saleIdArr.join(',')
            // 回款列表参数处理
            this.member.paybackList = this.paybackTableData
            // 提交集合部分
            if (this.proNums == 1) {// 大会员
                if (this.nums == 0) {
                    this.getserveIdAndname()
                    var serId = this.form_serve.ids
                    var serName = this.form_serve.names
                }
                // 服务ID获取旧逻辑
                // if (this.nums == 0) {
                //     if (this.sumSel.length == 0) {
                //         if (this.sArr.length == 0) {
                //             // return
                //         } else {
                //             this.sArr.forEach(j => {
                //                 serId.push(j.id)
                //                 serName.push(j.s_name)
                //             })
                //         }
                //     } else {
                //         this.sumSel.forEach(k => {
                //             serId.push(k.id)
                //             serName.push(k.s_name)
                //         })
                //     }
                // }
                // 服务ID获取旧逻辑 结束

                if (!this.member.payMoney) { // 合同金额为0 则计费模式置为免费
                    this.member.billingMode = 0
                } else {
                    this.member.billingMode = 1
                }
                // 会员套餐参数处理
                let newlevel = ''
                if (this.member.single) {
                    newlevel = 6
                } else {
                    newlevel = JSON.parse(this.member.level).id ? JSON.parse(this.member.level).id : 5// 5自定义
                }
                let obj = {
                    ...params,
                    contract_nature: this.member.contract_nature,
                    createTime: this.member.createTime,
                    phone: this.member.phone,
                    buySubject: this.member.buySubject,//主体
                    buyCount: this.member.buyCount,//购买数量
                    products: '',// 产品类型不需要传（传空）
                    billingMode: this.member.billingMode === '' ? 999 : this.member.billingMode,
                    level: newlevel,
                    // this.nums == 1 ? JSON.parse(this.member.level).id : 5,
                    payCycle: this.member.payCycle,
                    cycleType: this.member.cycleType,
                    startTime: this.member.createType == 2 || this.member.createType == 3 ? '' : this.member.beginTime,
                    paySub: this.member.paySub,
                    freeSub: this.member.freeSub,
                    bigMoney: this.fixedNum(this.member.bigMoney),
                    subMoney: this.fixedNum(this.member.subMoney),
                    supplyMoney: this.fixedNum(this.member.supplyMoney),
                    orderMoney: this.fixedNum(this.member.orderMoney),
                    contractUrl: this.member.contractUrl,
                    isAll: this.isAll ? 1 : this.member.contractUrl ? 3 : 2,
                    bigPayMoney: this.member.billingMode == 0 ? 0 : this.fixedNum(this.member.bigPayMoney),
                    subPayMoney: this.member.billingMode == 0 ? 0 : this.fixedNum(this.member.subPayMoney),
                    supplyPayMoney: this.member.billingMode == 0 ? 0 : this.fixedNum(this.member.supplyPayMoney),
                    payMoney: this.fixedNum(this.member.payMoney),
                    createType: this.member.createType,
                    // this.nums == 0 ? this.member.createType : '1',
                    comboId: this.member.single ? 6 : this.combo_id.id,
                    serversId: this.nums == 0 ? String(serId) : '',
                    serversName: this.nums == 0 ? String(serName) : '',
                    serversArr: serveData,
                    commission: this.fixedNum(this.member.commission),
                    proceduresMoney: this.fixedNum(this.member.proceduresMoney),
                    companyName: this.member.companyName,
                    agreementStatus: this.member.agreementStatus == '0' || this.member.agreementStatus == '1' ? this.member.agreementStatus : 999,
                    agreementTime: this.member.agreementStatus !== 0 ? this.timeReg(this.member.agreementTime) : '',
                    agreementNumber: this.member.agreementStatus !== '' ? this.member.agreementNumber : '',
                    salesChannel: this.member.salesChannel,
                    orderChannel: this.member.orderChannel ? this.member.orderChannel : 'd01',
                    paybackCompany: this.member.paybackCompany ? this.member.paybackCompany : 'h01',
                    remark: this.member.remark,
                    order_status: this.member.order_status,
                    sale_time: this.member.sale_time,
                    contract_archive_status: this.member.agreementStatus == '1' ? this.member.contract_archive_status : '',
                    contract_archive_time: this.member.agreementStatus == '1' ? this.member.contract_archive_time : '',
                    contract_archive_num: this.member.agreementStatus == '1' ? this.member.contract_archive_num : '',
                    areaCount: this.member.areaCount,
                    salesPerson: saleName,
                    salesPersonId: saleId,
                    saleDep: this.saleCode,
                    payType: this.member.payType,
                    saleMoney: JSON.stringify({ data: this.saleTableData }),
                    // 电子协议相关
                    e_contract_type: this.member.e_contract_type, // 电子协议类型
                    e_contract_userA_type: this.member.e_contract_userA_type, // 协议甲方类型
                    e_contract_userA_name: this.member.e_contract_userA_name, // 协议甲方
                    e_contract_userA_contacts_name: this.member.e_contract_userA_contacts_name, // 协议甲方联系人
                    e_contract_userA_contacts_tel: this.member.e_contract_userA_contacts_tel, // 协议甲方联系方式
                    e_contract_userA_contacts_address: this.member.e_contract_userA_contacts_address, // 协议甲方联系地址
                    e_contract_userB_contacts_name: this.member.e_contract_userB_contacts_name, // 协议乙方联系人
                    e_contract_remark: this.member.e_contract_remark, // 协议备注
                    paybackExpectDate: this.member.paybackNum == 1 ? this.member.paybackExpectDate : "", // 回款日期
                    paybackWorkDayNum: this.member.paybackNum == 1 ? this.member.paybackWorkDayNum : "", // 回款天数
                    paybackOpenServer: this.member.paybackOpenServer, // 回款开通服务  
                    paybackNum: this.member.paybackNum, // 回款次数 
                    paybackList: this.member.paybackNum > 1 ? JSON.stringify(this.member.paybackList) : '', // 回款列表
                    oldSerName: this.buyserveName || ''
                }
                if (this.showOrderStatus) {
                    this.urlReq('/order/createBigOrder', obj)
                } else {
                    this.urlReq('/order/myCreateBigOrder', obj)
                }
            } else if (this.proNums == 2) {// 子账号
                let obj = {
                    ...params,
                    entId: this.member.entId,
                    contactOrderCode: this.member.contactOrderCode || '',
                    contract_nature: this.member.contract_nature,
                    createTime: this.member.createTime,
                    phone: this.member.phone,
                    products: '',// 产品类型不需要传（传空）
                    buySubject: this.member.buySubject,//主体
                    buyCount: this.member.buyCount,//购买数量
                    billingMode: this.member.billingMode === '' ? 999 : this.member.billingMode,
                    paySub: this.member.paySub,
                    freeSub: this.member.freeSub,
                    orderMoney: this.fixedNum(this.member.orderMoney),
                    contractUrl: this.member.contractUrl,
                    isAll: this.isAll ? 1 : this.member.contractUrl ? 3 : 2,
                    payMoney: this.fixedNum(this.member.payMoney),
                    commission: this.fixedNum(this.member.commission),
                    proceduresMoney: this.fixedNum(this.member.proceduresMoney),
                    companyName: this.member.companyName,
                    agreementStatus: this.member.agreementStatus == '0' || this.member.agreementStatus == '1' ? this.member.agreementStatus : 999,
                    agreementTime: this.member.agreementStatus !== '' ? this.timeReg(this.member.agreementTime) : '',
                    agreementNumber: this.member.agreementStatus !== '' ? this.member.agreementNumber : '',
                    salesChannel: this.member.salesChannel,
                    orderChannel: this.member.orderChannel ? this.member.orderChannel : 'd01',
                    paybackCompany: this.member.paybackCompany ? this.member.paybackCompany : 'h01',
                    remark: this.member.remark,
                    order_status: this.member.order_status,
                    sale_time: this.member.sale_time,
                    contract_archive_status: this.member.agreementStatus == '1' ? this.member.contract_archive_status : '',
                    contract_archive_time: this.member.agreementStatus == '1' ? this.member.contract_archive_time : '',
                    contract_archive_num: this.member.agreementStatus == '1' ? this.member.contract_archive_num : '',
                    salesPerson: saleName,
                    salesPersonId: saleId,
                    saleDep: this.saleCode,
                    payType: this.member.payType,
                    saleMoney: JSON.stringify({ data: this.saleTableData }),
                    paybackExpectDate: this.member.paybackNum == 1 ? this.member.paybackExpectDate : "", // 回款日期
                    paybackWorkDayNum: this.member.paybackNum == 1 ? this.member.paybackWorkDayNum : "", // 回款天数
                    paybackOpenServer: this.member.paybackOpenServer, // 回款开通服务  
                    paybackNum: this.member.paybackNum, // 回款次数 
                    paybackList: this.member.paybackNum > 1 ? JSON.stringify(this.member.paybackList) : '', // 回款列表
                }
                if (!this.member.contactOrderCode) {
                    this.$Notice.warning({ title: '请选择关联订单' })
                    return
                }

                if (this.showOrderStatus) {
                    this.urlReq('/order/createSubOrder', obj)
                } else {
                    this.urlReq('/order/myCreateSubOrder', obj)
                }
            } else if (this.proNums == 3) {// 补充包
                let obj = {
                    ...params,
                    contract_nature: this.member.contract_nature,
                    createTime: this.member.createTime,
                    phone: this.member.phone,
                    products: '',// 产品类型不需要传（传空）
                    billingMode: this.member.billingMode === '' ? 999 : this.member.billingMode,
                    serversArr: serveData,
                    orderMoney: this.fixedNum(this.member.orderMoney),
                    buySubject: this.member.buySubject,//主体
                    buyCount: this.member.buyCount,//购买数量
                    contractUrl: this.member.contractUrl,
                    isAll: this.isAll ? 1 : this.member.contractUrl ? 3 : 2,
                    payMoney: this.fixedNum(this.member.payMoney),
                    commission: this.fixedNum(this.member.commission),
                    proceduresMoney: this.fixedNum(this.member.proceduresMoney),
                    companyName: this.member.companyName,
                    agreementStatus: this.member.agreementStatus == '0' || this.member.agreementStatus == '1' ? this.member.agreementStatus : 999,
                    agreementTime: this.member.agreementStatus !== '' ? this.timeReg(this.member.agreementTime) : '',
                    agreementNumber: this.member.agreementStatus !== '' ? this.member.agreementNumber : '',
                    salesChannel: this.member.salesChannel,
                    orderChannel: this.member.orderChannel ? this.member.orderChannel : 'd01',
                    paybackCompany: this.member.paybackCompany ? this.member.paybackCompany : 'h01',
                    remark: this.member.remark,
                    order_status: this.member.order_status,
                    sale_time: this.member.sale_time,
                    contract_archive_status: this.member.agreementStatus == '1' ? this.member.contract_archive_status : '',
                    contract_archive_time: this.member.agreementStatus == '1' ? this.member.contract_archive_time : '',
                    contract_archive_num: this.member.agreementStatus == '1' ? this.member.contract_archive_num : '',
                    salesPerson: saleName,
                    salesPersonId: saleId,
                    saleDep: this.saleCode,
                    payType: this.member.payType,
                    saleMoney: JSON.stringify({ data: this.saleTableData }),
                    paybackExpectDate: this.member.paybackNum == 1 ? this.member.paybackExpectDate : "", // 回款日期
                    paybackWorkDayNum: this.member.paybackNum == 1 ? this.member.paybackWorkDayNum : "", // 回款天数
                    paybackOpenServer: this.member.paybackOpenServer, // 回款开通服务  
                    paybackNum: this.member.paybackNum, // 回款次数 
                    paybackList: this.member.paybackNum > 1 ? JSON.stringify(this.member.paybackList) : '', // 回款列表
                }
                if (this.showOrderStatus) {
                    this.urlReq('/order/createSupplyOrder', obj)
                } else {
                    this.urlReq('/order/myCreateSupplyOrder', obj)
                }
            }
        },
        ordCancel() {
            // this.$refs.casRef.values = []
            this.member.saleCodeModel = []
            this.saleTableData = []
            this.bShow = false
        },
        visibleChange(val) {  // 调起弹窗
            if (val == false) {
                setTimeout(() => {
                    // 初始回款次数
                    this.member.paybackNum = 1
                    this.showXieYi = false
                    this.colr = ''
                    this.creAuth = ''
                    // 产品类型类型初始为大会员
                    this.member.products = '1'
                    this.member.contract_nature = '1'
                    this.member.phone = ''
                    //this.member.salesPerson = ''
                    this.member.billingMode = ''
                    this.member.level = ''
                    // this.member.createType = ''
                    this.member.order_status = '1'
                    this.member.buySubject = ''
                    this.member.buyCount = ''
                    this.nums = ''
                    this.serData = []
                    this.member.saleCodeModel = []
                    this.saleTableData = []
                    this.spinShow = false
                    this.noPhone = false
                    this.noPass = false
                    this.pReadon = false
                    this.member.salesChannel = ''
                    this.member.orderChannel = 'd01'
                    this.member.paybackCompany = 'h01'
                    //this.$refs.saleRef.salePerson = ''
                    // this.$refs.casRef.values = []
                    let sigs2 = this.$refs.sigleRef2
                    let sigs3 = this.$refs.casRef1
                    let sigs4 = this.$refs.casRef2
                    if (sigs2) {
                        this.$refs.sigleRef2.initd()
                    }
                    if (sigs3) {
                        this.$refs.casRef1.values = ['d01']
                    }
                    if (sigs4) {
                        this.$refs.casRef2.values = ['h01']
                    }
                    this.initialized()
                }, 500)
            } else {
                this.firstOpen = true
                this.creAuth = ''
                this.isDisable = false
                //业绩部门
                this.saleDepClick()
                setTimeout(() => {
                    if (this.$refs.saleRef) {
                        this.$refs.saleRef.setDefaultPerson = this.$store.getters.getAdminUser.username
                        this.$refs.saleRef.personData()
                    }
                }, 1000)
                // 产品类型类型初始为大会员 获取套餐信息
                this.member.products = '1'
                this.proChange(this.member.products)
                this.getNewservedata()

            }
        },
        areaCountClick(val) { // 处理单省版 radio 选中后取消
            if (this.member.single) {
                this.member.single = false
                this.member.areaCount = 0
            } else {
                this.member.single = true
                this.member.areaCount = val
            }

        },
        packsPrice() {// 补充包总价
            let strs1 = 0, strs2 = 0
            this.datas2.forEach(v => {
                if (v.id == 11 || v.id == 15) {
                    strs1 += v.price * v.count
                } else if (v.id == 14 || v.id == 16) {
                    if (this.repair == 1) {
                        strs2 += v.price / 12 * v.count * parseInt(this.member.payCycle ? this.member.payCycle : 0)
                    } else if (this.repair == 2) {
                        let strNums = 0
                        if (v.id == 14) {
                            if (this.currentId.indexOf(v.id) > -1) {
                                strNums = v.price / 12 * v.count * this.stopTime
                            } else {
                                strNums = v.price / 12 * v.count * parseInt(this.member.payCycle ? this.member.payCycle : 0)
                            }
                        } else {
                            if (this.currentId.indexOf(12) > -1 && this.currentId.indexOf(13) > -1) {
                                strNums = v.price / 12 * v.count * this.stopTime
                            } else {
                                strNums = v.price / 12 * v.count * parseInt(this.member.payCycle ? this.member.payCycle : 0)
                            }
                        }
                        strs2 += strNums
                    } else if (this.repair == 3) {
                        strs2 += v.price / 12 * v.count * (this.stopTime + parseInt(this.member.payCycle ? this.member.payCycle : 0))
                    }
                } else {
                    strs1 += v.price * v.count
                }
            })
            this.member.supplyMoney = parseInt(strs1) + parseInt(strs2)
            if (this.member.supplyMoney == 0 || this.allDis) {
                this.supplyDis = true
                this.member.supplyPayMoney = ''
            } else {
                this.supplyDis = false
            }
            // this.member.orderMoney = this.member.supplyPayMoney 
        },
        ordFunc() {// 订单金额
            let strs1 = 0, strs2 = 0
            this.datas2.forEach(v => {
                if (v.id == 11 || v.id == 15) {
                    strs1 += parseInt(v.price) * v.count
                } else if (v.id == 14 || v.id == 16) {
                    strs2 += parseInt(v.price) / 12 * v.count * this.stopTime
                }
            })
            // this.member.orderMoney = parseInt(strs1) + parseInt(strs2)
        },
        // 旧服务列表相关
        getServed(val) {
            this.serData = []
            this.pacData = []
            const resList = []
            this.resArr1 = []
            this.resArr2 = []
            this.resArr3 = []
            this.resArr4 = []
            this.resArr5 = []
            this.resArr6 = []
            this.$request('/order/getServer').data().success((res) => {// 获取自定义套餐所有服务选项
                this.servedData = res.data.lists
                res.data.lists.forEach(v => {
                    if (v.i_isserver == 1) {
                        if (this.repair == '1') {
                            if (v.id == 17 || v.id == 18) {
                                this.resArr1.push(v)
                            } else if (v.id == 4 || v.id == 19) {
                                this.resArr2.push(v)
                            } else if (v.id == 20 || v.id == 23) {
                                this.resArr3.push(v)
                            } else if (v.id == 13 || v.id == 21) {
                                this.resArr4.push(v)
                            } else if (v.id == 14 || v.id == 22) {
                                this.resArr5.push(v)
                            } else if (v.id == 24 || v.id == 25) {
                                this.resArr6.push(v)
                            } else {
                                if (v.id !== 12) {
                                    resList.push(v)
                                }
                            }
                        }
                        if (this.repair == '2') {
                            if (v.id == 17 || v.id == 18) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(1, 0, v)
                                } else {
                                    this.resArr1.push(v)
                                }
                            } else if (v.id == 4 || v.id == 19) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(4, 0, v)
                                } else {
                                    this.resArr2.push(v)
                                }
                            } else if (v.id == 20 || v.id == 23) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(14, 0, v)
                                } else {
                                    this.resArr3.push(v)
                                }
                            } else if (v.id == 13 || v.id == 21) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(16, 0, v)
                                } else {
                                    this.resArr4.push(v)
                                }
                            } else if (v.id == 14 || v.id == 22) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(18, 0, v)
                                } else {
                                    this.resArr5.push(v)
                                }
                            } else if (v.id == 24 || v.id == 25) {
                                if (this.currentId.indexOf(v.id) > -1) {
                                    resList.splice(20, 0, v)
                                } else {
                                    this.resArr6.push(v)
                                }
                            } else {
                                if (v.id !== 12) {
                                    resList.push(v)
                                }
                            }
                        }
                        if (this.repair == '3') {
                            if (v.id !== 12) {
                                resList.push(v)
                            }
                        }
                    }
                    if (v.i_ispackage == 1) {
                        this.pacData.push(v)
                    }
                })
                let arr1 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9119,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                let arr2 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9120,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                let arr3 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9121,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                let arr4 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9122,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                let arr5 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9123,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                let arr6 = {
                    i_ispackage: 0,
                    i_isserver: 1,
                    i_pkprice: null,
                    i_price_month: null,
                    i_price_year: null,
                    s_count_year: null,
                    id: 9124,
                    s_name: '',
                    s_pkcount: null,
                    _checked: false
                }
                if (this.repair == '1') {
                    resList.splice(1, 0, arr1)
                    resList.splice(3, 0, arr2)
                    resList.splice(13, 0, arr3)
                    resList.splice(14, 0, arr4)
                    resList.splice(15, 0, arr5)
                    resList.splice(17, 0, arr6)
                } else if (this.repair == '2') {
                    if (!(this.currentId.indexOf(17) > -1) && !(this.currentId.indexOf(18) > -1)) {
                        resList.splice(1, 0, arr1)
                    }
                    if (!(this.currentId.indexOf(4) > -1) && !(this.currentId.indexOf(19) > -1)) {
                        resList.splice(3, 0, arr2)
                    }
                    if (!(this.currentId.indexOf(20) > -1) && !(this.currentId.indexOf(23) > -1)) {
                        resList.splice(13, 0, arr3)
                    }
                    if (!(this.currentId.indexOf(13) > -1) && !(this.currentId.indexOf(21) > -1)) {
                        resList.splice(14, 0, arr4)
                    }
                    if (!(this.currentId.indexOf(14) > -1) && !(this.currentId.indexOf(22) > -1)) {
                        resList.splice(15, 0, arr5)
                    }
                    if (!(this.currentId.indexOf(24) > -1) && !(this.currentId.indexOf(25) > -1)) {
                        resList.splice(18, 0, arr6)
                    }
                }
                this.serData = resList
                if (val) {
                    this.checkedDis2(val)
                } else {
                    this.checkedDis1()
                }
            }).get()
        },
        checkedDis1() {// 服务列表选中已享有服务
            this.serData.forEach(k => {
                if (this.repair == '1') {
                    if (k.id == 1) {
                        k._checked = true
                        k._disabled = true
                        this.sumSel.push(k)
                    }
                } else if (this.repair == 2) {
                    if (this.currentId.indexOf(k.id) > -1) {
                        k._checked = true
                        k._disabled = true
                    }
                } else if (this.repair == '3') {
                    if (this.currentId.indexOf(k.id) > -1) {
                        k._checked = true
                        k._disabled = true
                    } else {
                        k._disabled = true
                    }
                }
            })
            this.pacData.forEach(j => {
                if (this.currentId.indexOf(j.id) > -1) {
                    j._rowDis = false
                } else {
                    if (j.id == 16) {
                        if (this.currentId.indexOf(12) > -1 && this.currentId.indexOf(13) > -1 || this.currentId.indexOf(23) > -1 && this.currentId.indexOf(13) > -1 || this.currentId.indexOf(20) > -1 && this.currentId.indexOf(21) > -1) {
                            j._rowDis = false
                        } else {
                            j._rowDis = true
                        }
                    } else {
                        if (this.currentId.indexOf(j.id) > -1) {
                            j._rowDis = false
                        } else {
                            j._rowDis = true
                        }
                    }
                }
            })
        },
        checkedDis2(val) {
            this.pacData.forEach(v => {
                if (v.id == 16) {
                    if (val.s_servers.indexOf(12) > -1 && val.s_servers.indexOf(13) > -1 || val.s_servers.indexOf(23) > -1 && val.s_servers.indexOf(13) > -1 || val.s_servers.indexOf(20) > -1 && val.s_servers.indexOf(21) > -1) {
                        v._rowDis = false
                    } else {
                        v._rowDis = true
                    }
                } else {
                    if (val.s_servers.indexOf(v.id) > -1) {
                        v._rowDis = false
                    } else {
                        v._rowDis = true
                    }
                }
            })
        },
        // 合计
        handleSummary({ columns, data }) {
            const sums = {}
            columns.forEach((column, index) => {
                const key = column.key
                if (index === 0) {
                    sums[key] = {
                        key,
                        value: '合计'
                    }
                    return
                }
                let values = []
                if (this.repair == 3) {
                    this.sArr = []
                    data.forEach(v => {
                        if (v._checked) {
                            this.sArr.push(v)
                        }
                    })
                    values = this.sArr.map(item => Number(item[key]))
                } else {
                    values = this.sumSel.map(item => Number(item[key]))
                }
                if (!values.every(value => isNaN(value))) {
                    const v = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0)
                    sums[key] = {
                        key,
                        value: v
                    }
                    // this.sPrice = sums.i_price_year.value
                    if (this.nums == 0) {
                        let arr2 = []
                        this.sumSel.forEach(v => {
                            if (v.id != 1) {
                                arr2.push(v.id)
                            }
                        })
                        if (arr2.length != 0) {
                            this.moneyFunc()// 大会员订单价格
                        }
                        if (this.repair == '2') {
                            this.member.payCycle = getDateSub('', this.overTime)
                            this.moneyFunc(this.valComs)// 大会员订单价格
                        }
                        if (this.repair == '3') {
                            this.moneyFunc(this.valComs)// 大会员订单价格
                        }
                    } else {
                        if (this.member.payCycle) {
                            this.moneyFunc()// 大会员订单价格
                        }
                    }
                } else {
                    if (key == 's_name') {
                        sums[key] = {
                            key,
                            value: '-'
                        }
                    } else {
                        sums[key] = {
                            key,
                            value: 0
                        }
                    }
                }
            })
            return sums;
        },
        // 多选
        selChage(selection) {
            const arrs = [], arrs1 = [], strItems = []
            this.selData = selection
            selection.map(v => {
                arrs1.push(v.id)
                if (this.repair == '1') {
                    if (v.id !== 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                        arrs.push(v)
                    }
                } else {
                    if (!v._disabled) {
                        arrs.push(v)
                    }
                }
                if (v.id == 9119) {
                    strItems.splice(1, 0, this.strItems1)
                } else if (v.id == 9120) {
                    strItems.splice(1, 0, this.strItems2)
                } else if (v.id == 9121) {
                    strItems.splice(1, 0, this.strItems3)
                } else if (v.id == 9122) {
                    strItems.splice(1, 0, this.strItems4)
                } else if (v.id == 9123) {
                    strItems.splice(1, 0, this.strItems5)
                } else if (v.id == 9124) {
                    strItems.splice(1, 0, this.strItems6)
                }
            })
            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                this.sumSel = arrs.concat(strItems)
            } else {
                this.sumSel = arrs
            }
            if (this.sumSel.length == 0) {
                this.member.bigMoney = 0
                this.allSum()
            }
            this.moneyFunc(this.valComs)// 大会员订单价格
        },
        allChange() {// 选择全选
            this.pacData.forEach((t, i) => {
                document.getElementById('counts' + i).disabled = false
            })
        },
        allCancel() {// 取消全选
            this.pacData.forEach((t, i) => {
                if (t.id == 16) {
                    if (this.currentId.indexOf(12) > -1 && this.currentId.indexOf(13) > -1) {
                        document.getElementById('counts' + i).disabled = false
                    } else {
                        document.getElementById('counts' + i).disabled = true
                    }
                } else {
                    if (this.currentId.indexOf(t.id) > -1) {
                        document.getElementById('counts' + i).disabled = false
                    } else {
                        document.getElementById('counts' + i).disabled = true
                    }
                }
                document.getElementById('counts' + i).value = ''
                this.datas2.forEach((k, index) => {
                    this.datas2[index].count = 0
                    this.datas2.splice(index, 1)
                    this.packsPrice()
                })
            })
        },
        curChange(selection, row) {// 选择单个
            let arr1 = []
            selection.forEach(l => {
                arr1.push(l.id)
            })
            if (arr1.indexOf(11) > -1) {
                document.getElementById('counts0').disabled = false
            }
            if (arr1.indexOf(15) > -1) {
                document.getElementById('counts2').disabled = false
            }
            if (arr1.indexOf(9121) > -1 && this.strItems3.id == 20 && arr1.indexOf(9122) > -1 && this.strItems4.id == 21) {
                document.getElementById('counts3').disabled = false
            }
            if (arr1.indexOf(9121) > -1 && this.strItems3.id == 23 && arr1.indexOf(9122) > -1 && this.strItems4.id == 13) {
                document.getElementById('counts3').disabled = false
            }
            if (arr1.indexOf(9123) > -1 && this.strItems5.id == 22) {
                document.getElementById('counts4').disabled = false
            }
            if (arr1.indexOf(9123) > -1 && this.strItems5.id == 14) {
                document.getElementById('counts1').disabled = false
            }
            if (arr1.indexOf(9124) > -1 && this.strItems5.id == 24) {
                document.getElementById('counts4').disabled = false
            }
            if (arr1.indexOf(9124) > -1 && this.strItems5.id == 25) {
                document.getElementById('counts1').disabled = false
            }
        },
        canChange(selection, row) {// 取消单个
            let arr2 = []
            this.pacData.forEach((t, i) => {
                if (row.id == t.id) {
                    document.getElementById('counts' + i).disabled = true
                    document.getElementById('counts' + i).value = ''
                    this.datas2.forEach((k, index) => {
                        if (k.id == row.id) {
                            this.datas2[index].count = 0
                            this.datas2.splice(index, 1)
                            this.packsPrice()
                        }
                    })
                }
            })
            if (selection.length == 0) {
                this.datas2 = []
            }
            selection.forEach(l => {
                arr2.push(l.id)
            })
            if (arr2.indexOf(12) > -1 && arr2.indexOf(13) > -1) {
                document.getElementById('counts3').disabled = false
            } else {
                document.getElementById('counts3').disabled = true
                document.getElementById('counts3').value = ''
            }
            this.allSum()
        },
        allSum() {// 总计
            this.member.sums = this.member.bigMoney + this.member.subMoney + this.member.supplyMoney
        },
        moneyFunc(str) {// 大会员金额
            let sumd1 = 0, sumd2 = 0, sumd3 = 0
            const arrs3 = [], arrs5 = [], arrs6 = [], arrs7 = []
            if (this.repair == '3') {
                this.sumSel = []
                this.serData.map(v => {
                    if (v._checked && v._disabled) {
                        this.sumSel.push(v)
                    }
                })
            }
            if (this.nums == 0) {
                this.sumSel.map(v => {
                    arrs5.push(v.id)
                    if (v.id == 17 || v.id == 18) {
                        arrs3.push(v)
                    } else {
                        arrs6.push(v)
                    }
                })
            } else {
                const sered = str.s_servers.split(',')
                this.servedData.forEach(c => {
                    sered.forEach(r => {
                        if (r == c.id) {
                            arrs7.push(c)
                        }
                    })
                })
                this.nums == 0 ? this.sumSel : arrs7.map(v => {
                    arrs5.push(v.id)
                    if (v.id == 17 || v.id == 18) {
                        arrs3.push(v)
                    } else {
                        arrs6.push(v)
                    }
                })
            }
            if (this.member.payCycle >= 12) {
                if (arrs5.indexOf(17) > -1 || arrs5.indexOf(18) > -1) {
                    const cycles1 = parseInt(this.member.payCycle / 12) // 取整
                    const cycles2 = this.member.payCycle % 12 // 取余
                    arrs3.forEach(p => {
                        if (this.member.payCycle == 12) {
                            sumd3 += parseInt(p.i_price_year * cycles1)
                        } else {
                            sumd1 += parseInt(p.i_price_year * cycles1 + p.i_price_month * cycles2)
                        }
                    })
                }
                arrs6.forEach(p => {
                    sumd2 += parseInt(p.i_price_year / 12 * this.member.payCycle)
                })
            } else {
                if (arrs5.indexOf(17) > -1 || arrs5.indexOf(18) > -1) {
                    arrs3.forEach(p => {
                        sumd1 += parseInt(p.i_price_month * this.member.payCycle)
                    })
                }
                arrs6.forEach(p => {
                    sumd2 += parseInt(p.i_price_year / 10 * this.member.payCycle)
                })
            }
            this.member.bigMoney = sumd1 + sumd2 + sumd3
            if (this.member.bigMoney == 0 || this.allDis) {
                this.bigDis = true
                this.member.bigPayMoney = ''
            } else {
                this.bigDis = false
            }
            this.allSum() // 总计
        },
        //旧服务列表相关结束
    },
    data() {
        return {
            firstOpen: true,
            buyserveName: '',
            serveEndtime: '',
            paybackTable: [
                {
                    title: '序号',
                    slot: 'code'
                },
                {
                    title: '预计回款时间',
                    slot: 'time'
                },
                {
                    title: '预计回款金额（元）',
                    slot: 'money'
                }
            ],
            paybackTableData: [],
            contactOrderList: [],
            contactOrderchoose: {},
            contactOrderColumns: [
                {
                    title: '请选择',
                    align: 'center',
                    key: 'choose',
                    render: (h, params) => {
                        return h('div', [
                            h('Radio', {
                                props: {
                                    value: params.row.choose,
                                    disabled: params.row.disabled
                                },
                                on: {
                                    'on-change': (e) => {
                                        this.contactOrderList.forEach((items) => {      //取消所有对象的勾选，choose设置为false
                                            this.$set(items, 'choose', false)
                                        });
                                        this.contactOrderList[params.index].choose = e;  //将勾选的对象的choose设置为true
                                        this.contactOrderchoose = this.contactOrderList[params.index]
                                        this.member.contactOrderCode = this.contactOrderchoose.order_code
                                        this.member.entId = this.contactOrderchoose.ent_id
                                        console.log(e, this.contactOrderchoose)
                                        this.orderPriceCount()
                                    }
                                }
                            })
                        ])
                    }
                },
                {
                    title: '订单编号',
                    key: 'order_code',
                    align: 'center',
                    render: (h, { row }) => {
                        return h('div', {
                            style: {
                                color: 'rgb(54, 163, 247)',
                                cursor: 'pointer'
                            },
                            on: {
                                click: () => {
                                    const news = this.$router.resolve({
                                        path: '/order/orderList/orderDetail',
                                        query: { id: row.id, proType: '大会员' }
                                    })
                                    window.open(news.href, '_blank')
                                }
                            }
                        }, [
                            h('span', row.order_code)
                        ])
                    }
                },
                {
                    title: '创建时间',
                    key: 'create_time',
                    align: 'center',
                    render: (h, { row }) => {
                        return h('span', dateFormatter(row.create_time * 1000, 'yyyy-MM-dd'))
                    }
                },
                {
                    title: '产品类型',
                    key: 'product_type',
                    align: 'center'
                },
                {
                    title: '到期时间',
                    key: 'vip_endtime',
                    align: 'center',
                    render: (h, { row }) => {
                        return h('span', dateFormatter(row.vip_endtime * 1000, 'yyyy-MM-dd'))
                    }
                },

            ],
            pricetimer: null,
            initbuyCount: '',
            showOrderOther: false,
            showXieYi: false,
            initnewServedata: [], // 初始化自定义服务信息
            form_serve: {},
            newServedata: [],
            i_member_status: '',
            saleCode: '',
            saleDep: [],
            saleTable: [
                {
                    title: '销售人员',
                    slot: 'name'
                },
                {
                    title: '销售业绩（元）',
                    slot: 'money'
                }
            ],
            saleTableData: [],
            comingIntoEffective: false,
            max_length: 2, //默认为月
            serData: [],
            servedData: [],
            pacData: [],
            resArr1: [],
            resArr2: [],
            resArr3: [],
            resArr4: [],
            resArr5: [],
            resArr6: [],
            optionDis1: false,
            optionDis2: false,
            optionDis3: false,
            optionDis4: false,
            optionDis5: false,
            optionDis6: false,
            repair: '1',
            spinShow: false,
            bShow: false,
            downDis: false,
            shiDis: false,
            valComs: {},
            strs1: 0,
            strs2: 0,
            pArr1: [],
            pArr2: [],
            combo_id: {},
            allDis: false,
            bigDis: true,
            subDis: true,
            supplyDis: true,
            sArr: [],
            noPhone: false,
            noPass: false,
            pReadon: false,
            isDisable: false,
            selData: [],
            placed: '请输入有效周期',
            // placed: '请输入有效周期（单位（月），最多输入60个月）',
            member: {
                paybackList: [],
                paybackNum: 1,
                entId: '',
                paybackOpenServer: false,
                contactOrderCode: '',
                paybackExpectDate: '',
                paybackWorkDayNum: '',
                contract_nature: '1', // 合同性质
                phone: '',
                products: '',
                billingMode: '',
                salesPerson: '',
                level: '',
                createType: '1',
                payCycle: '',
                cycleType: '0',
                buyCount: '',
                beginTime: '',
                paySub: '',
                freeSub: '',
                bigMoney: 0,
                subMoney: 0,
                supplyMoney: 0,
                orderMoney: 0,
                sums: 0,
                agreementStatus: '1',
                agreementTime: dateFormatter(new Date(), 'yyyy-MM-dd'),
                agreementNumber: '',
                contractUrl: '',
                payMoney: '',
                bigPayMoney: '',
                subPayMoney: '',
                supplyPayMoney: '',
                commission: '0',
                proceduresMoney: '0',
                companyName: '',
                salesChannel: '',
                orderChannel: 'd01',
                paybackCompany: 'h01',
                remark: '',
                sale_time: dateFormatter(new Date(), 'yyyy-MM-dd') + ' 00:00:00',
                order_status: '1',
                buySubject: '',
                contract_archive_status: '0',
                contract_archive_time: '',
                contract_archive_num: '',
                single: false, // 大会员商机版2.0-单省版 radio 选中状态
                areaCount: '0', // 大会员省份版-省份数量
                payType: '',
                saleCodeModel: [],
                // 电子协议相关
                e_contract_type: 1, // 电子协议类型
                e_contract_userA_type: 1, // 协议甲方类型
                e_contract_userA_name: '', // 协议甲方
                e_contract_userA_contacts_name: '', // 协议甲方联系人
                e_contract_userA_contacts_tel: '', // 协议甲方联系方式
                e_contract_userA_contacts_address: '', // 协议甲方联系地址
                e_contract_userB_contacts_name: '', // 协议乙方联系人
                e_contract_remark: '', // 协议备注
            },
            isAll: false,
            radioDis1: false,
            radioDis2: false,
            radioDis3: false,
            currentId: [],
            sPrice: 0,
            mPrice: 0,
            valNums: 0,
            rowArr: {},
            agreeStatus: [
                { v: '0', n: '不签协议' },
                { v: '1', n: '签协议' }
            ],
            payTypes: [
                { v: 'transferAccounts', n: '对公转账' },
                { v: 'wx', n: '微信' },
                { v: 'ali', n: '支付宝' }
            ],
            unitOptions: [
                { v: '0', n: '月' },
                { v: '1', n: '天' }
            ],
            columns1: [
                {
                    title: '补充包名称',
                    key: 's_name',
                    width: 280,
                    align: 'center',
                    render: (h, { row }) => {
                        return h('span', row.s_name ? row.s_name : '-')
                    }
                },
                {
                    title: '价格',
                    key: 'i_pkprice',
                    width: 130,
                    align: 'center',
                    render: (h, { row }) => {
                        let arr1 = [11, 15]
                        return h('span', row.i_pkprice ? row.s_pkcount ? row.s_pkcount + (arr1.indexOf(row.id) > -1 ? '次/' : '个/') + row.i_pkprice : row.i_pkprice : '-')
                    }
                },
                {
                    title: '购买数量',
                    key: 's_pkcount',
                    align: 'center',
                    render: (h, { row, index }) => {
                        return h('Input', {
                            props: {
                                placeholder: '请输入购买数量',
                                // value: row.s_pkcount,
                                disabled: row._rowDis,
                                elementId: 'counts' + index
                            },
                            on: {
                                'on-change': (event) => {
                                    this.rowArr = row
                                    event.currentTarget.value = event.currentTarget.value.replace(/[^\d]+/g, '')
                                    this.valNums = event.currentTarget.value
                                    if (event.currentTarget.value) {
                                        if (this.datas2.length !== 0) {
                                            var isOk = false;
                                            this.datas2.forEach(v => {
                                                if (row.id == v.id) {
                                                    isOk = true
                                                    v.count = this.valNums
                                                }
                                            })
                                            if (!isOk) {
                                                this.datas2.push({
                                                    id: row.id,
                                                    name: row.s_name,
                                                    price: row.i_pkprice,
                                                    s_pkcount: row.s_pkcount,
                                                    count: this.valNums
                                                })
                                            }
                                        } else {
                                            this.datas2.push({
                                                id: row.id,
                                                name: row.s_name,
                                                price: row.i_pkprice,
                                                s_pkcount: row.s_pkcount,
                                                count: this.valNums
                                            })
                                        }
                                    } else {
                                        this.datas2.forEach((v, i) => {
                                            if (row.id == v.id) {
                                                this.datas2.splice(i, 1)
                                            }
                                        })
                                    }
                                    this.packsPrice()
                                    this.ordFunc()
                                    this.allSum() // 总计
                                    this.orderPriceCount()// 接口计算价格
                                },
                                'on-keyup': (event) => {
                                    event.currentTarget.value = event.currentTarget.value.replace(/[^\d]+/g, '')
                                }
                            }
                        })
                    }
                }
            ],
            datas1: [],
            datas2: [],
            selStr: '',
            strItems1: [],
            strItems2: [],
            strItems3: [],
            strItems4: [],
            strItems5: [],
            strItems6: [],
            value1: '',
            columns2: [
                {
                    title: '金额明细',
                    key: 'name',
                    align: 'center',
                    render: (h, { row }) => {
                        return h('span', row.name ? row.name : '-')
                    }
                },
                {
                    title: '价格',
                    key: 'price',
                    width: 170,
                    align: 'center',
                    render: (h, { row }) => {
                        return h('span', row.price ? row.count ? row.price + '*' + row.count : row.price : '-')
                    }
                }
            ],
            // 服务列表相关
            columns3: [
                {
                    type: 'selection',
                    width: 40,
                    align: 'center'
                },
                {
                    title: '服务名称',
                    key: 's_name',
                    width: 260,
                    align: 'center',
                    render: (h, { row }) => {
                        if (this.repair == '1' || this.repair == '2') {
                            if (row.id == 9119) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择单日限量包',
                                        value: this.selStr,
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems1 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                } else if (v.id == 9124) {
                                                    strItems.splice(1, 0, this.strItems6)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    this.resArr1.map(item => {
                                        return h('Option', {
                                            props: {
                                                value: JSON.stringify(item)
                                            }
                                        }, item.s_name)
                                    })
                                )
                            } else if (row.id == 9120) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择企业全景分析',
                                        value: this.value1,
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            const ids = JSON.parse(val).id
                                            if (ids == 4) {
                                                this.optionDis3 = true
                                                this.optionDis4 = false
                                                this.optionDis5 = true
                                                this.optionDis6 = false
                                            } else if (ids == 19) {
                                                this.optionDis3 = false
                                                this.optionDis4 = true
                                                this.optionDis5 = false
                                                this.optionDis6 = true
                                            }
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems2 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                } else if (v.id == 9124) {
                                                    strItems.splice(1, 0, this.strItems6)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    [
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr2[1]),
                                                disabled: this.optionDis1
                                            }
                                        }, this.resArr2[1].s_name),
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr2[0]),
                                                disabled: this.optionDis2
                                            }
                                        }, this.resArr2[0].s_name)
                                    ]
                                )
                            } else if (row.id == 9121) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择企业情报监控',
                                        value: '',
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            const ids = JSON.parse(val).id
                                            if (ids == 20) {
                                                this.optionDis1 = false
                                                this.optionDis2 = true
                                                this.optionDis5 = false
                                                this.optionDis6 = true
                                            } else if (ids == 23) {
                                                this.optionDis1 = true
                                                this.optionDis2 = false
                                                this.optionDis5 = true
                                                this.optionDis6 = false
                                            }
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems3 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                } else if (v.id == 9124) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    [
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr3[0]),
                                                disabled: this.optionDis3
                                            }
                                        }, this.resArr3[0].s_name),
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr3[1]),
                                                disabled: this.optionDis4
                                            }
                                        }, this.resArr3[1].s_name)
                                    ]
                                )
                            } else if (row.id == 9122) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择企业中标动态',
                                        value: '',
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            const ids = JSON.parse(val).id
                                            if (ids == 21) {
                                                this.optionDis1 = false
                                                this.optionDis2 = true
                                                this.optionDis3 = false
                                                this.optionDis4 = true
                                            } else if (ids == 13) {
                                                this.optionDis1 = true
                                                this.optionDis2 = false
                                                this.optionDis3 = true
                                                this.optionDis4 = false
                                            }
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems4 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                } else if (v.id == 9124) {
                                                    strItems.splice(1, 0, this.strItems6)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    [
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr4[1]),
                                                disabled: this.optionDis5
                                            }
                                        }, this.resArr4[1].s_name),
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr4[0]),
                                                disabled: this.optionDis6
                                            }
                                        }, this.resArr4[0].s_name)
                                    ]
                                )
                            } else if (row.id == 9123) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择项目进度监控',
                                        value: '',
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems5 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    [
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr5[1])
                                            }
                                        }, this.resArr5[1].s_name),
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr5[0])
                                            }
                                        }, this.resArr5[0].s_name)
                                    ]
                                )
                            } else if (row.id == 9124) {
                                return h('Select', {
                                    props: {
                                        placeholder: '请选择业主监控',
                                        value: '',
                                    },
                                    on: {
                                        'on-change': (val) => {
                                            row.i_price_year = JSON.parse(val).i_price_year
                                            row.i_price_month = JSON.parse(val).i_price_month
                                        },
                                        'on-select': val => {
                                            this.strItems6 = JSON.parse(val.value)
                                            const arrs = [], arrs1 = [], strItems = []
                                            this.serData.forEach(s => {
                                                if (this.selData.length == 0) {
                                                    if (this.repair == '1') {
                                                        if (s.id == 1) {
                                                            this.selData.push(s)
                                                        }
                                                    } else {
                                                        if (!s._disabled) {
                                                            this.selData.push(s)
                                                        }
                                                    }
                                                }
                                            })
                                            this.selData.map(v => {
                                                arrs1.push(v.id)
                                                if (this.repair == '1') {
                                                    if (v.id != 9119 && v.id !== 9120 && v.id !== 9121 && v.id !== 9122 && v.id !== 9123 && v.id !== 9124) {
                                                        arrs.push(v)
                                                    }
                                                } else {
                                                    if (v.id != 9119 && !v._disabled) {
                                                        arrs.push(v)
                                                    }
                                                }
                                                if (v.id == 9119) {
                                                    strItems.splice(1, 0, this.strItems1)
                                                } else if (v.id == 9120) {
                                                    strItems.splice(1, 0, this.strItems2)
                                                } else if (v.id == 9121) {
                                                    strItems.splice(1, 0, this.strItems3)
                                                } else if (v.id == 9122) {
                                                    strItems.splice(1, 0, this.strItems4)
                                                } else if (v.id == 9123) {
                                                    strItems.splice(1, 0, this.strItems5)
                                                } else if (v.id == 9124) {
                                                    strItems.splice(1, 0, this.strItems6)
                                                }
                                            })
                                            if (arrs1.indexOf(9119) > -1 || arrs1.indexOf(9120) > -1 || arrs1.indexOf(9121) > -1 || arrs1.indexOf(9122) > -1 || arrs1.indexOf(9123) > -1 || arrs1.indexOf(9124) > -1) {
                                                this.sumSel = arrs.concat(strItems)
                                            } else {
                                                this.sumSel = arrs
                                            }
                                        }
                                    }
                                },
                                    [
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr6[1])
                                            }
                                        }, this.resArr6[1].s_name),
                                        h('Option', {
                                            props: {
                                                value: JSON.stringify(this.resArr6[0])
                                            }
                                        }, this.resArr6[0].s_name)
                                    ]
                                )
                            } else {
                                return h('span', row.s_name ? row.s_name : '-')
                            }
                        } else {
                            return h('span', row.s_name ? row.s_name : '-')
                        }
                    }
                },
                {
                    title: '年价格',
                    key: 'i_price_year',
                    align: 'center',
                    render: (h, { row }) => {
                        let arr1 = [11, 15]
                        if (row.i_price_year) {
                            if (row.s_count_year) {
                                if (row.id == 17 || row.id == 18) {
                                    return h('span', row.i_price_year)
                                } else {
                                    return h('span', row.s_count_year + (arr1.indexOf(row.id) > -1 ? '次/' : '个/') + row.i_price_year)
                                }
                            } else {
                                return h('span', row.i_price_year)
                            }
                        } else {
                            return h('span', '-')
                        }
                    }
                },
                {
                    title: '月价格',
                    key: 'i_price_month',
                    align: 'center',
                    render: (h, { row }) => {
                        let arr1 = [11, 15]
                        if (row.i_price_month) {
                            if (row.s_count_month) {
                                if (row.id == 17 || row.id == 18) {
                                    return h('span', row.i_price_month)
                                } else {
                                    return h('span', row.s_count_month + (arr1.indexOf(row.id) > -1 ? '次/' : '个/') + row.i_price_month)
                                }
                            } else {
                                return h('span', row.i_price_month)
                            }

                        } else {
                            return h('span', '-')
                        }
                    }
                }
            ],
            // 结束
            sumSel: [],
            creAuth: '',
            bigStas: Number,
            subStas: Number,
            yearStas: Number,
            isYears: Number,
            stopTime: Number,
            monthTime: Number,
            colr: '',
            proNums: 0,
            comVal: {},
            bigPro: [
                { v: '1', n: '大会员' },
                { v: '2', n: '大会员子账号' },
                { v: '3', n: '大会员补充包' }
            ],
            levelDown: [],
            nums: '',
            chargeStatus: [
                { v: 0, n: '免费' },
                { v: 1, n: '收费' }
            ],
            currentServerid:''


        }
    }
}
</script>

<style lang="scss" scoped>
.servechildrenbox {
    display: flex;
    // margin-top: 15px;
}

.serve-one {
    font-weight: bold;
}

.servebox {
    overflow: hidden;
    display: block;
}

.serve-two {
    display: flex;
    margin: 5px 0;

}

.one-group {
    float: left;
    margin: 5px 0;
}

.serve-content {
    display: flex;
    flex-wrap: wrap;
    float: left;
    width: 650px;
}

.sel-table.ivu-table-wrapper {
    overflow: unset;
}

.button-grey {
    color: #000000db;
    background-color: #c6c5c5;
    border-color: grey;
}

.ivu-form-item {
    margin-bottom: 10px;

}
</style>
