/* eslint-disable no-unreachable */
<template>
  <sd-webflow ref="webflow" :validate-form="validForm">
    <template v-slot:form="{ model, FlowData }">
      <sd-form-by-builder
        ref="builderform"
        :form-data="initDaF(FlowData.processFormData)"
        :keep-hidden-cell="false"
      />
    </template>
  </sd-webflow>
</template>

<script>
import LawService from '../law-service'
import components from './_import-components/law-lawyer-page-import'
import { message } from '@/common/one-ui'

export default {
  name: 'LawLawyerPage',
  metaInfo: {
    title: 'LawLawyerPage',
  },
  components,
  created() {
    const _this = this
    const ini = setInterval(() => {
      if (
        _this.$refs.webflow &&
        (_this.$refs.webflow.$refs.form || _this.$refs.webflow.$refs.sdForm)
      ) {
        clearInterval(ini)

        if (_this.$refs.webflow.getFieldValue('FLOW_STATUS')) {
          // 隐藏服务评价记录信息
          _this.$refs.webflow.setFieldValue(
            'STATUS',
            '' + _this.$refs.webflow.getFieldValue('FLOW_STATUS')
          )
        }
      }
    }, 100)
  },
  methods: {
    initDaF(array) {
      if (array) {
        array.attrFD.keepHiddenCell = false
      }
      return array
    },
    validForm() {
      this.$refs.webflow.setFieldValue('LAWYER_JBXX', 'true')
      // 判断律师服务记录 是否大于0
      this.$refs.webflow.setFieldValue('JL_JBXX', 'true')
      //

      var firm = this.$refs.webflow.getFieldValue('FIRM_NAME_QUOTE')
      if (firm !== undefined) {
        var firmObj = JSON.parse(firm)
        this.$refs.webflow.setFieldValue('FIRM_ID', firmObj[0].id)
        this.$refs.webflow.setFieldValue('FIRM_NAME', firmObj[0].name)
      }

      // 先判断这个字段是否有值
      const id = this.$refs.webflow.getFieldValue('id')
      if (id) {
        this.$refs.webflow.setFieldValue('LAW_LAWYER_ID', id)
      }

      // 获取环节号
      const flowNum = this.$refs.webflow.getFieldValue('FLOW_STATUS')
      // 起草环节才校验 校验审计单位是否重复下发
      if (flowNum === undefined) {
        // 账户校验
        const account = this.$refs.webflow.getFieldValue('USER_ACCOUNT')
        return LawService.getUser(account).then((res) => {
          if (res.data.id) {
            message.error('账户与系统账户重复', 1)
            return Promise.resolve(false)
          } else {
            return Promise.resolve(true)
          }
        })
      } else {
        return Promise.resolve(true)
      }
    },
    changebj() {
      console.log('---change')
    },
  },
}
</script>

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