<template>
  <div :class="$style.selectproject">
    <audit-advanced-query
      :expand="expand"
      :search-data="advSearchForm"
      :ref-name="searchform"
      :search-style="{
        height: '170px',
        left: '0px',
        top: '50px !important',
        width: 'calc(100% - 40px) !important',
      }"
      :search-fun="advSearch"
      @searchedClick="searchedClick"
    >
      <template>
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="项目名称" prop="projectTitle">
              <a-input v-model="advSearchForm.projectTitle" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目编号" prop="projectCode">
              <a-input v-model="advSearchForm.projectCode" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目组长" prop="groupLeaderName">
              <a-input v-model="advSearchForm.groupLeaderName" />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="年度" prop="planYear" style="padding-left:2em">
              <a-date-picker
                v-model="advSearchForm.planYear"
                mode="year"
                picker="YYYY"
                format="YYYY"
                :allow-clear="false"
                placeholder="选择年度"
                :input-read-only="true"
                :value="planYear"
                :open="endOpen"
                @panelChange="yearChange"
                @openChange="handleEndOpenChange"
              ></a-date-picker>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </template>
    </audit-advanced-query>
    <!-- 列表 -->
    <sd-data-table-ex
      ref="NBDataTable"
      :show-advance-btn="true"
      form-id="iamAuditProject"
      data-url="api/xcoa-mobile/v1/rectPlan-project/find-project"
      :pagination="{ pageSize: 10 }"
      :filter-expressions="filterExpressions"
      :check-type="'radio'"
      :columns="columns"
      :show-advance-query="true"
      :search-fields="['projectTitle', 'projectCode']"
      show-selection
      :process-res="processRes"
      :custom-row="
        (record, index) => {
          return {
            on: {
              dblclick: () => {
                fndblclick(record, index)
              },
            },
          }
        }
      "
      @searchbtnClick="searchbtnClick"
      @onChange="onChange"
    >
    </sd-data-table-ex>
  </div>
</template>

<script>
import moment from 'moment'
import axios from '@/common/services/axios-instance'
import auditAdvancedQuery from '../../components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '../../components/audit-advanced-query-mixins'
import components from './_import-components/audit-nb-selectproject-import'
const columns = [
  {
    title: '序号',
    dataIndex: 'sortNumber',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '项目id',
    dataIndex: 'id',
    width: '80px',
    sdHidden: true,
  },
  {
    title: '项目名称',
    dataIndex: 'projectTitle',
    width: '35%',
    scopedSlots: { customRender: 'isLink' },
  },
  {
    title: '项目编号',
    width: '15%',
    sorter: true,
    dataIndex: 'projectCode',
  },
  {
    title: '被审计单位',
    dataIndex: 'auditedUnitNames',
  },
  {
    title: '被审计单位Ids',
    dataIndex: 'auditedUnitcodeS',
    sdHidden: true,
  },
  {
    title: '项目组长',
    dataIndex: 'groupLeaderName',
  },
  {
    title: '项目组长Id',
    dataIndex: 'groupLeaderAccount',
    sdHidden: true,
  },
  {
    title: '年度',
    dataIndex: 'planYear',
    defaultSortOrder: 'descend',
    sdHidden: true,
  },
  {
    title: '状态',
    dataIndex: 'itemStatus',
    sdHidden: true,
  },
]
export default {
  name: 'AuditNbSelectproject',
  metaInfo: {
    title: '内部项目',
  },
  components: {
    ...components,
    auditAdvancedQuery,
  },
  mixins: [auditAdvancedQueryMixins],
  data() {
    return {
      itemStatusOptions: [],
      auditTypeOptions: [],
      auditModeOptions: [],
      columns,
      formData: {
        projectTitle: '',
        projectCode: '',
      },
      searchform: 'searchform',
      isShowAdvSearch: false,
      advSearchForm: {
        projectTitle: '',
        projectCode: '',
        groupLeaderName: '',
        auditMode: '',
        itemStatus: '',
        auditType: '',
        planYear: '',
      },
      projectId: '',
      setType: '',
      // 列表展示过滤条件
      filterExpressions: [],
      period: [],
      endOpen: false,
      planYear: null,
    }
  },
  created() {
    // 初始化数据字典信息
    this.initDictionaryInfo()
    this.planYear = moment(new Date())
    this.advSearchForm.planYear = moment(new Date()).format('YYYY')
  },
  methods: {
    moment,
    yearChange(value) {
      this.planYear = value
      this.advSearchForm.planYear = value.format('YYYY')
      if (document.getElementsByClassName('ant-calendar-picker-container').length > 0) {
        document.getElementsByClassName('ant-calendar-picker-container')[0].style.display = 'none'
      }
    },
    handleEndOpenChange(open) {
      this.endOpen = open
    },
    fndblclick(record, index) {
      this.$emit('listSelected', [record], index)
    },
    initDictionaryInfo() {
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=PRODUCT_IAM_AUDIT_PROJECT_STATUS',
        method: 'get',
      }).then((res) => {
        // if (res.status === 200) {
        this.itemStatusOptions = res.data
        // }
      })
      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_TYPE',
        method: 'get',
      }).then((res) => {
        // if (res.status === 200) {
        this.auditTypeOptions = res.data
        // }
      })
    },
    processRes(data) {
      let index = 0
      data.data.forEach((item) => {
        item.id = this.$refs.SJMXDataTable.localPagination.current + '-' + index
        index++
      })
      return data
    },

    // 翻页操作
    onChange(pagination, filters, sorter) {
      this.pageSize = pagination.pageSize
      this.startPosition = (pagination.current - 1) * pagination.pageSize
    },
    // 开启关闭
    searchedClick() {
      this.expand = false
    },
    advSearch() {
      this.filterExpressions = []
      // 项目名称
      if (this.advSearchForm.projectTitle) {
        this.filterExpressions.push({
          dataType: 'str',
          name: 'projectTitle',
          op: 'like',
          stringValue: `%${this.advSearchForm.projectTitle}%`,
        })
      }
      // 项目编号
      if (this.advSearchForm.projectCode) {
        this.filterExpressions.push({
          dataType: 'str',
          name: 'projectCode',
          op: 'like',
          stringValue: `%${this.advSearchForm.projectCode}%`,
        })
      }
      // 项目组长
      if (this.advSearchForm.groupLeaderName) {
        this.filterExpressions.push({
          dataType: 'str',
          name: 'groupLeaderName',
          op: 'like',
          stringValue: `%${this.advSearchForm.groupLeaderName}%`,
        })
      }
      // // 年度
      // if (this.advSearchForm.planYear) {
      //   this.filterExpressions.push({
      //     dataType: 'str',
      //     name: 'planYear',
      //     op: 'eq',
      //     stringValue: `${this.advSearchForm.planYear}`,
      //   })
      // }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.selectproject {
  :global(.ant-calendar-picker) {
    width: calc(100% + 33px);
  }
}
</style>
