<template>
  <div>
    <el-dialog
      title="入库记录"
      :close-on-click-modal="false"
	  draggable
      width="1100px"
      height="500px"
      @close="close"
      append-to-body
      v-model="visible">
      <div style="height: calc(100% - 80px);">

        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="400px"
          :loading="loading"
          ref="projectTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :print-config="{}"
          :sort-config="{remote:true}"
          :data="dataList"
          :row-config="{isCurrent: true}"
          :radio-config="{trigger: 'row'}"
        >
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
          <vxe-column min-width="160" align="center" title="入库编号" field="wareHouseNumber"></vxe-column>
          <vxe-column min-width="160" align="center" title="入库名称" field="wareHouseName">
            <template #default="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('material:list')" @click="view(scope.row.id)">{{scope.row.wareHouseName}}</el-link>
              <el-link  type="primary" :underline="false" v-else-if="hasPermission('material:list')"  @click="view(scope.row.id,)">{{scope.row.wareHouseName}}</el-link>
              <span v-else>{{scope.row.wareHouseName}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="160" align="center" title="入库时间" field="wareHouseDate"></vxe-column>
          <vxe-column min-width="160" align="center" title="经办人" field="handleByName"></vxe-column>
          <vxe-column min-width="160" align="center" title="经办人部门" field="handledByOfficeName"></vxe-column>

        </vxe-table>
        <vxe-pager
          background
          :current-page="tablePage.currentPage"
          :page-size="tablePage.pageSize"
          :total="tablePage.total"
          :page-sizes="[10, 20, 100, 1000, {label: '全量数据', value: 1000000}]"
          :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
          @page-change="currentChangeHandle">
        </vxe-pager>
      </div>
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			</span>
		</template>
    </el-dialog>
    <WareHouseAddForm ref="wareHouseAddForm"></WareHouseAddForm>
  </div>
</template>

<script>
  import WareHouseAddForm from '../wareHouse/WareHouseAddForm'
  import WareHouseService from '@/api/materialManagement/WareHouseService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        tableKey: '',
        dataList: [],
        searchForm: {
          purchaseSketch: '',
          purchaseId: '',
          contractDates: [],
          // 查入库记录所需的状态数组
          statusTwo: []
        }
      }
    },
    wareHouseService: null,
    created () {
      this.wareHouseService = new WareHouseService()
    },
    components: {
      WareHouseAddForm,
    },
    methods: {
      // 查看
      view (id) {
        // this.$refs.updateInfoForm.init('view', id)
        this.$refs.wareHouseAddForm.init('view', id)
      },
      init (id) {
        this.visible = true
        this.searchForm.purchaseId = id
        this.list()
      },
      list () {
        this.loading = true
        // eslint-disable-next-line no-unused-vars
        let status = ['0', '5']
        this.searchForm.statusTwo = status
        // this.searchForm.createId = this.$store.state.user.id
        this.wareHouseService.wareHouseList({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then((data) => {
          this.dataList = data.records
          this.tablePage.total = data.total
          this.tableKey = Math.random()
          this.loading = false
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.visible = false
      }
    }
  }
</script>
<style scoped>
  /deep/ .el-dialog__body {
    padding-top: 0px;
    padding-bottom: 15px;
  }
</style>
