<template>
  <div :class="$style.rectprojectForm">
    <sd-webflow
      ref="flow"
      :validate-form="validForm"
      :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="projectName">
              <a-input v-model="model.projectName" read-only @click="mxRelSelect" />
            </sd-form-item-td>
            <sd-form-item-td name="projectSource">
              <span>{{ model.projectSource }}</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 项目code -->
            <sd-form-item-td name="projectCode">
              <span>{{ model.projectCode }}</span>
            </sd-form-item-td>

            <!-- 审计方式 -->
            <sd-form-item-td name="auditMode">
              <span>{{ model.auditMode }}</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 外聘机构 -->
            <sd-form-item-td name="externalUnitNames">
              <span>{{ model.externalUnitNames }}</span>
            </sd-form-item-td>
            <!-- 整改责任主体code -->
            <sd-form-item-td name="auditedUnitCode" :hidden="true" />
            <!-- 整改责任主体名称 -->
            <sd-form-item-td name="auditedUnitName" :hidden="true" />
            <!-- 整改责任主体 -->
            <sd-form-item-td name="auditedUnit">
              <sd-group-picker
                v-model="model.auditedUnit"
                :hierarchical="false"
                :single="true"
                @change="onChange"
              />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 项目id -->
            <sd-form-item-td name="projectId" :colspan="3" :hidden="true" />
          </tr>
          <tr>
            <!-- 整改责任主体联系人 -->
            <sd-form-item-td name="auditedContacts">
              <sd-user-picker
                v-model="model.auditedContacts"
                :disabled-keys="
                  model.auditedContacts && model.auditedContacts[0]
                    ? [model.auditedContacts[0].code]
                    : []
                "
                :hierarchical="false"
                :root-node="rootNode"
                :single="true"
              />
            </sd-form-item-td>
            <!-- 整改责任主体联系人账号 -->
            <sd-form-item-td name="auditedContactsAccount" :hidden="true" />
            <!-- 整改责任主体联系人名称 -->
            <sd-form-item-td name="auditedContactsName" :hidden="true" />
            <!-- 整改跟踪人账号 -->
            <sd-form-item-td name="resppersonsAccount" :hidden="true" />
            <!-- 整改跟踪人名称 -->
            <sd-form-item-td name="resppersonsName" :hidden="true" />
            <!-- 整改跟踪人 -->
            <sd-form-item-td name="resppersons" />
          </tr>
          <!--  审计意见书下发时间  -->
          <tr>
            <sd-form-item-td name="opinionGiveTime"> </sd-form-item-td>
          </tr>
          <tr>
            <!--  整改要求 -->
            <sd-form-item-td name="requirement" :colspan="3">
              <a-textarea v-model="model.requirement" :rows="3" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 整改要求附件 -->
            <sd-form-item-td name="rectattach" :colspan="3">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                  v-model="model.rectattach"
                  :read-only="!editable"
                  :group-id="JSON.parse(fields.rectattach.value).value"
                ></sd-attachment>
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 整改计划状态 -->
            <sd-form-item-td name="planStatus" :colspan="3" :hidden="true" />
          </tr>
        </table>

        <table>
          <tr
            ><td :colspan="4">
              <!-- <sd-form-item name="iamWorkFindRectplanList" :label="null"> -->
              <sd-form-item name="spicWorkFindRectplanEntityList" :label="null">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="findExpand"
                    :expand-str="'findExpand'"
                    :group-label="'审计问题'"
                    @changedClick="changedClick"
                    ><template>
                      <template>
                        <div :class="$style.wrapper">
                          <div
                            v-show="findExpand && editable && rectProjectId !== '' && isDraft"
                            :class="$style.btnselect"
                          >
                            <a-button
                              type="link"
                              :class="$style.batchselect"
                              @click="showselectfind"
                              ><a-icon type="check-circle" :theme="'filled'" />
                              选择
                            </a-button>
                          </div>
                        </div>
                      </template>
                      <!-- v-model="model.iamWorkFindRectplanList" -->
                      <!-- ].concat(Array.from(fields.iamWorkFindRectplanList.attr.dync)) -->
                      <audit-rectchild-table
                        ref="tabaData"
                        v-model="model.spicWorkFindRectplanEntityList"
                        :deleteqx="isDraft"
                        label="审计问题-整改内容"
                        :read-only="!editable"
                        :findinfoeditable="findinfoeditable"
                        :fields="
                          [
                            {
                              caption: '序号',
                              name: 'sortNum',
                              dataType: 'number',
                              attr: {},
                            },
                            {
                              caption: '操作',
                              name: 'opt',
                              dataType: 'action',
                              attr: {},
                            },
                          ].concat(Array.from(fields.spicWorkFindRectplanEntityList.attr.dync))
                        "
                        :columns="FlowData.attrs.rectplanproject$findedit ? Columnszg : Columns"
                        :flagpage="true"
                        :fnrowclick="fnrowclick"
                      >
                        <!-- <template v-slot:opt="{ index }">
                          <a @click="fnzgjh(index, $event)">整改计划</a>
                        </template> -->
                        <!-- form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:form="{ model, fields }">
                          <table>
                            <tr>
                              <td style="padding-left: 5px">
                                <audit-advanced-group
                                  :expand="findinfoExpand"
                                  :expand-str="'findinfoExpand'"
                                  :group-label="'审计问题-基本信息'"
                                  tablestyle="''"
                                  @changedClick="changedClick"
                                ></audit-advanced-group>
                              </td>
                            </tr>
                          </table>

                          <table :class="$style.rectprojectchildForm">
                            <colgroup>
                              <col style="width: 15%" />
                              <col style="width: 35%" />
                              <col style="width: 15%" />
                              <col style="width: 35%" />
                            </colgroup>
                            <tr v-show="findinfoExpand">
                              <sd-form-item-td
                                :label="'审计问题标题'"
                                name="findingTitle"
                                style="width: 50%"
                              >
                                {{ model.findingTitle }}
                              </sd-form-item-td>
                              <!-- 审计发现编号  -->
                              <sd-form-item-td
                                :label="'审计问题编号'"
                                name="findingCode"
                                style="width: 50%"
                              >
                                {{ model.findingCode }}
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoExpand">
                              <!-- 审计发现类别 -->
                              <!-- <sd-form-item-td name="findType" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  {{ fngetjson(model.findType) }}
                                </template>
                              </sd-form-item-td> -->
                              <!-- 问题分类 -->
                              <!-- <sd-form-item-td name="problemCategoryFunction" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  {{ fngetjson(model.problemCategoryFunction) }}
                                </template>
                              </sd-form-item-td> -->
                            </tr>
                            <tr v-show="findinfoExpand">
                              <!-- 审计发现描述 -->
                              <sd-form-item-td name="findDesc" :colspan="3" :label="'审计问题描述'">
                                {{ model.findDesc }}
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoExpand">
                              <!-- 审计建议描述 -->
                              <!-- <sd-form-item-td name="suggestion" :colspan="3">
                                {{ model.suggestion }}
                              </sd-form-item-td> -->
                              <!-- 审计处理意见 -->
                              <sd-form-item-td
                                name="handleSuggestion"
                                :colspan="3"
                                :label="'审计处理意见'"
                              >
                                {{ model.handleSuggestion }}
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoExpand">
                              <!-- 问题责任部门 -->
                              <sd-form-item-td
                                name="responsibleDept"
                                :label="'问题责任部门'"
                                :colspan="3"
                              >
                                {{ model.responsibleDept }}
                              </sd-form-item-td>
                              <!-- 所属业务部 -->
                              <!-- <sd-form-item-td name="businessProcess">
                                {{ fngetlabel(fields.businessProcess, model.businessProcess) }}
                              </sd-form-item-td> -->
                            </tr>
                            <tr v-show="findinfoExpand">
                              <!-- 是否问责 -->
                              <!-- <sd-form-item-td name="whetherOrderDuty">
                                {{ fngetlabel(fields.whetherOrderDuty, model.whetherOrderDuty) }}
                              </sd-form-item-td> -->
                              <!-- 问责要求 -->
                              <!-- <sd-form-item-td name="orderDutyAsk">
                                {{ model.orderDutyAsk }}
                              </sd-form-item-td> -->
                            </tr>
                            <!-- </table>

                        <table> -->
                            <tr>
                              <td style="padding-left: 5px" colspan="4">
                                <audit-advanced-group
                                  :expand="findinfoplanExpand"
                                  :expand-str="'findinfoplanExpand'"
                                  :group-label="'审计问题-整改内容'"
                                  tablestyle="''"
                                  @changedClick="changedClick"
                                ></audit-advanced-group>
                              </td>
                            </tr>
                            <tr v-show="findinfoplanExpand && findinfoeditable">
                              <!-- 整改责任部门 -->
                              <!-- <sd-form-item-td name="responsibleDeptName" :label="'整改责任部门'" /> -->
                              <!-- 直接责任人 -->
                              <!-- <sd-form-item-td name="directResponsible" /> -->
                            </tr>
                            <tr v-show="findinfoplanExpand && findinfoeditable">
                              <!-- 领导责任人 -->
                              <!-- <sd-form-item-td name="leaderResponsible" /> -->
                              <!-- 共同责任部门 -->
                              <!-- <sd-form-item-td name="commonDutyDepart" /> -->
                            </tr>
                            <!-- 完成日期 隐藏-->
                            <!-- <tr v-show="findinfoplanExpand && findinfoeditable">

                              <sd-form-item-td name="finishDate" :colspan="3"  />
                            </tr>
                            <tr v-show="findinfoplanExpand && findinfoeditable">

                              <sd-form-item-td :colspan="3" name="measure">
                                <a-textarea v-model="model.measure" :rows="3" />
                              </sd-form-item-td>
                            </tr> -->
                            <!-- 措施 隐藏-->
                            <!-- {{ getFormSelectFieldValue(model.problemNature) }} -->
                            <tr v-show="findinfoplanExpand && findinfoeditable">
                              <!-- 问题性质 -->
                              <sd-form-item-td name="problemNature">
                                <!-- <span>{{ model.problemNature }}</span> -->
                                <span>{{ getFormSelectFieldValue(model.problemNature) }}</span>
                              </sd-form-item-td>
                              <!-- 整改类别 -->
                              <sd-form-item-td name="rectType">
                                <!-- <template v-if="model.rectType !== ''">{{
                                  rtgetjson(model.rectType)
                                }}</template>
                                <template v-else> </template> -->
                                <span>{{ model.rectType }}</span>
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoplanExpand && findinfoeditable">
                              <!-- 整改状态 -->
                              <sd-form-item-td name="rectState" />
                            </tr>
                            <tr v-show="findinfoplanExpand && findinfoeditable">
                              <!-- 说明 -->
                              <!-- <sd-form-item-td :colspan="3" name="remark">
                                <a-textarea v-model="model.remark" :rows="3" />
                              </sd-form-item-td> -->
                            </tr>
                            <!-- </table> -->

                            <!-- <table v-show="findinfoplanExpand && !findinfoeditable"> -->
                            <tr v-show="findinfoplanExpand && !findinfoeditable">
                              <!-- 整改责任人 -->
                              <!-- <sd-form-item-td
                                name="responsibleDeptName"
                                style="width: 50%"
                                :label="'整改责任部门'"
                              >
                                <span>{{ model.responsibleDeptName }}</span>
                              </sd-form-item-td> -->
                              <!-- 直接责任人 -->
                              <!-- <sd-form-item-td name="directResponsible" style="width: 50%">
                                <span>{{ model.directResponsible }}</span>
                              </sd-form-item-td> -->
                            </tr>
                            <tr v-show="findinfoplanExpand && !findinfoeditable">
                              <!-- 领导责任人 -->
                              <!-- <sd-form-item-td name="leaderResponsible">
                                <span>{{ model.leaderResponsible }}</span>
                              </sd-form-item-td> -->
                              <!-- 共同责任部门 -->
                              <!-- <sd-form-item-td name="commonDutyDepart">
                                <span>{{ model.commonDutyDepart }}</span>
                              </sd-form-item-td> -->
                            </tr>
                            <!-- 完成日期 -->
                            <!-- <tr v-show="findinfoplanExpand && !findinfoeditable">

                              <td class="ant-form-item-label ant-form-item-label"
                                ><label title=" 拟整改完成日期"> 拟整改完成日期 </label></td
                              >
                              <td>
                                <span>{{ model.finishDate | sdDateFormat('YYYY-MM-DD') }}</span></td
                              >
                            </tr>
                            <tr v-show="findinfoplanExpand && !findinfoeditable">

                              <td class="ant-form-item-label ant-form-item-label"
                                ><label title=" 拟整改措施"> 拟整改措施 </label></td
                              >
                              <td colspan="3">
                                <span>{{ model.measure }}</span></td
                              >
                            </tr> -->
                            <!-- 措施  -->
                            <tr v-show="findinfoplanExpand && !findinfoeditable">
                              <!-- 问题性质 -->
                              <sd-form-item-td name="problemNature">
                                <!-- <span>{{ model.problemNature }}</span> -->
                                <span>{{ getFormSelectFieldValue(model.problemNature) }}</span>
                              </sd-form-item-td>
                              <!-- 整改类别 -->
                              <sd-form-item-td name="rectType">
                                <!-- <template v-if="model.rectType !== ''">{{
                                  rtgetjson(model.rectType)
                                }}</template>
                                <template v-else> </template> -->
                                <!-- <template>{{ rtgetjson(model.rectType) }}</template> -->
                                <span>{{ model.rectType }}</span>
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoplanExpand && !findinfoeditable">
                              <!-- 整改状态 -->
                              <sd-form-item-td name="rectState">
                                <span>{{ model.rectState }}</span>
                              </sd-form-item-td>
                            </tr>
                            <tr v-show="findinfoplanExpand && !findinfoeditable">
                              <!-- 说明 -->
                              <!-- <sd-form-item-td :colspan="3" name="remark">
                                <span>{{ model.remark }}</span>
                              </sd-form-item-td> -->
                            </tr>
                          </table>
                        </template>
                      </audit-rectchild-table>
                    </template>
                  </audit-advanced-group>
                </template>
              </sd-form-item></td
            >
          </tr>
        </table>

        <audit-selectproject-modal
          :visible="visibleY"
          @listMxSelected="listMxSelected"
          @close="mxRelSelect"
        ></audit-selectproject-modal>

        <audit-selectfind-modal
          ref="selectfind"
          :visible="visibleZ"
          :project-id="projectId"
          @Selectedfind="Selectedfind"
          @closefind="showselectfind"
        ></audit-selectfind-modal>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import { Modal, message } from 'ant-design-vue'

import HandoverService from '@/work-handover/handover-service'
import axios from '@/common/services/axios-instance'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import auditSelectprojectModal from './audit-selectproject-modal.vue'
import auditSelectfindModal from './audit-selectfind-modal.vue'
// import auditSelectwbfindModal from './audit-selectwbfind-modal.vue'
import auditRectchildTable from './table/audit-rectchild-table.vue'
import components from './_import-components/audit-rectplanproject-form-import'
import crossWindowWatcher from '@/common/services/cross-window-watcher'

export default {
  name: 'AuditRectplanprojectForm',
  metaInfo: {
    title: '整改内容',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditSelectprojectModal,
    auditSelectfindModal,
    auditRectchildTable,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      rootNode: undefined,
      findinfoExpand: true,
      findinfoplanExpand: true,
      findinfoeditable: false,
      visibleY: false,
      visibleZ: false,
      visibleW: false,
      projectId: '',
      rectProjectId: '',
      infoExpand: true,
      findExpand: true,
      Columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          width: '80px',
          customRender: (text, record, index) => `${index + 1}`,
          sdHidden: false,
        },
        { dataIndex: 'findingTitle', sdHidden: false, width: '30%' },
        { dataIndex: 'findingCode', sdHidden: false },
        { dataIndex: 'responsibleDeptName', title: '整改责任部门', sdHidden: false },
        { dataIndex: 'problemNature', title: '问题性质', sdHidden: false },
        { dataIndex: 'rectType', title: '整改类别', sdHidden: false },
        { dataIndex: 'rectState', title: '整改状态', sdHidden: false },
        // { dataIndex: 'finishDate', sdHidden: false },
        // {
        //   dataIndex: 'measure',
        //   sdHidden: false,
        //   width: '30%',
        // },
        { dataIndex: 'projectId', sdHidden: true },
        { dataIndex: 'findType', sdHidden: true },
        // { dataIndex: 'problemCategoryFunction', sdHidden: true },
        { dataIndex: 'findDesc', sdHidden: true },
        { dataIndex: 'suggestion', sdHidden: true },
        { dataIndex: 'handleSuggestion', sdHidden: true },
        { dataIndex: 'businessProcess', sdHidden: true },
        { dataIndex: 'whetherOrderDuty', sdHidden: true },
        { dataIndex: 'orderDutyAsk', sdHidden: true },
        { dataIndex: 'directResponsible', sdHidden: true },
        { dataIndex: 'leaderResponsible', sdHidden: true },
        { dataIndex: 'commonDutyDepart', sdHidden: true },
        { dataIndex: 'remark', sdHidden: true },
        { dataIndex: 'findingId', sdHidden: true },
        { dataIndex: 'rectProjectId', sdHidden: true },
        // {
        //   title: '操作',
        //   dataIndex: 'opt',
        //   sdHidden: true,
        // },
      ],
      Columnszg: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          width: '80px',
          customRender: (text, record, index) => `${index + 1}`,
          sdHidden: false,
        },
        { dataIndex: 'findingTitle', sdHidden: false, width: '25%' },
        { dataIndex: 'findingCode', sdHidden: false },
        { dataIndex: 'responsibleDeptName', title: '整改责任部门', sdHidden: false },
        { dataIndex: 'problemNature', title: '问题性质', sdHidden: false },
        { dataIndex: 'rectType', title: '整改类别', sdHidden: false },
        { dataIndex: 'rectState', title: '整改状态', sdHidden: false },
        // { dataIndex: 'finishDate', sdHidden: false },
        // {
        //   dataIndex: 'measure',
        //   sdHidden: false,
        //   width: '25%',
        // },
        { dataIndex: 'projectId', sdHidden: true },
        { dataIndex: 'findType', sdHidden: true },
        // { dataIndex: 'problemCategoryFunction', sdHidden: true },
        { dataIndex: 'findDesc', sdHidden: true },
        { dataIndex: 'suggestion', sdHidden: true },
        { dataIndex: 'handleSuggestion', sdHidden: true },
        { dataIndex: 'businessProcess', sdHidden: true },
        { dataIndex: 'whetherOrderDuty', sdHidden: true },
        { dataIndex: 'orderDutyAsk', sdHidden: true },
        { dataIndex: 'directResponsible', sdHidden: true },
        { dataIndex: 'leaderResponsible', sdHidden: true },
        { dataIndex: 'commonDutyDepart', sdHidden: true },
        { dataIndex: 'remark', sdHidden: true },
        { dataIndex: 'findingId', sdHidden: true },
        { dataIndex: 'rectProjectId', sdHidden: true },
        // {
        //   title: '操作',
        //   dataIndex: 'opt',
        //   sdHidden: false,
        // },
      ],
      isDraft: false,
      problemNatureOptions: [],
    }
  },

  created() {
    setTimeout(() => {
      if (this.$refs.flow.getFieldValue('projectId') !== '') {
        this.projectId = this.$refs.flow.getFieldValue('projectId')
      }
      // 當前ID
      if (
        this.$refs.flow.getFieldValue('id') !== '' ||
        this.$refs.flow.getFieldValue('id') !== undefined
      ) {
        this.rectProjectId = this.$refs.flow.getFieldValue('id')
      }
    }, 1000)
    const flag = window.location.href.indexOf('draft')
    if (flag > -1) {
      this.isDraft = true
    }
  },
  mounted() {
    axios({
      url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=IAM_PROBLEM_NATURE',
      method: 'get',
    }).then((res) => {
      if (res.status === 200) {
        this.problemNatureOptions = res.data
      }
    })
  },
  methods: {
    onChange() {
      debugger
      const id = this.$refs.flow.getFieldValue('auditedUnit')[0].code
      const name = this.$refs.flow.getFieldValue('auditedUnit')[0].name
      this.rootNode = { code: id, name: name }
    },
    fngetjson(data) {
      if (data !== undefined || data !== '') {
        if (typeof JSON.parse(data) === 'object') {
          return JSON.parse(data).text
        } else {
          return data
        }
      } else {
        return ''
      }
    },
    validForm() {
      // const child = this.$refs.flow.getFieldValue('iamWorkFindRectplanList')
      const child = this.$refs.flow.getFieldValue('spicWorkFindRectplanEntityList')
      if (child === undefined || child.length === 0) {
        Modal.warning({
          title: '提示',
          content: '请增加至少一条审计发现问题!',
        })
        return Promise.resolve(false)
      }
      const findinfoeditable = this.$refs.flow.FlowData.attrs.rectplanproject$findedit
      if (findinfoeditable) {
        const flag = true
        // let flag = true
        // child.forEach((c) => {
        //   if (c.measure === '' || c.measure === null || c.measure === undefined) {
        //     flag = false
        //   }
        //   if (c.finishDate === '' || c.finishDate === null || c.finishDate === undefined) {
        //     flag = false
        //   }
        // })
        if (flag) {
          return Promise.resolve(true)
        } else {
          Modal.warning({
            title: '提示',
            content: '请完善审计发现问题中的信息!',
          })
          return Promise.resolve(false)
        }
      } else {
        return Promise.resolve(true)
      }
    },
    actionBtnClick(evt, { button, FlowData }) {},
    // 问题发现
    showselectfind() {
      const type = this.$refs.flow.getFieldValue('projectSource')
      if (type === '') {
        Modal.warning({
          title: '提示',
          content: '请选择项目!',
        })
        return false
      }
      // if (type === '内部项目') {
      this.$refs.selectfind.projectId = this.projectId
      if (this.projectId !== '') {
        this.$refs.selectfind.filterExpressions = [
          {
            dataType: 'long',
            name: 'projectId',
            op: 'eq',
            longValue: parseFloat(this.projectId),
          },
        ]
      }
      this.visibleZ = !this.visibleZ
    },
    Selectedfind(keys, findlist) {
      // let list = this.$refs.flow.getFieldValue('iamWorkFindRectplanList')
      let list = this.$refs.flow.getFieldValue('spicWorkFindRectplanEntityList')
      if (list === undefined) {
        list = []
      }
      findlist.forEach((item) => {
        // 判断 list 是否有改id
        const index = list.findIndex((i) => i.findingId === item.id)
        if (index !== -1) {
          list.splice(index, 1)
        }
        item.findingId = item.id
        item.id = null
        item.rectProjectId = this.rectProjectId
        item.findingTitle = item.findTitle
        item.findingCode = item.findCode
        // if (item.auditedUnitNames !== undefined && item.auditedUnitNames) {
        //   const unitname = item.auditedUnitNames
        //   if (unitname.indexOf(',') > -1) {
        //     const arrunit = unitname.split(',').filter((item) => item.trim())
        //     item.responsibleDeptName = arrunit.join(',')
        //   } else {
        //     item.responsibleDeptName = item.auditedUnitNames
        //   }
        // } else {
        //   item.responsibleDeptName = ''
        // }
        item.select = true
        list.push(item)
      })
      // this.$refs.flow.setFieldValue('iamWorkFindRectplanList', list)
      this.$refs.flow.setFieldValue('spicWorkFindRectplanEntityList', list)
    },
    // 项目选择器列表
    mxRelSelect() {
      this.visibleY = !this.visibleY
    },

    listMxSelected(keys, keyinfos, key) {
      this.projectId = keyinfos[0].id
      this.$refs.flow.setFieldValue('projectId', keyinfos[0].id)
      this.$refs.flow.setFieldValue('projectName', keyinfos[0].projectTitle)
      this.$refs.flow.setFieldValue('projectCode', keyinfos[0].projectCode)
      this.$refs.flow.setFieldValue('auditMode', keyinfos[0].auditMode) // 审计方式
      this.$refs.flow.setFieldValue('externalUnitNames', keyinfos[0].externalUnitNames) // 外聘机构
      if (key === '1') {
        this.$refs.flow.setFieldValue('projectSource', '内部项目')
      } else {
        this.$refs.flow.setFieldValue('projectSource', '外部项目')
      }
      const unitsname = keyinfos[0].auditedUnitNames
      if (unitsname != null) {
        let unitscode = ''
        if (keyinfos[0].auditedUnitCodes !== undefined) {
          unitscode = keyinfos[0].auditedUnitCodes
        }
        if (keyinfos[0].auditedUnitIds !== undefined) {
          unitscode = keyinfos[0].auditedUnitIds
        }

        const vname = unitsname.split(',')
        const vcode = unitscode.split(',')
        const vunits = []
        if (vname.length < 2) {
          // 单位只有一个时才给整改责任主体赋值 add by zhangtt 2023-2-27
          vname.forEach((item, index) => {
            vunits.push({
              type: 'Group',
              code: vcode[index].toString(),
              name: vname[index].toString(),
            })
          })
          this.$refs.flow.setFieldValue('auditedUnit', vunits)
          this.onChange()
        } else {
          this.$refs.flow.setFieldValue('auditedUnit', [])
        }
      }

      // this.$refs.flow.setFieldValue('iamWorkFindRectplanList', [])
      this.$refs.flow.setFieldValue('spicWorkFindRectplanEntityList', [])
    },
    fnrowclick(record) {
      this.findinfoeditable = false
    },
    fnzgjh(index, event) {
      this.findinfoeditable = true
      this.$refs.tabaData.editlsfk(index, true)
      event.stopPropagation()
    },
    fngetlabel(obj, val) {
      if (obj.attr.selectListItem) {
        const o = obj.attr.selectListItem.find((item) => item.value === val)
        if (o) {
          return o.label
        } else {
          return val
        }
      } else {
        return val
      }
    },
    rtgetjson(data) {
      debugger
      var name = ''
      if (data !== undefined && data !== '') {
        var arr = JSON.parse(data)
        name = arr[0].name
        return name
      } else {
        return ''
      }
    },
    getFormSelectFieldValue(value) {
      let result = ''
      if (value !== undefined) {
        const resultArry = this.problemNatureOptions.filter((e) => {
          return e.id === value
        })
        if (resultArry.length > 0) {
          result = resultArry[0].name
        }
      }
      return result
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.btnselect {
  position: relative;
  float: right;
  .batchselect {
    top: 4px;
    z-index: 100;
    margin-right: 100px;
  }
}
.rectprojectchild-form {
  :global(td.ant-form-item-label) {
    width: 15%;
  }
  :global(td.ant-form-item-control-wrapper) {
    width: 35%;
  }
}

.rectproject-form {
  :global(td.ant-form-item-label) {
    width: 15%;
  }
  :global(td.ant-form-item-control-wrapper) {
    width: 35%;
  }
  :global(.ant-calendar-picker) {
    width: 100%;
  }
  :global(.rectprojevtfinishdate) {
    :global(td.ant-form-item-control-wrapper) {
      border-right: none !important;
    }
  }
}
</style>
