<template>
  <div>
    <sd-webflow
      ref="flow"
      :removed-tabs="['sdRelatedDoc']"
      @actionBtnClick="actionBtnClick"
      @saveproject="saveproject"
      @afterDispatch="afterDispatch"
    >
      <template v-slot:form="{ model, fields, FlowData }">
        <table>
          <tr>
            <td style="border: none">
              <audit-advanced-group
                :expand="Expand"
                :expand-str="'Expand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="Expand">
          <tr v-show="false">
            <!-- ID -->
            <sd-form-item-td name="id" />
            <!-- 随机ID -->
            <sd-form-item-td name="riskDutiesId" />
          </tr>
          <tr>
            <!-- 风险分类 -->
            <sd-form-item-td name="riskCategoryPath">
              {{ model.riskCategoryPath }}
            </sd-form-item-td>
            <!-- 风险事项编号 -->
            <sd-form-item-td name="eventCode">
              {{ model.eventCode }}
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 风险事项名称 -->
            <sd-form-item-td name="eventName">
              {{ model.eventName }}
            </sd-form-item-td>
            <!-- 风险应对策略 -->
            <sd-form-item-td name="riskResponseStrategy" />
          </tr>
          <tr>
            <!-- 风险事项描述 -->
            <sd-form-item-td name="eventDesc" :colspan="3">
              <a-textarea v-model="model.eventDesc" :rows="3" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 应对措施 -->
            <sd-form-item-td name="riskResponseMeasures" :colspan="3">
              <a-textarea v-model="model.riskResponseMeasures" :rows="3" />
            </sd-form-item-td>
          </tr>

          <tr>
            <!-- 应对责任部门 -->
            <sd-form-item-td name="responsibleDeptOpt" @change="changedept" />
            <!-- 应对责任人 -->
            <sd-form-item-td name="responsePersonOpt" />
          </tr>
          <tr>
            <!-- 应对完成状态 -->
            <sd-form-item-td name="responseCompletionState" />
          </tr>
          <tr>
            <!-- 应对完成情况描述 -->
            <sd-form-item-td name="responseCompletionDesc" :colspan="3">
              <a-textarea v-model="model.responseCompletionDesc" :rows="3" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 填报人员 -->
            <sd-form-item-td name="testUserName">
              {{ model.testUserName }}
            </sd-form-item-td>
            <!-- 填报日期 -->
            <sd-form-item-td name="creationTime" />
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                  v-model="model.attachment"
                  :group-id="JSON.parse(fields.attachment.value).value"
                  :read-only="!editable"
                ></sd-attachment>
              </template>
            </sd-form-item-td>
          </tr>
        </table>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import { Modal, message } from 'ant-design-vue'
import riskTasksService from '../risk-tasks-service'
import auditAdvancedGroup from '../../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../../components/audit-advanced-group-mixins'
import components from './_import-components/risk-response-form-import'

export default {
  name: 'RiskResponseForm',
  metaInfo: {
    title: '风险应对',
  },
  components: {
    ...components,
    auditAdvancedGroup,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      Expand: true,
      flag: true,
      taskId: '',
    }
  },
  methods: {
    actionBtnClick(evt, { button, FlowData }) {
      if (button.fakeId === 'save') {
      }
    },
    // 保存操作，记录标识位
    saveproject() {
      this.isSave = true
    },
    changedept() {
      let deptname = ''
      const value = this.$refs.flow.getFieldValue('responsibleDeptOpt')
      if (value) {
        value.forEach((d) => {
          deptname += ',' + d.name
        })
        if (deptname !== '') deptname = deptname.substring(1, deptname.length)
        this.$refs.flow.setFieldValue('responsibleDeptName', deptname)
      }
    },
    /**
     * 提交后事件
     */
    afterDispatch() {
      // 提交也认为是保存
      this.isSave = true
    },
  },
}
</script>

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