<template>
  <audit-form-top-banner :form-data="'readonly'">
    <a-card :class="$style.conditions">
      <a-form-model
        ref="advancedSearchForm"
        class="ant-advanced-search-form"
        :model="form"
        v-bind="formItemLayout"
      >
        <a-row :gutter="24" :class="$style.antformitem">
          <a-col :span="8">
            <a-form-model-item :label="'整改状态'" prop="reformStatus">
              <a-select v-model="form.reformStatus" placeholder="请选择整改状态" allow-clear>
                <a-select-option value="0">期限内已整改</a-select-option>
                <a-select-option value="1">逾期已整改</a-select-option>
                <a-select-option value="2">期限内未整改完成</a-select-option>
                <a-select-option value="3">逾期未整改完成</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item :label="'审核状态'" prop="endType">
              <a-select v-model="form.endType" placeholder="请选择审核状态" allow-clear>
                <a-select-option value="2">未提交审核</a-select-option>
                <a-select-option value="1">已提交待审核</a-select-option>
                <a-select-option value="5">审核通过</a-select-option>
                <a-select-option value="0">审核驳回</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="整改截止时间" prop="timeRange">
              <!-- <AuditRangeDatePicker
                  :time-placeholder="['开始时间', '结束时间']"
                  :time-mode="['date', 'date']"
                  :time-format="'YYYY-MM-DD'"
                  :time-range.sync="form.reformDeadline"
                /> -->
              <a-range-picker
                v-model="reformDeadline"
                :format="'YYYY-MM-DD'"
                @change="changeReformDeadline"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="问题推送时间" prop="timeRange">
              <!-- <AuditRangeDatePicker
                  :time-placeholder="['开始时间', '结束时间']"
                  :time-mode="['date', 'date']"
                  :time-format="'YYYY-MM-DD'"
                  :time-range.sync="form.pushDate"
                /> -->
              <a-range-picker v-model="pushDate" :format="'YYYY-MM-DD'" @change="changePushDate" />
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <div :class="$style.buttonContent">
              <a-button type="primary" @click="handleAction('serach')">查询</a-button>
              <a-button @click="handleReset">重置</a-button>
              <a-button :loading="exportLoading" @click="DecideClick">判定问题</a-button>
              <!-- 导出 -->
              <a-button @click="exportExcel">导出</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>
    <div>
      <a-card>
        <sd-data-table-ex
          ref="SJMXDataTable"
          :key="dataKey"
          :columns="columns"
          :process-req="processReq"
          form-id="iamModelMaintain"
          :scroll="{ x: 2800 }"
          data-url="api/xcoa-mobile/v1/iamquestionreform/iamQuestionReformQueryList"
          :filter-expressions="expressions"
          :show-selection="(item) => ![1, 5].includes(item.endType)"
        >
          <div slot="questionFlag" slot-scope="text, record">
            <span>{{ record.questionFlag === 0 ? '否' : '是' }}</span>
          </div>
          <div slot="reformStatus" slot-scope="text, record">
            <span v-if="record.reformStatus === 0" title="期限内已整改">期限内已整改</span>
            <span v-if="record.reformStatus === 1" title="逾期已整改">逾期已整改</span>
            <span v-if="record.reformStatus === 2" title="期限内未整改完成">期限内未整改完成</span>
            <span v-if="record.reformStatus === 3" title="逾期未整改完成">逾期未整改完成</span>
          </div>
          <div slot="endType" slot-scope="text, record">
            <span v-if="record.endType === null" title="未提交审核">未提交审核</span>
            <span v-if="record.endType === 1" title="已提交待审核">已提交待审核</span>
            <span v-if="record.endType === 5" title="审核通过">审核通过</span>
            <span v-if="record.endType === 0" title="审核驳回">审核驳回</span>
          </div>
          <div slot="action" slot-scope="text, record">
            <!-- 如果 -->
            <a-button type="link" @click="showModal(record)">详情</a-button>
            <a-button type="link" :disabled="record.questionFlag === 0" @click="exportClick(record)"
              >下载</a-button
            >
            <a-button
              v-if="ifSaveShow(record)"
              type="link"
              :disabled="record.endType === 1 || record.endType === 5 || record.questionFlag === 0"
              @click="openTJSH(record)"
              >提交</a-button
            >
            <a-button type="link" @click="askClick(record)">整改要求</a-button>
          </div>
        </sd-data-table-ex>
      </a-card>
      <a-modal v-model="visible" title="问题详情" :footer="null" width="1200px" @cancel="cancel">
        <div :class="$style.modelDetail">
          <span>模型编码：{{ modelDetail.batchCode }}</span>
          <span>模型名称：{{ modelDetail.batchName }}</span>
          <span>业务领域：{{ modelDetail.modelDomainName }}</span>
        </div>
        <div :class="$style.detail">
          <a-table
            :columns="columnsDetail"
            :data-source="dataDetail"
            :row-key="(_, index) => index"
            :scroll="{ x: 1150, y: 500 }"
          >
          </a-table>
        </div>
      </a-modal>

      <a-modal
        v-model="visibleDecide"
        class="ant-advanced-search-form"
        title="问题判定"
        width="700px"
        @ok="DecideFormhandleOk"
        @cancel="DecideFormhandleCancel"
      >
        <a-form-model
          ref="DecideForm"
          :model="DecideForm"
          v-bind="formItemLayout"
          :rules="{
            nonQuestionDesc: [{ required: true, message: '请填写问题说明', trigger: 'blur' }],
          }"
        >
          <a-form-model-item label="问题判定" prop="questionFlag">
            <a-select
              v-model="DecideForm.questionFlag"
              placeholder="请选择问题判定"
              @change="decFormChange"
            >
              <a-select-option :value="1">是</a-select-option>
              <a-select-option :value="0">否</a-select-option>
            </a-select>
          </a-form-model-item>
          <a-form-model-item
            v-if="DecideForm.questionFlag !== 1"
            prop="nonQuestionTag"
            label="问题标签"
          >
            <a-select
              v-model="DecideForm.problemStatementId"
              placeholder="请选择问题标签"
              @change="questionChange"
            >
              <a-select-option
                v-for="(item, index) in nonQuestionList"
                :key="item.id"
                :value="item.id"
                >{{ item.name }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
          <a-form-model-item
            v-if="DecideForm.questionFlag !== 1"
            prop="nonQuestionDesc"
            label="问题说明"
          >
            <a-input
              v-model="DecideForm.nonQuestionDesc"
              placeholder="请填写问题说明"
              :auto-size="{ minRows: 5, maxRows: 5 }"
              type="textarea"
              :disabled="isDescStatus"
            />
          </a-form-model-item>
        </a-form-model>
      </a-modal>
      <a-modal
        v-model="askvisible"
        class="ant-advanced-search-form"
        title="整改要求"
        :footer="null"
        width="700px"
        @ok="askFormhandleOk"
        @cancel="askFormCancel"
      >
        <a-form-model ref="askForm" :model="askForm" v-bind="formItemLayout">
          <a-form-model-item prop="reformAsk" label="整改要求说明">
            <a-input
              v-model="askForm.reformAsk"
              placeholder="暂无整改要求说明"
              read-only
              :auto-size="{ minRows: 5, maxRows: 5 }"
              type="textarea"
            />
          </a-form-model-item>
        </a-form-model>
      </a-modal>
    </div>
  </audit-form-top-banner>
</template>

<script>
import components from './_import-components/audit-summarry-list-import'
import axios from '@/common/services/axios-instance'
import { message, Modal } from 'ant-design-vue'
import AuditRiskbraryService from './riskLibrary'
import moment from 'moment/moment'
import storeMixin, { getUserInfo } from '@/common/store-mixin'
import download from '@/common/services/download'
import sdDataTableEx from '@/common/components/sd-data-table-ex.vue'
import auditFormTopBanner from './audit-top-banner'

export default {
  name: 'AuditSummarryRectificationList',
  metaInfo: {
    title: '审计问题明细-整改类',
  },
  components: {
    ...components,
    sdDataTableEx,
    auditFormTopBanner,
  },
  mixins: [storeMixin],
  data() {
    return {
      exportExpressions: [],
      modelDetail: {},
      // 问题标签
      isDescStatus: false,
      mainSendPersonal: [],
      visible: false,
      visibleDecide: false,
      visibleRectification: false,
      askvisible: false,
      exportLoading: false,
      dataKey: 0,
      ModalquestionDetail: '',
      form: {
        reformStatus: null,
        endType: null,
      },
      reformDeadline: [],
      pushDate: [],
      DecideForm: {
        questionFlag: null,
        nonQuestionTag: null,
        nonQuestionDesc: null,
        nonQuestionTagId: null,
        problemStatementId: null,
        // ids: [],
      },
      lockId: '',
      attachments: [],
      fileList: [],
      infoProperties: {},
      RectificationForm: {
        reformDesc: undefined,
        attachment: undefined,
        id: '',
        fileName: '',
      },
      askForm: {
        reformAsk: undefined,
        id: '',
      },
      nonQuestionList: [],
      reqData: {
        reformDeadlineSt: '',
        reformDeadlineEd: '',
        pushDateSt: '',
        pushDateEd: '',
      },
      queryData: {},
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 },
      },
      // 详情信息
      columnsDetail: [],
      dataDetail: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          width: '70px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        // {
        //   title: '批次号',
        //   dataIndex: 'batchCode',
        // },
        // {
        //   title: '批次名称',
        //   dataIndex: 'batchName',
        // },
        {
          title: '模型编码',
          dataIndex: 'batchCode',
        },
        {
          title: '模型名称',
          dataIndex: 'batchName',
        },
        {
          title: '业务领域',
          dataIndex: 'modelDomainName',
        },
        {
          title: '业务阶段',
          dataIndex: 'modelPhaseName',
        },
        // 模型编码 模型名称

        {
          title: '风险描述',
          dataIndex: 'risk',
        },
        {
          title: '问题推送日期',
          dataIndex: 'pushDate',
        },
        {
          title: '整改截止日期',
          dataIndex: 'reformDeadline',
        },
        {
          title: '整改期限',
          dataIndex: 'reformTime',
        },
        {
          title: '判定问题',
          dataIndex: 'questionFlag',
          scopedSlots: { customRender: 'questionFlag' },
        },
        {
          title: '非问题标签',
          dataIndex: 'nonQuestionTag',
        },
        {
          title: '非问题说明',
          dataIndex: 'nonQuestionDesc',
        },
        {
          title: '提交说明',
          dataIndex: 'reformDesc',
        },
        {
          dataIndex: 'fileName',
          sdHidden: true,
        },
        {
          title: '提交人',
          dataIndex: 'viewAccount',
        },
        {
          title: '整改状态',
          dataIndex: 'reformStatus',
          scopedSlots: { customRender: 'reformStatus' },
        },
        {
          title: '审核状态',
          dataIndex: 'endType',
          scopedSlots: { customRender: 'endType' },
        },
        {
          title: '审核说明',
          dataIndex: 'examineDesc',
        },
        {
          title: '初审人',
          dataIndex: 'checker',
        },
        {
          title: '初审时间',
          dataIndex: 'checkDate',
        },
        {
          title: '复审人',
          dataIndex: 'reviewer',
        },
        {
          title: '复审时间',
          dataIndex: 'reviewDate',
        },
        {
          title: '问题性质',
          dataIndex: 'questionNature',
        },
        // reformUserAccount
        {
          title: '整改人',
          dataIndex: 'reformUserAccount',
          sdHidden: true,
        },
        // modelId,  detailGroupId,隐藏
        { title: '模型ID', dataIndex: 'modelId', sdHidden: true },
        { title: '明细组ID', dataIndex: 'detailGroupId', sdHidden: true },
        // {
        // title: '问题责任人',
        // dataIndex: 'personResponsible',
        // },
        // {
        //   title: '操作',
        //   dataIndex: 'sharedSetting',
        //   fixed: 'right',
        //   width: '300px',
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      expressions: [
        {
          dataType: 'str',
          name: 'modelType',
          op: 'eq',
          stringValue: '1',
        },
      ],
      startFlowList: {},
      detailList: [],
    }
  },

  created() {
    this.initColumns()
    this.initQueryData()
  },
  methods: {
    //
    // 初始化initQueryData
    initQueryData() {
      this.queryData = this.$route.query
      this.queryData.modelType = '1'
    },
    // 导出
    exportExcel() {
      // 判断选中的数据，至少选中一条数据
      const selectedRows = this.$refs.SJMXDataTable.getSelectedRows()
      if (selectedRows.length === 0) {
        message.warning('请至少选择一条数据')
        return
      }
      // 调用导出
      // 导出参数
      const params = selectedRows.map((item) => {
        return {
          modelId: item.modelId,
          detailGroupId: item.detailGroupId,
          businessCode: item.businessCode,
          jmEventType: item.jmEventType,
          eventTagName: item.eventTagName,
          modelTypeName: item.modelTypeName,
          pushDate: item.pushDate,
          unitCode: item.unitCode,
          modelType: item.modelType,
        }
      })
      // exportQuestionDetail
      AuditRiskbraryService.exportQuestionDetail(params).then((res) => {
        if (res.status === 200) {
          const url = URL.createObjectURL(res.data)
          const filename = res.headers['content-disposition']
          const fname = filename.substring(filename.indexOf('filename=') + 9, filename.length)
          download(url, decodeURI(fname))
          message.success('导出成功')
        } else {
          Modal.warning({
            title: '提示',
            content: '导出报错，请联系管理员!',
          })
          return false
        }
      })
    },
    // 时间变化
    changeReformDeadline(val) {
      this.reqData.reformDeadlineSt = moment(val[0]._d).format('YYYY-MM-DD')
      this.reqData.reformDeadlineEd = moment(val[1]._d).format('YYYY-MM-DD')
    },
    changePushDate(val) {
      this.reqData.pushDateSt = moment(val[0]._d).format('YYYY-MM-DD')
      this.reqData.pushDateEd = moment(val[1]._d).format('YYYY-MM-DD')
    },

    ifSaveShow(record) {
      const userInfo = getUserInfo()
      // // account是否是整改人
      return record.reformUserAccount === userInfo.account
    },
    initColumns() {
      // resp_person
      const userInfo = getUserInfo()
      // account
      const allUserAdmin = ['00942922', '00332032', '00372263']
      if (allUserAdmin.includes(userInfo.account)) {
        this.columns.push({
          title: '责任人',
          dataIndex: 'respPerson',
        })
      }
      this.columns.push({
        title: '操作',
        dataIndex: 'sharedSetting',
        fixed: 'right',
        width: '300px',
        scopedSlots: { customRender: 'action' },
      })
    },
    decFormChange(val) {
      // 如果是是 则清空 问题标签和问题说明
      if (val === 1) {
        this.DecideForm.nonQuestionTag = null
        this.DecideForm.nonQuestionDesc = null
        this.DecideForm.nonQuestionTagId = null
      }
    },
    // 问题标签数据变化
    questionChange(val) {
      // 如果问题标签说明为空，则清空问题说明比需要填写
      // 如果不为空，则填入问题说明详情，并且不允许修改
      const onDesc = this.nonQuestionList.find((item) => item.id === val)
      const { description, name } = onDesc
      this.DecideForm.nonQuestionDesc = description
      this.DecideForm.nonQuestionTag = name
      // 如果详情为空或者null则 isDescStatus ==false
      if (description === '' || description === null) {
        this.isDescStatus = false
      } else {
        this.isDescStatus = true
      }
    },
    processReq(req) {
      req.data.expressions = [
        { dataType: 'str', name: 'reformStatus', op: 'eq', stringValue: this.form.reformStatus },
        { dataType: 'str', name: 'endType', op: 'eq', stringValue: this.form.endType },
        {
          dataType: 'str',
          name: 'reformDeadlineSt',
          op: 'eq',
          stringValue: this.reqData.reformDeadlineSt,
        },
        {
          dataType: 'str',
          name: 'reformDeadlineEd',
          op: 'eq',
          stringValue: this.reqData.reformDeadlineEd,
        },
        { dataType: 'str', name: 'pushDateSt', op: 'eq', stringValue: this.reqData.pushDateSt },
        { dataType: 'str', name: 'pushDateEd', op: 'eq', stringValue: this.reqData.pushDateEd },
      ]
      Object.keys(this.queryData).map((key) => {
        req.data.expressions.push({
          dataType: 'str',
          name: key,
          op: 'eq',
          stringValue: this.queryData[key],
        })
      })
      // 过滤没有stringvalue的对象
      req.data.expressions = req.data.expressions.filter(
        (item) => item?.stringValue !== undefined || item.stringValue === ''
      )
      return req
    },
    handleReset() {
      this.$refs.advancedSearchForm.resetFields()
      this.reqData = {
        reformDeadlineSt: '',
        reformDeadlineEd: '',
        pushDateSt: '',
        pushDateEd: '',
      }
      this.reformDeadline = []
      this.pushDate = []
      this.handleSearch()
    },
    // 查询
    handleAction(type) {
      switch (type) {
        case 'serach':
          this.handleSearch()
          break
      }
    },
    handleSearch() {
      this.dataKey++
    },
    // 判断点击
    DecideClick() {
      if (this.$refs.SJMXDataTable.getSelectedRows().length !== 1) {
        message.warning('请选中一条数据')
        return
      }
      // this.DecideForm.ids = this.$refs.SJMXDataTable.getSelectedRows()
      //   .map((item) => {
      //     return item.id
      //   })
      //   .filter((l) => l !== undefined)
      this.visibleDecide = true
      axios({ url: 'api/xcoa-mobile/v1/problem-statement/all', method: 'get' }).then((res) => {
        res.data.length ? (this.nonQuestionList = res.data) : (this.nonQuestionList = [])
      })
    },
    // 判断提交
    DecideFormhandleOk() {
      // 获取选中列 modelId detailGroupId
      const { modelId, detailGroupId } = this.$refs.SJMXDataTable.getSelectedRows()[0]
      this.$refs.DecideForm.validate((valid) => {
        if (valid) {
          const params = {
            ...this.DecideForm,
            ...this.queryData,
            modelId,
            detailGroupId,
          }
          AuditRiskbraryService.batchDecide(params).then((res) => {
            if (res) {
              message.success('提交成功')
              // this.visibleDecide = false
              this.DecideFormhandleCancel()
              this.handleSearch()
              this.$refs.SJMXDataTable.refresh()

              // this.$refs.DecideForm.resetFields()
            }
          })
        }
      })
    },
    // 判断取消
    DecideFormhandleCancel() {
      this.$refs.DecideForm.resetFields()
      this.visibleDecide = false
      this.DecideForm = {
        questionFlag: null,
        nonQuestionTag: null,
        nonQuestionDesc: null,
        nonQuestionTagId: null,
        problemStatementId: null,
        // ids: [],
      }
    },
    // 附件自定义上传
    customRequest(data, catnum = 0, item) {
      if (data.file.size === 0) {
        message.warn(`不能上传大小为0的文件`)
        return
      }
      const file = {
        FileName: data.file.name,
        Completed: 0,
        CatNum: catnum,
      }
      this.RectificationForm.fileName = data.file.name
      if (catnum === -1) {
        this.attachments.unshift(file)
      } else {
        this.attachments.push(file)
      }
      this.attachments = [...this.attachments]
      const strTime = moment().format('YYYY-MM-DD HH:mm:ss')
      const formData = new FormData()
      formData.append('file', data.file)
      formData.append('FileName', data.file.name)
      formData.append('lockId', this.lockId)
      formData.append('groupId', this.groupId)
      Object.keys(this.infoProperties).forEach((key) => {
        formData.append(key, this.infoProperties[key])
      })

      formData.append(
        'querystring',
        `<file_unid></file_unid><file_name>${data.file.name}</file_name><file_size>${data.file.size}</file_size><completed>1</completed><file_create>${strTime}</file_create><file_update>${strTime}</file_update><file_editmodel>0</file_editmodel><file_lockuser>0</file_lockuser><CreateInfo>${this.userInfo.account} ${strTime}</CreateInfo><filetype></filetype><user_name>${this.userInfo.account}</user_name><UpdateInfo>${this.userInfo.account}于${strTime}创建.</UpdateInfo><TaodaInfo></TaodaInfo><CatNum>${catnum}</CatNum><Ext></Ext>`
      )
      const url = 'api/xcoa-mobile/v1/iam-attachment-extend/attachments-upload/indi'
      axios
        .post(url, formData, {
          headers: {
            'Content-Type': 'multipart/form-data',
          },
        })
        .then((_) => {
          if (_.data.startsWith('false')) {
            message.error(`${data.file.name} 上传失败`)
          } else {
            data.onSuccess(_, data.file)
          }
        })
        .catch((e) => {
          throw e
        })
    },
    // 跳转提交流程
    openTJSH(data) {
      // batchCode
      // batchName
      // risk
      // businessCode
      // eventTagName
      // modelTypeName
      // questionId
      // fileName
      const query = {
        batchCode: data.batchCode,
        batchName: data.batchName,
        risk: data.risk,
        businessCode: data.businessCode,
        eventTagName: data.eventTagName,
        modelTypeName: data.modelTypeName,
        detailGroupId: data.detailGroupId,
        modelId: data.modelId,
        unitCode: data.unitCode,
        pushDate: data.pushDate,
        jmEventType: data.jmEventType,
      }
      const queryUrl = Object.keys(query)
        .map((key) => {
          return key + '=' + query[key]
        })
        .join('&')
      const url = '#/sd-flow-guide?code=PRODUCT_IAM_FXSJ&' + queryUrl
      window.open(url)
    },
    // 附件上传
    handleChange(info) {
      const status = info.file.status
      let fileList = [...info.fileList]
      fileList = fileList.slice(-1)
      fileList = fileList.map((file) => {
        if (file.response) {
          file.url = file.response.data
        }
        return file
      })
      this.fileList = fileList
      if (status === 'done') {
        message.success(`${info.file.name} 上传成功.`)
      } else if (status === 'error') {
        message.error(`${info.file.name} 上传失败.`)
      }
    },
    // 下载
    exportClick(row) {
      if (!row.attachment) {
        message.warning('未上传附件无法下载')
        return
      }
      const attachmentList = row.attachment.split(',')
      const fileNameList = row.fileName.split(',')
      for (let i = 0; i < attachmentList.length; i++) {
        const spliceIndex = attachmentList[i].lastIndexOf('|')
        const destStep = attachmentList[i].substring(spliceIndex + 1, attachmentList[i].length)
        download(
          'api/framework/v1/task-form-process/download-attachments/' + destStep,
          fileNameList[i]
        )
      }
    },
    // 提交点击
    rectificationClick(row) {
      this.visibleRectification = true
      this.RectificationForm.id = row.id
      AuditRiskbraryService.startProcessPages({
        extParams: [{ name: 'code', value: 'PRODUCT_IAM_FXSJ' }],
        businessTypeId: 200362,
      }).then((res) => {
        this.startFlowList = {
          actionId: this.findActionId(res.data.pushButtons), // start已有获取
          activeStepId: res.data.activeStepId, // start已有获取
          auditElement: [],
          flowCallbackBeanName: 'subflowDataBinderCallback',
          flowFormModelRelationId: res.data.flowFormModelRelationId, // start已有获取
          flowId: res.data.processId, // start已有获取
          formId: res.data.processFormData.formId, // start已有获取
          inputs: this.mapProcessFormData(row),
          instId: res.data.instId, // start已有获取
          lockId: res.data.lockId, // start已有获取
          participantInfos: [], // 下一步提交获取
          props: { sendNotify: '', source: 'WE.OFFICE' },
          timer: null,
        }
      })
    },
    findActionId(list) {
      const arr = list.find((item) => item.buttonName === '提交')
      return arr.buttonId
    },
    mapProcessFormData(row) {
      return [
        { name: 'id' },
        { name: 'questionId', value: row.id },
        { name: 'title', value: '风险审核' },
        { name: 'businessTypeId', value: '200362' },
        { name: 'businessTypeName', value: '风险问题审计' },
        { name: 'batchCode', value: row.batchCode },
        { name: 'batchName', value: row.batchName },
        { name: 'businessCode', value: row.businessCode },
        { name: 'eventTagName', value: row.eventTagName },
        { name: 'modelTypeName', value: row.modelTypeName },
        { name: 'viewAccount', value: row.viewAccount },
        { name: 'risk', value: row.risk },
        { name: 'questionNature' },
        { name: 'personResponsible', value: row.personResponsible },
        { name: 'belongedOrgId', value: '-1' },
      ]
    },
    // 提交确认
    RectificationhandleOk() {
      const attachment = this.fileList.length ? this.fileList[0].url : ''
      const fileName = this.fileList.length
        ? this.fileList[0].url
          ? this.RectificationForm.fileName
          : ''
        : ''
      const param = {
        reformStatus: 1,
        reformDesc: this.RectificationForm.reformDesc,
        id: this.RectificationForm.id,
        attachment: attachment,
        fileName: fileName,
      }
      AuditRiskbraryService.saveIamQuestionReform(param).then((res) => {
        if (res) {
          message.success('提交成功')
          this.startFlowList.inputs.push(
            { name: 'attachment', value: attachment },
            { name: 'fileName', value: fileName },
            { name: 'reformDesc', value: this.RectificationForm.reformDesc }
          )
          // this.visibleRectification = false
          // this.handleSearch()
          setTimeout(() => {
            this.$refs.pRelSelect.openPicker()
          }, 0)
        }
      })
    },
    // 提交关闭
    RectificationCancel() {
      this.visibleRectification = false
    },
    // 整改说明点击弹框
    askClick(row) {
      this.askvisible = true
      this.askForm.id = row.id
      this.askForm.reformAsk = row.reformAsk
    },
    // 整改说明提交
    askFormhandleOk() {
      const param = {
        reformDesc: this.askForm.reformAsk,
        id: this.askForm.id,
      }
      AuditRiskbraryService.saveIamQuestionReform(param).then((res) => {
        if (res) {
          message.success('提交成功')
          this.$refs.askForm.resetFields()
          this.askvisible = false
          this.handleSearch()
        }
      })
    },
    // 整改说明关闭
    askFormCancel() {
      this.$refs.askForm.resetFields()
      this.askvisible = false
    },
    changep(values) {
      const arr = values.map((item) => {
        return {
          attrs: { we_expanded: 'false', we_selected: 'false' },
          checkable: true,
          code: item.code,
          key: item.code,
          name: item.name,
          title: item.name,
          type: item.type,
        }
      })
      const spliceIndex = this.startFlowList.actionId.indexOf('.')
      const destStep = this.startFlowList.actionId.substring(0, spliceIndex) + '.2'
      this.startFlowList.participantInfos.push({ destStepId: destStep, participants: arr })
      AuditRiskbraryService.startDispatch(this.startFlowList).then((res) => {
        if (res.data.flowInstanceResult.length) {
          message.success('提交成功')
          this.RectificationForm.reformDesc = undefined
          this.RectificationForm.attachment = undefined
          this.RectificationForm.id = ''
          this.RectificationForm.fileName = ''
          this.fileList = []
          this.visibleRectification = false
          this.handleSearch()
        }
      })
    },
    showModal(row) {
      // this.ModalquestionDetail = JSON.parse(row.questionDetail)
      const params = {
        modelId: row.modelId,
        detailGroupId: row.detailGroupId,
        ...this.queryData,
      }
      const formData = new FormData()
      Object.keys(params).forEach((key) => {
        formData.append(key, params[key])
      })
      this.modelDetail = {
        modelDomainName: row.modelDomainName,
        batchName: row.batchName,
        batchCode: row.batchCode,
      }
      AuditRiskbraryService.getDetailInfo(params).then((res) => {
        const allField = []
        this.columnsDetail = res.data[0].detailArr.map((item) => {
          allField.push(item.commit)
          return {
            title: item.commit,
            dataIndex: item.commit,
            width: item.value === 'null' ? '100px' : '240px',
          }
        })
        this.dataDetail = res.data.map((item) => {
          const obj = {}
          allField.forEach((field) => {
            const onfield = item.detailArr.find((i) => i.commit === field).value
            obj[field] = onfield !== 'null' ? onfield : ''
          })
          obj.id = item.questionId
          return obj
        })
      })
      this.visible = true
    },
    cancel() {
      this.visible = false
      this.dataDetail = []
      this.columnsDetail = []
      this.modelDetail = {}
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.wrap-height {
  height: 100%;
  .row-height {
    display: flex;
    flex: auto;
    height: 100%;
    .rightcard {
      flex: 1;
      width: calc(100% - 20%);
      height: 100%;
    }
  }
}
.button-content {
  button {
    margin: 0 4px;
  }
}
.no-action {
  padding: 0 15px;
  color: $text-color-secondary;
}
.detail {
  width: 100%;
  overflow-x: auto;
}
.model-detail {
  display: flex;
  margin-bottom: 10px;

  span {
    margin-right: 20px;
  }
}
</style>
