<template>
  <sd-form
    ref="form"
    v-sd-watermark="waterMark"
    :init-values="FlowData.processFormData.processFormPropertyValues"
    :description="sdGet(FlowData, 'processFormData.attrFD?.description')"
    :read-only="readOnly"
    :class="[$style.form, 'sd-full-page-form']"
    :formula-validator="sdGet(FlowData, 'processFormData.attr?.formulaValidator')"
    :form-relations="sdGet(FlowData, 'processFormData.attr?.formRelations')"
  >
    <template v-slot="scope">
      <h2
        v-if="!sdGet(FlowData, 'processFormData.attrFD?.hideTableTxt')"
        :class="$style.title"
        class="sd-page-title"
        >{{ FlowData.pageTitle }}</h2
      >
      <slot v-bind="scope" :FlowData="FlowData" />
      <a-form-model-item
        v-show="false"
        v-if="scope.fields.approveOpinion && !scope.fields.approveOpinion.readonly"
        ref="approveOpinion"
        prop="approveOpinion"
        :rules="{
          validator: (rule, value, callback) =>
            $refs.opinionModel.validator(
              rule,
              value,
              callback
            )(scope.fields.approveOpinion.required),
          trigger: 'change',
        }"
      >
        <portal to="approve-opinion" :disabled="disabled">
          <div
            v-if="scope.fields.approveOpinion && scope.fields.approveOpinion.attr.showReplaceOption"
            :class="$style.coveropinion"
          >
            <span>覆盖上一次意见:</span>
            <a-switch @change="(checked) => (scope.fields.approveOpinion.attr.replace = checked)" />
          </div>
          <sd-opinion-model
            ref="opinionModel"
            v-model="scope.model.approveOpinion"
            :group-id="
              sdGet(JSON.parse(scope.fields.approveOpinion.value), 'value?.attrs?.attachment')
            "
          />
        </portal>
      </a-form-model-item>
    </template>
  </sd-form>
</template>

<script>
import systemManage from '@/system-manage/system-manage'
import sdFormPublicMethodsNew from '@/common/components/sd-form/sd-form-public-methods-new'
import components from './_import-components/sd-flow-form-import'
export default {
  name: 'SdFlowForm',
  components,
  mixins: [sdFormPublicMethodsNew],
  props: {
    /**
     * 整个表单是否只读
     */
    readOnly: {
      type: Boolean,
      default: false,
    },
    flowData: {
      type: Object,
      default: () => {},
    },
    waterMark: {
      type: String,
      default: systemManage.getFormWaterMark(),
    },
  },
  metaInfo() {
    return {
      title: this?.FlowData?.pageTitle,
    }
  },
  data() {
    return {
      loginInfo: {},
      disabled: true,
    }
  },
  computed: {
    FlowData() {
      return this.flowData
    },
  },
  mounted() {
    this.disabled = false // 意见组件等渲染好了再传送，否则$refs里可能会取不到（起草暂存之后）
  },
  methods: {},
}
</script>

<style module lang="scss" src="@/webflow/sd-flow-form.scss"></style>
