<template>
  <sd-webflow
    ref="webflow"
    :class="$style.webflow"
    :validate-form="validForm"
    @afterDispatch="afterDispatch"
    @saveproject="save"
    @actionBtnClick="actionBtnClick"
  >
    <template v-slot:form="{ model, FlowData }">
      <sd-form-by-builder
        ref="builderform"
        :form-data="FlowData.processFormData"
        :keep-hidden-cell="false"
      />
    </template>
  </sd-webflow>
</template>

<script>
import LawService from '../law-service'
import CaseMixins from '../case/case-mixins.js'
import components from './_import-components/law-case-finish-form-import'

export default {
  name: 'LawCaseFinishForm',
  metaInfo: {
    title: '案件结案',
  },
  components,
  mixins: [CaseMixins],
  data() {
    return { caseId: '' }
  },
  created() {
    this.caseId = this.$route.query?.id
    this.initDataf(this.caseId)
  },
  mounted() {
    this.type = 'finish'
  },
  methods: {
    validForm() {
      return new Promise((resolve, reject) => {
        resolve(true)
      })
    },
    // 初始化案件信息
    initDataf(caseId) {
      if (caseId) {
        debugger
        // 获取案件信息
        LawService.getCaseData(caseId).then((res) => {
          this.$refs.webflow.setFieldValue('CASE_ID', caseId)
          this.$refs.webflow.setFieldValue('title', res.data.caseName + '-案件结案')
          this.$refs.webflow.setFieldValue('CASE_PROCESS_STAGE', res.data.caseProcessStage)
          this.$refs.webflow.setFieldValue('CASE_NAME', res.data.caseName)
          this.$refs.webflow.setFieldValue('REPORT_UNIT_ID', res.data.reportUnitId)
          this.$refs.webflow.setFieldValue('REPORT_UNIT_NAME', res.data.reportUnitName)
          this.$refs.webflow.setFieldValue('CASE_TYPE', res.data.caseType)
          this.$refs.webflow.setFieldValue('CASE_AMOUNT', res.data.caseAmount)
          this.$refs.webflow.setFieldValue('OWNER_POSITION', res.data.ownerPosition)
          this.$refs.webflow.setFieldValue('IMPORTANT', res.data.important)
          this.$refs.webflow.setFieldValue('DEFENDANT_USER_NAME', res.data.defendantUserName)
        })
        // 获取案件信息
        LawService.getBeanByFormId(this.caseId, 'onl:d0bb8202233c48f0b5148776754461e1').then(
          (res) => {
            const obj = res.data.pageFormData.pageFieldInfos
            const reportuserobj = obj.find((o) => o.name === 'REPORT_USER_OPT')
            if (reportuserobj) {
              const user = JSON.parse(reportuserobj.value)
              this.$refs.webflow.setFieldValue('REPORT_USER', user)
            }
            this.showflag = true
          }
        )
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
