<template>
  <section class="AiEvaluation">
    <AiPagePicker v-if="type=='submit'&&!hasEvaluated" type="custom" :ops="ops" nodeKey="">
      <slot v-if="$slots.default"/>
      <div v-else v-text="placeholder"/>
    </AiPagePicker>
    <div v-if="type=='show'">
      <slot v-if="$slots.default"/>
      <AiGroup description no-border labelColor="#999" v-else>
        <AiItem label="评级分数">
          <u-rate v-model="detail.score" disabled inactive-icon="star-fill" active-color="#F8B425"/>
          {{ detail.rateText || "" }}
        </AiItem>
        <AiItem label="评价详情" top-label>
          <div v-html="detail.content"/>
        </AiItem>
        <AiItem label="附件" top-label>
          <AiUploader :def="detail.files" disabled/>
        </AiItem>
      </AiGroup>
    </div>
    <slot name="finish" v-if="$slots.finish"/>
  </section>
</template>

<script>
import AiPagePicker from "./AiPagePicker";
import AiGroup from "./AiGroup";
import AiItem from "./AiItem";
import AiUploader from "./AiUploader";

export default {
  name: "AiEvaluation",
  model: {
    prop: "info",
    event: "input"
  },
  props: {
    info: {default: () => ({})},
    placeholder: {default: "去评价"},
    bid: {default: ""},
    type: {default: "submit"} //可选值: submit:提交评价,show:展示评价
  },
  components: {AiUploader, AiItem, AiGroup, AiPagePicker},
  computed: {
    isShow: v => v.type == 'show',
    hasEvaluated: v => !!v.detail?.id
  },
  data() {
    return {
      detail: {},
      ops: {
        rateTexts: ['非常不满意', '不满意', '一般', '满意', '非常满意'],
        url: "/components/pages/submitEvaluation?bid=" + this.bid
      }
    }
  },
  watch: {
    bid: {
      immediate: true,
      handler() {
        this.getDetail()
      }
    }
  },
  methods: {
    getDetail() {
      const bizId = this.bid
      bizId && this.$http.post("/app/appbusinesscompletionevaluation/queryMyEvaluationByBizId", null, {
        params: {bizId}
      }).then(res => {
        if (res?.data) {
          const info = res.data?.[0]
          this.detail = {...info, rateText: this.rateTexts?.[info.score - 1]}
          this.$emit("input", this.detail)
        }
      })
    }
  },
}
</script>
