<script setup lang="ts">
import { ElForm } from "element-plus";
import { reactive, ref, watchEffect } from "vue";

const emit = defineEmits(["changeStatus"]);

const formData = reactive({
  status: "",
  remark: ""
});

const rules = reactive({
  status: [
    {
      required: true,
      trigger: "change",
      message: "选择审核状态"
    }
  ],
  remark: [
    {
      required: true,
      trigger: "change",
      message: "请输入备注"
    }
  ]
});

const formRef = ref<InstanceType<typeof ElForm>>(null);

const onSaveStatus = () => {
  formRef.value.validate(isValid => isValid && emit("changeStatus", formData));
};

watchEffect(() => (rules.remark[0].required = formData.status === "5"));
</script>

<template>
  <el-form
    ref="formRef"
    label-width="100px"
    size="small"
    :model="formData"
    :rules="rules"
  >
    <el-form-item label="审批状态" prop="status" w-400px>
      <el-select w-400px v-model="formData.status">
        <el-option label="通过" value="2" />
        <el-option label="不通过" value="5" />
      </el-select>
    </el-form-item>

    <el-form-item label="备注" prop="remark" w-400px>
      <el-input type="textarea" v-model="formData.remark" />
    </el-form-item>

    <el-form-item w-full flex justify-end>
      <el-button type="primary" @click="onSaveStatus">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<style lang="scss">
.upload {
  width: 178px;
  height: 178px;
  display: block;
  border: 1px dashed var(--el-border-color);

  .text {
    font-size: 20px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    text-align: center;
    line-height: 178px;
  }

  &:hover {
    border-color: var(--el-color-primary);
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
