<template>
  <div :class="$style.odrForm">
    <sd-webflow ref="flow" :removed-tabs="['sdRelatedDoc']" @actionBtnClick="actionBtnClick">
      <template v-slot:form="{ model, fields }">
        <table>
          <tr>
            <td style=" padding-left: 5px;border: none">
              <audit-advanced-group
                :expand="planchangeExpand"
                :expand-str="'planchangeExpand'"
                :group-label="'变更信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="planchangeExpand">
          <colgroup>
            <col style="width: 185px" />
            <col />
            <col style="width: 185px" />
            <col />
          </colgroup>
          <tr>
            <sd-form-item-td name="planTitle">
              <span>{{ model.planTitle }}</span>
            </sd-form-item-td>
            <sd-form-item-td name="changeType">
              <a-select
                v-model="model.changeType"
                :disabled="true"
                show-search
                option-filter-prop="children"
              >
                <a-select-option
                  v-for="(item, index) in fields.changeType.attr.selectListItem"
                  :key="index"
                  :value="item.value"
                >
                  {{ item.label }}
                </a-select-option>
              </a-select>
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td name="changeReson" :colspan="3">
              <a-textarea v-model="model.changeReson" :rows="3" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制人员 -->
            <sd-form-item-td name="creatorName" />
            <!-- 编制日期 -->
            <sd-form-item-td name="creationTime" />
          </tr>
        </table>

        <table>
          <tr>
            <td style=" padding-left: 5px;border: none">
              <audit-advanced-group
                :expand="projectExpand"
                :expand-str="'projectExpand'"
                :group-label="'项目信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="projectExpand">
          <colgroup>
            <col style="width: 185px" />
            <col />
            <col style="width: 185px" />
            <col />
          </colgroup>
          <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="projectTitle"
              @keyup="setTitle(model)"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="projectTitle">
              {{ model.projectTitle }}
            </sd-form-item-td>
            <!-- <sd-form-item-td v-if="model.changeType !== '03'" name="auditType"></sd-form-item-td> -->
            <sd-form-item-td
              v-if="
                model.changeType === '03' ||
                  (model.projectCode !== '' &&
                    model.projectCode !== null &&
                    model.projectCode !== undefined)
              "
              name="auditType"
            >
              {{ getFormSelectFieldValue('auditType', model.auditType) }}
            </sd-form-item-td>
            <sd-form-item-td v-else name="auditType"></sd-form-item-td>
          </tr>
          <tr class="bklabeloverflow">
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              label="项目负责人"
              name="projectPrincipalId"
            >
              <sd-user-picker
                v-model="model.projectPrincipalId"
                :single="true"
                :read-only="false"
              />
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType === '03'"
              label="项目负责人"
              name="projectPrincipalName"
            >
              <span>{{ model.projectPrincipalName }}</span>
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType !== '03'" name="projectCode">
              <a-input
                v-model="model.projectCode"
                :disabled="true"
                placeholder="系统自动生成"
              ></a-input>
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="projectCode">
              {{ model.projectCode }}
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="auditedUnitIds"
              :colspan="3"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="auditedUnitNames" :colspan="3">
              <span>{{ model.auditedUnitNames }}</span>
            </sd-form-item-td>
            <!-- <sd-form-item-td v-if="model.changeType !== '03'" name="auditBasis"></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="auditBasis">
              <span>{{ getFormSelectFieldValue('auditBasis', model.auditBasis) }}</span>
            </sd-form-item-td> -->
          </tr>
          <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="auditMode"></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="auditMode">
              <span>{{ getFormSelectFieldValue('auditMode', model.auditMode) }}</span>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="
                (model.changeType !== '03' && model.auditType === '03') ||
                  (model.changeType !== '03' && model.auditType === '04')
              "
              name="auditedUser"
            ></sd-form-item-td>
            <sd-form-item-td
              v-if="
                (model.changeType === '03' && model.auditType === '03') ||
                  (model.changeType === '03' && model.auditType === '04')
              "
              name="auditedUser"
            >
              {{ model.auditedUser }}
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03' && model.auditMode === '02'"
              name="externalUnitIds"
              :colspan="3"
            >
              <template v-slot:read-and-edit="{ editable }">
                <AuditGroupPicker
                  v-if="editable"
                  v-model="model.externalUnitIds"
                  :read-only="false"
                  :selectclick="showselectexternal"
                />
                <span v-else>{{ model.externalUnitNames }}</span>
              </template>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType === '03' && model.auditMode === '02'"
              name="externalUnitNames"
              :colspan="3"
            >
              <span>{{ model.externalUnitNames }}</span>
            </sd-form-item-td>
          </tr>
          <!-- <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="auditObjective" :colspan="3">
              <a-textarea v-model="model.auditObjective" :rows="3" />
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="auditObjective" :colspan="3">
              {{ model.auditObjective }}
            </sd-form-item-td>
          </tr> -->
          <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="projectContent" :colspan="3">
              <a-textarea v-model="model.projectContent" :rows="3" />
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="projectContent" :colspan="3">
              {{ model.projectContent }}
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td v-if="model.changeType === '03'" name="whetherFinance" hidden="true">
              <span>{{ getFormSelectFieldValue('whetherFinance', model.whetherFinance) }}</span>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="whetherFinance"
              hidden="true"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="whetherOverseas" hidden="true">
              <span>{{ getFormSelectFieldValue('whetherOverseas', model.whetherOverseas) }}</span>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="whetherOverseas"
              hidden="true"
            ></sd-form-item-td>
          </tr>
          <tr class="bklabeloverflow">
            <sd-form-item-td v-if="model.changeType === '03'" name="whetherAuditCoverage">
              <span>{{
                getFormSelectFieldValue('whetherAuditCoverage', model.whetherAuditCoverage)
              }}</span>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="whetherAuditCoverage"
            ></sd-form-item-td>
            <!-- <sd-form-item-td v-if="model.changeType === '03'" name="isPlanIn">
              <span>{{ getFormSelectFieldValue('isPlanIn', model.isPlanIn) }}</span>
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType !== '03'" name="isPlanIn"></sd-form-item-td> -->
          </tr>
          <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="planStartTime"
              @change="getDay"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="planStartTime">
              <span>{{ getFormTimeField(model.planStartTime) }}</span>
            </sd-form-item-td>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="planEndTime"
              range-after="planStartTime"
              @change="getDay"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="planEndTime">
              <span>{{ getFormTimeField(model.planEndTime) }}</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="planDays" />
            <sd-form-item-td v-if="model.changeType === '03'" name="planDays">
              {{ model.planDays }}
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="groupLeaderId" :colspan="3">
              <sd-user-picker v-model="model.groupLeaderId" :single="true" :read-only="false" />
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="groupLeaderName" :colspan="3">
              <span>{{ model.groupLeaderName }}</span>
            </sd-form-item-td>
            <!-- <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="projectSource"
              component="a-select"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="projectSource">
              <span>{{ getFormSelectFieldValue('projectSource', model.projectSource) }}</span>
            </sd-form-item-td> -->
          </tr>
          <!-- <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="exPersonnelNum"
            ></sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="exPersonnelNum">
              {{ model.exPersonnelNum }}
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType !== '03'" name="predictedCost">
              <a-input-number
                v-model="model.predictedCost"
                :min="0"
                :precision="2"
                style="width: 100%"
              ></a-input-number>
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="predictedCost">
              {{
                model.predictedCost === null
                  ? model.predictedCost
                  : parseFloat(model.predictedCost).toFixed(2)
              }}
            </sd-form-item-td>
          </tr> -->
          <!-- <tr>
            <sd-form-item-td
              v-if="model.changeType !== '03'"
              name="secondAuditDeptPerson"
              :colspan="3"
            >
              <sd-user-picker
                v-model="model.secondAuditDeptPerson"
                :single="true"
                :read-only="false"
                :colspan="3"
              />
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="secondAuditDeptPersonName">
              <span>{{ model.secondAuditDeptPersonName }}</span>
            </sd-form-item-td>
          </tr> -->
          <tr v-show="showAttachment">
            <sd-form-item-td v-if="model.changeType !== '03'" name="attachment" :colspan="3">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                  ref="planAtta"
                  v-model="model.attachment"
                  list-type="list"
                  :group-id="projectGroupId"
                  :read-only="!editable"
                />
              </template>
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="attachment" :colspan="3">
              <template v-slot:read-and-edit>
                <sd-attachment
                  ref="planAtta"
                  v-model="model.attachment"
                  list-type="text"
                  :group-id="projectGroupId"
                  :read-only="true"
                  :uploadable="false"
                />
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <sd-form-item-td v-if="model.changeType !== '03'" name="projectRemarks" :colspan="3">
              <a-textarea v-model="model.projectRemarks" :rows="3" />
            </sd-form-item-td>
            <sd-form-item-td v-if="model.changeType === '03'" name="projectRemarks" :colspan="3">
              {{ model.projectRemarks }}
            </sd-form-item-td>
          </tr>
        </table>

        <a-modal
          :visible="modalvisible"
          title="请选择"
          width="1200px"
          :body-style="{
            minHeight: '700px',
          }"
          :destroy-on-close="true"
          @ok="handleOk"
          @cancel="handleCancel"
        >
          <sd-data-table-ex
            ref="externalTable"
            check-type="checkbox"
            :filter-expressions="expressions"
            :columns="modalcolumns"
            form-id="iamExternalBase"
            page-id="audit/auditsource/extrnal/iamExternalBase"
            :search-fields="['name', 'code', 'address']"
            show-selection
          >
          </sd-data-table-ex>
        </a-modal>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import moment from 'moment'
import AuditService from '@product/iam/audit/plan/audit-service'
import AuditGroupPicker from '../../components/picker/audit-group-picker.vue'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import components from './_import-components/audit-planchange-form-import'
import axios from '@/common/services/axios-instance'
import logUtil from '@/common/services/log-util'
import TableColumnTypes from '@/common/services/table-column-types'

export default {
  name: 'AuditPlanchangeForm',
  metaInfo: {
    title: '审计计划项目变更',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    AuditGroupPicker,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      oper: '',
      planYear: '',
      planchangeExpand: true,
      projectExpand: true,
      showAttachment: false,
      auditTypeOptions: [],
      auditModeOptions: [],
      auditBasisOptions: [],
      projectSourceOptions: [],
      whetherFinanceOptions: [],
      whetherOverseasOptions: [],
      whetherAuditCoverageOptions: [],
      projectGroupId: new Date().getTime(), // 附件默认值
      modalvisible: false,
      modalcolumns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          width: '70px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          title: '企业名称',
          dataIndex: 'name',
          // sdClickable: true, // 列内容是否可点击
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '类型',
          dataIndex: 'category',
          width: '160px',
        },
        {
          title: '统一社会信用代码',
          dataIndex: 'code',
          width: '180px',
        },
        {
          title: '住所',
          dataIndex: 'address',
          width: '70px',
        },
        {
          title: '企业状态',
          sorter: true,
          dataIndex: 'status',
        },
        {
          title: '当前所参与项目',
          dataIndex: 'joinProject',
          width: '180px',
          scopedSlots: { customRender: 'isProject' },
        },
        {
          title: '编制人员',
          dataIndex: 'authName',
          width: '120px',
        },
        {
          title: '编制日期',
          dataIndex: 'authTime',
          sorter: true,
          defaultSortOrder: 'descend',
          sdRender: TableColumnTypes.date,
        },
      ],
      expressions: [],
    }
  },
  mounted() {
    this.initPlanChangeInfo()
    this.initProjectInfo()
    this.initDictionaryInfo()
    var _this = this
    logUtil.$on('modifyLogCustomData', function(modifyLogData) {
      _this.modifyLogCustomData(modifyLogData)
    })
  },
  methods: {
    modifyLogCustomData(modifyLogData) {
      // 修改modifyLogData中的元素
      return modifyLogData
    },
    actionBtnClick(evt, { button, FlowData }) {
      // if(this.$refs.flow.getFieldValue('externalUnitIds')){
      //   this.$refs.flow.setFieldValue('externalUnitIds',JSON.stringify(this.$refs.flow.getFieldValue('externalUnitIds')))
      // }
      FlowData.processFormData.processFormPropertyValues.forEach((item) => {
        if (item.name === 'attachment') {
          item.value = this.projectGroupId
        }
      })
      if (button.fakeId === 'save') {
        evt.waitUntil(
          new Promise((resolve, reject) => {
            const auditType = this.$refs.flow.getFieldValue('auditType')
            if (auditType === '' || auditType === undefined || auditType === null) {
              // Message.warn('审计类型为空')
              this.$refs.flow.validateField('auditType').then((res) => {
                console.log(res)
              })
              evt.preventDefault()
              resolve()
            } else {
              resolve()
            }
          })
        )
      }
    },
    // 初始化计划变更信息
    initPlanChangeInfo() {
      let changeType = null
      if (JSON.stringify(this.$route.query) !== '{}') {
        this.oper = JSON.parse(this.$route.query.extParams).oper
        this.planYear = JSON.parse(this.$route.query.extParams).planYear
        if (this.oper === 'create') {
          changeType = '01'
        } else if (this.oper === 'edit' || this.oper === 'cancel') {
          if (this.oper === 'edit') {
            changeType = '02'
          }
          if (this.oper === 'cancel') {
            changeType = '03'
          }
          const projectId = JSON.parse(this.$route.query.extParams).projectId
          this.$refs.flow.setFieldValue('projectId', projectId)
        }
        this.$refs.flow.setFieldValue('changeType', changeType)
        this.$refs.flow.setFieldValue('planYear', this.planYear)
        AuditService.getPlanByPlanYear(this.planYear).then((res) => {
          // 通过计划年度获取计划信息
          if (res.data !== null && res.data !== '') {
            this.$refs.flow.setFieldValue(
              'planTitle',
              res.data[0].planYear + res.data[0].unitName + '审计计划'
            )
          }
        })
      }
    },
    // 初始化项目信息
    initProjectInfo() {
      const projectId = this.$refs.flow.getFieldValue('projectId')
      const newProjectId = this.$refs.flow.getFieldValue('newProjectId')
      const tempProjectId = this.$refs.flow.getFieldValue('tempProjectid')
      const endType = this.$refs.flow.getFieldValue('endType')
      const changeType = this.$refs.flow.getFieldValue('changeType')
      if (projectId || newProjectId || tempProjectId) {
        let id = newProjectId
        if (projectId && !newProjectId) {
          id = projectId
        }
        if (tempProjectId && changeType === '02') {
          id = tempProjectId
        }
        AuditService.getProjectInfoById(id).then((res) => {
          // 获取项目信息·
          if (res.data) {
            this.$refs.flow.setFieldValue('projectTitle', res.data.projectTitle)
            this.$refs.flow.setFieldValue('projectCode', res.data.projectCode)
            this.$refs.flow.setFieldValue('auditType', res.data.auditType)
            this.$refs.flow.setFieldValue(
              'projectPrincipalId',
              this.initAdvancedField(
                res.data.projectPrincipalAccount,
                res.data.projectPrincipalName,
                'User'
              )
            )
            this.$refs.flow.setFieldValue('projectPrincipalName', res.data.projectPrincipalName)
            this.$refs.flow.setFieldValue(
              'auditedUnitIds',
              this.initAdvancedField(res.data.auditedUnitCodes, res.data.auditedUnitNames, 'Group')
            )
            this.$refs.flow.setFieldValue('auditedUnitNames', res.data.auditedUnitNames)
            if (res.data.externalUnitCodes) {
              this.$refs.flow.setFieldValue(
                'externalUnitIds',
                this.initAdvancedField(
                  res.data.externalUnitCodes,
                  res.data.externalUnitNames,
                  'Group'
                )
              )
              // if (changeType === '03') {
              //   this.$refs.flow.setFieldValue(
              //     'externalUnitIds',
              //     JSON.stringify(
              //       this.initAdvancedField(
              //         res.data.externalUnitCodes,
              //         res.data.externalUnitNames,
              //         'Group'
              //       )
              //     )
              //   )
              // }
              this.$refs.flow.setFieldValue('externalUnitNames', res.data.externalUnitNames)
            }
            this.$refs.flow.setFieldValue('auditMode', res.data.auditMode)
            this.$refs.flow.setFieldValue('auditBasis', res.data.auditBasis)
            this.$refs.flow.setFieldValue('auditedUser', res.data.auditedUser)
            this.$refs.flow.setFieldValue('auditObjective', res.data.auditObjective)
            this.$refs.flow.setFieldValue('projectContent', res.data.projectContent)
            this.$refs.flow.setFieldValue('planDays', res.data.planDays)
            this.$refs.flow.setFieldValue('whetherFinance', res.data.whetherFinance)
            this.$refs.flow.setFieldValue('whetherOverseas', res.data.whetherOverseas)
            this.$refs.flow.setFieldValue('whetherAuditCoverage', res.data.whetherAuditCoverage)

            this.$refs.flow.setFieldValue(
              'secondAuditDeptPerson',
              this.initAdvancedField(
                res.data.secondAuditDeptPersonAccount,
                res.data.secondAuditDeptPersonName,
                'User'
              )
            )
            this.$refs.flow.setFieldValue(
              'secondAuditDeptPersonName',
              res.data.secondAuditDeptPersonName
            )
            this.$refs.flow.setFieldValue(
              'planStartTime',
              res.data.planStartTime === null
                ? res.data.planStartTime
                : moment(res.data.planStartTime)
            )
            this.$refs.flow.setFieldValue(
              'planEndTime',
              res.data.planEndTime === null ? res.data.planEndTime : moment(res.data.planEndTime)
            )
            this.$refs.flow.setFieldValue(
              'groupLeaderId',
              this.initAdvancedField(res.data.groupLeaderAccount, res.data.groupLeaderName, 'User')
            )
            this.$refs.flow.setFieldValue('groupLeaderName', res.data.groupLeaderName)
            this.$refs.flow.setFieldValue('projectSource', res.data.projectSource)
            this.$refs.flow.setFieldValue('exPersonnelNum', res.data.exPersonnelNum)
            if (endType === 5) {
              this.$refs.flow.setFieldValue(
                'predictedCost',
                res.data.predictedCost === null
                  ? res.data.predictedCost
                  : parseFloat(res.data.predictedCost).toFixed(2)
              )
            } else {
              this.$refs.flow.setFieldValue('predictedCost', res.data.predictedCost)
            }
            this.$refs.flow.setFieldValue('projectRemarks', res.data.projectRemarks)
            let attachment = res.data.attachment
            if (!attachment.includes('value')) {
              attachment = '{"value": "' + attachment + '"}'
            }
            this.projectGroupId = JSON.parse(attachment).value
            const attachArry = []
            attachArry.push(attachment)
            this.$refs.flow.setFieldValue('attachment', attachArry)
            // 重新获取一下附件
            setTimeout(() => {
              if (this.$refs.planAtta) this.$refs.planAtta.getFileList()
            })

            this.$refs.flow.setFieldValue(
              'title',
              this.$refs.flow.getFieldValue('projectTitle') + '的变更申请'
            )
            this.showAttachment = true
          }
        })
      } else {
        this.$refs.flow.setFieldValue('auditMode', '01')
        this.$refs.flow.setFieldValue('auditBasis', '01')
        this.$refs.flow.setFieldValue('projectSource', '01')
        this.showAttachment = true
      }
    },
    initDictionaryInfo() {
      const changeType = this.$refs.flow.getFieldValue('changeType')
      if (changeType === '03') {
        // 只有取消操作才获取数据字典类型数据
        axios({
          url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=PRODUCT_IAM_AUDIT_METHOD',
          method: 'get',
        }).then((res) => {
          if (res.status === 200) {
            this.auditModeOptions = res.data
          }
        })

        axios({
          url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=PRODUCT_IAM_AUDIT_BASIS',
          method: 'get',
        }).then((res) => {
          if (res.status === 200) {
            this.auditBasisOptions = res.data
          }
        })
        axios({
          url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=PRODUCT_IAM_AUDIT_SOURCE',
          method: 'get',
        }).then((res) => {
          if (res.status === 200) {
            this.projectSourceOptions = res.data
          }
        })
      }
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=PRODUCT_IAM_AUDIT_TYPE',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.auditTypeOptions = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=WHETHER',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.whetherFinanceOptions = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=WHETHER',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.whetherOverseasOptions = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=WHETHER',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.whetherAuditCoverageOptions = res.data
        }
      })
    },
    // 初始化高级字段信息
    initAdvancedField(codeArryData, nameArryData, type) {
      const resultDataArry = []
      let codeArry = []
      let nameArry = []
      if (codeArryData !== null) {
        codeArry = codeArryData.split(',')
      }
      if (nameArryData != null) {
        nameArry = nameArryData.split(',')
      }
      for (let i = 0; i < codeArry.length; i++) {
        resultDataArry.push({
          type: type,
          code: codeArry[i],
          name: nameArry[i],
        })
      }
      return resultDataArry
    },
    getFormFieldValue(name) {
      const objArry = this.$refs.flow.getFieldValue(name)
      if (objArry !== undefined) {
        if (objArry.length > 0) {
          let result = ''
          objArry.forEach((e) => {
            result += e.name + ','
          })
          return result.substr(0, result.length - 1)
        }
      }
      return ''
    },
    getFormSelectFieldValue(name, value) {
      let result = ''
      if (value !== undefined) {
        if (name === 'auditType') {
          const resultArry = this.auditTypeOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'auditMode') {
          const resultArry = this.auditModeOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'auditBasis') {
          const resultArry = this.auditBasisOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'projectSource') {
          const resultArry = this.projectSourceOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'whetherFinance') {
          const resultArry = this.whetherFinanceOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'whetherOverseas') {
          const resultArry = this.whetherOverseasOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
        if (name === 'whetherAuditCoverage') {
          const resultArry = this.whetherAuditCoverageOptions.filter((e) => {
            return e.id === value
          })
          if (resultArry.length > 0) {
            result = resultArry[0].name
          }
        }
      }
      return result
    },
    getFormTimeField(value) {
      return moment(value).format('YYYY-MM-DD')
    },
    getDay() {
      const planStartTime = this.$refs.flow.getFieldValue('planStartTime')
      const planEndTime = this.$refs.flow.getFieldValue('planEndTime')
      if (planStartTime !== undefined && planEndTime !== undefined) {
        const planDays =
          (new Date(moment(planEndTime).format('YYYY/MM/DD')).getTime() -
            new Date(moment(planStartTime).format('YYYY/MM/DD')).getTime()) /
          1000 /
          60 /
          60 /
          24
        this.$refs.flow.setFieldValue('planDays', planDays + 1)
      } else {
        this.$refs.flow.setFieldValue('planDays', undefined)
      }
    },
    setTitle(model) {
      this.$refs.flow.setFieldValue('title', model.projectTitle + '的变更申请')
    },
    // 展示选择列表
    showselectexternal() {
      this.modalvisible = !this.modalvisible
    },
    // 弹出窗确认
    handleOk() {
      this.showselectexternal()
      // 获取别选择的行信息
      const selectInfo = this.$refs.externalTable.getSelectedRows()
      const list = []
      selectInfo.forEach((item) => {
        const obj = {
          title: item.name,
          id: item.id,
          code: item.id,
          name: item.name,
          text: item.name,
          type: 'Group',
          props: {},
        }
        list.push(obj)
      })
      this.$refs.flow.setFieldValue('externalUnitIds', list)
    },
    // 弹出窗取消
    handleCancel() {
      this.showselectexternal()
    },
  },
}
</script>

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

.odrForm {
  /* :global .sd-page-title {
     display: none;
   } */
  :global(.header_sd-child-table_common) {
    right: 100px !important;
  }

  .btnexcel {
    position: relative;
    top: 4px;
    float: right;

    .batchexcel {
      z-index: 100;
      margin-left: 10px;
    }
  }

  :global(.ant-form-item-label > label) {
    width: 100% !important;
    white-space: normal;
  }

  :global(.ant-input-number) {
    width: 100% !important;
  }

  :global(.ant-form-item-label) {
    width: 165px !important;
  }
}
</style>
