<template>
  <sd-webflow
    ref="webflow"
    @afterDispatch="afterDispatch"
    @saveproject="save"
    @sdFormReady="initDatap"
    @actionBtnClick="actionBtnClick"
  >
    <template v-slot:form="{ model, FlowData }">
      <sd-form-by-builder ref="builderform" :form-data="FlowData.processFormData" />
    </template>
  </sd-webflow>
</template>

<script>
import CaseMixins from '../case-mixins.js'
import components from './_import-components/case-progress-sqsfjd-form-import'

export default {
  name: 'CaseProgressSqsfjdForm',
  metaInfo: {
    title: '案件进展-诉前司法鉴定',
  },
  components,
  mixins: [CaseMixins],
  data() {
    return {}
  },
  created() {
    this.type = 'progress'
  },
  mounted() {
    this.type = 'progress'
    const _this = this
    const ini = setInterval(() => {
      if (
        _this.$refs.webflow &&
        (_this.$refs.webflow.$refs.form || _this.$refs.webflow.$refs.sdForm)
      ) {
        clearInterval(ini)
        const mmc = _this.$refs.webflow.getFieldValue('STEP_NAME')
        if (mmc) {
          document.querySelector('.toptitle_sd-header_common').innerHTML = mmc
          // 案件名称
          const CASE_NAME = _this.$refs.webflow.getFieldValue('CASE_NAME')
          // 案件阶段中文名
          const CASE_STAGE_NAME = _this.$refs.webflow.getFieldValue('CASE_STAGE_NAME')
          _this.$refs.webflow.setFieldValue('title', CASE_NAME + '-' + CASE_STAGE_NAME + mmc)
        }
      }
    }, 100)
  },
  methods: {
    initDatap() {
      if (this.create) {
        this.initData()

        const _this = this
        const ini = setInterval(() => {
          if (
            _this.$refs.webflow &&
            (_this.$refs.webflow.$refs.form || _this.$refs.webflow.$refs.sdForm)
          ) {
            clearInterval(ini)
            const mmc = _this.$refs.webflow.getFieldValue('STEP_NAME')
            if (mmc) {
              document.querySelector('.toptitle_sd-header_common').innerHTML = mmc
              // 案件名称
              const CASE_NAME = _this.$refs.webflow.getFieldValue('CASE_NAME')
              // 案件阶段中文名
              const CASE_STAGE_NAME = _this.$refs.webflow.getFieldValue('CASE_STAGE_NAME')

              _this.$refs.webflow.setFieldValue('title', CASE_NAME + '-' + CASE_STAGE_NAME + mmc)
            }
          }
        }, 1000)
      }
    },
  },
}
</script>

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