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

        <table v-show="infoExpand">
          <colgroup>
            <col style="width: 180px;"/>
            <col />
            <col style="width: 180px;"/>
            <col
          /></colgroup>
          <tr>
            <!-- 审计发现标题 -->
            <sd-form-item-td name="findingTitle" readonly>
              {{ model.findingTitle }}
            </sd-form-item-td>
            <!-- 审计发现编号 -->
            <sd-form-item-td name="findingCode" readonly :label="'问题编号'">
              {{ model.findingCode }}
            </sd-form-item-td>
          </tr>
          <!-- <tr> -->
          <!-- 审计问题类别 -->
          <!-- <sd-form-item-td name="findType" readonly :label="'问题类别'">
              {{ model.findType }}
            </sd-form-item-td> -->
          <!-- 问题分类 -->
          <!-- <sd-form-item-td name="problemCategoryFunction" readonly :label="'问题分类'" /> -->
          <!-- </tr> -->
          <tr>
            <!--  审计问题描述 -->
            <sd-form-item-td name="findDesc" :colspan="3" readonly :label="'描述'">
              {{ model.findDesc }}
            </sd-form-item-td>
          </tr>
          <tr>
            <!--  问题下发时间-->
            <sd-form-item-td name="creationTime" :colspan="3" readonly :label="'问题下发时间'">
              {{ model.creationTime }}
            </sd-form-item-td>
          </tr>
        </table>

        <table>
          <tr>
            <td style="padding-left:5px;border:none">
              <audit-advanced-group
                :expand="findExpand"
                :expand-str="'findExpand'"
                :group-label="'建议落实情况'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="findExpand">
          <colgroup>
            <col style="width: 180px;"/>
            <col />
            <col style="width: 180px;"/>
            <col
          /></colgroup>
          <tr>
            <!-- 整改责任部门 -->
            <sd-form-item-td name="responsibleDeptName" :label="'整改责任部门'" />
            <!-- 直接责任人 -->
            <sd-form-item-td name="directResponsible" :label="'直接责任人'" />
          </tr>
          <tr>
            <!-- 整改类别 -->
            <sd-form-item-td name="rectType" :label="'建议状态'">
              <a-select
                v-model="model.rectType"
                @change="handlerRectType(model, model.rectType, fields)"
              >
                <a-select-option
                  v-for="item in fields.rectType.attr.selectListItem.filter((itc) =>
                    ['06', '07', '08'].includes(itc.value)
                  )"
                  :key="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </a-select-option>
              </a-select>
              <!-- <template v-slot>
                <sd-select v-model="model.rectType" :options="rectTypeOptions" />
              </template>
              <template v-slot:read>
                {{ rtgetjson(model.rectType) }}

              </template> -->
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 说明 -->
            <sd-form-item-td name="remark" :colspan="3" :label="'说明'">
              <a-textarea v-model="model.remark" :rows="3"
            /></sd-form-item-td>
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3" />
          </tr>
        </table>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import axios from '@/common/services/axios-instance'
import auditAdvancedGroup from '@product/iam/components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '@product/iam/components/audit-advanced-group-mixins'
import components from './_import-components/spic-suggestfeedback-form-import'

export default {
  name: 'SpicSuggestfeedbackForm',
  metaInfo: {
    title: 'SpicSuggestfeedbackForm',
  },
  components: {
    ...components,
    auditAdvancedGroup,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return { projectId: '', infoExpand: true, findExpand: true, groupId: '', rectTypeOptions: [] }
  },
  mounted() {
    // 初始化数据字典信息
    this.initDictionaryInfo()
    let query = {}
    if (this.$route.query.extParams) {
      query = JSON.parse(this.$route.query.extParams)
    } else {
      query = {
        id: this.$refs.flow.getFieldValue('id'),
      }
    }
    axios({
      url: `api/xcoa-mobile/v1/spicrectfeedback/getInfoById?id=${query.id}`,
      method: 'get',
    }).then((res) => {
      debugger
      this.$refs.flow.setFieldValue('findingTitle', res.data.findingTitle)
      this.$refs.flow.setFieldValue('findingCode', res.data.findingCode)
      // this.$refs.flow.setFieldValue('findType', res.data.findType)
      this.$refs.flow.setFieldValue('findDesc', res.data.findDesc)
      this.$refs.flow.setFieldValue('creationTime', res.data.creationTime)
      // this.$refs.flow.setFieldValue('problemCategoryFunction', res.data.problemCategoryFunction)
    })
  },
  methods: {
    initDictionaryInfo() {
      // 获取审计流程下拉框信息
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=RECT_TYPE',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          var newArr = []
          res.data.forEach((item) => {
            if (item.id === '06' || item.id === '07' || item.id === '08') {
              newArr.push(item)
            }
          })
          this.rectTypeOptions = newArr
        }
      })
    },
    fngetjson(data) {
      if (data !== undefined && data !== '') {
        if (typeof JSON.parse(data) === 'object') {
          return JSON.parse(data).text
        } else {
          return data
        }
      } else {
        return ''
      }
    },
    rtgetjson(data) {
      var name = ''
      if (data !== undefined && data !== '') {
        var arr = JSON.parse(data)
        name = arr[0].name
        return name
      } else {
        return ''
      }
    },
    actionBtnClick(evt, { button, FlowData }) {
      // debugger
      evt.waitUntil(
        new Promise((resolve, reject) => {
          if (button.buttonId === 'G_1_SUGGEST_FEED_BACK.7') {
            // 开始-> 转其他人反馈环节
            this.$refs.flow.FlowData.processFormData.processFormPropertyValues.find((item) => {
              return item.name === 'rectType'
            }).required = false

            this.$refs.flow.FlowData.processFormData.processFormPropertyValues.find((item) => {
              return item.name === 'remark'
            }).required = false
          }
          if (button.buttonId === 'G_1_SUGGEST_FEED_BACK.1') {
            // 开始-> 转其他人反馈环节
            this.$refs.flow.FlowData.processFormData.processFormPropertyValues.find((item) => {
              return item.name === 'rectType'
            }).required = true

            this.$refs.flow.FlowData.processFormData.processFormPropertyValues.find((item) => {
              return item.name === 'remark'
            }).required = true
          }
          resolve()
        })
      )
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.btnselect {
  position: relative;
  float: right;
  .batchselect {
    z-index: 100;
    margin-right: 190px;
  }
}
:global(.ant-modal-content) {
  :global(.ant-input-number) {
    width: 100%;
  }
}
</style>
