<template>
  <a-drawer
      v-model:visible="vdata.isShow"
      :title=" vdata.isAdd ? '新增交易路由策略' : '修改交易路由策略' "
      :confirmLoading="vdata.confirmLoading"
      @ok="handleOkFunc"
      @close="onClose"
      width="70%"
  >
    <a-card class="card-box-div">


      <div class="div-top-title">
        <div  class="div-top-title-tio1">
          <span class="div-top-title-tio-span">基础信息 </span>
        </div>
        <!--      <div class="div-top-title-tio2" @click="onClose">-->
        <!--        <a-button type="link" style="color: #808080 ;"><left-outlined />返回列表页</a-button>-->
        <!--      </div>-->
      </div>
      <a-divider class="divider-box-top" />

      <a-form class="edit-box" ref="infoFormModel" layout="vertical" :model="vdata.saveObject" :rules="vdata.rules">

        <a-row justify="space-between" type="flex">
          <a-col :sm="10">
            <a-form-item label="策略名称：" name="name">
              <a-input v-model:value="vdata.saveObject.name" placeholder="请输入交易路由策略名称" />
            </a-form-item>
          </a-col>
          <a-col :sm="10">
            <a-form-item label="是否默认"  name="isDefault">
              <a-radio-group v-model:value="vdata.saveObject.isDefault">
                <a-radio :value="0">否</a-radio>
                <a-radio :value="1">是</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
          <a-col :sm="24">
            <a-form-item  name="payMethod">
              <label for="页面类型">页面类型
                <a-tooltip  title="消费者扫收款码后会跳转对应的支付页面">
                  <info-circle-outlined />
                </a-tooltip>
              </label><br>
              <a-radio-group v-model:value="vdata.saveObject.payMethod">
                <a-radio :value="0">默认(未指定，取决于二维码是否绑定到微信侧)</a-radio>
                <a-radio :value="1">小程序页面</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>


      </a-form>
    </a-card>

    <a-card  class="card-box-div">
      <div class="div-top-title">
        <div  class="div-top-title-tio1">
          <span class="div-top-title-tio-span">策略规则设置 </span>
        </div>
      </div>
      <div>
        <div class="typography-value-title">规则内容</div>
        <div class="typography-container">
          <div class="typography-value-int">门店符合以下所有条件时</div>
          <div  v-for="(item, index) in vdata.ruleList">
            <div class="ruleList_box" >
              <div class="ruleList_box_top" >
                <a-select  class="tb_width_200"  v-model:value="item.type"  :filter-option="false" @change="getType(item,index)">
                  <a-select-option value="NUM">成交笔数  </a-select-option>
                  <a-select-option value="AMOUNT">成交金额  </a-select-option>
                  <a-select-option value="FAIL_NUM">连续失败笔数  </a-select-option>
                  <a-select-option value="RATE">付款率 </a-select-option>
                </a-select>
                <a-select class="tb_width_150"  v-model:value="item.timeVal"  :filter-option="false">
                  <a-select-option :value="5"> 近5分钟 </a-select-option>
                  <a-select-option :value="10"> 近10分钟 </a-select-option>
                  <a-select-option :value="30"> 近30分钟 </a-select-option>
                  <a-select-option :value="60"> 近1小时 </a-select-option>
                  <a-select-option :value="360"> 近6小时 </a-select-option>
                  <a-select-option :value="720"> 近12小时 </a-select-option>
                  <a-select-option :value="1440"> 近1天  </a-select-option>
                </a-select>
                <a-select  class="tb_width_150"  v-model:value="item.condition" :filter-option="false">
                  <a-select-option :value="1">大于等于  </a-select-option>
                  <a-select-option :value="2">小于等于  </a-select-option>
                  <a-select-option :value="3">介于  </a-select-option>
                </a-select>
                <div v-if="item.condition != 3" >
                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value" v-if="item.type == 'NUM'" placeholder="请输入成交笔数"/>
                  <a-input-number  class="tb_width_50" addon-after="元" :min="1" :precision="2" v-model:value="item.value" v-if="item.type == 'AMOUNT'" placeholder="请输入成交金额"/>
                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value" v-if="item.type == 'FAIL_NUM'" placeholder="请输入连续失败笔数"/>
                  <a-input-number  class="tb_width_50" addon-after="%" :min="0" :precision="2" v-model:value="item.value" v-if="item.type == 'RATE'" placeholder="请输入付款率"/>

                </div>
                <div v-if="item.condition == 3">
                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value" v-if="item.type == 'NUM'" placeholder="请输入成交笔数"/>
                  <span v-if="item.type == 'NUM'">-</span>
                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value1" v-if="item.type == 'NUM'" placeholder="请输入成交笔数"/>

                  <a-input-number  class="tb_width_50" addon-after="元" :min="1" :precision="2" v-model:value="item.value" v-if="item.type == 'AMOUNT'" placeholder="请输入成交金额"/>
                  <span v-if="item.type == 'AMOUNT'">-</span>
                  <a-input-number  class="tb_width_50" addon-after="元" :min="1" :precision="2" v-model:value="item.value1" v-if="item.type == 'AMOUNT'" placeholder="请输入成交金额"/>

                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value" v-if="item.type == 'FAIL_NUM'" placeholder="请输入连续失败笔数"/>
                  <span v-if="item.type == 'FAIL_NUM'">-</span>
                  <a-input-number  class="tb_width_50" addon-after="笔" :min="1" :precision="0" v-model:value="item.value1" v-if="item.type == 'FAIL_NUM'" placeholder="请输入连续失败笔数"/>


                  <a-input-number  class="tb_width_50" addon-after="%" :min="0" :precision="2" v-model:value="item.value" v-if="item.type == 'RATE'" placeholder="请输入付款率"/>
                  <span v-if="item.type == 'RATE'">-</span>
                  <a-input-number  class="tb_width_50" addon-after="%" :min="0" :precision="2" v-model:value="item.value1" v-if="item.type == 'RATE'" placeholder="请输入付款率"/>

                </div>
              </div>

              <div class="ruleList_box_buttom">
                <a-select class="tb_width_200"  v-model:value="item.opType"   :filter-option="false" @change="getOpType(item,index)">
                  <a-select-option value="STORE_STATE"> 门店状态 </a-select-option>
                  <a-select-option value="SEND_NOTIFY"> 仅发送通知 </a-select-option>
                  <!--                <a-select-option value="NUM" v-if="item.type == 'NUM'"> 更新成交笔数 </a-select-option>-->
                  <!--                <a-select-option value="AMOUNT" v-if="item.type == 'AMOUNT'"> 更新成交金额 </a-select-option>-->
                  <!--                <a-select-option value="FAIL_NUM" v-if="item.type == 'FAIL_NUM'"> 更新连续失败笔数 </a-select-option>-->
                  <!--                <a-select-option value="RATE" v-if="item.type == 'RATE'"> 更新付款率 </a-select-option>-->
                </a-select>

                <a-select  class="tb_width_150" v-if="item.opType == 'STORE_STATE'"  v-model:value="item.method"  :filter-option="false">
                  <a-select-option value="open">启用门店  </a-select-option>
                  <a-select-option value="exclude">不路由门店  </a-select-option>
                  <a-select-option value="close">停用门店  </a-select-option>
                </a-select>
                <!--              <a-select  class="tb_width_150" v-if="item.opType == 'SEND_NOTIFY'"  v-model:value="item.method"  :filter-option="false">-->
                <!--                <a-select-option value="day" data-selected="1" :disabled="true">每天每个门店  </a-select-option>-->
                <!--              </a-select>-->
                <a-input  class="tb_width_150"  v-if="item.opType == 'SEND_NOTIFY'" :disabled="true"  value="调整频率"  />




                <!--              <a-input-number  class="tb_width_50"  v-if="item.opType == 'SEND_NOTIFY'"  addon-after="次" :min="0" :precision="2" v-model:value="vdata.saveObject.value"  />-->


                <a-select  class="tb_width_150" v-if="item.opType != 'STORE_STATE' && item.opType != 'SEND_NOTIFY'"  v-model:value="item.method"  :filter-option="false">
                  <a-select-option value="up">提高 </a-select-option>
                  <a-select-option value="down">降低 </a-select-option>
                  <a-select-option value="adjust">调整至 </a-select-option>
                </a-select>

                <a-input-number  class="tb_width_50" v-if="item.opType != 'STORE_STATE' && item.opType != 'SEND_NOTIFY'" :addon-after="item.opType=='NUM'?'笔':item.opType=='AMOUNT'?'元':item.opType=='FAIL_NUM'?'笔':item.opType=='RATE'?'%':''" :min="0"  v-model:value="item.optValue"  />

                <a-select  class="tb_width_150" v-if="item.opType == 'SEND_NOTIFY'"  v-model:value="item.optValue"  :filter-option="false">
                  <a-select-option :value="1">1次 </a-select-option>
                  <a-select-option :value="2">2次 </a-select-option>
                  <a-select-option :value="3">3次 </a-select-option>
                </a-select>

                <a-button class="tb_width_100"    type="primary"     @click="getStrategyBinDing()"  >  <plus-outlined /> 绑定推送接收人  </a-button>

                <!--              <a-button  type="danger" @click="deleteBatchFunc(item.key)"><delete-outlined /></a-button>-->

              </div>

            </div>
          </div>

<!--                   <button class="strategy_button" @click="getAdd">-->
<!--                       <PlusOutlined style="padding-right: 5px;font-size: 14px"/> 新建规则条件-->
<!--                   </button>-->
        </div>

<!--        <div class="typography-container">-->
<!--          <div class="typography-value-int">则执行如下操作</div>-->
<!--          <div>-->
<!--            <div>-->
<!--              <a-select class="tb_width_200"  v-model:value="vdata.saveObject.operate.type"   :filter-option="false">-->
<!--                <a-select-option value="STORE_STATE"> 门店状态 </a-select-option>-->
<!--                <a-select-option value="SEND_NOTIFY"> 仅发送通知 </a-select-option>-->
<!--                <a-select-option value="NUM" v-if="vdata.ruleList.length == 1 && vdata.ruleList[0].type == 'NUM'"> 更新成交笔数 </a-select-option>-->
<!--                <a-select-option value="AMOUNT" v-if="vdata.ruleList.length == 1 && vdata.ruleList[0].type == 'AMOUNT'"> 更新成交金额 </a-select-option>-->
<!--                <a-select-option value="FAIL_NUM" v-if="vdata.ruleList.length == 1 && vdata.ruleList[0].type == 'FAIL_NUM'"> 更新连续失败笔数 </a-select-option>-->
<!--                <a-select-option value="RATE" v-if="vdata.ruleList.length == 1 && vdata.ruleList[0].type == 'RATE'"> 更新付款率 </a-select-option>-->

<!--              </a-select>-->

<!--              <a-select  class="tb_width_200" v-if="vdata.saveObject.operate.type == 'STORE_STATE'"  v-model:value="vdata.saveObject.operate.method"  :filter-option="false">-->
<!--                <a-select-option value="open">启用门店  </a-select-option>-->
<!--                <a-select-option value="exclude">不路由门店  </a-select-option>-->
<!--                <a-select-option value="close">停用门店  </a-select-option>-->
<!--              </a-select>-->
<!--              <a-select  class="tb_width_200" v-if="vdata.saveObject.operate.type == 'SEND_NOTIFY'"  v-model:value="vdata.saveObject.operate.method"  :filter-option="false">-->
<!--                <a-select-option value="day" data-selected="1" :disabled="true">每天每个门店  </a-select-option>-->
<!--              </a-select>-->

<!--              <a-input-number  class="tb_width_200"  v-if="vdata.saveObject.operate.type == 'SEND_NOTIFY'"  addon-after="次" :min="0" :precision="2" v-model:value="vdata.saveObject.value"  />-->


<!--              <a-select  class="tb_width_200" v-if="vdata.saveObject.operate.type != 'STORE_STATE' && vdata.saveObject.operate.type != 'SEND_NOTIFY'"  v-model:value="vdata.saveObject.operate.method"  :filter-option="false">-->
<!--                <a-select-option value="up">提高 </a-select-option>-->
<!--                <a-select-option value="down">降低 </a-select-option>-->
<!--                <a-select-option value="adjust">调整至 </a-select-option>-->
<!--              </a-select>-->

<!--              <a-input-number  class="tb_width_200" v-if="vdata.saveObject.operate.type != 'STORE_STATE' && vdata.saveObject.operate.type != 'SEND_NOTIFY'" :addon-after="vdata.ruleList[0].type=='NUM'?'笔':vdata.ruleList[0].type=='AMOUNT'?'元':vdata.ruleList[0].type=='FAIL_NUM'?'笔':vdata.ruleList[0].type=='RATE'?'%':''" :min="0"  v-model:value="vdata.saveObject.value"  />-->


<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
      </div>
    </a-card>

    <a-card  class="card-box-div">
      <div class="div-top-title">
        <div  class="div-top-title-tio1">
          <span class="div-top-title-tio-span">高级策略设置 </span>
        </div>
      </div>
      <!--    <a-divider class="jeepay-m-divider" orientation="left" style="color: #1A66FF;">高级策略设置</a-divider>-->

      <a-form ref="infoFormModel" class="edit-box"  style="margin-bottom: 50px"   :model="vdata.saveObject" :rules="vdata.rules">
        <a-row >
          <a-col :sm="10">
            <a-form-item label="指定支付方式：" name="isPayType" >
<!--              <div style="display: grid">-->
<!--                <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isPayType">-->
<!--                  <a-radio :value="1">启用</a-radio>-->
<!--                  <a-radio :value="0">禁用</a-radio>-->
<!--                </a-radio-group>-->
<!--                <span  class="jeepay-tip-text">开启后可设置新用户前X笔付款不路由，以及同一用户累计支付未满X元不路由的阈值</span>-->
<!--              </div>-->
                   <JeepayTableColState style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isPayType" :showSwitchType="true"  :onChange="getUserChange" />
            </a-form-item>

            <a-form-item v-if="vdata.saveObject.seniorStrategy.isPayType" label="选择支付方式：" name="payTypeValue" >
<!--              <a-select class="con-flex-span tb_width_80"   v-model:value="vdata.saveObject.seniorStrategy.payTypeValue"  mode="multiple" style="width: 100%"  placeholder="请选择支付类型"  :options="vdata.payWay"  />-->
              <a-checkbox-group v-model:value="vdata.saveObject.seniorStrategy.payTypeValue">
                <a-checkbox v-for="(value) in vdata.payWay" :key="value.value"   :value="value.value">{{ value.label }}</a-checkbox>
              </a-checkbox-group>
            </a-form-item>

          </a-col>




          <a-col :sm="10">
            <a-form-item label="指定结算类型：" name="isSettleType" >
<!--              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isSettleType">-->
<!--                <a-radio :value="1">启用</a-radio>-->
<!--                <a-radio :value="0">禁用</a-radio>-->
<!--              </a-radio-group>-->
              <JeepayTableColState style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isSettleType" :showSwitchType="true"  :onChange="getSettingChange" />

            </a-form-item>
            <a-form-item v-if="vdata.saveObject.seniorStrategy.isSettleType" label="选择结算类型：" name="settleTypeValue" >
              <!--              <a-select class="con-flex-span tb_width_80"   v-model:value="vdata.saveObject.seniorStrategy.payTypeValue"  mode="multiple" style="width: 100%"  placeholder="请选择支付类型"  :options="vdata.payWay"  />-->

<!--                <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.settleTypeValue">-->
<!--                  <a-radio value="D0">D0</a-radio>-->
<!--                  <a-radio value="D1">D1</a-radio>-->
<!--                  <a-radio value="T1">T1</a-radio>-->
<!--                </a-radio-group>-->
              <a-checkbox-group v-model:value="vdata.saveObject.seniorStrategy.settleTypeValue">
                <a-checkbox value="D0">D0</a-checkbox>
                <a-checkbox value="D1">D1</a-checkbox>
                <a-checkbox value="T1">T1</a-checkbox>
              </a-checkbox-group>
            </a-form-item>
          </a-col>

<!--          <a-col :sm="16" v-if="vdata.saveObject.seniorStrategy.isSettleType">-->
<!--            <a-form-item label="选择结算类型：" name="settleTypeValue" >-->
<!--              <a-select   class="con-flex-span tb_width_80"   v-model:value="vdata.saveObject.settleTypeValue"  style="width: 100%"  placeholder="指定结算类型"    >-->
<!--                <a-select-option value="D0">D0</a-select-option>-->
<!--                <a-select-option value="D1">D1</a-select-option>-->
<!--                <a-select-option value="T1">T1</a-select-option>-->
<!--              </a-select>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
<!--          <a-col :sm="16" v-if="!vdata.saveObject.seniorStrategy.isSettleType"></a-col>-->




          <!--        <a-col :sm="6">-->
          <!--          <a-form-item label="指定支付渠道：" name="isIsv" >-->
          <!--            <a-radio-group v-model:value="vdata.saveObject.isIsv">-->
          <!--              <a-radio :value="1">启用</a-radio>-->
          <!--              <a-radio :value="0">禁用</a-radio>-->
          <!--            </a-radio-group>-->
          <!--&lt;!&ndash;            <JeepayTableColState :state="vdata.saveObject.isIsv"  :onChange="getIsPayIsvChannel" :showSwitchType="true"   />&ndash;&gt;-->
          <!--          </a-form-item>-->
          <!--        </a-col>-->
          <!--        <a-col :sm="16" v-if="vdata.saveObject.isIsv">-->
          <!--          <a-form-item label="选择支付渠道：" name="isIsv" >-->
          <!--            <a-select v-model:value="vdata.saveObject.ifCode" >-->
          <!--              <a-select-option  v-for="item in vdata.payDefines" :key="item.ifCode" :value="item.ifCode">{{ item.ifName }} [{{ item.ifCode }}]</a-select-option>-->
          <!--            </a-select>-->
          <!--          </a-form-item>-->
          <!--        </a-col>-->
          <!--        <a-col :sm="16" v-if="!vdata.saveObject.isIsv"></a-col>-->

          <a-col :sm="10">
            <a-form-item label="指定路由类型：" name="isRouteType" >
<!--              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isRouteType">-->
<!--                <a-radio :value="1">启用</a-radio>-->
<!--                <a-radio :value="0">禁用</a-radio>-->
<!--              </a-radio-group>-->
                 <JeepayTableColState :state="vdata.saveObject.seniorStrategy.isRouteType"  :onChange="getIsPayTypeChannel" :showSwitchType="true"   />
            </a-form-item>
            <a-form-item v-if="vdata.saveObject.seniorStrategy.isRouteType" label="选择路由类型：" name="routeTypeValue" >
              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.routeTypeValue">
                <a-radio value="RANDOM">随机路由</a-radio>
                <a-radio value="SORT">顺序路由</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>

          <a-col :sm="10">
            <a-form-item label="用户交易策略：" name="isTradeRule" >
<!--              <div style="display: grid">-->
<!--                <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isTradeRule">-->
<!--                  <a-radio :value="1">启用</a-radio>-->
<!--                  <a-radio :value="0">禁用</a-radio>-->
<!--                </a-radio-group>-->
<!--                <div  class="jeepay-tip-text"> 用户优先使用上一个门店交易 用户优先与其他门店交易</div>-->
<!--              </div>-->
                  <JeepayTableColState style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isTradeRule"  :onChange="getIsPayTradeChannel" :showSwitchType="true"   />
            </a-form-item>

            <a-form-item v-if="vdata.saveObject.seniorStrategy.isTradeRule" label="选择交易策略：" name="tradeRuleValue" >
              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.tradeRuleValue">
                <a-radio value="PREV">优先使用上一个门店交易</a-radio>
                <a-radio value="OHTER">优先与其他门店交易</a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>


<!--          <a-col :sm="10">-->
<!--            <a-form-item label="费用最低策略：" name="isCostRateMin" >-->
<!--              <div style="display: grid">-->
<!--                  <JeepayTableColState style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isCostRateMin"  :onChange="getIsCostRateMinChannel" :showSwitchType="true"   />-->
<!--              </div>-->
<!--            </a-form-item>-->
<!--          </a-col>-->



<!--          <a-col :sm="10">-->
<!--            <a-form-item label="成功率最高策略：" name="isSucRateMax" >-->
<!--              <div style="display: grid">-->
<!--                            <JeepayTableColState style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isSucRateMax"  :onChange="getIsSucRateMaxChannel" :showSwitchType="true"   />-->
<!--              </div>-->
<!--            </a-form-item>-->
<!--          </a-col>-->






<!--          <a-col :sm="20">-->
<!--            <a-form-item label="权重交易策略：" name="isWeight" >-->
<!--                          <JeepayTableColState  style="margin: 5px 5px 0 5px !important;" :state="vdata.saveObject.seniorStrategy.isWeight"  :onChange="getIsPayWeightChannel" :showSwitchType="true"   />-->
<!--            </a-form-item>-->
<!--          </a-col>-->


          <a-col :sm="10">
            <a-form-item label="指定支付通道：" name="seniorStrategy.isIfCode" >
<!--              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isIfCode">-->
<!--                <a-radio :value="1">启用</a-radio>-->
<!--                <a-radio :value="0">禁用</a-radio>-->
<!--              </a-radio-group>-->
               <JeepayTableColState :state="vdata.saveObject.seniorStrategy.isIfCode"  :onChange="getIsIfCodeChannel" :showSwitchType="true"   />
              <!--              <div  class="jeepay-tip-text" style="margin: 0 5px 0 5px !important;">开启后允许商户在支付时自主选择支付通道，若选择的通道内无商户，则提示报错。</div>-->
            </a-form-item>
            <a-form-item class="tb_width_600"  v-if="vdata.saveObject.seniorStrategy.isIfCode" label="选择支付通道："  name="ifCodeValue" >
              <a-select v-model:value="vdata.saveObject.seniorStrategy.ifCodeValue" @change="getIfCodeValue" >
                <a-select-option  v-for="item in vdata.payDefines" :key="item.ifCode" :value="item.ifCode">{{ item.ifName }} [{{ item.ifCode }}]</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :sm="6">
            <a-form-item label="指定支付渠道：" name="seniorStrategy.isIsvNo;" >
              <!--              <a-radio-group v-model:value="vdata.saveObject.seniorStrategy.isIfCode">-->
              <!--                <a-radio :value="1">启用</a-radio>-->
              <!--                <a-radio :value="0">禁用</a-radio>-->
              <!--              </a-radio-group>-->
              <JeepayTableColState :state="vdata.saveObject.seniorStrategy.isIsvNo"  :onChange="getIsIsvNoChannel" :showSwitchType="true"   />
              <!--              <div  class="jeepay-tip-text" style="margin: 0 5px 0 5px !important;">开启后允许商户在支付时自主选择支付通道，若选择的通道内无商户，则提示报错。</div>-->
            </a-form-item>
            <a-form-item class="tb_width_600" v-if="vdata.saveObject.seniorStrategy.isIsvNo" label="选择支付渠道：" name="isvNoValue" >
              <a-select v-model:value="vdata.saveObject.seniorStrategy.isvNoValue" @search="handleIsvChange">
                <a-select-option  v-for="item in vdata.payIsvfines" :key="item.isvNo" :value="item.isvNo">{{ item.isvName }} [{{ item.isvNo }}]</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
<!--          <a-col :sm="16" v-if="!vdata.saveObject.seniorStrategy.isIfCode"></a-col>-->

        </a-row>
      </a-form>


      <div class="drawer-btn-center">
        <a-button :style="{ marginRight: '8px' }" @click="onClose"><close-outlined /> 取消</a-button>
        <a-button type="primary" :loading="vdata.confirmLoading" @click="handleOkFunc"><check-outlined /> 保存</a-button>
      </div>
    </a-card>
    <!-- 新增页面组件  -->
    <SybNotice ref="infoSybNotice" v-if="props.configMode == 'mch'" :callbackFunc="searchBinDingFunc" />
  </a-drawer>
</template>

<script lang="ts" setup>
import {
  API_MCH_PAY_DEFINES,
  API_URL_MCH_APPS,
  API_URL_PAY_ORDER_ROUTE_ADD,
  API_URL_PAY_ORDER_ROUTE_SAVE,
  API_URL_ISV_LIST,
  req, API_URL_MCHAPPLYMENTS_SUCCEEDIFNAME,API_URL_MCHAPPLYMENTS_SUCCEEDISVNAME
} from '@/api/manage'
const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties
import { message } from 'ant-design-vue'
import {defineEmits, getCurrentInstance, reactive, ref} from 'vue'

const  props = defineProps({
  configMode: { type: String, default: '' },   // 模式
  callbackFunc: { type: Function,default:null }
})

const infoFormModel = ref()
const infoSybNotice = ref()
const vdata = reactive ({
  ruleList:[ {key:1,timeVal:5,type:'NUM',condition:1,value:0,value1:0,opType:"STORE_STATE",method:"open",optValue:0}],
  filteredMchNameInfoList:[] as any,
  filteredMchNoInfoList:[] as any,
  storeList:[] as any,
  detailData:[] as any,
  modeList:[
    {name:"按比例分账",value:0},
    {name:"按金额分账",value:1},
  ],
  typeList:[
    {name:"实时分账",value:0},
    {name:"延时分账",value:1},
    {name:"秒到分账",value:2},
  ],
  payDefines: [] as any,
  payIsvfines:[] as any,
  isvList:[] as any,
  confirmLoading: false, // 显示确定按钮loading图标
  isAdd: true, // 新增 or 修改页面标识
  isShow: false, // 是否显示弹层/抽屉
  saveObject: {isDefault:0,operate:{},seniorStrategy:{isPayType:0,payTypeValue:"",isSettleType:0,settleTypeValue:"",isIfCode:0,ifCodeValue:"",isRouteType:0,routeTypeValue:"RANDOM",isCostRateMin:0,isSucRateMax:0,isTradeRule:0,tradeRuleValue:"PREV",isWeight:0}} as any, // 数据对象
  recordId: null, // 更新对象ID
  rules: {
    name: [{ required: true, message: '请输入策略名称', trigger: 'blur' }],
    isDefault: [{ required: true, message: '请选择是否默认', trigger: 'blur' }],
    payMethod: [{ required: true, message: '请选择页面类型', trigger: 'blur' }],
    type: [{ required: true, message: '请选择策略规则', trigger: 'blur' }],
    sortStrategy: [{ required: true, message: '请选择交易顺序策略', trigger: 'blur' }],
    divisionType: [{ required: true, message: '请输入分账类型', trigger: 'blur' }],
    divisionAmount: [{ required: true, message: '请输入分账金额', trigger: 'blur' }],
    minAmount: [{ required: true, message: '请输入最小支付金额', trigger: 'blur' }],
    isSpecify: [{ required: true, message: '请指定指定设备', trigger: 'blur' }],
    deviceInfo: [{ required: true, message: '请选择设备信息', trigger: 'blur' }]
  },
  filteredAppidInfoList:[] as any,
  appidList:[] as any,
  payWay:[
    {
      value: 'WECHAT',
      label: '微信',
    },
    {
      value: 'ALIPAY',
      label: '支付宝',
    }
  ]
})

function  show (record) { // 弹层打开事件
  vdata.isAdd = !record
  vdata.ruleList = [ {key:1,timeVal:5,type:'NUM',condition:1,value:0,value1:0,opType:"STORE_STATE",optValue:0,method:"open"}]
  vdata.saveObject = {isDefault:0,payMethod:0, operate:{},seniorStrategy:{isPayType:0,payTypeValue:"",isSettleType:0,settleTypeValue:"",isIfCode:0,ifCodeValue:"",isRouteType:0,routeTypeValue:"RANDOM",isCostRateMin:0,isSucRateMax:0,isTradeRule:0,tradeRuleValue:"PREV",isWeight:0}} as any, // 数据对象

      vdata.confirmLoading = false // 关闭loading

  if (infoFormModel.value !== undefined) {
    infoFormModel.value.resetFields()
  }

  // req.list(API_URL_MCH_APPS, { 'pageSize': -1,state:1 }).then(res => {
  //   vdata.appidList =  res.records
  //   vdata.filteredAppidInfoList = res.records
  // })

  payFefines()
  payIsvfines()
  if (!vdata.isAdd) { // 修改信息 延迟展示弹层
    console.log(record,'recordrecord')
    vdata.saveObject = record
    let conditionList = [] as any
    for (let i=0;i<record.ruleStrategy.conditionList.length;i++){

      if(record.ruleStrategy.conditionList[i].value.length == 1){
        record.ruleStrategy.conditionList[i].value = record.ruleStrategy.conditionList[i].value[0]
      }else{
        record.ruleStrategy.conditionList[i].value = record.ruleStrategy.conditionList[i].value[0]
        record.ruleStrategy.conditionList[i].value1 = record.ruleStrategy.conditionList[i].value[1]
      }
      // const value = record.ruleStrategy.conditionList[i] as any
      conditionList.push(record.ruleStrategy.conditionList[i] as any)

    }
    // record.conditionList.forEach(item=>{
    //     if(item.value.length == 1){
    //       item.value = item.value[0]
    //     }else{
    //       item.value = item.value[0]
    //       item.value = item.value[1]
    //     }
    //     return item;
    // })
    vdata.saveObject.operate = record.ruleStrategy.operate
    vdata.ruleList = conditionList
    vdata.saveObject.name = record.name
    vdata.recordId = record.routeId
    vdata.isShow = true // 立马展示弹层信息
  } else {
    vdata.isShow = true // 立马展示弹层信息
  }
}
function  payFefines() {
  req.list(API_URL_MCHAPPLYMENTS_SUCCEEDIFNAME,{ 'pageSize': 10000 }).then(res => {
    vdata.payDefines = res
  })
}


function  payIsvfines() {
  vdata.payIsvfines = []
  vdata.isvList = []
  req.list(API_URL_MCHAPPLYMENTS_SUCCEEDISVNAME,{ 'pageSize': 10000,ifCode:vdata.saveObject.seniorStrategy.ifCodeValue }).then(res => {
    vdata.payIsvfines = res.records
    vdata.isvList = res.records
  })
}
mchApp()
function mchApp(){
  req.list(API_URL_MCH_APPS, { 'pageSize': -1,state:1 }).then(res => {
    vdata.appidList =  res.records
    vdata.filteredAppidInfoList = res.records
  })

}

function getIfCode(){
  console.log(vdata.saveObject.ifCode,'saveObjectsaveObjectsaveObject')
}
const emit = defineEmits(['itemRender'])
function  handleOkFunc() { // 点击【确认】按钮事件


  infoFormModel.value.validate().then(valid=>{
    vdata.confirmLoading = true // 显示loading

    // vdata.saveObject.isNewUser = vdata.saveObject.seniorStrategy.isNewUser==1?true:false
    // vdata.saveObject.isSplit = vdata.saveObject.seniorStrategy.isSplit==1?true:false
    if (vdata.isAdd) {
      vdata.confirmLoading = false // 显示loading
      vdata.ruleList.forEach(item=>{
        if(item.condition == 3){
          item.value  = [item.value,item.value1] as any
        }
        return item;
      })
      let data = vdata.saveObject
      data.ruleStrategy = {conditionList:{},operate:{}}
      data.ruleStrategy.conditionList = vdata.ruleList
      data.ruleStrategy.operate = vdata.saveObject.operate
      req.add(API_URL_PAY_ORDER_ROUTE_ADD, data).then(res => {
        message.success('添加成功')
        vdata.isShow = false
        emit('itemRender')
      }).catch(res => { vdata.confirmLoading = false })
    } else {
      vdata.ruleList.forEach(item=>{
        if(item.condition == 3){
          item.value  = [item.value,item.value1] as any
        }
        return item;
      })
      let data = vdata.saveObject
      data.ruleStrategy = {conditionList:{},operate:{}}
      data.ruleStrategy.conditionList = vdata.ruleList
      data.ruleStrategy.operate = vdata.saveObject.operate
      req.updateById(API_URL_PAY_ORDER_ROUTE_SAVE, vdata.recordId,data).then(res => {
        message.success('修改成功')
        vdata.isShow = false
        emit('itemRender')
      }).catch(res => { vdata.confirmLoading = false })
    }
  })
}


function getUserChange(e){
  vdata.saveObject.seniorStrategy.isPayType = e
}
function getSettingChange(e){

  vdata.saveObject.seniorStrategy.isSettleType = e
}

function getIsPayChannel(e){
  vdata.saveObject.seniorStrategy.isPay = e
}
function getIsPayIsvChannel(e){
  vdata.saveObject.seniorStrategy.isIsv = e
}
function getIsPayTypeChannel(e){
  vdata.saveObject.seniorStrategy.isRouteType = e
}


function getIsSucRateMaxChannel(e){
  vdata.saveObject.seniorStrategy.isSucRateMax = e
}
function getIsPayFeeChannel(e){
  vdata.saveObject.seniorStrategy.isCostRateMin = e
}
function getIsCostRateMinChannel(e){

  vdata.saveObject.seniorStrategy.isCostRateMin = e
}
function getIsPayFeeRateChannel(e){
  vdata.saveObject.seniorStrategy.isFeeRate = e
}

function getIsPayTradeChannel(e){
  vdata.saveObject.seniorStrategy.isTradeRule = e
}

function getIsPayWeightChannel(e){
  vdata.saveObject.seniorStrategy.isWeight = e
}
function getIsIfCodeChannel(e){
  vdata.saveObject.seniorStrategy.isIfCode = e
}

const getIfCodeValue = (value) => {
  payIsvfines()
}
function getIsIsvNoChannel(e){
  vdata.saveObject.seniorStrategy.isIsvNo = e
  if(!vdata.saveObject.seniorStrategy.isIfCode){
    vdata.saveObject.seniorStrategy.isIsvNo = 0
      message.error("请先开启支付通道")
     return false
  }

  if(!vdata.saveObject.seniorStrategy.ifCodeValue){
    vdata.saveObject.seniorStrategy.isIsvNo = 0
    message.error("请先选择支付通道")
    return false
  }

}


//门店搜索
const handleAppidChange = (value) => {
  vdata.filteredAppidInfoList = [];
  vdata.appidList.forEach((item: { appName: string | any[], appId:  any[] },index) => {
    if (item.appName.includes(value) || item.appId.toString().includes(value) ) {
      vdata.filteredAppidInfoList.push(vdata.appidList[index]);
    }
  });
};

const handleIsvChange = (value) => {
  vdata.payIsvfines = [];
  vdata.isvList.forEach((item,index) => {
    if (item.isvName.includes(value) ) {
      vdata.payIsvfines.push(item)
    }
  });
};
function getSaveObjectAppid(e){

}

//接收方
const tableColumns = reactive([
  // { key: 'key', title: '序号', dataIndex: 'key', align: 'center',width:'5%'},
  { key: 'storeId',title: '门店名称', dataIndex: 'storeId', align: 'center',slots: { customRender: 'storeId' },width:'25%' },
  { key: 'value',title: '配置', dataIndex: 'value', align: 'center',slots: { customRender: 'value' } ,width:'15%'},
  { key: 'scope',title: '时效', dataIndex: 'scope', align: 'center',slots: { customRender: 'scope' } ,width:'10%'},
  { key: 'typeStrategy',title: '支付类型', dataIndex: 'typeStrategy', align: 'center',slots: { customRender: 'typeStrategy' } ,width:'15%'},
  { key: 'rate',title: '付款率', dataIndex: 'rate', tooltipTitle: '付款率低于设置的，自动下架', align: 'center',slots: { customRender: 'rate' } ,width:'10%'},
  { key: 'state',title: '状态', dataIndex: 'state', align: 'center',slots: { customRender: 'state' } ,width:'10%'},
  { key: 'operation',title: '操作', dataIndex: 'operation', align: 'center',slots: { customRender: 'operation' },width:'10%' },
])



function dateFormat(time) {
  let date = new Date(time);
  let year = date.getFullYear();
  let wk = date.getDay()
  /* 在日期格式中，月份是从0开始的，因此要加0
  * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
  * */
  let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  let weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  let week = weeks[wk]
  // 拼接
  return  hours + ":" + minutes;
  // return year + "年" + month + "月" + day + "日" + " " + hours + ":" + minutes + ":" + seconds + ' ' + week;
}


const deleteBatchFunc = (key,type=0) => {
  if (vdata.ruleList.length <= 1) {
    $infoBox.message.error('最少保留一项')
    return false
  }
  vdata.ruleList = vdata.ruleList.filter(item => item.key !== key)
}


const onClose = () => {
  vdata.isShow = false
  emit('callbackFunc')
}
function getAdd(){
  vdata.ruleList.push({key:vdata.ruleList[vdata.ruleList.length - 1].key + 1,timeVal:5,type:'NUM',condition:1,value:0,value1:0,opType:"STORE_STATE",optValue:0,method:"open"})
}

function getOpType(item,index){
  if(item.opType == 'STORE_STATE'){
    vdata.ruleList[index].method = 'open'
  }else if(item.opType == 'SEND_NOTIFY'){
    vdata.ruleList[index].optValue = 1
  }else{
    vdata.ruleList[index].method = 'up'
  }
  console.log(item,'itemitemitem')

}

function getType(item,index){
  // STORE_STATE
  vdata.ruleList[index].opType = item.type
  vdata.ruleList[index].method = 'up'
  vdata.ruleList[index].opType = "STORE_STATE"
  vdata.ruleList[index].method = 'open'

  // <a-select-option value="NUM" v-if="item.type == 'NUM'"> 更新成交笔数 </a-select-option>
  //     <a-select-option value="AMOUNT" v-if="item.type == 'AMOUNT'"> 更新成交金额 </a-select-option>
  //     <a-select-option value="FAIL_NUM" v-if="item.type == 'FAIL_NUM'"> 更新连续失败笔数 </a-select-option>
  //     <a-select-option value="RATE" v-if="item.type == 'RATE'"> 更新付款率 </a-select-option>
  // <a-select-option value="NUM">成交笔数  </a-select-option>
  //     <a-select-option value="AMOUNT">成交金额  </a-select-option>
  //     <a-select-option value="FAIL_NUM">连续失败笔数  </a-select-option>
  //     <a-select-option value="RATE">付款率 </a-select-option>
  console.log(item,'itemitemitem')

}
let btnLoading = ref(false)
function getStrategyBinDing(){
  infoSybNotice.value.show()
}
function searchBinDingFunc () { // 点击【查询】按钮点击事件
  btnLoading.value = true
}
defineExpose({show})
</script>
<style lang="less" scoped>
.jeepay-tip-text::before{
  border: none !important;
}

.user-ploy-span{
  padding: 5px 10px;
}
.span-color{
  color: #595959 !important;
}
:deep(.span-color .ant-form-item-label>label){
  color: #595959 !important;
}

:deep(.jeepay-table-top-row){
  display: none;
}
.rule-span{
  padding: 5px 10px;
}
.con-flex-span{
  flex: 1 !important;
}
.tb_width_80{
  width: 80px !important;
  margin: 0 5px ;
}
.con-flex-div{
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
}
.operation-a{
  margin-right: 10px;
}

.card-box-div{
  margin-bottom: 10px;
}


.div-top-title{
  display: flex;
  position: relative;
  padding: 15px 20px;
}
.div-top-title-tio-span{
  font-size: 17px;
  font-weight: 600;
}
.div-top-title-tio1{
  width: 50%;
}
.div-top-title-tio2{
  width: 50%;
  text-align: right;
}

.div-top-title-tio2 bottom{
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  box-shadow: 0 2px 0 rgba(0,0,0,.015);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5715;
  padding: 4px 25px !important;
  text-align: center;
}
.divider-box-top{
  margin:unset !important;
}
.color-box-span{
  font-size: 13px;
  color: #2C6EF6 !important;
  text-align: left;
  padding: 10px 0;
}
.edit-box{
  padding: 20px 30px;
  //margin-bottom: 20px;
}
.typography-value-title{
  font-weight: 700;
  font-size: 14px;
  margin: 10px 15px 10px 20px;
}
.typography-value-int{
  color: var(--gray-g-11, #323335);
  font-size: 14px;
  font-style: normal;
  font-weight: 600;
  line-height: 22px;
  margin-bottom: 16px;
}
.typography-container{
  background: var(--gray-g-1, #fff);
  border: 1px solid var(--gray-g-5, #ebebed);
  border-radius: 8px;
  padding: 16px;
  margin: 10px;
}
.tb_width_200{
  width: 200px !important;
  margin: 0 5px ;
}

.tb_width_600{
  width: 400px !important;
  margin: 5px ;
}
.tb_width_150{
  width: 150px !important;
  margin: 0 5px ;
}
.tb_width_50{
  width: 100px !important;
  margin: 0 5px ;
}
.strategy_button{
  width: 100%;
  margin-top: 10px;
  align-items: center;
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  outline: none;
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  vertical-align: text-bottom;
  white-space: nowrap;
  background-color: #fff;
  border-color: #dfe0e2;
  color: #323335;
  border-style: dashed;font-size: 14px;
  line-height: 22px;
  min-width: 100px;
  padding: 4px 16px;
  margin-top: 10px;

}
.ruleList_box{
  //display: flex;
  margin: 10px 0;
}
.ruleList_box_top{
  display: flex;
}

.ruleList_box_buttom{
  margin-top: 5px;
}
</style>
