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

<script>
import { Modal } from 'ant-design-vue'
import LawService from '../law-service'
import DisputeMixins from './dispute-mixins.js'
import components from './_import-components/law-dispute-finish-form-import'

export default {
  name: 'LawDisputeFinishForm',
  metaInfo: {
    title: '纠纷结案',
  },
  components,
  mixins: [DisputeMixins],
  data() {
    return {}
  },
  mounted() {
    this.type = 'jfFinish'
  },
  methods: {
    validForm() {
      return new Promise((resolve, reject) => {
        const jfcl = this.$refs.webflow.getFieldValue('DISPUTE_RESULT')
        const id = this.$refs.webflow.getFieldValue('DISPUTE_ID')
        if (jfcl === 'ZC' || jfcl === 'SS') {
          Modal.confirm({
            title: '是否立即创建案件？',
            cancelText: '暂不创建',
            okText: '立即创建',
            onOk: () => {
              // 调用创建案件接口
              LawService.createCase(id, jfcl).then((res) => {
                if (res.data.success) {
                  let text = ''
                  if (res.data.code === 0) {
                    text = '案件已创建完成，请进入案件上报模块查看'
                  } else {
                    text = '该纠纷已经生成过案件上报，请进入案件上报模块查看'
                  }
                  Modal.info({
                    content: text,
                  })
                  resolve(true)
                } else {
                  Modal.info({
                    content: '案件创建失败，请联系管理员',
                  })
                  resolve(false)
                }
              })
            },
            onCancel() {
              resolve(true)
            },
          })
        } else {
          resolve(true)
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.disputefinishform {
  :global td > div > div.content_sd-form-item-help_common {
    color: red;
    padding-left: 160px;
  }
}
</style>
