<template>
  <a-drawer
    v-model:visible="vdata.visible"
    :mask-closable="false"
    title="用户高级配置"
    :body-style="{ paddingBottom: '80px' }"
    width="60%"
    class="drawer-width"
    @close="vdata.visible = false"
  >
    <div style="background: #fff">
      <a-tabs v-if="vdata.visible" @change="selectTabs">
        <a-tab-pane key="orderConfig" tab="支付配置">
          <div v-if="vdata.groupKey == 'orderConfig'" class="account-settings-info-view">
            <a-form ref="configFormModel" :model="vdata.mchConfigData" layout="vertical">
              <a-row justify="start" type="flex" style="margin-top: 20px">
                <a-col v-for="(item, config) in vdata.mchConfigData" :key="config" :span="7" :offset="1">
                  <a-form-item :label="item.configName">
                    <a-radio-group v-if="item.type === 'radio'" v-model:value="item.configVal">
                      <a-radio value="1">启用</a-radio>
                      <a-radio value="0">禁用</a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-form-item class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirm"><check-circle-outlined />确认更新</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane>

        <a-tab-pane key="payOrderNotifyExtParams" tab="回调和查单参数">
          <div v-if="vdata.groupKey == 'payOrderNotifyExtParams'" class="account-settings-info-view" style="margin-left: 40px">
            <a-form>
              <a-form-item label="POS支付回调地址" name="mchPayNotifyUrl" :wrapper-col="{ span: 16 }">
                <a-input v-model:value="vdata.mchPayNotifyUrl" />
              </a-form-item>
              <a-form-item label="POS退款回调地址" name="mchRefundNotifyUrl" :wrapper-col="{ span: 16 }">
                <a-input v-model:value="vdata.mchRefundNotifyUrl" />
                <div class="jeepay-tip-text">
                  <p>智能POS收款、退款等场景下，需要配置用户回调地址</p>
                  <p>接口下单以下单传参为准</p>
                </div>
              </a-form-item>

              <a-form-item>
                <template #label>
                  <span>支付回调开关</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>启用：启用后订单支付成功后将按支付回调地址发送异步通知</p>
                      <p>禁用：禁用后支付成功后不会发送异步通知</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-radio-group v-model:value="vdata.mchNotifyFlag.payNotifyFlag">
                  <a-radio value="1">启用</a-radio>
                  <a-radio value="0">禁用</a-radio>
                </a-radio-group>
              </a-form-item>
              <a-form-item>
                <template #label>
                  <span>退款回调开关</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>启用：启用后订单退款成功后将按退款回调地址发送异步通知</p>
                      <p>禁用：禁用后退款成功后不会发送异步通知</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-radio-group v-model:value="vdata.mchNotifyFlag.refundNotifyFlag">
                  <a-radio value="1">启用</a-radio>
                  <a-radio value="0">禁用</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item>
                <template #label>
                  <span>回调方式</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>回调方式</span></template>
                    <template #content>
                      <p>设置后该用户接收支付网关所有的通知（支付、退款等回调）将全部以此方式发送。</p>
                      <p>POST(Body形式)： method: POST; Content-Type: application/x-www-form-urlencoded; 回调参数（ 例如a=1&b=2 ）放置在Body 发送。</p>
                      <p>POST(QueryString形式)： method: POST; Content-Type: application/x-www-form-urlencoded; 回调参数（ 例如a=1&b=2 ）放置在QueryString 发送。</p>
                      <p>POST(JSON形式)： method: POST; Content-Type: application/json; 回调参数（ 例如{a: 1, b: 2} ）放置在Body 发送。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                   &nbsp;
                </template>
                <a-radio-group v-model:value="vdata.mchNotifyPostType">
                  <a-radio value="POST_BODY">POST(Body 形式)</a-radio>
                  <a-radio value="POST_QUERYSTRING">POST(QueryString 形式)</a-radio>
                  <a-radio value="POST_JSON">POST(JSON 形式)</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-table :dataSource="vdata.notifyTableData" :columns="vdata.notifyTableColumns" :pagination="false" size="small">
                <!-- header 标题 插槽 -->
                <template #headerCell="{ column }">
                  <template v-if="column.key === 'batch'">
                    <a-checkbox @change="(e) => notifyAllCehcked(e.target.checked)" />
                  </template>
                </template>

                <template #bodyCell="{ column, record }">
                  <template v-if="column.key === 'batch'"><a-checkbox v-model:checked="record.checked" :disabled="record.disabled" /></template>
                  <template v-if="column.key === 'wayName'">{{ record.wayName }}[{{ record.wayCode }}]</template>
                </template>

                <template #title>回调参数配置</template>
              </a-table>


              <a-form-item class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmByNotify"><check-circle-outlined />确认更新</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane>


        <a-tab-pane key="divisionManage" tab="分账管理">
          <div v-if="vdata.groupKey == 'divisionManage'" class="account-settings-info-view" style="margin-top: 20px">
            <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
              <a-form-item>
                <template #label>
                  <span>全局自动分账</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>全局自动分账</span></template>
                    <template #content>
                      <p>开启：将根据[全局自动分账规则]进行自动分账处理（屏蔽下单API的分账参数， 订单标识都是自动分账模式）</p>
                      <p>关闭：以API传参为准</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                   &nbsp;
                </template>
                <a-radio-group v-model:value="vdata.divisionConfig.overrideAutoFlag">
                  <a-radio :value="1">开启</a-radio>
                  <a-radio :value="0">关闭</a-radio>
                </a-radio-group>
              </a-form-item>

              <div v-if="vdata.divisionConfig.overrideAutoFlag == 1" style="margin-left: 50px">
                <a-divider orientation="left">全局自动分账规则</a-divider>

                <a-form-item label="金额限制">
                  <span style="line-height: 30px;">当订单金额大于等于 &nbsp;</span>
                  <a-input-number v-model:value="vdata.divisionConfig.autoDivisionRules.amountLimit" :min="0" :precision="2" style="width:140px">
                    <template #addonAfter>元</template>
                  </a-input-number>
                  <span style="line-height: 30px;"> &nbsp;时自动分账</span>
                </a-form-item>

                <a-form-item label="自动分账时间">
                  订单支付成功： <a-select v-model:value="vdata.divisionConfig.autoDivisionRules.delayTime" style="width: 110px" placeholder="时间">
                    <a-select-option :value=" (2 * 60) ">2分钟</a-select-option>
                    <a-select-option :value=" (5 * 60) ">5分钟</a-select-option>
                    <a-select-option :value=" (10 * 60) ">10分钟</a-select-option>
                    <a-select-option :value=" (30 * 60) ">30分钟</a-select-option>
                    <a-select-option :value=" (60 * 60) ">1小时</a-select-option>
                    <a-select-option :value=" (2 * 60 * 60) ">2小时</a-select-option>
                  </a-select> 后
                </a-form-item>
              </div>


              <a-form-item>
                <template #label>
                  <span>用户管理功能限制</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>用户管理功能限制</span></template>
                    <template #content>
                      <p>允许管理：用户可查看到所有的分账接收者账号和分账配置项并支持更改。</p>
                      <p>不允许管理：屏蔽用户的分账管理功能和菜单， 当运营平台维护分账时建议屏蔽用户管理功能。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                   &nbsp;
                </template>
                <a-radio-group v-model:value="vdata.divisionConfig.mchDivisionEntFlag">
                  <a-radio :value="1">允许管理</a-radio>
                  <a-radio :value="0">不允许管理</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item>
                <template #label>
                  <span>计算分账金额的基数</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>选择计算分账金额的基数</span></template>
                    <template #content>
                      <p>基于订单金额： 分账金额 = 订单金额 * 分账比例</p>
                      <p>基于入账金额： 分账金额 = （订单金额-手续费） * 分账比例</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                   &nbsp;
                </template>
                <a-radio-group v-model:value="vdata.divisionConfig.calBaseAmountType">
                  <a-radio :value="'ORDER_AMOUNT'">基于订单金额</a-radio>
                  <a-radio :value="'INCOME_AMOUNT'">基于入账金额</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmByDivisionManage"><check-circle-outlined />保存</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane>

        <a-tab-pane key="mchApiEnt" tab="接口权限">
          <a-table :dataSource="vdata.mchApiEntTableData" :columns="vdata.mchApiEntTableColumns" :pagination="false" size="small">
            <!-- header 标题 插槽 -->
            <template #headerCell="{ column }">
              <template v-if="column.key === 'batch'">
                <a-checkbox @change="(e) => mchApiEntAllCehcked(e.target.checked)" />
              </template>
            </template>

            <template #bodyCell="{ column, record }">
              <template v-if="column.key === 'batch'"><a-checkbox v-model:checked="record.checked" :disabled="record.disabled" /></template>
            </template>

            <template #title>用户可自调用接口</template>
          </a-table>


          <a-form-item class="bottom-btn">
            <a-button type="primary" :loading="vdata.btnLoading" @click="confirmByApiEnt"><check-circle-outlined />确认更新</a-button>
          </a-form-item>
        </a-tab-pane>

        <a-tab-pane key="advertConfig" tab="广告配置">
          <div v-if="vdata.groupKey == 'advertConfig'" class="account-settings-info-view" style="margin-top: 20px">
            <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
              <a-form-item>
                <template #label>
                  <span>刷脸设备广告</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>广告配置</span></template>
                    <template #content>
                      <p>开启：开启后可配置刷脸设备广告</p>
                      <p>关闭：不可配置刷脸设备广告</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                   &nbsp;
                </template>
                <a-radio-group v-model:value="vdata.advertConfig.advertFlag">
                  <a-radio :value="1">开启</a-radio>
                  <a-radio :value="0">关闭</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmByAdvertManage"><check-circle-outlined />保存</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane>
        <a-tab-pane key="selfCashier" tab="便捷收银台配置">
          <div v-if="vdata.groupKey == 'selfCashier'" class="account-settings-info-view" style="margin-top: 20px">
            <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
              <a-form-item>
                <template #label>
                  <span>便捷收银台开关</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>启用：启用后用户可查看和使用便捷收银台页面及地址</p>
                      <p>禁用：禁用后用户不可操作及查看便捷收银台</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-radio-group v-model:value="vdata.selfCashierState.configVal">
                  <a-radio value="1">启用</a-radio>
                  <a-radio value="0">禁用</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item v-if="vdata.selfCashierState.configVal == 1">
                <template #label>
                  <span>logo/底部显示配置</span>
                </template>
                <a-radio-group v-model:value="vdata.selfCashierSiteInfoType.configVal">
                  <a-radio value="DEFAULT">默认</a-radio>
                  <a-radio value="NONE">隐藏</a-radio>
                  <!-- <a-radio disabled="true" value="CUSTOM">自定义</a-radio> -->
                </a-radio-group>
              </a-form-item>
              <a-form-item v-if="vdata.selfCashierState.configVal == 1">
                <template #label>
                  <span>H5支付配置</span>
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>1. 用户的实际支付方式将根据配置的先后顺序优先选择；</p>
                      <p>2. 若配置为空， 收银台不显示H5支付按钮。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-select
                  v-model:value="vdata.selfCashierWxH5Config.configVal"
                  mode="multiple"
                  style="width: 100%"
                  :options="vdata.cashierWxH5Data"
                  placeholder="请选择微信H5支付顺序"
                />
              </a-form-item>
              <a-form-item v-if="vdata.selfCashierState.configVal == 1">
                <template #label>
                  <span>支付宝H5支付配置</span>
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>1. 用户的实际支付方式将根据配置的先后顺序优先选择；</p>
                      <p>2. 若配置为空， 收银台不显示H5支付按钮。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-select
                  v-model:value="vdata.selfCashierAliWapConfig.configVal"
                  style="width: 100%"
                  mode="multiple"
                  :options="vdata.cashierAliWebData"
                  placeholder="请选择支付宝WAP支付顺序"
                />
              </a-form-item>
              
              <a-form-item style="margin-top: 20px;" class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmBySelfCashierManage"><check-circle-outlined />保存</a-button>
              </a-form-item>

              <a-divider v-if="vdata.selfCashierState.configVal == 1" orientation="left">用户便捷收银台</a-divider>
              <a-card v-if="vdata.selfCashierState.configVal == 1" style="box-sizing:border-box;padding:30px">
                <!-- 选择下单的应用列表 -->
                <a-form>
                  <div style="display:flex;flex-direction:row">
                    <!-- <p style="margin-top:9px;margin-right:10px;"></p> -->
                    <a-form-item label="" class="table-head-layout">
                      <span>应用：</span>
                      <a-select v-model:value="vdata.appId" style="width:300px" @change="changeAppId">
                        <a-select-option key="">应用APPID</a-select-option>
                        <a-select-option v-for="(item) in vdata.mchAppList" :key="item.appId">{{ item.appName }} [{{ item.appId }}]</a-select-option>
                      </a-select>
                      <span style="margin-left: 30px;">门店：</span>
                      <a-select v-model:value="vdata.storeId" style="width:300px;" @change="changeStoreId">
                        <a-select-option key="">选择门店</a-select-option>
                        <a-select-option v-for="(item) in vdata.mchStoreList" :key="item.storeId">{{ item.storeName }} [{{ item.storeId }}]</a-select-option>
                      </a-select>
                    </a-form-item>
                  </div>
                </a-form>

                <!-- 未选择应用/门店提示框 -->
                <a-divider v-if="!vdata.appId">请选择应用APPID</a-divider>
                <a-divider v-if="vdata.appId && !vdata.storeId">请选择门店ID</a-divider>

                <div v-if="vdata.cashierUrl && vdata.isShowCashier">
                  <div>
                    <span>收银台地址链接：</span>
                    <a-button v-clipboard:copy="vdata.cashierUrl" v-clipboard:success="() => $infoBox.message.success('复制成功')" style="margin-left: 10px;margin-bottom: 10px;" size="small" type="primary">复制</a-button>
                    <br>
                    <a :href="vdata.cashierUrl" target="_blank">{{ vdata.cashierUrl }}</a>
                  </div>
                  <br>
                  <div>
                    <span>收银台地址二维码：</span>
                    <div style="padding: 10px 0 30px 0px;"><QrcodeVue :value="vdata.cashierUrl" :size="200" /></div>
                  </div>
                </div>
              </a-card>
            </a-form>
          </div>
        </a-tab-pane>

        <a-tab-pane key="webCashier" tab="WEB收银台配置">
          <div v-if="vdata.groupKey == 'webCashier'" class="account-settings-info-view" style="margin-top: 20px">
            <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
              <a-form-item>
                <template #label>
                  <span>WEB收银台开关</span> &nbsp;
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>启用：启用后用户可查看和使用WEB收银台页面及地址</p>
                      <p>禁用：禁用后用户不可操作及查看WEB收银台</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-radio-group v-model:value="vdata.webCashierState.configVal">
                  <a-radio value="1">启用</a-radio>
                  <a-radio value="0">禁用</a-radio>
                </a-radio-group>
              </a-form-item>

              <a-form-item v-if="vdata.webCashierState.configVal == 1">
                <template #label>
                  <span>logo/底部显示配置</span>
                </template>
                <a-radio-group v-model:value="vdata.webCashierSiteInfoType.configVal">
                  <a-radio value="DEFAULT">默认</a-radio>
                  <a-radio value="NONE">隐藏</a-radio>
                  <!-- <a-radio disabled="true" value="CUSTOM">自定义</a-radio> -->
                </a-radio-group>
              </a-form-item>
              <a-form-item v-if="vdata.webCashierState.configVal == 1">
                <template #label>
                  <span>微信H5支付配置</span>
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>1. 用户的实际支付方式将根据配置的先后顺序优先选择；</p>
                      <p>2. 若配置为空， 收银台不显示H5支付按钮。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-select
                  v-model:value="vdata.webCashierWxH5Config.configVal"
                  mode="multiple"
                  style="width: 100%"
                  :options="vdata.cashierWxH5Data"
                  placeholder="请选择微信H5支付顺序"
                />
              </a-form-item>
              <a-form-item v-if="vdata.webCashierState.configVal == 1">
                <template #label>
                  <span>支付宝H5支付配置</span>
                  <a-popover placement="top">
                    <template #title><span>配置说明</span></template>
                    <template #content>
                      <p>1. 用户的实际支付方式将根据配置的先后顺序优先选择；</p>
                      <p>2. 若配置为空， 收银台不显示H5支付按钮。</p>
                    </template>
                    <question-circle-outlined />
                  </a-popover>
                </template>
                <a-select
                  v-model:value="vdata.webCashierAliWapConfig.configVal"
                  style="width: 100%"
                  mode="multiple"
                  :options="vdata.cashierAliWebData"
                  placeholder="请选择支付宝WAP支付顺序"
                />
              </a-form-item>
              
              <a-form-item style="margin-top: 20px;" class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmByWebCashierManage"><check-circle-outlined />保存</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane>

        <a-tab-pane v-if="$hasMemberEnt()" key="memberConfig" tab="会员管理">
          <div v-if="vdata.groupKey == 'memberConfig'" class="account-settings-info-view">
            <a-form ref="configFormModel" :model="vdata.memberConfigData" layout="vertical">
              <a-row justify="start" type="flex" style="margin-top: 20px">
                <a-col v-for="(item, config) in vdata.memberConfigData" :key="config" :span="7" :offset="1">
                  <a-form-item :label="item.configName">
                    <a-radio-group v-if="item.type === 'radio'" v-model:value="item.configVal">
                      <a-radio value="1">启用</a-radio>
                      <a-radio value="0">禁用</a-radio>
                    </a-radio-group>

                    <a-input-number v-if="item.type === 'text'" v-model:value="item.configVal" placeholder="请输入" :min="0" style="width: 60%;" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-form-item class="bottom-btn">
                <a-button type="primary" :loading="vdata.btnLoading" @click="confirmUpdateMemberConfig"><check-circle-outlined />保存</a-button>
              </a-form-item>
            </a-form>
          </div>
        </a-tab-pane> 
      </a-tabs>
    </div>
  </a-drawer>
</template>
<script setup lang="ts">
import { API_URL_MCH_CONFIG, API_URL_MCH_LIST, req, $mchConfigCreateCashier, API_URL_MCH_APP, API_URL_MCH_STORE_LIST, } from '@/api/manage'
import { ref, reactive, getCurrentInstance } from 'vue'
import QrcodeVue from 'qrcode.vue'

  const { $infoBox, $access, $hasMemberEnt } = getCurrentInstance()!.appContext.config.globalProperties

  const configFormModel = ref()
  const payTestBarCode =ref()


  const vdata : any = reactive ({

    recordId: null, // 更新对象ID
    visible: false, // 是否显示弹层/抽屉

    mchAppList: [] as any, // app列表
    mchStoreList: [] as any, // 门店列表
    appId: '', // 已选择的appId
    storeId: '', // 已选择的门店ID
    cashierUrl: '',  // 收银台地址
    isShowCashier: true as any,

    btnLoading: false,
    groupKey: 'orderConfig',
    mchConfigData: [] as any, // 配置保存对象
    defaultConfig: [{
      configKey: 'appVoice',
      configName: '是否启用app订单语音播报',
      configVal: '1',
      type: 'radio'
    },
    {
      configKey: 'qrcEscaping',
      configName: '是否启用码牌防逃单功能',
      configVal: '1',
      type: 'radio'
    },
    {
    configKey: 'weChatVoice',
    configName: '小程序语音推送',
    configVal: '0',
    type: 'radio'
    }
  ], // 默认配置项

    mchPayNotifyUrl: '', // 用户支付回调地址
    mchRefundNotifyUrl: '', // 用户退款回调地址

    mchNotifyFlag: {
      payNotifyFlag: '1',
      refundNotifyFlag: '1'
    },  // 用户回调开关

    mchNotifyPostType: 'POST_BODY', // 发送用户通知的方式  POST_BODY   POST_QUERYSTRING  POST_JSON
    
    notifyTableColumns: [
      {key: 'batch', title: '批量选择' },
      {key: 'key', dataIndex: 'key', title: '参数KEY' },
      {key: 'name', dataIndex: 'name', title: '参数名称' },
      // {key: 'desc', dataIndex: 'desc', title: '参数描述' }
    ],

    notifyTableData: [
      {key: 'payOrderId', name: '支付订单号', desc: '', checked: true, disabled: true },
      {key: 'mchNo', name: '用户号', desc: '用户号', checked: true, disabled: true },
      {key: 'appId', name: '应用ID', desc: '', checked: true, disabled: true },
      {key: 'mchOrderNo', name: '用户订单号', desc: '', checked: true, disabled: true },
      {key: 'ifCode', name: '支付接口', desc: '', checked: true, disabled: true },
      {key: 'wayCode', name: '支付方式', desc: '', checked: true, disabled: true },
      {key: 'amount', name: '支付金额', desc: '', checked: true, disabled: true },
      {key: 'currency', name: '货币代码', desc: '', checked: true, disabled: true },
      {key: 'state', name: '订单状态', desc: '', checked: true, disabled: true },
      {key: 'clientIp', name: '客户端IP', desc: '', checked: true, disabled: true },
      {key: 'subject', name: '商品标题', desc: '', checked: true, disabled: true },
      {key: 'body', name: '商品描述', desc: '', checked: true, disabled: true },
      {key: 'channelOrderNo', name: '渠道订单号', desc: '', checked: true, disabled: true },
      {key: 'errCode', name: '渠道错误码', desc: '', checked: true, disabled: true },
      {key: 'errMsg', name: '渠道错误描述', desc: '', checked: true, disabled: true },
      {key: 'extParam', name: '扩展参数', desc: '', checked: true, disabled: true },
      {key: 'successTime', name: '支付成功时间', desc: '', checked: true, disabled: true },
      {key: 'createdAt', name: '创建时间', desc: '', checked: true, disabled: true },
      {key: 'sign', name: '签名', desc: '', checked: true, disabled: true },

      {key: 'storeId', name: '门店ID', desc: '', checked: false, disabled: false },
      {key: 'lng', name: '经度', desc: '', checked: false, disabled: false },
      {key: 'lat', name: '纬度', desc: '', checked: false, disabled: false },
      {key: 'qrcId', name: '码牌ID', desc: '', checked: false, disabled: false },
      {key: 'wayCodeType', name: '支付方式代码分类', desc: '', checked: false, disabled: false },
      {key: 'mchFeeRate', name: '用户手续费费率快照', desc: '', checked: false, disabled: false },
      {key: 'mchFeeAmount', name: '用户手续费,单位分', desc: '', checked: false, disabled: false },
      {key: 'channelUser', name: '渠道用户标识,如微信openId,支付宝账号', desc: '', checked: false, disabled: false },
      {key: 'divisionMode', name: '订单分账模式', desc: '', checked: false, disabled: false },
      {key: 'buyerRemark', name: '买家备注', desc: '买家备注', checked: false, disabled: false },
      {key: 'sellerRemark', name: '卖家备注', desc: '卖家备注', checked: false, disabled: false },
      {key: 'expiredTime', name: '订单失效时间', desc: '', checked: false, disabled: false },
      {key: 'platformOrderNo', name: '支付凭证交易单号', desc: '', checked: false, disabled: false },
      {key: 'platformMchOrderNo', name: '支付凭证用户单号', desc: '', checked: false, disabled: false },
    ],

    mchApiEntTableColumns: [
      {key: 'batch', title: '批量选择' },
      {key: 'title', dataIndex: 'title', title: '名称' },
      {key: 'key', dataIndex: 'key', title: 'KEY' },
      {key: 'apiPath', dataIndex: 'apiPath', title: '路径' },
    ],

    mchApiEntTableData: [
      // {key: 'API_PAY_ORDER', title: '统一下单', apiPath: '/api/pay/unifiedOrder', checked: false },
      // {key: 'API_PAY_ORDER_QUERY', title: '查询支付订单', apiPath: '/api/pay/query', checked: false },
      // {key: 'API_PAY_ORDER_CLOSE', title: '支付订单关闭', apiPath: '/api/pay/close', checked: false },
      // {key: 'API_CHANNEL_USER', title: '获取渠道用户ID', apiPath: '/api/channelUserId/jump', checked: false },
      // {key: 'API_REFUND_ORDER', title: '发起支付退款', apiPath: '/api/refund/refundOrder', checked: false },
      // {key: 'API_REFUND_ORDER_QUERY', title: '查询退款订单', apiPath: '/api/refund/query', checked: false },
      // {key: 'API_TRANS_ORDER', title: '发起转账订单', apiPath: '/api/transferOrder', checked: false },
      // {key: 'API_TRANS_ORDER_QUERY', title: '查询转账订单', apiPath: '/api/transfer/query', checked: false },
      // {key: 'API_TRANS_BALANCE_QUERY', title: '查询转账可用余额', apiPath: '/api/transfer/balance/query', checked: false },
      // {key: 'API_DIVISION_BIND', title: '绑定分账用户', apiPath: '/api/division/receiver/bind', checked: false },
      // {key: 'API_DIVISION_EXEC', title: '发起订单分账', apiPath: '/api/division/exec', checked: false },
      // {key: 'API_DIVISION_CHANNEL_BALANCE', title: '查询分账用户可用余额', apiPath: '/api/division/receiver/channelBalanceQuery', checked: false },
      // {key: 'API_DIVISION_CHANNEL_CASHOUT', title: '对分账用户的渠道余额发起提现', apiPath: '/api/division/receiver/channelBalanceCashout', checked: false },
      {key: 'API_APP_PAY', title: 'APP支付', apiPath: '', checked: false },
      {key: 'API_H5_PAY', title: '手机网站支付', apiPath: '', checked: false },
      {key: 'API_PC_PAY', title: '电脑网站支付', apiPath: '', checked: false },
      {key: 'API_JSAPI_PAY', title: '公众号/生活号支付', apiPath: '', checked: false },
      {key: 'API_CASHIER_PAY', title: '聚合收银台支付', apiPath: '', checked: false },
      {key: 'API_SCAN_PAY', title: '聚合反扫支付(B扫C)（扫码）', apiPath: '', checked: false },
      {key: 'API_UNIFIED_REFUND', title: '统一退款', apiPath: '', checked: false },
      {key: 'API_ORDER_QUERY', title: '订单查询', apiPath: '', checked: false },
      {key: 'API_REFUND_QUERY', title: '退款查询', apiPath: '', checked: false },
      {key: 'API_WXUSER_QUERY', title: '微信用户标识查询', apiPath: '', checked: false },
      {key: 'API_ORDER_DIVISION', title: '订单分账', apiPath: '', checked: false },
      {key: 'API_DIVISION_QUERY', title: '分账查询', apiPath: '', checked: false },
     ],

    cashierWxH5Data: [
      { label: '微信H5', value: 'WX_H5', },
      { label: '微信小程序', value: 'WX_LITE', },
    ],
    cashierAliWebData: [ 
      { label: '支付宝WAP', value: 'ALI_WAP', },
      { label: '支付宝生活号', value: 'ALI_JSAPI', },
      { label: '支付宝小程序', value: 'ALI_LITE', },
    ],


    // 分账管理菜单 
    divisionConfig: { overrideAutoFlag: 0, autoDivisionRules: { amountLimit: 0, delayTime: 120  }, mchDivisionEntFlag: 1, calBaseAmountType: 'INCOME_AMOUNT' },

    // 广告配置
    advertConfig: { advertFlag: 0 },

    // 便捷收银台配置
    selfCashierState : { configKey: 'selfCashierState', configName: '便捷收银台权限开关', configVal: '0', type: 'radio' }, 
    selfCashierSiteInfoType: { configKey: 'selfCashierSiteInfoType', configName: '便捷收银台logo/底部显示配置', configVal: 'DEFAULT', type: 'text' }, 
    selfCashierWxH5Config: { configKey: 'selfCashierWxH5Config', configName: '便捷收银台微信H5配置', configVal: ['WX_H5'], type: 'text' }, 
    selfCashierAliWapConfig: { configKey: 'selfCashierAliWapConfig', configName: '便捷收银台支付宝WAP配置', configVal: ['ALI_WAP'], type: 'text'},
    
    // 用户web收银台配置
    wabCashierState: { configKey: 'wabCashierState', configName: 'WEB收银台权限开关', configVal: '0', type: 'radio' },
    wabCashierSiteInfoType: { configKey: 'wabCashierSiteInfoType', configName: 'WEB收银台logo/底部显示配置', configVal: 'DEFAULT', type: 'text' },
    wabCashierWxH5Config: { configKey: 'wabCashierWxH5Config', configName: 'WEB收银台微信H5配置', configVal: ['WX_H5'], type: 'text' },
    wabCashierAliWapConfig: { configKey: 'wabCashierAliWapConfig', configName: 'WEB收银台支付宝WAP配置', configVal: ['ALI_WAP'], type: 'text' },

    // 会员配置
    memberConfigData: [
      { configKey: 'memberModelState', configName: '会员模块状态开关', configVal: '1', type: 'radio' },
      { configKey: 'memberPayState', configName: '会员支付开关', configVal: '0', type: 'radio' },
      { configKey: 'memberCustomAmountState', configName: '充值自定义金额', configVal: '1', type: 'radio' },
      { configKey: 'mbrMaxBalance', configName: '会员最大储值余额(元), 0表示依据系统配置', configVal: '0', type: 'text' },
    ],
  })


  function show (recordId) { // 弹层打开事件

      vdata.recordId = recordId
      selectTabs('orderConfig') //初始化数据
      vdata.visible = true
  }


  function selectTabs (key) { // 清空必填提示
    
    if (key) {
      vdata.groupKey = key

      if(key == 'orderConfig'){

        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            vdata.mchConfigData = res
            // 遍历总配置列表；如果configKey不存在则push进该条记录
            for (var key in vdata.defaultConfig) {
              // configKey是否存在 默认为不存在
              var isdefault = true
              vdata.mchConfigData.forEach((item) => {
                // 遍历到相同key时，key存在，赋值false
                if (item.configKey == vdata.defaultConfig[key].configKey) {
                  isdefault = false
                }
              })
              // 如果不存在 true 添加该条默认记录
              if(isdefault) {
                vdata.mchConfigData.push(vdata.defaultConfig[key])
              }
            }

          }else {
            vdata.mchConfigData = vdata.defaultConfig
          }
        })
      }else if(key == 'payOrderNotifyExtParams'){

         // 恢复初始值
         vdata.notifyTableData.filter(r => !r.disabled).forEach(r => {
             r. checked = false
         })
        
         vdata.mchNotifyPostType = 'POST_BODY'
         vdata.mchPayNotifyUrl = ''
         vdata.mchRefundNotifyUrl = ''

        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            res.forEach(item => {
              if (item.configKey == 'payOrderNotifyExtParams') {
                let arr = JSON.parse(item.configVal)
                vdata.notifyTableData.filter(r => !r.disabled).forEach(r => {
                  r.checked =  arr.indexOf(r.key) >= 0
                })
              }else if (item.configKey == 'mchPayNotifyUrl') {
                vdata.mchPayNotifyUrl = item.configVal
              }else if (item.configKey == 'mchRefundNotifyUrl') {
                vdata.mchRefundNotifyUrl = item.configVal
              }else if (item.configKey == 'mchNotifyPostType') {
                vdata.mchNotifyPostType = item.configVal
              }else if (item.configKey == 'mchNotifyFlag') {
                if (item.configVal) {
                  vdata.mchNotifyFlag = JSON.parse(item.configVal)
                }
              }

            })
          }
        })
      }else if(key == 'divisionManage'){

        // 分账管理恢复默认
        vdata.divisionConfig = { overrideAutoFlag: 0, autoDivisionRules: { amountLimit: 0, delayTime: 120  }, mchDivisionEntFlag: 1, calBaseAmountType: 'INCOME_AMOUNT' }

        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            vdata.divisionConfig = JSON.parse(res[0].configVal)
            if(!vdata.divisionConfig.calBaseAmountType){
              vdata.divisionConfig.calBaseAmountType = 'INCOME_AMOUNT' // 存量数据为空， 默认为： 入账金额。 
            }
            vdata.divisionConfig.autoDivisionRules.amountLimit = Number.parseFloat((vdata.divisionConfig.autoDivisionRules.amountLimit / 100).toFixed(2))
          }
        })
      }else if(key == 'mchApiEnt'){ // 接口权限 


        // 恢复初始值
        vdata.mchApiEntTableData.forEach(r => {
             r. checked = false
         })

        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            res.forEach(item => {
              if (item.configKey == 'mchApiEntList') { // 用户接口权限集合 
                let arr = JSON.parse(item.configVal)
                vdata.mchApiEntTableData.forEach(r => {
                  r.checked = arr.indexOf(r.key) >= 0
                })
              }
            })
          }
        })
        
      }else if(key == 'advertConfig'){ // 广告权限 


        // 恢复初始值
        vdata.mchApiEntTableData.forEach(r => {
            r. checked = false
        })

        req.getById(API_URL_MCH_LIST, vdata.recordId).then(res => {
          vdata.advertConfig = res
        })

      }else if(key == 'selfCashier'){ // 便捷收银台配置

        // 初始化配置
        vdata.selfCashierState = { configKey: 'selfCashierState', configName: '便捷收银台权限开关', configVal: '0', type: 'radio' }, 
        vdata.selfCashierSiteInfoType = { configKey: 'selfCashierSiteInfoType', configName: '便捷收银台logo/底部显示配置', configVal: 'DEFAULT', type: 'text' }, 
        vdata.selfCashierWxH5Config = { configKey: 'selfCashierWxH5Config', configName: '便捷收银台微信H5配置', configVal: ['WX_H5'], type: 'text' }, 
        vdata.selfCashierAliWapConfig = { configKey: 'selfCashierAliWapConfig', configName: '便捷收银台支付宝WAP配置', configVal: ['ALI_WAP'], type: 'text'},
    
        
        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            res.forEach(value => {
              
              if(value.configKey == 'selfCashierState') {
                vdata.selfCashierState = value
              }else if (value.configKey == 'selfCashierSiteInfoType') {
                vdata.selfCashierSiteInfoType = value
              }else if (value.configKey == 'selfCashierWxH5Config') {
                vdata.selfCashierWxH5Config = value
                if (vdata.selfCashierWxH5Config.configVal) {
                  vdata.selfCashierWxH5Config.configVal = JSON.parse(vdata.selfCashierWxH5Config.configVal)
                }
              }else if (value.configKey == 'selfCashierAliWapConfig') {
                vdata.selfCashierAliWapConfig = value
                if (vdata.selfCashierAliWapConfig.configVal) {
                  vdata.selfCashierAliWapConfig.configVal = JSON.parse(vdata.selfCashierAliWapConfig.configVal)
                }
              }
            })
          }
        })


        vdata.appId = ''
        vdata.storeId = ''
        // 请求接口，获取所有的appid，只有此处进行pageSize=-1传参
        req.list(API_URL_MCH_APP, { pageSize: -1, mchNo: vdata.recordId, state: 1 }).then(res => {
          vdata.mchAppList = res.records
          if (vdata.mchAppList.length > 0) {
            // 赋予默认值
            //vdata.appId = vdata.mchAppList[0].appId
            //TODO
            if(vdata.appId == '') vdata.appId = vdata.mchAppList[0].appId
            // 根据appId的值，动态显示支付方式
            // appPaywayListHandle(vdata.appId)
            one()
          }
          
        })
        function one (){
          // 请求接口，获取用户所有门店，只有次数进行pageSize=-1传参
          req.list(API_URL_MCH_STORE_LIST, { pageSize: -1, mchNo: vdata.recordId }).then(res => {
            vdata.mchStoreList = res.records
            if (vdata.mchStoreList.length > 0) {
              // 赋予默认值
              if(vdata.storeId == '') vdata.storeId = vdata.mchStoreList[0].storeId
              two()
            }
          })
        }
        function two (){
          $mchConfigCreateCashier({
            appId: vdata.appId, // appId
            storeId: vdata.storeId, // storeId
            mchNo: vdata.recordId
          }).then(res => {
            vdata.cashierUrl = res
          }).catch(() => {
            payTestBarCode.value.processCatch()
          })
        }

      }else if(key == 'webCashier'){ // web收银台配置

        // 初始化配置
        vdata.webCashierState = { configKey: 'webCashierState', configName: 'WEB收银台权限开关', configVal: '0', type: 'radio' }, 
        vdata.webCashierSiteInfoType = { configKey: 'webCashierSiteInfoType', configName: 'WEB收银台logo/底部显示配置', configVal: 'DEFAULT', type: 'text' }, 
        vdata.webCashierWxH5Config = { configKey: 'webCashierWxH5Config', configName: 'WEB收银台微信H5配置', configVal: ['WX_H5'], type: 'text' }, 
        vdata.webCashierAliWapConfig = { configKey: 'webCashierAliWapConfig', configName: 'WEB收银台支付宝WAP配置', configVal: ['ALI_WAP'], type: 'text'},


        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {
          if (res != null && res.length > 0) {
            res.forEach(value => {
              
              if(value.configKey == 'webCashierState') {
                vdata.webCashierState = value
              }else if (value.configKey == 'webCashierSiteInfoType') {
                vdata.webCashierSiteInfoType = value
              }else if (value.configKey == 'webCashierWxH5Config') {
                vdata.webCashierWxH5Config = value
                if (vdata.webCashierWxH5Config.configVal) {
                  vdata.webCashierWxH5Config.configVal = JSON.parse(vdata.webCashierWxH5Config.configVal)
                }
              }else if (value.configKey == 'webCashierAliWapConfig') {
                vdata.webCashierAliWapConfig = value
                if (vdata.webCashierAliWapConfig.configVal) {
                  vdata.webCashierAliWapConfig.configVal = JSON.parse(vdata.webCashierAliWapConfig.configVal)
                }
              }
            })
          }
        })

      }else if(key == 'memberConfig'){
        req.list(API_URL_MCH_CONFIG, {groupKey: vdata.groupKey, mchNo: vdata.recordId}).then(res => {

          if (res != null && res.length > 0) {
            vdata.memberConfigData.forEach(item =>{
              res.forEach(res => {
                if (item.configKey == res.configKey) {
                  item.configVal = res.configVal

                  if (item.configKey == 'mbrMaxBalance' && res.configVal) {
                    item.configVal = Number.parseFloat((res.configVal / 100).toFixed(2))
                  }
                }
              })
            })
          }

        })
      }

    }
  }


  // 确认更新
  function confirm (e) {
    configFormModel.value.validate().then(valid => {
      $infoBox.confirmPrimary('确认修改支付配置吗？', '', () => {
        vdata.btnLoading = true // 打开按钮上的 loading

        req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: JSON.stringify(vdata.mchConfigData)}).then(res => {
          $infoBox.message.success('修改成功')
          vdata.btnLoading = false
        }).catch(res => {
          vdata.btnLoading = false
        })
      })
    })
  }


  // 确认更新
  function confirmByNotify (e) {

    $infoBox.confirmPrimary('确认修改回调参数吗？', '更新完成后请尽快检查回调接收地址，避免验签失败造成业务损失！', () => {
      vdata.btnLoading = true // 打开按钮上的 loading


      let arr : any = []
      vdata.notifyTableData.filter(r => !r.disabled).forEach(r => {
          if(r.checked){
            arr.push(r.key)
          }
      })

      let configItem = [
                  { groupKey: vdata.groupKey, configName: '支付订单回调和查单参数', configKey: 'payOrderNotifyExtParams', configVal : JSON.stringify(arr) },
                  { groupKey: vdata.groupKey, configName: 'POS支付回调地址', configKey: 'mchPayNotifyUrl', configVal : vdata.mchPayNotifyUrl },
                  { groupKey: vdata.groupKey, configName: 'POS退款回调地址', configKey: 'mchRefundNotifyUrl', configVal : vdata.mchRefundNotifyUrl },
                  { groupKey: vdata.groupKey, configName: '回调开关', configKey: 'mchNotifyFlag', configVal : vdata.mchNotifyFlag },
                  { groupKey: vdata.groupKey, configName: '用户接收通知方式', configKey: 'mchNotifyPostType', configVal : vdata.mchNotifyPostType }
                      ]

      req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: JSON.stringify(configItem)}).then(res => {
        $infoBox.message.success('修改成功')
        vdata.btnLoading = false
      }).catch(res => {
        vdata.btnLoading = false
      })
    })
  }

  function confirmByDivisionManage(){

    $infoBox.confirmPrimary('确认修改分账设置？', '', () => {
      vdata.btnLoading = true // 打开按钮上的 loading

      let reqObject : any = JSON.parse(JSON.stringify(vdata.divisionConfig))
      reqObject.autoDivisionRules.amountLimit = Number.parseInt((reqObject.autoDivisionRules.amountLimit * 100) + '')

      req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: [{configKey: 'divisionConfig', configName: '分账管理', configVal: JSON.stringify(reqObject)}]}).then(res => {
        $infoBox.message.success('修改成功')
        vdata.btnLoading = false
      }).catch(res => {
        vdata.btnLoading = false
      })
    })

  }
  function confirmByAdvertManage(){

    $infoBox.confirmPrimary('确认修改广告设置？', '', () => {
      vdata.btnLoading = true // 打开按钮上的 loading

      let reqObject : any = JSON.parse(JSON.stringify(vdata.advertConfig))

      req.updateById(API_URL_MCH_LIST, vdata.recordId, reqObject).then(res => {
        $infoBox.message.success('修改成功')
        vdata.btnLoading = false
      }).catch(res => {
        vdata.btnLoading = false
      })
    })

  }

  function confirmBySelfCashierManage(){

    $infoBox.confirmPrimary('确认修改便捷收银台设置？', '', () => {
      vdata.btnLoading = true // 打开按钮上的 loading

      let arr : any = []
      arr.push(vdata.selfCashierState)
      arr.push(vdata.selfCashierSiteInfoType)
      arr.push(vdata.selfCashierWxH5Config)
      arr.push(vdata.selfCashierAliWapConfig)

      let reqObject : any = JSON.stringify(arr)

      req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: reqObject}).then(res => {
        vdata.btnLoading = false
        $infoBox.message.success('修改成功')
      }).catch(res => {
        vdata.btnLoading = false
      })
    })

  }

  function confirmByWebCashierManage(){

    $infoBox.confirmPrimary('确认修改WEB收银台设置？', '', () => {
      vdata.btnLoading = true // 打开按钮上的 loading

      let arr : any = []
      arr.push(vdata.webCashierState)
      arr.push(vdata.webCashierSiteInfoType)
      arr.push(vdata.webCashierWxH5Config)
      arr.push(vdata.webCashierAliWapConfig)

      let reqObject : any = JSON.stringify(arr)

      req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: reqObject}).then(res => {
        vdata.btnLoading = false
        $infoBox.message.success('修改成功')
      }).catch(res => {
        vdata.btnLoading = false
      })
    })

  }

  // 更新会员配置
function confirmUpdateMemberConfig(){
  $infoBox.confirmPrimary('确认修改会员配置吗？', '', () => {
    vdata.btnLoading = true // 打开按钮上的 loading

    let reqObject : any = JSON.parse(JSON.stringify(vdata.memberConfigData))

    // 最大储值金额
    reqObject.forEach(item => {
      if (item.configKey == 'mbrMaxBalance') {
        const mbrMaxBalance = item.configVal ? item.configVal : 0
        item.configVal = Number.parseInt((mbrMaxBalance * 100).toFixed(0)).toString()
      }
    })

    req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: reqObject}).then(res => {
      $infoBox.message.success('修改成功')
      vdata.btnLoading = false

      selectTabs('memberConfig')
    }).catch(res => {
      vdata.btnLoading = false
    })
  })
}


    // 确认更新
  function confirmByApiEnt (e) {

    $infoBox.confirmPrimary('确认修改用户的接口权限？', '', () => {
      vdata.btnLoading = true // 打开按钮上的 loading

      let arr : any = []
      vdata.mchApiEntTableData.forEach(r => {
          if(r.checked){
            arr.push(r.key)
          }
      })

      let configItem = [{ groupKey: vdata.groupKey, configName: '用户接口权限集合', configKey: 'mchApiEntList', configVal : JSON.stringify(arr) }]

      req.updateById(API_URL_MCH_CONFIG, vdata.groupKey, {mchNo: vdata.recordId, configData: JSON.stringify(configItem)}).then(res => {
        $infoBox.message.success('修改成功')
        vdata.btnLoading = false
      }).catch(res => {
        vdata.btnLoading = false
      })
    })
  }


   // 全选，反选
  function notifyAllCehcked(isChekced){
      vdata.notifyTableData.filter(r => !r.disabled).forEach(r => {
        r.checked = isChekced
      })
  }

  // 全选，反选
  function mchApiEntAllCehcked(isChekced){
    vdata.mchApiEntTableData.filter(r => !r.disabled).forEach(r => {
      r.checked = isChekced
    })
  }

 // 变更 appId的事件
 function changeAppId (value) {
    immediatelyPay()
  }
  // 变更 门店ID的事件
  function changeStoreId (value) {
    immediatelyPay()
  }
  // 立即支付按钮
  function immediatelyPay () {

    // 判断是否选择门店
    if (vdata.appId === '') {
      vdata.isShowCashier = false
      return false
    }
    // 判断是否选择门店
    if (vdata.storeId === '') {
      vdata.isShowCashier = false
      return false
    }

    vdata.isShowCashier = true
    $mchConfigCreateCashier({
      appId: vdata.appId, // appId
      storeId: vdata.storeId, // storeId
      mchNo: vdata.recordId
    }).then(res => {
      vdata.cashierUrl = res
    }).catch(() => {
      payTestBarCode.value.processCatch()
    })
  }

defineExpose({
  show
})
</script>
<style lang="less" scoped>
  .bottom-btn{
    /deep/ div{
      display: flex;
      justify-content: center;
    }
  }
  .typePopover {
  position: absolute;
  top: -30px;
  left: 93px;
}
</style>
