<template>
  <Dialog title="商户审核" v-model="dialogVisible" width="70%">
    <ContentWrap v-loading="formLoading" style="max-height:550px;min-height:550px;overflow-y: auto;border:none ;">
      <div class="left ">
        <SPuUploadImg v-model="picUrl" :disabled="true" />
        <el-tabs v-model="activeName" tab-position="left" class="child-tabs">
          <el-tab-pane label="基本信息" name="info" />
        </el-tabs>
      </div>
      <div class="right">
        <MerchantApplyBaseInfo :propFormData="Obj" :isDetail="isDetail" :openType="openType" 
            v-if="activeName == 'info'" />

      </div>

      <div style="clear: both;"></div>
    </ContentWrap>
    <!-- 20240527注释 隐藏操作 -->

      <template #footer v-if="checkPermi(['sale:merchant-apply:update'])">
        <div class="dialog-footer">

          <el-form ref="formRef" v-loading="formLoading"  label-width="80px" style="display: flex;" :rules="formRules" :model="formData">
            <el-form-item label="审核意见" prop="checkComment" >
              <el-input v-model="formData.checkComment" placeholder="请输入审核意见"  style="width: 300px;" />
            </el-form-item>
          </el-form>
          <el-button @click="openApplyList">审核列表</el-button>
          <el-button type="danger" @click="reject" v-hasPermi="['sale:merchant-apply:update']">拒绝</el-button>
          <el-button type="primary" @click="agree" v-hasPermi="['sale:merchant-apply:update']">同意</el-button>
        </div>
      </template>
 
 
  </Dialog>
  <MerchantApplyLog ref="merchantApplyLogRef" />
</template>

<script lang="ts" setup>
import Dialog from '@/components/Dialog/src/Dialog.vue'
import MerchantApplyBaseInfo from './MerchantApplyBaseInfo.vue'
import MerchantApplyLog from './MerchantApplyLog.vue'
import { MerchantApi, MerchantVO } from '@/api/system/sale/merchant'
import { FormRules } from 'element-plus'
import { checkPermi } from "@/utils/permission"; // 权限判断函数
const { t } = useI18n() // 国际化
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const activeName = ref('info') // Tag 激活的窗口
const dialogVisible = ref(false) // 弹窗的是否展示
const isDetail = ref(false)
const openType = ref('view')
const Obj = ref({})
const picUrl = ref('picUrl') //头像
/** 打开弹窗 */
const open = async (type: string, obj) => {
  picUrl.value = obj.logoUrl
  Obj.value = obj
  dialogVisible.value = true
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const message = useMessage() // 消息弹窗
const formData = reactive({
	checkComment: '', 
})

const formRules = reactive<FormRules>({
  checkComment: [{ required: true, message: '请输入审核意见'}],
})
const merchantApplyLogRef = ref()
/** 打开审核列表 */
const openApplyList = () => {
  merchantApplyLogRef.value.open(Obj.value.id)
}
/** 同意售后 */
const agree = async () => {
  if (formData.checkComment === '') {
    message.error('请填写审核意见');
    return;
  }
  Obj.value.checkComment = formData.checkComment;
  Obj.value.checkStatus = 1;
  try {
    // 二次确认
    await message.confirm('同意审核？')
    MerchantApi.updateMerchantApply(Obj.value).then(() => {
      // 提示成功
      message.success(t('common.success'))
      dialogVisible.value = false
      emit('success')
    })
    
  } catch { }
}

/** 拒绝申请 */
const reject = async () => {
  if (formData.checkComment === '') {
    message.error('请填写审核意见');
    return;
  }
  Obj.value.checkComment = formData.checkComment;
  Obj.value.checkStatus = 2;
  try {
    // 二次确认
    await message.confirm('拒绝申请?')
    await MerchantApi.updateMerchantApply(Obj.value).then(() => {
      // 提示成功
      message.success(t('common.success'))
      dialogVisible.value = false
      emit('success')
    })
    
  } catch { }
}


</script>

<style lang="scss">
.el-dialog__body {
  padding: 0;
}

.left {
  width: 106px;
  float: left;
}

.child-tabs {
  border-top: 2px solid #e4e7ef;
  margin-top: -7px;
}

.child-tabs .el-tabs__item {
  width: 106px;
  justify-content: center;
}

.right {
  padding: 10px 0 0 10px;
  border-left: 2px solid #e4e7ee;
  margin-left: -2px;
  float: left;
  width: calc(100% - 120px);
}
</style>