<template>
  <div :class="$style.questionForm">
    <audit-form-top-banner>
      <div :class="$style.titleHide">
        <sd-detail-form
          ref="docform"
          form-id="iamQuestionInventory"
          page-id="audit/question/iamQuestionInventory"
          :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
          :class="$style.form"
          :read-only="true"
          @close="close(true)"
          @saved="saved"
        >
          <template v-slot="{ model, fields }">
            <table>
              <tr>
                <td style="padding-left:5px;border:none">
                  <audit-advanced-group
                    :expand="findExpand"
                    :expand-str="'findExpand'"
                    :group-label="'审计发现_基本信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="findExpand">
              <colgroup>
                <col style="width: 200px;" />
                <col />
                <col style="width: 200px;" />
                <col />
              </colgroup>
              <tr>
                <!-- 审计发现标题 -->
                <sd-form-item-td name="findingTitle">{{ model.findingTitle }}</sd-form-item-td>
                <!-- 审计发现编号 -->
                <sd-form-item-td name="findingCode">{{ model.findingCode }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计发现类别 -->
                <sd-form-item-td name="findType" :colspan="3">
                  <template v-slot:read-and-edit="{ editable }">
                    {{ JSON.parse(model.findType).text }}
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计发现描述 -->
                <sd-form-item-td name="findDesc" :colspan="3">{{ model.findDesc }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计建议描述 -->
                <sd-form-item-td name="suggestion" :colspan="3">{{
                  model.suggestion
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 问题责任部门 -->
                <sd-form-item-td name="responsibleDeptName">{{
                  model.responsibleDeptName
                }}</sd-form-item-td>
                <!-- 所属业务域 -->
                <sd-form-item-td name="businessProcess">{{
                  model.businessProcess
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 是否问责 -->
                <sd-form-item-td name="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;border:none">
                  <audit-advanced-group
                    :expand="rectplanExpand"
                    :expand-str="'rectplanExpand'"
                    :group-label="'审计发现_整改计划信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="rectplanExpand">
              <colgroup>
                <col style="width: 200px;" />
                <col />
                <col style="width: 200px;" />
                <col />
              </colgroup>
              <tr>
                <!-- 整改责任部门 -->
                <sd-form-item-td name="responsibleDeptName">{{
                  model.responsibleDeptName
                }}</sd-form-item-td>
                <!-- 直接责任人 -->
                <sd-form-item-td name="directResponsible">{{
                  model.directResponsible
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 领导责任人 -->
                <sd-form-item-td name="leaderResponsible">{{
                  model.leaderResponsible
                }}</sd-form-item-td>
                <!-- 共同责任部门 -->
                <sd-form-item-td name="commonDutyDepart">{{
                  model.commonDutyDepart
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 拟整改完成日期 -->
                <sd-form-item-td name="finishDate" :colspan="3">{{
                  model.finishDate
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 拟整改措施 -->
                <sd-form-item-td name="measure" :colspan="3">{{ model.measure }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 说明 -->
                <sd-form-item-td name="remark" :colspan="3">{{ model.remark }}</sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="padding-left:5px;border:none">
                  <audit-advanced-group
                    :expand="lsxxExpand"
                    :expand-str="'lsxxExpand'"
                    :group-label="'审计发现_落实信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="lsxxExpand">
              <colgroup>
                <col style="width: 200px;" />
                <col />
                <col style="width: 200px;" />
                <col />
              </colgroup>
              <tr>
                <!-- 整改状态 -->
                <sd-form-item-td name="rectStatus" :colspan="model.rectStatus === '03' ? 1 : 3">{{
                  model.rectStatus
                }}</sd-form-item-td>
                <!-- 整改完成日期 -->
                <sd-form-item-td v-if="model.rectStatus === '03'" name="rectFinishDate">
                  <span>{{ model.rectFinishDate | sdDateFormat('YYYY-MM-DD') }}</span>
                </sd-form-item-td>
              </tr>
              <tr v-show="model.rectStatus === '01'">
                <!-- 是否超期未整改 -->
                <sd-form-item-td name="isTrue" :colspan="3">{{ model.isTrue }}</sd-form-item-td>
              </tr>
              <tr v-if="model.isTrue === '1' || model.isTrue === 1">
                <!-- 超期原因 -->
                <sd-form-item-td name="overdueReason" :colspan="3">{{
                  model.overdueReason
                }}</sd-form-item-td>
              </tr>
              <tr v-if="model.rectStatus !== '04' && model.rectStatus !== '03'">
                <!-- 预计整改完成日期 -->
                <sd-form-item-td name="expectedCompleteDate" :colspan="3">{{
                  model.expectedCompleteDate
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 整改情况说明 -->
                <sd-form-item-td name="description" :colspan="3">{{
                  model.description
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 整改问题金额分类 -->
                <sd-form-item-td name="rectMoneyType">{{ model.rectMoneyType }}</sd-form-item-td>
                <!-- 整改问题金额 -->
                <sd-form-item-td name="rectMoneySum">{{ model.rectMoneySum }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 成果利用 -->
                <sd-form-item-td name="resultUse">{{ model.resultUse }}</sd-form-item-td>
                <!-- 成果利用数量 -->
                <sd-form-item-td name="resultUseSum">{{ model.resultUseSum }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 处分信息 -->
                <sd-form-item-td name="punishInfo">{{ model.punishInfo }}</sd-form-item-td>
                <!-- 处分人数 -->
                <sd-form-item-td name="punishSum">{{ model.punishSum }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 向司法机关移送或报案线索 -->
                <sd-form-item-td name="transferToJustice">{{
                  model.transferToJustice
                }}</sd-form-item-td>
                <!-- 涉案人员 -->
                <sd-form-item-td name="personInvolved">{{ model.personInvolved }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 附件 -->
                <sd-form-item-td name="lsAttachment" :colspan="3">
                  <template v-slot:read-and-edit="{ editable }">
                    <sd-attachment
                      v-model="model.lsAttachment"
                      :group-id="JSON.parse(fields.lsAttachment.value).value"
                      :read-only="!editable"
                    />
                  </template>
                  <!-- <template v-slot:read-and-edit="{ editable }">
                    <sd-attachment-ex
                      v-model="model.lsAttachment"
                      :group-id="JSON.parse(fields.lsAttachment.value).value"
                      :read-only="!editable"
                      :zw-uploadable="false"
                    />
                  </template> -->
                </sd-form-item-td>
              </tr>
              <tr>
                <td :colspan="4" style="border:none"
                  ><a @click="fnopenhistoryrecify">历史反馈记录</a></td
                >
              </tr>
              <tr>
                <td :colspan="4" style="border:none">
                  <table style="width:100%">
                    <tr>
                      <td width="5.8%" style="text-align:center">序号</td
                      ><td style="text-align:center">反馈日期</td
                      ><td style="text-align:center">反馈状态</td>
                    </tr>
                    <tr v-for="(fk, index) in model.iamWorkRectCarryOutHistoryEntity" :key="index">
                      <td style="text-align:center">{{ index + 1 }}</td
                      ><td style="text-align:center"
                        ><a @click="fnopenfk(fngetnr(fk, 'id'))">{{
                          fngetnr(fk, 'lastModifiedTime') | sdDateFormat('YYYY-MM-DD')
                        }}</a></td
                      ><td style="text-align:center">{{
                        fngetlabel(fields.rectStatus, fngetnr(fk, 'rectStatus'))
                      }}</td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="padding-left:5px;border:none">
                  <audit-advanced-group
                    :expand="zgqrExpand"
                    :expand-str="'zgqrExpand'"
                    :group-label="'审计发现_整改确认'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <!-- <table v-show="zgqrExpand">
            {{ model.iamRectifyCancelLogEntities }}
          </table> -->
            <table v-show="zgqrExpand">
              <colgroup>
                <col style="width: 200px;" />
                <col />
                <col style="width: 200px;" />
                <col />
              </colgroup>
              <tr>
                <td colspan="4">
                  <a @click="fnopenhistoryrecify">历史确认记录</a>
                </td>
              </tr>
              <tr>
                <td class="ant-form-item-label ant-form-item-label">确认状态</td
                ><td colspan="3">{{
                  fngetlabel(
                    fields.iamRectifyCancelLogEntities.attr.dync.find(
                      (i) => i.name === 'confirmStatus'
                    ),
                    fngetnr(model.iamRectifyCancelLogEntities, 'confirmStatus')
                  )
                }}</td>
              </tr>
              <tr>
                <td class="ant-form-item-label ant-form-item-label">确认意见</td
                ><td colspan="3">{{
                  fngetnr(model.iamRectifyCancelLogEntities, 'confirmOpinion')
                }}</td>
              </tr>
              <tr>
                <td class="ant-form-item-label ant-form-item-label">确认人</td
                ><td>{{ fngetnr(model.iamRectifyCancelLogEntities, 'confirmName') }}</td>
                <td class="ant-form-item-label ant-form-item-label">确认时间</td
                ><td>{{
                  fngetnr(model.iamRectifyCancelLogEntities, 'confirmTime')
                    | sdDateFormat('YYYY-MM-DD')
                }}</td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="padding-left:5px;border:none">
                  <audit-advanced-group
                    :expand="bgExpand"
                    :expand-str="'bgExpand'"
                    :group-label="'审计发现_变更信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <!-- <table v-show="bgExpand">
            {{ model.iamDetailFormModifyLogEntities }}
          </table> -->

            <table
              v-for="(bg, index) in fndeal(model.iamDetailFormModifyLogEntities)"
              v-show="bgExpand"
              :key="index"
              :class="$style.tablexm"
            >
              <colgroup>
                <col style="width: 200px;" />
                <col />
                <col style="width: 200px;" />
                <col />
              </colgroup>
              <tr>
                <td style="width:160px;text-align:right;vertical-align:top">{{ bg.creatorName }}</td
                ><td colspan="3"
                  ><div
                    style="
    width: 18px;margin-left:2px;
    font-size: 8px;
    color: #fff;
    text-align:center;
    background-color: lightgreen;
    border-radius: 100%;
"
                    >√</div
                  ><div style="padding-left:10px;margin-left:9px;border-left:1px solid gray"
                    >{{ bg.creationTime | sdDateFormat('YYYY-MM-DD HH:mm:ss') }}
                    <table
                      ><tr v-for="(x, index) in bg.xx" :key="index">
                        <td>[{{ x.fieldDesc }}]</td
                        ><td
                          >{{ x.oldValue !== '' ? '"' : ''
                          }}{{
                            x.oldValue.indexOf('[') !== -1 ||
                            x.oldValue.indexOf('{') !== -1 ||
                            x.newValue.indexOf('[') !== -1 ||
                            x.newValue.indexOf('{') !== -1
                              ? ''
                              : x.oldValue === 'null'
                              ? ''
                              : x.oldValue
                          }}{{ x.oldValue !== '' ? '" 改为 ' : ''
                          }}<span v-if="x.oldValue === ''" style="color:green">
                            {{
                              x.newValue.indexOf('[') !== -1 || x.newValue.indexOf('{') !== -1
                                ? '修改动态表格数据'
                                : x.newValue
                            }}</span
                          >
                          <span v-else>{{
                            x.newValue.indexOf('[') !== -1 || x.newValue.indexOf('{') !== -1
                              ? '修改动态表格数据'
                              : '"' + x.newValue + '"'
                          }}</span>
                        </td></tr
                      ></table
                    >
                  </div></td
                >
              </tr>
            </table>
          </template>
        </sd-detail-form>
      </div>
    </audit-form-top-banner>
  </div>
</template>

<script>
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import components from './_import-components/audit-question-form-import'

export default {
  name: 'AuditQuestionForm',
  metaInfo: {
    title: '整改问题清单',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      rectplanExpand: true,
      findExpand: true,
      trackExpand: true,
      zgqrExpand: true,
      lsxxExpand: true,
      bgExpand: true,
    }
  },
  methods: {
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    saved() {
      return false
    },
    fnopenhistoryrecify() {
      return false
    },
    fngetnr(obj, item) {
      if (obj === undefined) {
        return ''
      } else {
        if (obj.length === undefined) {
          return obj[item]
        } else if (obj.length > 0) {
          return obj[obj.length - 1][item]
        } else {
          return ''
        }
      }
    },
    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
      }
    },
    fndeal(obj) {
      const newobj = []
      if (obj !== undefined) {
        obj.forEach((item) => {
          item.xt = item.creatorName + '_' + item.creationTime
          const i = newobj.find((n) => n.xt === item.xt)
          if (i !== undefined) {
            i.xx.push({
              fieldDesc: item.fieldDesc,
              fieldName: item.fieldName,
              newValue: item.newValue,
              oldValue: item.oldValue,
            })
          } else {
            item.xx = [
              {
                fieldDesc: item.fieldDesc,
                fieldName: item.fieldName,
                newValue: item.newValue,
                oldValue: item.oldValue,
              },
            ]
            newobj.push(item)
          }
        })
      }
      return newobj
    },
    fnopenfk(id) {
      const url = '#/audit-question-feedback-form?record=' + id
      window.open(url)
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
.titleHide {
  :global(.title_sd-detail-form_common) {
    display: none;
  }
}
.tablexm tr td {
  border: none !important;
}
.questionForm {
  width: 100%;
  height: 100%;
  :global(span.toptitle.toptitle_audit-form-top-banner_product::after) {
    content: '整改问题清单';
  }
  :global(span.toptitle.toptitle_audit-form-top-banner_product span) {
    display: none;
  }
}
</style>
