<template>
  <div class="system-user-dialog-container">
    <el-dialog v-model="state.dialog.isShowDialog" :close-on-click-modal="false" width="400px" draggable>
      <template #header="{ titleId, titleClass }">
        <div class="my-header">
          <span>审核</span>
        </div>
      </template>
      <el-form ref="userDialogFormRef" :model="state.ruleForm" size="default" label-width="80px">
        <el-row :gutter="35">
          <el-col :xs="24" class="mb20">
            <el-form-item label="备注">
              <el-input v-model="state.ruleForm.approvalRemark" type="textarea" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel" size="default">取 消</el-button>
          <el-button type="danger" @click="onSubmit(0)" size="default">拒绝</el-button>
          <el-button type="primary" @click="onSubmit(1)" size="default">通过</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts" name="systemUserDialog">
import { reactive, ref, defineAsyncComponent, nextTick } from "vue";
import { ElAlert, ElMessage, ElNotification, rowProps } from "element-plus";
import { UploadFilled } from '@element-plus/icons-vue'
import { getApi } from "/@/api/district/examine";

// 定义子组件向父组件传值/事件
const emit = defineEmits(["refresh"]);

const forms = {
  approvalRemark: '',
  id: '',
  businessState: ""
};
// 定义变量内容
const state = reactive({
  ruleForm: {
    approvalRemark: '',
    id: '',
    businessState: ""
  } as any,
  dialog: {
    isShowDialog: false,
  }
});

// 打开弹窗
const openDialog = (row?: any) => {
  state.ruleForm = Object.assign({}, forms);
  nextTick(() => {
    state.ruleForm = {
      approvalRemark: row.approvalRemark,
      id: row.id,
      businessState: ""
    };
  })
  state.dialog.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
  state.dialog.isShowDialog = false;
};
// 取消
const onCancel = () => {
  closeDialog();
};
// 提交
const onSubmit = async (e: number) => {
  let _form = state.ruleForm;
  if (e == 0) {
    if (_form.approvalRemark == "") return ElMessage.error("请输入备注");
    _form.businessState = 3
    let item = await getApi().editApi(_form)
    if (item.success) {
      ElMessage.success(item.msg)
      state.dialog.isShowDialog = false;
      emit('refresh')
    } else {
      ElMessage.error(item.msg)
    }
  } else {
    _form.businessState = 2
    let item = await getApi().editApi(_form)
    if (item.success) {
      ElMessage.success(item.msg)
      state.dialog.isShowDialog = false;
      emit('refresh')
    } else {
      ElMessage.error(item.msg)
    }
  }


};
// 暴露变量
defineExpose({
  openDialog,
});
</script>
