<template>
  <div class="app-container">
      <el-tabs v-model="activeName"    >
        <el-tab-pane label="CID配置" name="cidConfig">
          <el-form ref="cidConfigForm" :model="cidConfig" label-width="200px">
            <el-form-item label="是否开启手机号配置" prop="enablePhoneConfig">
              <el-switch v-model="cidConfig.enablePhoneConfig"></el-switch>
            </el-form-item>

            <template v-if="cidConfig.enablePhoneConfig">
              <el-form-item label="生成条数" prop="generateCount">
                <el-input-number
                  v-model="cidConfig.generateCount"
                  :min="1"
                  :step="1"
                  :precision="0"
                  placeholder="请输入生成条数"
                ></el-input-number>
              </el-form-item>

              <el-form-item label="开始位置" prop="startIndex">
                <el-input-number
                  v-model="cidConfig.startIndex"
                  :min="1"
                  :max="11"
                  :step="1"
                  :precision="0"
                  placeholder="例如: 1"
                ></el-input-number>
                <span class="tip-text">（从第几位开始生成）</span>
              </el-form-item>

              <el-form-item label="结束位置" prop="endIndex">
                <el-input-number
                  v-model="cidConfig.endIndex"
                  :min="1"
                  :max="11"
                  :step="1"
                  :precision="0"
                  placeholder="例如: 11"
                ></el-input-number>
                <span class="tip-text">（到第几位结束）</span>
              </el-form-item>
            </template>

             <el-form-item label="是否允许重复客户导入" prop="allowRepeatCustomer">
              <el-switch v-model="cidConfig.allowRepeatCustomer"></el-switch>
            </el-form-item>
            <el-form-item label="Ai外呼回调地址" prop="callbackUrl">
               <el-input v-model="cidConfig.callbackUrl" style="width:800px"></el-input>
            </el-form-item>
              <el-form-item label="人工外呼后是否填写意向度" prop="enableManualCallIntent">
                  <el-switch v-model="cidConfig.enableManualCallIntent"></el-switch>
              </el-form-item>

            <el-divider content-position="left">外呼线路执行限制</el-divider>
              <el-form-item label="启用外呼线路执行限制" prop="outboundLineLimitEnabled">
                  <el-switch v-model="cidConfig.outboundLineLimitEnabled"></el-switch>
                  <span class="tip-text">（开启后，系统将按以下规则限制各外呼线路的呼出次数）</span>
              </el-form-item>

              <template v-if="cidConfig.outboundLineLimitEnabled">
                  <div style="margin-bottom: 12px; display: flex; align-items: center;">
                      <el-button type="primary" size="small" icon="el-icon-plus" @click="addLimitRule">新增规则</el-button>
                      <span class="tip-text" style="margin-left: 10px;">可配置多个时间粒度规则，同时生效</span>
                  </div>

                  <el-table :data="cidConfig.outboundLineRules" border stripe size="mini" style="width: 100%; margin-bottom: 15px;" empty-text="暂无规则，请点击上方按钮新增">
                      <el-table-column label="指定线路" min-width="200" align="center">
                          <template slot-scope="scope">
                              <el-select v-model="scope.row.lineIds" multiple filterable collapse-tags clearable placeholder="不选则对所有线路生效" style="width: 100%;">
                                  <el-option
                                      v-for="item in gatewayList"
                                      :key="item.id"
                                      :label="item.gwDesc"
                                      :value="item.id"
                                  />
                              </el-select>
                          </template>
                      </el-table-column>
                      <el-table-column label="时间粒度" width="160" align="center">
                          <template slot-scope="scope">
                              <el-select v-model="scope.row.timeWindow" placeholder="选择粒度" style="width: 130px;">
                                  <el-option label="每30分钟" :value="30"></el-option>
                                  <el-option label="每1小时" :value="60"></el-option>
                                  <el-option label="每2小时" :value="120"></el-option>
                                  <el-option label="每6小时" :value="360"></el-option>
                                  <el-option label="每天(24小时)" :value="1440"></el-option>
                              </el-select>
                          </template>
                      </el-table-column>
                      <el-table-column label="最大呼出次数" width="150" align="center">
                          <template slot-scope="scope">
                              <el-input-number v-model="scope.row.maxCalls" :min="1" :max="99999" :step="1" placeholder="次数" controls-position="right" size="mini" style="width: 100px;"></el-input-number>
                          </template>
                      </el-table-column>
                      <el-table-column label="说明" min-width="220" align="left">
                          <template slot-scope="scope">
                    <span style="color: #909399; font-size: 12px; line-height: 1.6; white-space: normal; word-break: break-all;">
                      {{ scope.row.lineIds && scope.row.lineIds.length > 0 ? '仅对指定线路生效' : '对所有外呼线路统一生效' }}，
                      每{{ formatTimeWindow(scope.row.timeWindow) }}最多呼出 {{ scope.row.maxCalls || 0 }} 次
                    </span>
                          </template>
                      </el-table-column>
                      <el-table-column label="操作" width="60" align="center" fixed="right">
                          <template slot-scope="scope">
                              <el-button type="text" icon="el-icon-delete" style="color: #F56C6C;" @click="removeLimitRule(scope.$index)"></el-button>
                          </template>
                      </el-table-column>
                  </el-table>

                  <div class="outbound-limit-tip">
                      <strong>规则说明：</strong><br/>
                      · 多条规则同时生效，取最严格的限制<br/>
                      · 指定线路后，该规则仅对选中线路生效；不指定则对所有外呼线路生效<br/>
                      · 例如：设置「线路A + 每30分钟=50次」+「每天=500次」，则线路A每30分钟最多50次，且全天累计不超过500次
                  </div>
              </template>

             <!-- <el-form-item label="线路呼入回调地址" prop="inboundCallbackUrl">
               <el-input v-model="cidConfig.inboundCallbackUrl" style="width:800px"></el-input>
            </el-form-item> -->
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmitCidConfig">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
          <el-tab-pane label="客户管理配置" name="sysConfig">
          <el-form ref="sysConfig" :model="sysConfig" label-width="120px">
            <el-form-item label="领取无跟进公海回收规则">
                <el-row>
                    <el-input-number  v-model="sysConfig.visitLimt"  :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">领取无跟进N天自动回收</span>
                </el-row>
            </el-form-item>
            <el-form-item label="未跟进公海回收规则" label-width="170px">
                  <el-row>
                      <el-input-number  v-model="sysConfig.visitLimt1"  :min="0" :max="100" ></el-input-number>
                  </el-row>
                  <el-row>
                      <span class="tip">无跟进记录N天自动回收</span>
                  </el-row>
            </el-form-item>
            <el-form-item label="未成交公海回收规则" label-width="170px">
                  <el-row>
                      <el-input-number  v-model="sysConfig.visitLimt2"  :min="0" :max="356" ></el-input-number>
                  </el-row>
                  <el-row>
                      <span class="tip">无商机N天自动回收</span>
                  </el-row>
            </el-form-item>
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit1">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="企微客服配置" name="qwkfConfig">
          <el-form ref="qwkfConfig" :model="qwkfConfig" label-width="120px">
            <el-form-item label="企业CoripID">
              <el-input v-model="qwkfConfig.corpId" style="width:400px"   ></el-input>
            </el-form-item>
            <el-form-item label="Secret">
              <el-input v-model="qwkfConfig.secret" style="width:400px"   ></el-input>
            </el-form-item>
            <el-form-item label="Token">
              <el-input v-model="qwkfConfig.token" style="width:400px"   ></el-input>
            </el-form-item>
            <el-form-item label="EncodingAESKey">
              <el-input v-model="qwkfConfig.encodingAESKey" style="width:400px"   ></el-input>
            </el-form-item>
            <el-form-item label="回调地接">
              <el-input disabled v-model="qwkfConfig.notifyUrl" style="width:600px"   ></el-input>
            </el-form-item>
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit3">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane  label="客户字段配置" name="customerExt">
          <el-row :gutter="10" class="mb8" style="margin:0px 0px 10px;">
            <el-col :span="1.5">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="mini"
                @click="handleCustomerExtAdd"
              >新增</el-button>
            </el-col>
          </el-row>
          <el-table border :data="customerExtList" >
            <el-table-column label="ID" align="center" prop="extId" />
            <el-table-column label="字段名称" align="center" prop="name" />
            <el-table-column  label="状态" align="center" prop="status">
              <template slot-scope="scope">
                  <el-tag prop="status" v-for="(item, index) in statusOptions"    v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="排序号" align="center" prop="sort" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleCustomerExtUpdate(scope.row)"
                >修改</el-button>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleCustomerExtDelete(scope.row)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit2">提交</el-button>
            </div>
        </el-tab-pane>
<!--        <el-tab-pane label="企微配置" name="qwConfig">-->
<!--          <el-form ref="qwConfig" :model="qwConfig" label-width="200px">-->
<!--            <el-form-item label="企业CoripID">-->
<!--              <el-input v-model="qwConfig.corpId" style="width:400px"   ></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="通讯录Secret">-->
<!--              <el-input v-model="qwConfig.bookSecret" style="width:400px"   ></el-input>-->
<!--            </el-form-item>-->

<!--            <el-form-item label="应用Secret">-->
<!--              <el-input v-model="qwConfig.appSecret" style="width:400px"   ></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="应用AgentId">-->
<!--              <el-input v-model="qwConfig.AgentId" style="width:400px"   ></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="Token">-->
<!--              <el-input v-model="qwConfig.token" style="width:400px"   :readonly="true"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="EncodingAESKey">-->
<!--              <el-input v-model="qwConfig.encodingAESKey" style="width:400px"   :readonly="true"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="域名地址">-->
<!--              <el-input v-model="qwConfig.realmNameURL" style="width:600px"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="回调地接">-->
<!--              <el-input v-model="qwConfig.notifyUrl" style="width:600px"   :readonly="true"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="聊天工具栏跳转地址">-->
<!--              <el-input v-model="qwConfig.chatToolbar" style="width:600px"   :readonly="true"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="聊天工具栏实际运用地址">-->
<!--              <el-input v-model="qwConfig.chatToolbarOAuth2" :rows="2"  type="textarea" style="width:1000px;"   :readonly="true"></el-input>-->
<!--            </el-form-item>-->
<!--            <div class="line"></div>-->
<!--            <div style="float:right;margin-right:20px">-->
<!--              <el-button type="primary" @click="onSubmit4">提交</el-button>-->
<!--            </div>-->
<!--          </el-form>-->
<!--        </el-tab-pane>-->
        <el-tab-pane label="AI客服配置" name="AiKfConfig">
          <el-form ref="AiKfConfig" :model="AiKfConfig" label-width="120px">
            <el-form-item label="通用Key">
              <el-input  v-model="AiKfConfig.Key" style="width:600px"   ></el-input>
            </el-form-item>
            <el-form-item label="调用地址">
              <el-input  v-model="AiKfConfig.url" style="width:600px"   ></el-input>
            </el-form-item>
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit5">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="红包商户配置" name="redPacketConfig" >
          <el-form ref="redPacketConfig" :model="redPacketConfig"  label-width="150px">
            <el-form-item   label="红包接口类型" prop="isNew">
              <el-radio-group v-model="redPacketConfig.isNew">
                <el-radio label="0">商家转账到零钱(旧)</el-radio>
                <el-radio label="1">商家转账(新)</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item   label="公众号appid" prop="appId">
              <el-input   v-model="redPacketConfig.appId"  label="请输入appId"></el-input>
            </el-form-item>
            <el-form-item   label="小程序appid" prop="appId">
              <el-input   v-model="redPacketConfig.miniappId"  label="请输入appId"></el-input>
            </el-form-item>
            <el-form-item   label="商户号" prop="mchId">
              <el-input   v-model="redPacketConfig.mchId"  label="请输入mchId"></el-input>
            </el-form-item>
            <el-form-item   label="商户密钥" prop="mchKey">
              <el-input   v-model="redPacketConfig.mchKey"  label="mchKey"></el-input>
            </el-form-item>
            <el-form-item   label="p12证书路径" prop="keyPath">
              <el-input   v-model="redPacketConfig.keyPath"  label="请输入keyPath"></el-input>
            </el-form-item>
            <el-form-item   label="apiV3密钥" prop="apiV3Key">
              <el-input   v-model="redPacketConfig.apiV3Key"  label="请输入apiV3Key"></el-input>
            </el-form-item>
            <el-form-item   label="公钥ID" prop="publicKeyId">
              <el-input   v-model="redPacketConfig.publicKeyId"  label="请输入公钥ID"></el-input>
            </el-form-item>
            <el-form-item   label="公钥证书" prop="publicKeyPath">
              <el-input   v-model="redPacketConfig.publicKeyPath"  label="请输入publicKeyPath"></el-input>
            </el-form-item>
            <el-form-item   label="key路径" prop="privateKeyPath">
              <el-input   v-model="redPacketConfig.privateKeyPath"  label="请输入"></el-input>
            </el-form-item>
            <el-form-item   label="cert路径" prop="privateCertPath">
              <el-input   v-model="redPacketConfig.privateCertPath"  label="请输入"></el-input>
            </el-form-item>
            <el-form-item   label="回调地址" prop="notifyUrl">
              <el-input   v-model="redPacketConfig.notifyUrl"  label="请输入"></el-input>
            </el-form-item>

            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit4">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="app提现配置" name="hisAppRedPacket" >
              <el-form ref="hisAppRedPacket" :model="hisAppRedPacket"  label-width="150px">
                  <el-form-item   label="红包接口类型" prop="isNew">
                      <el-radio-group v-model="hisAppRedPacket.isNew">
                          <el-radio label="0">商家转账到零钱(旧)</el-radio>
                          <el-radio label="1">商家转账(新)</el-radio>
                      </el-radio-group>
                  </el-form-item>
                  <el-form-item   label="公众号appid" prop="appId">
                      <el-input   v-model="hisAppRedPacket.appId"  label="请输入appId"></el-input>
                  </el-form-item>
                  <el-form-item   label="小程序appid" prop="appId">
                      <el-input   v-model="hisAppRedPacket.miniappId"  label="请输入appId"></el-input>
                  </el-form-item>
                  <el-form-item   label="商户号" prop="mchId">
                      <el-input   v-model="hisAppRedPacket.mchId"  label="请输入mchId"></el-input>
                  </el-form-item>
                  <el-form-item   label="商户密钥" prop="mchKey">
                      <el-input   v-model="hisAppRedPacket.mchKey"  label="mchKey"></el-input>
                  </el-form-item>
                  <el-form-item   label="p12证书路径" prop="keyPath">
                      <el-input   v-model="hisAppRedPacket.keyPath"  label="请输入keyPath"></el-input>
                  </el-form-item>
                  <el-form-item   label="apiV3密钥" prop="apiV3Key">
                      <el-input   v-model="hisAppRedPacket.apiV3Key"  label="请输入apiV3Key"></el-input>
                  </el-form-item>
                  <el-form-item   label="公钥ID" prop="publicKeyId">
                      <el-input   v-model="hisAppRedPacket.publicKeyId"  label="请输入公钥ID"></el-input>
                  </el-form-item>
                  <el-form-item   label="公钥证书" prop="publicKeyPath">
                      <el-input   v-model="hisAppRedPacket.publicKeyPath"  label="请输入publicKeyPath"></el-input>
                  </el-form-item>
                  <el-form-item   label="key路径" prop="privateKeyPath">
                      <el-input   v-model="hisAppRedPacket.privateKeyPath"  label="请输入"></el-input>
                  </el-form-item>
                  <el-form-item   label="cert路径" prop="privateCertPath">
                      <el-input   v-model="hisAppRedPacket.privateCertPath"  label="请输入"></el-input>
                  </el-form-item>
                  <el-form-item   label="回调地址" prop="notifyUrl">
                      <el-input   v-model="hisAppRedPacket.notifyUrl"  label="请输入"></el-input>
                  </el-form-item>

                  <div style="float:right;margin-right:20px">
                      <el-button type="primary" @click="onSubmit8">提交</el-button>
                  </div>
              </el-form>
          </el-tab-pane>
        <el-tab-pane label="配置销售会员审核" name="companyUserConfig">
          <el-form ref="companyUserConfig" label-width="140px">
            <el-form-item label="会员是否小黑屋"><!--会员是否默认黑名单-->
              <el-row>
                <el-switch v-model="userIsDefaultBlack"></el-switch>
              </el-row>
            </el-form-item>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit6">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="配置销售端隐藏总账号" name="adminIsShowForm">
          <el-form ref="adminIsShowForm" label-width="140px">
            <el-form-item label="账号是否显示">
              <el-row>
                <el-switch v-model="adminIsShow"></el-switch>
                <span style="margin-left: 10px;">
                  <el-tag :type="adminIsShow ? 'success' : 'info'" size="mini">
                    {{ adminIsShow ? '当前显示' : '当前隐藏' }}
                  </el-tag>
                </span>
              </el-row>
            </el-form-item>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit7">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <el-dialog :title="customerExt.title" :visible.sync="customerExt.open" width="500px" append-to-body>
        <el-form ref="customerExtForm" :model="customerExtForm" :rules="customerExtRules" label-width="80px">
          <el-form-item label="字段名称" prop="name">
            <el-input v-model="customerExtForm.name" placeholder="请输入字段名称" />
          </el-form-item>
          <el-form-item label="状态">
            <el-radio-group v-model="customerExtForm.status">
              <el-radio label="1"  >正常</el-radio>
              <el-radio label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="排序号" prop="sort">
            <el-input-number v-model="customerExtForm.sort" :min="1" placeholder="请输入排序号" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitCustomerExtForm">确 定</el-button>
          <el-button @click="customerExt.open=false">取 消</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import { getCompanyInfo } from "@/api/company/company";
import { getConfigKey,updateConfig,configUserCheck } from "@/api/company/companyConfig";
import { listCustomerExt, getCustomerExt, delCustomerExt, addCustomerExt, updateCustomerExt } from "@/api/crm/customerExt";
import { getGatewayList } from '@/api/company/easyCall'

export default {
  name: "config",
  watch: {
    qwConfig: {
      handler(newValue) {
        // 根据新值更新
        this.qwConfig.chatToolbarOAuth2="https://open.weixin.qq.com/connect/oauth2/authorize?" +
          "appid="+newValue.corpId+"" +
          "&redirect_uri="+newValue.chatToolbar+"" +
          "&response_type=code" +
          "&scope=snsapi_base" +
          "&state=STATE" +
          "&agentid="+newValue.AgentId+"#wechat_redirect";

        this.qwConfig.notifyUrl=newValue.realmNameURL+"/qw/data/"+this.company.companyId;
      },
      deep: true
    }
  },
  data() {
    return {
      cidConfig: {
        enablePhoneConfig: false,
        generateCount: 0,
        startIndex: 1,
        endIndex: 5
      },
      adminIsShow: false,
      company:null,
      statusOptions:[],
      customerExt:{
        open:false,
        title:"扩展字段"
      },
      customerExtForm:{
        name:"",
        status:"1",
        sort:"1",
      },
      customerExtRules:{

      },
      customerExtList: [],
      activeName: 'sysConfig',
      customerConfig:{
          rlLimit: 1,
          txLimit: 1,
          hsLimit: 1
      },
      sysConfig:{
          tel:"18900000000",
          noticeType:1,
          visitLimt:0,
          visitLimt1:0,
          visitLimt2:0,
          contractLimt:0
      },
      sysConfigForm:{},
      customerConfigForm:{},
      qwkfConfig:{

      },
      AiKfConfig:{},
      AiKfConfigForm:{},

      qwConfig:{
      },
      qwConfigForm:{},
      qwkfConfigForm:{},
      companyUserConfig: {},
      adminIsShowForm:{},
      userIsDefaultBlack: null,
      redPacketConfig:{},
      hisAppRedPacket:{},
        gatewayList: [],
      redPacketConfigForm:{},
      hisAppRedPacketForm:{},
      cidConfigForm:{}
    };
  },
  created() {
    this.getCompanyInfo();
    this.getConfigKey("sys:config");
    this.getConfigKey("qw:config");
    this.getConfigKey("sys:qw:config");
    this.getConfigKey("customer:config");
    this.getConfigKey("sys:AiKf:config");
    this.getConfigKey("company:admin:show");
    this.getConfigKey("redPacket:config");
    this.getConfigKey("cId.config");
    this.getDicts("sys_company_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getCustomerExt()
    this.loadGatewayList()
  },
  mounted() {

  },

  methods: {
    getCompanyInfo(){
      getCompanyInfo().then(response => {
        this.company = response.data;
        if(response.data.fsUserIsDefaultBlack != null){
          const userIsDefaultBlack = response.data.fsUserIsDefaultBlack
          if(userIsDefaultBlack == 1){
            this.userIsDefaultBlack = true
          } else{
            this.userIsDefaultBlack = false
          }
        }
      });
    },
      addLimitRule() {
          if (!this.cidConfig.outboundLineRules) {
              this.$set(this.cidConfig, 'outboundLineRules', []);
          }
          this.cidConfig.outboundLineRules.push({ lineIds: [], timeWindow: 60, maxCalls: 100 });
      },

      removeLimitRule(index) {
          this.cidConfig.outboundLineRules.splice(index, 1);
      },

      loadGatewayList() {
          getGatewayList().then(response => {
              this.gatewayList = response.rows || response.data || [];
          }).catch(() => {});
      },
      formatTimeWindow(minutes) {
          const map = { 30: '30分钟', 60: '1小时', 120: '2小时', 360: '6小时', 1440: '天' };
          return map[minutes] || (minutes + '分钟');
      },
    /** 新增按钮操作 */
    handleCustomerExtAdd() {
      this.customerExt.open = true;
      this.customerExt.title = "添加客户字段";
      this.customerExtForm={
        name:"",
        status:"1",
        sort:"1",
      }
    },
    /** 修改按钮操作 */
    handleCustomerExtUpdate(row) {
      const extId = row.extId
      getCustomerExt(extId).then(response => {
        this.customerExtForm = response.data;
        this.customerExt.open = true;
        this.customerExtForm.status = response.data.status.toString();
        this.customerExt.title = "修改客户字段";
      });
    },
    /** 提交按钮 */
    submitCustomerExtForm() {
      this.$refs["customerExtForm"].validate(valid => {
        if (valid) {
          if (this.customerExtForm.extId != null) {
            updateCustomerExt(this.customerExtForm).then(response => {
              if (response.code === 200) {
                this.getCustomerExt("修改成功");
                this.customerExt.open = false;
                this.getList();
              }
            });
          } else {
            addCustomerExt(this.customerExtForm).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.customerExt.open = false;
                this.getCustomerExt();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleCustomerExtDelete(row) {
      const extIds = row.extId || this.ids;
      this.$confirm('是否确认删除客户字段扩展编号为"' + extIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCustomerExt(extIds);
        }).then(() => {
          this.getCustomerExt();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    getCustomerExt() {
      var data={}
      listCustomerExt(data).then(response => {
        this.customerExtList = response.data;
      });
    },
    getConfigKey(key){
        getConfigKey(key).then((response) => {
            if(key=="sys:config"){
                this.sysConfigForm=response.data;
                if(response.data.configValue!=null){
                    this.sysConfig=JSON.parse(response.data.configValue);
                }
            }
            else if(key=="qw:config"){
                this.qwkfConfigForm=response.data;
                if(response.data.configValue!=null){
                    this.qwkfConfig=JSON.parse(response.data.configValue);
                    this.qwkfConfig.notifyUrl="http://kf.qw.ifeiyu100.com/app/common/weixinkfAuth/"+this.company.companyId;
                }
            }
            else if(key=="customer:config"){
                this.customerConfigForm=response.data;
                if(response.data.configValue!=null){
                    this.customerConfig=JSON.parse(response.data.configValue);
                }
            }
            else if(key=="sys:qw:config"){
                this.qwConfigForm=response.data;
                if(response.data.configValue!=null){
                    this.qwConfig=JSON.parse(response.data.configValue);

                }
                this.qwConfig.token="1o62d3YxvdHd4LEUiltnu7sK";
                this.qwConfig.encodingAESKey="UJfTQ5qKTKlegjkXtp1YuzJzxeHlUKvq5GyFbERN1iU";
                this.qwConfig.notifyUrl=this.qwConfig.realmNameURL+"/qw/data/"+this.company.companyId;
                this.qwConfig.chatToolbar="https://company.his.cdwjyyh.com/qwh5/?companyId="+this.company.companyId;
                this.qwConfig.chatToolbarOAuth2="https://open.weixin.qq.com/connect/oauth2/authorize?" +
                  "appid="+this.qwConfig.corpId+"" +
                  "&redirect_uri="+this.qwConfig.chatToolbar+"" +
                  "&response_type=code" +
                  "&scope=snsapi_base" +
                  "&state=STATE" +
                  "&agentid="+this.qwConfig.AgentId+"#wechat_redirect";
            }else if (key=="sys:AiKf:config"){
              this.AiKfConfigForm=response.data;
              if(response.data.configValue!=null){
                this.AiKfConfig=JSON.parse(response.data.configValue);
              }
            }else if (key=="companyUser:config"){
              this.companyUserConfig=response.data;
              if(response.data.configValue != null){
                this.userIsDefaultBlack = JSON.parse(response.data.configValue);
              }
            }else if(key == "company:admin:show"){
              this.adminIsShowForm = response.data;
              if(response.data.configValue != null){
                this.adminIsShow = JSON.parse(response.data.configValue);
              }
            }else if(key=="redPacket:config"){
              this.redPacketConfigForm=response.data;
              if(response.data.configValue!=null){
                this.redPacketConfig=JSON.parse(response.data.configValue);
              }
            }else if(key == "cId.config"){
              this.cidConfigForm = response.data;
              if(response.data.configValue != null){
                this.cidConfig = JSON.parse(response.data.configValue);
              }
            }
            else if(key == "his:AppRedPacket"){
                this.hisAppRedPacketForm = response.data;
                if(response.data.configValue != null){
                    this.hisAppRedPacket = JSON.parse(response.data.configValue);
                }
            }
        });
    },
    onSubmit1() {
      this.sysConfigForm.configValue=JSON.stringify(this.sysConfig);
      updateConfig(this.sysConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("sys:config");
        }
      });
    },
    onSubmit2() {
      this.customerConfigForm.configValue=JSON.stringify(this.customerConfig);
      updateConfig(this.customerConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("customer:config");
        }
      });
    },
    onSubmit3() {
      this.qwkfConfigForm.configValue=JSON.stringify(this.qwkfConfig);
      updateConfig(this.qwkfConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("sys:config");
        }
      });
    },
    // onSubmit4() {
    //   this.qwConfigForm.configValue=JSON.stringify(this.qwConfig);
    //   updateConfig(this.qwConfigForm).then(response => {
    //     if (response.code === 200) {
    //       this.msgSuccess("修改成功");
    //       this.getConfigKey("sys:qw:config");
    //     }
    //   });
    // },
    onSubmit4() {
      this.redPacketConfigForm.configValue=JSON.stringify(this.redPacketConfig);
      updateConfig(this.redPacketConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("redPacket:config");
        }
      });
    },
    onSubmit5() {
      this.AiKfConfigForm.configValue=JSON.stringify(this.AiKfConfig);
      updateConfig(this.AiKfConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("sys:AiKf:config");
        }
      });
    },
    onSubmit6() {
      this.companyUserConfig.configValue=JSON.stringify(this.userIsDefaultBlack);
      configUserCheck({userIsDefaultBlack: this.userIsDefaultBlack}).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("companyUser:config");
        }
      });
    },
    onSubmit7() {
      // 实现提交逻辑
      this.adminIsShowForm.configValue=JSON.stringify(this.adminIsShow);
      updateConfig(this.adminIsShowForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("company:admin:show");
        }
      })
    },

      onSubmit8() {
          this.hisAppRedPacketForm.configValue=JSON.stringify(this.hisAppRedPacket);
          updateConfig(this.hisAppRedPacketForm).then(response => {
              if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.getConfigKey("his:AppRedPacket");
              }
          });
      },
    onSubmitCidConfig() {
      if (this.cidConfig.enablePhoneConfig) {
        if (!this.cidConfig.generateCount || this.cidConfig.generateCount < 1) {
          this.msgError('生成条数不能为空且不能小于1');
          return;
        }
        if (!this.cidConfig.startIndex || this.cidConfig.startIndex < 1 || this.cidConfig.startIndex > 11) {
          this.msgError('开始位置不能为空，且必须在1到11之间');
          return;
        }
        if (!this.cidConfig.endIndex || this.cidConfig.endIndex < 1 || this.cidConfig.endIndex > 11) {
          this.msgError('结束位置不能为空，且必须在1到11之间');
          return;
        }
        if (this.cidConfig.startIndex > this.cidConfig.endIndex) {
          this.msgError('开始位置不能大于结束位置');
          return;
        }

        if (this.cidConfig.endIndex - this.cidConfig.startIndex < 4) {
          this.msgError('开始和结束位置之间的位数不能少于4位');
          return;
        }
      }

      this.cidConfigForm.configValue = JSON.stringify(this.cidConfig);
      updateConfig(this.cidConfigForm).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfigKey("cId.config");
        }
      });
    },
  }
};
</script>
<style scoped lang="scss">
.tip{
  color:indianred;
}
.line{
  margin: 10px 0;
  background-color:gainsboro;
  height:1px;
}
.el-row {
  margin-bottom: 0px;
  &:last-child {
    margin-bottom: 0;
  }
}
</style>

