<template>
  <audit-form-top-banner :handel-save-form="saveForm" :form-data="mode" @handelSaveForm="saveForm">
    <sd-detail-form
      ref="docform"
      page-id="vue:audit/spicengineconstruceproject/spicEngineConstruceProject"
      :record-id="this.$route.query.id ? parseInt(this.$route.query.id) : null"
      :read-only="readOnly"
      :class="[$style.form]"
      @close="close(true)"
      @saved="saved"
      @sdFormReady="sdFormReady"
    >
      <template v-slot="{ formData, model, fields }">
        <table>
          <tr>
            <audit-advanced-group
              :expand="expandC"
              :expand-str="'expandC'"
              :group-label="'项目信息'"
              tablestyle="''"
              @changedClick="changedClick"
            ></audit-advanced-group>
          </tr>
        </table>

        <table v-show="expandC">
          <tr>
            <!-- 项目名称 -->
            <sd-form-item-td
              name="projectName"
              :input-props="{ defaultValue: projectName, disabled: true }"
            />
            <!-- 项目编号 -->
            <sd-form-item-td
              name="projectCode"
              :input-props="{ defaultValue: projectCode, disabled: true }"
            />
          </tr>
          <tr>
            <!-- 审计类型 -->
            <sd-form-item-td name="auditType" :input-props="{ defaultValue: JSON.parse('[]') }">
              <sd-select v-model="model.auditType" :options="option" />
            </sd-form-item-td>
            <!-- 二级单位/三级 -->
            <sd-form-item-td
              name="auditedUnitName"
              :input-props="{ defaultValue: auditedUnitName, disabled: true }"
            />
          </tr>
          <tr>
            <!-- 审批概算(万元) -->
            <sd-form-item-td name="auditApproximateAmount" />
          </tr>
          <tr class="bklabeloverflow">
            <!-- 集团公司投资决策批复时间 -->
            <sd-form-item-td name="investDecisionDate">
              <!-- <span>{{ investDecisionDate | sdDateFormat('YYYY-MM-DD') }}</span> -->
              <a-date-picker v-model="model.investDecisionDate" />
            </sd-form-item-td>
            <!-- 跟踪审计/决算计划完成时间 -->
            <sd-form-item-td name="auditDecisionDate" />
          </tr>
          <tr>
            <!-- 累计投资(万元) -->
            <sd-form-item-td
              name="cumulativeInvestment"
              :input-props="{ defaultValue: cumulativeInvestment, disabled: false }"
            />
            <!-- 开工时间 -->
            <sd-form-item-td name="commencementDate">
              <!-- <span>{{ commencementDate | sdDateFormat('YYYY-MM-DD') }}</span> -->
              <a-date-picker v-model="model.commencementDate" />
            </sd-form-item-td>
          </tr>

          <tr>
            <!-- 计划投产时间 -->
            <sd-form-item-td name="planedProductionDate">
              <!-- <span>{{ planedProductionDate | sdDateFormat('YYYY-MM-DD') }}</span> -->
              <a-date-picker v-model="model.planedProductionDate" />
            </sd-form-item-td>
          </tr>
          <tr class="bklabeloverflow">
            <!-- 项目概况及形象进度(简要概括) -->
            <sd-form-item-td name="description" :input-props="{ type: 'textarea' }" :colspan="3" />
          </tr>
        </table>

        <table>
          <tr>
            <audit-advanced-group
              :expand="expandJ"
              :expand-str="'expandJ'"
              :group-label="'审计开展情况'"
              @changedClick="changedClick"
            />
          </tr>
        </table>

        <table v-show="expandJ">
          <tr class="bklabeloverflow">
            <!-- 外委审计机构 -->
            <sd-form-item-td name="outerUnitName" />
            <!-- 签订审计合同以来首次进场时间 -->
            <sd-form-item-td name="firstApproachDate" />
          </tr>
          <tr>
            <!-- 审计进场情况 -->
            <sd-form-item-td
              name="auditApproachSituation"
              :input-props="{ type: 'textarea' }"
              :colspan="3"
            />
          </tr>
          <tr>
            <!-- 本月审计发现问题 -->
            <sd-form-item-td
              name="cumonthAuditFinding"
              :input-props="{ type: 'textarea' }"
              :colspan="3"
            />
          </tr>
          <tr class="bklabeloverflow">
            <!-- 建议集团重点关注问题 -->
            <sd-form-item-td
              name="suggestAttentProblem"
              :input-props="{ type: 'textarea' }"
              :colspan="3"
            />
          </tr>
          <tr class="bklabeloverflow">
            <!-- 本月需集团审计部或二级单位审计部协调的问题 -->
            <sd-form-item-td
              name="cumonthCoordinateProblem"
              :input-props="{ type: 'textarea' }"
              :colspan="3"
            />
          </tr>
        </table>

        <table>
          <tr
            ><td :colspan="4">
              <sd-form-item name="spicEngineConstruceProProblemList" :label="null">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="findExpand"
                    :expand-str="'findExpand'"
                    :group-label="'跟踪审计问题台账'"
                    tablestyle="''"
                    ><template>
                      <template>
                        <div :class="$style.wrapper">
                          <div :class="$style.btnselect"> </div>
                        </div>
                      </template>

                      <sd-child-table
                        v-show="findExpand"
                        ref="findData"
                        v-model="model.spicEngineConstruceProProblemList"
                        :mode="mode"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :colspan="8"
                        :columns="findcolumns"
                        name="spicEngineConstruceProProblemList"
                        :fields="
                          [
                            {
                              caption: '序号',
                              name: 'sortNum',
                              dataType: 'number',
                            },
                          ].concat(Array.from(fields.spicEngineConstruceProProblemList.attr.dync))
                        "
                        :read-only="!editable"
                      >
                        <template v-slot:form="{ model, fields }">
                          <table :class="$style.iamAuditChildTable">
                            <tr><sd-form-item-td name="sortNum" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="id" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="mainId" :hidden="true"/></tr>
                            <tr
                              ><sd-form-item-td name="projectTitle" :colspan="3"> </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td name="auditRecordOrPapercode" :colspan="3">
                                <a-textarea v-model="model.auditRecordOrPapercode" />
                              </sd-form-item-td>
                            </tr>
                            <tr
                              ><sd-form-item-td name="auditMatter" :colspan="3">
                                <a-textarea v-model="model.auditMatter" /> </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td name="auditFindingDesscription" :colspan="3">
                                <a-textarea
                                  v-model="model.auditFindingDesscription"
                                /> </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td name="auditAccording" :colspan="3">
                                <a-textarea v-model="model.auditAccording" /> </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td name="auditSuggection" :colspan="3">
                                <a-textarea v-model="model.auditSuggection" /> </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td name="auditSuggestionDate" :colspan="3">
                              </sd-form-item-td
                            ></tr>
                            <tr
                              ><sd-form-item-td
                                name="rectStatus"
                                :input-props="{ defaultValue: JSON.parse('[]') }"
                                :colspan="3"
                              >
                                <template v-slot>
                                  <sd-select v-model="model.rectStatus" :options="rectOptions" />
                                </template>
                                <!-- <sd-select v-model="model.rectStatus" :options="rectOptions" /> -->
                                <template v-slot:read>
                                  {{ JSON.parse(model.rectStatus)[0].name }}
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr
                              ><sd-form-item-td name="remark">
                                <a-textarea v-model="model.remark" /> </sd-form-item-td
                            ></tr>
                          </table>
                        </template>
                        <!-- input-fieldName 表示这部分是子表行显示的插槽 -->
                        <template
                          v-if="!readOnly"
                          v-slot:auditRecordOrPapercode="{ field, text, record }"
                        >
                          <a-textarea v-model="record.auditRecordOrPapercode" @click.stop="" />
                        </template>
                        <template v-if="!readOnly" v-slot:auditMatter="{ field, text, record }">
                          <a-textarea v-model="record.auditMatter" @click.stop="" />
                        </template>
                        <template
                          v-if="!readOnly"
                          v-slot:auditFindingDesscription="{ field, text, record }"
                        >
                          <a-textarea v-model="record.auditFindingDesscription" @click.stop="" />
                        </template>
                        <template v-if="!readOnly" v-slot:auditAccording="{ field, text, record }">
                          <a-textarea v-model="record.auditAccording" @click.stop="" />
                        </template>
                        <template v-if="!readOnly" v-slot:auditSuggection="{ field, text, record }">
                          <a-textarea v-model="record.auditSuggection" @click.stop="" />
                        </template>
                        <template v-if="!readOnly" v-slot:remark="{ field, text, record }">
                          <a-textarea v-model="record.remark" @click.stop="" />
                        </template>
                      </sd-child-table>
                    </template>
                  </audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
        </table>

        <table>
          <tr>
            <audit-advanced-group
              :expand="expandY"
              :expand-str="'expandY'"
              :group-label="'月报'"
              @changedClick="changedClick"
            />
          </tr>
        </table>

        <table v-show="expandY">
          <tr>
            <!-- <sd-select v-model="val" name="submittedMonth" :options="options" /> -->

            <!-- 报送月份 -->
            <!--             <a-form-model-item label="报送月份" prop="submittedMonth">
              <a-month-picker
                name="submittedMonth"
                placeholder="请选择月份"
                required="true"
              ></a-month-picker>
            </a-form-model-item>-->
            <sd-form-item-td name="submittedMonth" :input-props="{ defaultValue: JSON.parse('[]') }"
              ><sd-select v-model="model.submittedMonth" :options="options"
            /></sd-form-item-td>
            <!-- 月报附件 -->
            <sd-form-item-td name="monthAttachment" />
          </tr>
        </table>

        <table>
          <tr>
            <audit-advanced-group
              :expand="expandS"
              :expand-str="'expandS'"
              :group-label="'季报'"
              @changedClick="changedClick"
            />
          </tr>
        </table>

        <table v-show="expandS">
          <tr>
            <!-- 报送季度 -->
            <sd-form-item-td
              name="submittedQuarter"
              :input-props="{ defaultValue: JSON.parse('[]') }"
            >
              <sd-select v-model="model.submittedQuarter" :options="quarterOption" />
            </sd-form-item-td>
            <!-- 季报附件 -->
            <sd-form-item-td name="quarterAttachment" />
          </tr>
          <tr v-show="false">
            <!-- 编辑人员 -->
            <sd-form-item-td name="editUser" />
            <!-- 编辑日期 -->
            <sd-form-item-td name="editDate" />
          </tr>
          <tr>
            <!-- 编辑人员 -->
            <sd-form-item-td name="creatorName" />
            <!-- 编辑日期 -->
            <sd-form-item-td name="creationTime" />
          </tr>
          <tr>
            <!-- id -->
            <sd-form-item-td name="id" hidden />
            <sd-form-item-td name="mainId" hidden />
            <sd-form-item-td name="auditedUnitCode" hidden />
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import { Modal, Message } from 'ant-design-vue'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
import auditAdvancedGroup from '@product/iam/components/audit-advanced-group.vue'
import components from './_import-components/spic-engine-construce-table-import'
import axios from '@/common/services/axios-instance'
import moment from 'moment'

export default {
  name: 'SpicEngineConstruceTable',
  metaInfo: {
    title: '工程建设项目信息－表单',
  },
  components: {
    ...components,
    auditFormTopBanner,
    auditAdvancedGroup,
  },

  data() {
    return {
      initialled: false,
      auditedUnitName: '',
      auditedUnitCode: '',
      cumulativeInvestment: '',
      investDecisionDate: null,
      commencementDate: null,
      planedProductionDate: null,
      projectName: '',
      projectCode: '',
      flag: true,
      mainId: null,
      orgId: '',
      expandC: true,
      expandJ: true,
      expandY: true,
      expandS: true,
      findExpand: true,
      readOnly: false,
      message: '保存成功',
      mode: null,
      rectOptions: [
        {
          id: 1,
          name: '已整改',
        },
        {
          id: 2,
          name: '部分整改',
        },
        {
          id: 3,
          name: '未整改',
        },
      ],
      quarterOption: [
        {
          id: 1,
          name: '第一季度',
        },
        {
          id: 2,
          name: '第二季度',
        },
        {
          id: 3,
          name: '第三季度',
        },
        {
          id: 4,
          name: '第四季度',
        },
      ],
      option: [
        {
          id: 1,
          name: '全过程跟踪审计',
        },
        {
          id: 2,
          name: '工程结算及竣工财务决算审计',
        },
      ],
      options: [
        {
          id: 1,
          name: '一月',
          title: '悬停提示信息',
        },
        {
          id: 2,
          name: '二月',
        },
        {
          id: 3,
          name: '三月',
        },
        {
          id: 4,
          name: '四月',
        },
        {
          id: 5,
          name: '五月',
        },
        {
          id: 6,
          name: '六月',
        },
        {
          id: 7,
          name: '七月',
        },
        {
          id: 8,
          name: '八月',
        },
        {
          id: 9,
          name: '九月',
        },
        {
          id: 10,
          name: '十月',
        },
        {
          id: 11,
          name: '十一月',
        },
        {
          id: 12,
          name: '十二月',
        },
      ],
      findcolumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          width: '50px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: 'id',
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          title: 'mainId',
          dataIndex: 'mainId',
          sdHidden: true,
        },
        {
          title: '项目名称',
          dataIndex: 'projectTitle',
        },
        {
          title: '审计记录或底稿编号',
          dataIndex: 'auditRecordOrPapercode',
        },
        { title: '审计事项', dataIndex: 'auditMatter' },
        {
          title: '审计发现问题简述',
          dataIndex: 'auditFindingDesscription',
        },
        {
          title: '审计依据',
          dataIndex: 'auditAccording',
        },
        { title: '审计建议意见', dataIndex: 'auditSuggection' },
        { title: '审计建议意见下达时间', dataIndex: 'auditSuggestionDate' },
        {
          title: '整改情况',
          dataIndex: 'rectStatus',
          customRender: (text, record, index) =>
            JSON.parse(text) === null ? '' : JSON.parse(text)[0].name,
        },
        { title: 'remark', dataIndex: '备注' },
      ],
    }
  },

  mounted() {
    this.initData()
    const ini = setInterval(() => {
      if (
        this.$refs.docform &&
        (this.$refs.docform.$refs.form || this.$refs.docform.$refs.sdForm)
      ) {
        this.$refs.docform.setFieldValue(
          'investDecisionDate',
          Number(this.$route.query.investDecisionDate)
        )

        this.$refs.docform.setFieldValue(
          'commencementDate',
          Number(this.$route.query.commencementDate)
        )
        this.$refs.docform.setFieldValue(
          'planedProductionDate',
          Number(this.$route.query.planedProductionDate)
        )
        clearInterval(ini)
      }
    }, 100)
  },
  methods: {
    onChange(value) {
      if (value) {
        this.docform.submittedMonth = 111
      } else {
        this.docform.submittedMonth = ''
      }
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },

    // 保存
    saveForm() {
      this.isSave = true
      this.$refs.docform.setFieldValue('mainId', this.mainId)
      this.$refs.docform.saveBtnClick()
    },

    saved(data) {
      Message.success('保存成功', 1).then((res) => {
        crossWindowWatcher.notifyChange(this.$route.fullPath, true)
        window.close()
      })
    },

    initData() {
      // debugger
      this.projectName = this.$route.query.projectName
      this.projectCode = this.$route.query.projectCode
      this.auditedUnitName = this.$route.query.auditedUnitName
      this.cumulativeInvestment = Number(this.$route.query.cumulativeInvestment)
      if (this.$route.query.auditedUnitCode) {
        this.auditedUnitCode = this.$route.query.auditedUnitCode
      }
      this.mainId = Number(this.$route.query.mainId)
      setTimeout(() => {
        this.investDecisionDate = Number(this.$route.query.investDecisionDate)
        this.commencementDate = Number(this.$route.query.commencementDate)
        this.planedProductionDate = Number(this.$route.query.planedProductionDate)
      }, 2000)
      // setTimeout(() => {
      //   this.$refs.docform.setFieldValue('investDecisionDate', this.$route.query.investDecisionDate)
      //   this.$refs.docform.setFieldValue('commencementDate', this.$route.query.commencementDate)
      //   this.$refs.docform.setFieldValue(
      //     'planedProductionDate',
      //     this.$route.query.planedProductionDate
      //   )
      // }, 1000)
    },
    sdFormReady() {
      debugger
      if (this.$route.query.isEdit === 'VIEW') {
        this.readOnly = true
        this.mode = 'VIEW'
      } else if (this.$route.query.isEdit === 'EDIT') {
        this.readOnly = false
      }
      // this.$refs.docform.setFieldValue('mainId', this.$route.query.mainId)
    },
    rtgetjson(data) {
      debugger
      var name = ''
      if (data !== undefined && data !== '') {
        name = JSON.parse(data) === null ? '' : JSON.parse(data)[0].name
        return name
      } else {
        return ''
      }
    },
    changedClick(event) {
      if (event === 'expandC') {
        this.expandC = !this.expandC
      }
      if (event === 'expandJ') {
        this.expandJ = !this.expandJ
      }
      if (event === 'expandS') {
        this.expandS = !this.expandS
      }
      if (event === 'expandY') {
        this.expandY = !this.expandY
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
@import '@/webflow/sd-flow-form.scss';
.ant-card-body {
  padding: 12px;
}
.btnselect {
  position: relative;
  float: right;
  .batchselect {
    z-index: 100;
    margin-right: 190px;
    top: 4px;
  }
}

.odrForm {
  /* :global .sd-page-title {
     display: none;
   } */
  :global(.child-table-title) {
    display: none;
  }

  .lastTr {
    :global(.ant-form-item-control-wrapper) {
      border: none !important;
    }
  }

  :global(.header_sd-child-table_common) {
    right: 115px !important;
  }

  .btnexcel {
    position: relative;
    top: -5px;
    float: right;

    .batchexcel {
      z-index: 100;
      margin-left: 10px;
    }
    .autoprequeue {
      right: 180px;
      z-index: 100;
    }
    .viewSjjh {
      right: 180px;
      z-index: 100;
    }
  }

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

.projecttable {
  table {
    border-collapse: collapse;
  }
}

.iam-audit-child-table {
  :global(td.ant-form-item-label) {
    width: 5%;
    padding-right: 20px;
    overflow: auto;
    white-space: normal;
  }

  :global(td.ant-form-item-label::after) {
    position: absolute;
    margin: 0 8px 0 8px;
    content: ':';
  }

  :global(td.ant-form-item-label > label::after) {
    margin: 0;
    content: '';
  }

  :global(td.ant-form-item-control-wrapper) {
    width: 32%;
  }
}
:global(.auditplanformmodalcksjjh) {
  :global(.ant-pagination) {
    display: none;
  }
}
</style>
