<template>
  <div style="background: #fff">
    <div class="account-settings-info-view">
      <a-form ref="configFormModel" layout="vertical">
        <a-divider orientation="left">代理商平台</a-divider>
        <a-row>
          <a-col  :span="8" :offset="1">
            <a-form-item label="代理商平台网址(不包含结尾/)"  name="agentSiteUrl">
              <a-input v-model:value="vdata.configData.agentSiteUrl" type="text" autocomplete="off" />
            </a-form-item>
          </a-col>
          <a-col  :span="8" :offset="1">

          </a-col>
          <a-col :span="8" :offset="1">
            <a-form-item label="服务商域名SSL证书文件" name="agentSiteCrtUrl">
              <JeepayUpload v-model:src="vdata.configData.agentSiteCrtUrl" fileType="file" bizType="cert" />
              <span class="jeepay-tip-text">文件格式：pem</span>
            </a-form-item>
          </a-col>
          <a-col :span="8" :offset="1">
            <a-form-item label="服务商域名SSL私钥文件" name="agentSitePriKeyUrl">
              <JeepayUpload v-model:src="vdata.configData.agentSitePriKeyUrl" fileType="file" bizType="cert" />
              <span class="jeepay-tip-text">文件格式：key</span>
            </a-form-item>
          </a-col>
        </a-row>

        <a-divider orientation="left">商户平台</a-divider>
        <a-row>
          <a-col  :span="8" :offset="1">
            <a-form-item label="商户平台网址(不包含结尾/)"  name="mchSiteUrl">
              <a-input v-model:value="vdata.configData.mchSiteUrl" type="text" autocomplete="off" />
            </a-form-item>
          </a-col>

          <a-col  :span="8" :offset="1">

          </a-col>
          <a-col :span="8" :offset="1">
            <a-form-item label="商户平台域名SSL证书文件" name="mchSiteCrtUrl">
              <JeepayUpload v-model:src="vdata.configData.mchSiteCrtUrl" fileType="file" bizType="cert" />
              <span class="jeepay-tip-text">文件格式：pem</span>
            </a-form-item>
          </a-col>
          <a-col :span="8" :offset="1">
            <a-form-item label="商户平台域名SSL私钥文件" name="mchSitePriKeyUrl">
              <JeepayUpload v-model:src="vdata.configData.mchSitePriKeyUrl" fileType="file" bizType="cert" />
              <span class="jeepay-tip-text">文件格式：key</span>
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item class="bottom-btn">
          <a-button v-if="$access('ENT_SYS_CONFIG_EDIT')" :disabled="!vdata.isEdit" type="primary" :loading="vdata.btnLoading" @click="confirm">
            <check-circle-outlined />确认更新
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
<script setup lang="ts">
import {
  API_URL_SYS_CONFIG,
  req,
  $getConfigs,
  $getAgentConfigSiteConfig,
  $postAgentConfigSiteConfig
} from '@/api/manage'
import { reactive, onMounted, getCurrentInstance } from 'vue'

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

// 组件注入
const props: any = defineProps({
  currentAgentNo: { type: String, default: '' }, // 当前代理商No
})

  const vdata = reactive ({
    isEdit:$access('ENT_PUSH_CONFIG_EDIT'),
    btnLoading: false,
    groupKey: 'applicationConfig',
    configData: {
      agentSiteUrl:"",
      mchSiteUrl:"",
    } as any, // 配置保存对象
  }) as any

  onMounted(()=>{
    $getAgentConfigSiteConfig(props.currentAgentNo).then(res => {
      vdata.configData = res
    })
  })

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

      vdata.configData.agentNo = props.currentAgentNo
      $postAgentConfigSiteConfig(vdata.configData).then(res => {
        $infoBox.message.success('修改成功')
        vdata.btnLoading = false
      }).catch(res => {
        vdata.btnLoading = false
      })
    })

  }

</script>
<style lang="less" scoped>
  .bottom-btn{
    /deep/ div{
      display: flex;
      justify-content: center;
    }
  }
</style>
