<template>
  <div>
    <sd-webflow ref="flow" :removed-tabs="['sdRelatedDoc']" :validate-form="validForm">
      <template v-slot:form="{ model }">
        <table>
          <tr>
            <td style="border:none;padding-left:5px">
              <audit-advanced-group
                :expand="basicExpand"
                :expand-str="'basicExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="basicExpand">
          <tr>
            <!-- 疑点名称 -->
            <sd-form-item-td name="suspectsName" />
            <!-- 项目名称 -->
            <sd-form-item-td name="projectName">
              <a-input v-model="model.projectName" :read-only="true" @click="openModel"></a-input>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 模型名称 -->
            <sd-form-item-td name="modelName" @click="mxRelSelect" />
            <sd-form-item-td name="modelNum">
              <span>{{ model.modelNum }}</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 疑点核实单位 -->
            <sd-form-item-td name="suspectsVerifyUnit">
              <span>{{ model.suspectsVerifyUnit }}</span>
            </sd-form-item-td>
            <!-- 疑点核实联系人 -->
            <sd-form-item-td name="suspectsLinkMan" @change="handlChange" />
          </tr>
          <tr>
            <!-- 疑点核实截至日期 -->
            <sd-form-item-td name="suspectsVerifyEndDate" :colspan="3" />
          </tr>
          <tr>
            <!-- 备注 -->
            <sd-form-item-td name="suspectsRemark" :colspan="3">
              <a-textarea v-model="model.suspectsRemark" :autosize="{ minRows: 3, maxRows: 3 }" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制日期 -->
            <sd-form-item-td name="creationTime" />
            <!-- 编制人员 -->
            <sd-form-item-td name="creatorName" />
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3" />
          </tr>
          <tr>
            <!-- 项目id -->
            <sd-form-item-td name="projectId" :hidden="true" />
          </tr>
        </table>

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

        <table v-show="feedbackExpand">
          <tr>
            <!-- 是否核实 -->
            <sd-form-item-td name="verified" :colspan="3">
              <a-select v-model="model.verified" :llow-clear="true" :placeholder="'请选择'">
                <a-select-option value="1">
                  是
                </a-select-option>
                <a-select-option value="0">
                  否
                </a-select-option>
              </a-select>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 反馈说明 -->
            <sd-form-item-td name="feedbackDesc" :colspan="3">
              <a-textarea v-model="model.feedbackDesc" :autosize="{ minRows: 3, maxRows: 3 }" />
            </sd-form-item-td>
          </tr>
        </table>
      </template>
    </sd-webflow>
    <AuditSelectMaintain :visible="visibleY" @listMxSelected="listMxSelected"></AuditSelectMaintain>
    <AuditSelectProject :visible="visibleP" @listPSelected="listPSelected"></AuditSelectProject>
  </div>
</template>

<script>
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import service from './audit-suspects'
import AuditSelectProject from './audit-select-project.vue'
import AuditSelectMaintain from './audit-select-maintain.vue'
import components from './_import-components/audit-suspects-form-import'

export default {
  name: 'AuditSuspectsForm',
  metaInfo: {
    title: '审计疑点',
  },
  components: {
    ...components,
    AuditSelectMaintain,
    AuditSelectProject,
    auditAdvancedGroup,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    const self = this
    return {
      visibleY: false,
      visibleP: false,
      basicExpand: true,
      feedbackExpand: true,
      projectlist: [],
      projectTitle: '',
      projectId: '',

      columns: [
        {
          title: '序号',
          dataIndex: 'id',
          width: '300',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '项目标题',
          dataIndex: 'projectTitle',
          width: '300',
        },
      ],
      rowSelection: {
        onSelect: (record, selected, selectedRows) => {
          if (selected) {
            self.projectTitle = selectedRows[0].projectTitle
          }
        },
        columnWidth: '200',
        // columnTitle: '项目选择',
        fixed: true,
        type: 'radio',
      },
    }
  },
  created() {
    this.getProjectList()
  },
  mounted() {},
  methods: {
    validForm() {
      return true
    },
    getProjectList() {
      service.getProjectInfoList().then((res) => {
        this.projectlist = res.data
      })
    },
    handleOk() {
      this.$refs.flow.setFieldValue('projectName', this.projectTitle)
    },
    openModel() {
      this.visibleP = true
    },
    listPSelected(keys, keyinfos) {
      this.$refs.flow.setFieldValue('projectName', keyinfos[0].projectTitle)
      this.$refs.flow.setFieldValue('projectId', keyinfos[0].id)
    },

    handlChange(val) {
      if (val && val.length > 0) {
        var account = val[0].code
        service.getUnitNameByAccount(account).then((res) => {
          this.$refs.flow.setFieldValue('suspectsVerifyUnit', res.data)
        })
      }
    },

    // 审计模型选择器列表
    mxRelSelect() {
      this.visibleY = true
    },

    listMxSelected(keys, keyinfos) {
      const modelCode = []
      const modelName = []
      keyinfos.forEach((element) => {
        modelCode.push(element.modelCode)
        modelName.push(element.modelName)
      })
      this.$refs.flow.setFieldValue('modelNum', modelCode.join(','))
      this.$refs.flow.setFieldValue('modelName', modelName.join(','))
    },
  },
}
</script>

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