<template>
  <div class="AIImageDetail">
    <p class="titleText">请主管了解情况后回复原因及解决方案</p>
    <div class="feedbackReason">
      <div class="result">
        <div class="title">
          <span style="color: red">*</span>
          <span>AI识别结果</span>
        </div>
        <van-radio-group v-model="AIResult" :disabled="approveState == '1'">
          <van-radio name="1">正确</van-radio>
          <van-radio name="0">不正确</van-radio>
        </van-radio-group>
      </div>
      <div class="cause">
        <div class="title">
          <span style="color: red">*</span>
          <span>{{ causeTitle }}</span>
        </div>
        <van-field
          v-model="causeMessageData"
          :disabled="approveState == '1'"
          rows="1"
          autosize
          type="textarea"
          :placeholder="'请输入' + causeTitle" />
      </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: '',
    },
  },
  data() {
    return {
      AIResult: '1',
      causeMessageData: '',
    };
  },
  watch: {
    AIResult: {
      handler(val) {
        if (val == 1) {
          this.causeTitle = '拜访照异常原因及解决方案';
        } else {
          this.causeTitle = '反馈AI识别结果有误';
        }
      },
      immediate: true,
    },
    detail: {
      handler(val) {
        this.causeMessageData = this.causeMessage;
      },
      immediate: true,
    },
  },
  mounted() {},
  methods: {
    confirm() {
      if (!this.causeMessageData) {
        this.$toast('请输入' + this.causeTitle);
        return;
      }
      savePhotoApprove({
        photoApproveId: this.photoApproveId, //	long	主键
        resultCorrect: this.AIResult, //	string	AI识别是否正确： 1 正确 0不正确
        reasonsSolutions: this.AIResult == '1' ? this.causeMessageData : '', //	string	原因及解决方案
        feedbackError: this.AIResult == '0' ? this.causeMessageData : '', //	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>
