<template>
  <div class="AIImageDetail">
    <p class="titleText">请主管了解情况后回复原因及解决方案</p>
    <div class="feedbackReason">
      <div class="cause">
        <div class="title">
          <span style="color: red">*</span>
          <span>反馈原因及解决方案</span>
        </div>
        <van-field
          v-model="causeMessageData"
          :disabled="approveState == '1'"
          rows="1"
          autosize
          type="textarea"
          placeholder="请反馈原因及解决方案" />
      </div>
    </div>
    <div class="confirmBtn" v-if="approveState == '0'">
      <van-button type="info" @click="confirm">提交</van-button>
    </div>
  </div>
</template>
<script>
import { savePhotoApprove } from '@/api/AIImage';
export default {
  name: 'AIImageDetail',
  props: {
    detail: {
      type: Object,
    },
    approveState: {
      type: String,
      default: '0',
    },
    causeMessage: {
      type: String,
      default: '',
    },
    photoApproveId: {
      type: [String, Number],
      default: '',
    },
  },
  watch: {
    detail: {
      handler(val) {
        this.causeMessageData = this.causeMessage;
      },
      immediate: true,
    },
  },
  data() {
    return {
      causeMessageData: '',
    };
  },
  methods: {
    confirm() {
      if (!this.causeMessageData) {
        this.$toast('请反馈原因及解决方案');
        return;
      }
      savePhotoApprove({
        photoApproveId: this.photoApproveId, //	long	主键
        resultCorrect: '', //	string	AI识别是否正确： 1 正确 0不正确
        reasonsSolutions: this.causeMessageData, //	string	原因及解决方案
        feedbackError: '', //	string	反馈AI识别不正确
      }).then((res) => {
        if (res.code == 200) {
          this.$toast.loading({
            duration: 1000,
            message: '已反馈给本部',
            forbidClick: true,
            onClose: () => {
              this.onClickLeft();
            },
          });
        } else {
          this.$toast('提交失败');
        }
      });
    },
    onClickLeft() {
      this.$router.replace({
        path: '/AIImage',
      });
    },
  },
};
</script>
