<template>
  <div id="">
    <a-form
      :model="ruleForm"
      :rules="rules"
      :label-col="{span: 6}"
      :wrapper-col="{span: 18}"
      class="demo-ruleForm"
      ref="ruleForm">
      <a-form-item label="删除人姓名" prop="pblmDelPersnm">
        <a-input v-model:value="ruleForm.pblmDelPersnm " disabled/>
      </a-form-item>
      <a-form-item label="删除原因" prop="pblmDelNote">
        <a-textarea v-model:value="ruleForm.pblmDelNote " />
      </a-form-item>
      <a-form-item label="删除时间">
        <a-row :span="11">
          <a-form-item prop="date1">
            <a-date-picker
              placeholder="选择日期"
              disabled
              v-model:value="ruleForm.date1"
              style="width: 100%;"
              mode="time"
              format="YYYY-MM-DD HH:mm:ss"></a-date-picker>
          </a-form-item>
        </a-row>
      </a-form-item>
      <a-form-item :wrapper-col="{ span: 18, offset: 6 }">
        <a-button type="primary" @click="submitForm('ruleForm')">删除并添加原因</a-button>
        <a-button @click="resetForm('ruleForm')">重置</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
import moment from 'moment';
import {
  deleteFileById,
  findPageInfo,
  removeSupervise,
  showDetailsXq,
  submitUpload,
  updateMiaoshu,
} from '../../api/duChaAPI.js';
export default {
  props: ['deleteProblemId'],
  data() {
    return {
      moment,
      userId: localStorage.getItem('persId'),
      ruleForm: {
        pblmDelPersnm: localStorage.getItem('account1'),
        pblmDelPers: localStorage.getItem('persId'),
        date1: moment(new Date()),
        pblmDelNote: '',
      },
      rules: {
        pblmDelNote: [
          {
            required: true,
            message: '请填写删除原因',
            trigger: 'blur',
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    // 操作成功反馈
    successInfo() {
      this.ruleForm = {
        pblmDelPersnm: localStorage.getItem('account1'),
        pblmDelPers: localStorage.getItem('userid'),
        date1: moment(new Date()),
        pblmDelNote: '',
      };
      this.$message.success('删除成功');
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const that = this;
          this.$confirm({
            title: '提示',
            content: '删除该问题并添加删除原因, 是否继续?',
            okType: 'warning',
            onOk: () => {
              const data = this.ruleForm;
              data.pblmId = this.deleteProblemId;
              updateMiaoshu(data).then((res) => {
                console.log(res);
                if (res.success) {
                  removeSupervise(this.deleteProblemId, this.userId).then(
                    (res1) => {
                      if (res1.success) {
                        that.successInfo();
                        this.$emit('deleteSuccess');
                      } else {
                        // that.failInfo(res.message);
                      }
                    },
                  );
                }
              });
            },
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang='less' scoped>

</style>
