<template>
	<div>
		<el-card>
			<span class="show-text">二维码信息:</span>
			<el-input v-model="TagName" clearable style="width: 280px;margin-right: 26px" placeholder="请输入二维码信息"/>
			<span class="show-text">扫描时间:</span>
			<el-date-picker
				v-model="collectionTime"
				:clearable="false"
				popper-class="virtual-cell-time-picker"
				value-format="yyyy-MM-dd HH:mm:ss"
				format="yyyy-MM-dd HH:mm:ss"
				type="datetimerange"
				range-separator="-"
				style="width: 360px;margin-right: 16px;vertical-align: top"
				start-placeholder="开始时间"
				end-placeholder="结束时间" />
			<el-button :disabled="loading" icon="el-icon-search" type="primary" @click="searchTable()">查询</el-button>
			<el-button style="margin-left: 14px" type="warning" icon="el-icon-download" @click="searchTableALL()">导出</el-button>
			<div style="margin-top: 26px">
				<el-table
					v-loading="loading"
					:data="tableData"
					:header-row-style= "{fontSize: '18px',fontFamily:'MiSans Demibold',height: '64px',backgroundColor:'#fff'}"
					:row-style="{fontSize: '16px',fontFamily:'MiSans Regular',height: '64px'}"
					element-loading-text="数据加载中"
					element-loading-spinner="el-icon-loading"
					element-loading-background="rgba(0, 0, 0, 0.2)"
					tooltip-effect="dark"
					style="width: 100%"
					height="788"
					border
					size="mini">
					<el-table-column type="index" label=" " align="center" width="100"/>
					<el-table-column align="center" label="工件类型">
						<template slot-scope="scope">
							{{ scope.row.TypeName }}
						</template>
					</el-table-column>
					<el-table-column align="center" label="二维码信息">
						<template slot-scope="scope">
							{{ scope.row.PartNum }}
						</template>
					</el-table-column>
					<el-table-column align="center" label="扫描时间">
						<template slot-scope="scope">
							{{ scope.row.ScanTime }}
						</template>
					</el-table-column>
				</el-table>
				<div class="block" style="margin-top: 32px;">
					<el-pagination
						v-if="!loading"
						:current-page="pageList"
						:page-sizes="[50, 100, 200, 300]"
						:page-size="pageSize"
						:total="total"
						background
						layout="total, sizes, prev, pager, next, jumper"
						@size-change="handleSizeChange"
						@current-change="handleCurrentChange"/>
				</div>
			</div>
		</el-card>
	</div>
</template>

<script>
export default {
  data() {
    return {
      TagName: '',
      collectionTime: [],
      tableDataExcel: [],
      loading: false,
      tableData: [],
      total: 0, // 总条数
      pageSize: 50, // 每页显示条数
      pageList: 1 // 后台获取页
    }
  },
  created() {
  },
  methods: {
    // 查询
    searchTable() {
      if (this.collectionTime.length === 0) {
        this.$message.error('请选择需要查询的时间段！')
        return
      }
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['PartNum', this.TagName]
      param[1] = ['开始时间', this.collectionTime[0]]
      param[2] = ['结束时间', this.collectionTime[1]]
      param[3] = ['PageCurrent', this.pageList]
      param[4] = ['PageSize', this.pageSize]
      param[5] = ['PageCount', '1111', 'int', '1']
      param[6] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', '工件数据_查询_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          const str = '\u0000'
          for (let i = 0; i < response.data.result.length; i++) {
            response.data.result[i].PartNum = response.data.result[i].PartNum.replaceAll(str, '')
            this.tableData.push(response.data.result[i])
          }
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    // 导出数据
    searchTableALL() {
      if (this.collectionTime.length === 0) {
        this.$message.error('请选择需要查询的时间段！')
        return
      }
      if (this.tableData.length === 0) {
        this.$message.error('请查询需要导出的数据！')
        return
      }
      var param = []
      if (this.tableData.length === 0) {
        this.$message.warning('请查询要导出的数据')
        return
      }
      param[0] = ['PartNum', this.TagName]
      param[1] = ['开始时间', this.collectionTime[0]]
      param[2] = ['结束时间', this.collectionTime[1]]
      var Data = this.CreateData('2003', '工件数据_查询_导出', param)
      const blob = 'data:image/gif;base64,R0lGODlhCQACAIAAAMzMzP///yH5BAEAAAEALAAAAAAJAAIAAAIEjI9pUAA7'
      this.exportExcel_NPOI(Data, blob)
    },
    closePage() {
      window.location.href = 'about:blank'
      window.close()
    },
    // 分页
    handleSizeChange(val) {
      this.pageList = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageList = val
      this.searchTable()
    }
  }
}
</script>
<style>
	.show-text {
		font-family: "MiSans Regular",serif ;
		margin-right: 20px;
		font-size: 20px;
		color: #595959;
	}
</style>
