<template>
  <w-card-panel v-bind="panelAttrsComputed">
    <div class="flex flex-row gap-4">
      <div v-if="rating.cm.isAwaitSubmitProcessStatus.value" class="basis-1/4">
        <w-info-panel :info="rating.overturnTipData.value" :column-num="1"></w-info-panel>
      </div>
      <div :class="rating.cm.isAwaitSubmitProcessStatus.value ? 'basis-2/3' : 'flex-1'">
        <w-form
          ref="overturnFormRef"
          :fields="[
            { label: '附件', name: 'file', type: 'w-file' },
            { label: '是否推翻', name: 'isOverturn', type: 'w-checkbox' },
            {
              label: '推翻类型',
              name: 'overturnType',
              type: 'w-select',
              options: Options.dictionary(rating.dictionary.overturnType),
              requiredIf: true,
              showIf: (args) => {
                if (args?.form && args.form.getFieldValue('isOverturn')) {
                  return true;
                }
                return false;
              },
            },
            {
              label: '建议等级',
              name: 'suggestLevel',
              type: 'w-select',
              options: RatingLevelOptions,
              requiredIf: true,
              showIf: (args) => {
                if (args?.form && args.form.getFieldValue('isOverturn')) {
                  return true;
                }
                return false;
              },
            },
            {
              label: '意见说明',
              name: 'adjReason',
              type: 'w-textarea',
              requiredIf: true,
            },
          ]"
          :cols-num="1"
        ></w-form>
      </div>
    </div>
  </w-card-panel>
</template>
<script setup lang="ts">
import { Options } from 'platform-core';
import { computed, ref, inject } from 'vue';
import { RatingLevelOptions } from '../../CustRating';
import { Rating } from '../ts/Rating';

const rating = <Rating>inject('rating');
const overturnFormRef = ref();
const getOverturnFormRef = () => {
  return overturnFormRef.value;
};
rating.refs.setOverturnFormRefFunction(getOverturnFormRef);
const panelAttrsComputed = computed(() => {
  if (rating.cm.isAwaitSubmitProcessStatus.value) {
    return {
      label: '评级推翻',
      icon: 'model_training',
    };
  } else {
    return {
      label: '审批意见',
      icon: 'comment',
    };
  }
});
</script>
