<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">工位号：</span>
        <el-select v-model="dataTypeValue" placeholder="工位号" clearable size="small" style="width:100px">
          <el-option
            v-for="item in dataType"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span style="margin-left: 10px">变量类型：</span>
        <el-select v-model="valueTypeValue" placeholder="变量类型" clearable size="small" style="width:100px">
          <el-option
            v-for="item in valueType"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-button type="primary" plain size="small" icon="el-icon-search" style="margin-left: 5px" @click="pageSize=100;pageCurrent=1;searchTable()">查询</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        height="740"
        center
        style="width: 100%">
        <el-table-column type="index" width="60" label="序号" align="center"/>
        <el-table-column label="TagID" align="center">
          <template slot-scope="scope">
            {{ scope.row.TagID }}
          </template>
        </el-table-column>
        <el-table-column label="TagName" width="200px" align="center">
          <template slot-scope="scope">
            {{ scope.row.TagName }}
          </template>
        </el-table-column>
        <el-table-column label="工位号" align="center">
          <template slot-scope="scope">
            {{ scope.row.工位号 }}
          </template>
        </el-table-column>
        <el-table-column label="数据来源" align="center">
          <template slot-scope="scope">
            {{ scope.row.数据来源 }}
          </template>
        </el-table-column>
        <el-table-column label="IP" align="center">
          <template slot-scope="scope">
            {{ scope.row.IP }}
          </template>
        </el-table-column>
        <el-table-column label="TagTypeID" width="90px" align="center">
          <template slot-scope="scope">
            {{ scope.row.TagTypeID }}
          </template>
        </el-table-column>
        <el-table-column label="TagLong" align="center">
          <template slot-scope="scope">
            {{ scope.row.TagLong }}
          </template>
        </el-table-column>
        <el-table-column label="DbName" align="center">
          <template slot-scope="scope">
            {{ scope.row.DbName }}
          </template>
        </el-table-column>
        <el-table-column label="变量类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量类型 }}
          </template>
        </el-table-column>
        <el-table-column label="变量地址" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量地址 }}
          </template>
        </el-table-column>
        <el-table-column label="变量其它" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量其它 }}
          </template>
        </el-table-column>
        <el-table-column label="演示偏移" align="center">
          <template slot-scope="scope">
            {{ scope.row.演示偏移 }}
          </template>
        </el-table-column>
        <el-table-column label="列位置" align="center">
          <template slot-scope="scope">
            {{ scope.row.列位置 }}
          </template>
        </el-table-column>
        <el-table-column label="测量位置" align="center">
          <template slot-scope="scope">
            {{ scope.row.测量位置 }}
          </template>
        </el-table-column>
        <el-table-column label="测量项目" align="center">
          <template slot-scope="scope">
            {{ scope.row.测量项目 }}
          </template>
        </el-table-column>
        <el-table-column label="测量单位" align="center">
          <template slot-scope="scope">
            {{ scope.row.测量单位 }}
          </template>
        </el-table-column>
        <el-table-column label="变量类型代码" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量类型代码 }}
          </template>
        </el-table-column>
        <el-table-column label="变量类型名称" width="300px" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量类型名称 }}
          </template>
        </el-table-column>
        <el-table-column label="机体类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.机体类型 }}
          </template>
        </el-table-column>
        <el-table-column label="线体类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.线体类型 }}
          </template>
        </el-table-column>
        <el-table-column label="TagAdrDemo" align="center">
          <template slot-scope="scope">
            {{ scope.row.TagAdrDemo }}
          </template>
        </el-table-column>
        <el-table-column label="是否启用" align="center">
          <template slot-scope="scope">
            {{ scope.row.是否启用 }}
          </template>
        </el-table-column>
        <el-table-column label="监控组" align="center">
          <template slot-scope="scope">
            {{ scope.row.监控组 }}
          </template>
        </el-table-column>
        <el-table-column label="监控时间间隔" align="center">
          <template slot-scope="scope">
            {{ scope.row.监控时间间隔 }}
          </template>
        </el-table-column>
        <el-table-column label="OpcServer_OPNAME" width="100px" align="center">
          <template slot-scope="scope">
            {{ scope.row.OpcServer_OPNAME }}
          </template>
        </el-table-column>
        <el-table-column label="变量特点" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量特点 }}
          </template>
        </el-table-column>
        <el-table-column label="是否监控" align="center">
          <template slot-scope="scope">
            {{ scope.row.是否监控 }}
          </template>
        </el-table-column>
        <el-table-column label="变量排序" align="center">
          <template slot-scope="scope">
            {{ scope.row.变量排序 }}
          </template>
        </el-table-column>
        <el-table-column label="工序能力" align="center">
          <template slot-scope="scope">
            {{ scope.row.工序能力 }}
          </template>
        </el-table-column>
        <el-table-column label="监控属性代码" align="center">
          <template slot-scope="scope">
            {{ scope.row.监控属性代码 }}
          </template>
        </el-table-column>
        <el-table-column label="测量位置短" align="center">
          <template slot-scope="scope">
            {{ scope.row.测量位置短 }}
          </template>
        </el-table-column>
        <el-table-column label="上限值" align="center">
          <template slot-scope="scope">
            {{ scope.row.上限值 }}
          </template>
        </el-table-column>
        <el-table-column label="下限值" align="center">
          <template slot-scope="scope">
            {{ scope.row.下限值 }}
          </template>
        </el-table-column>
        <el-table-column label="理论值" align="center">
          <template slot-scope="scope">
            {{ scope.row.理论值 }}
          </template>
        </el-table-column>
        <el-table-column label="IsGoodBad" align="center">
          <template slot-scope="scope">
            {{ scope.row.IsGoodBad }}
          </template>
        </el-table-column>
        <el-table-column label="IsSaveToSql" align="center">
          <template slot-scope="scope">
            {{ scope.row.IsSaveToSql }}
          </template>
        </el-table-column>
        <el-table-column label="IsWebSocket" align="center">
          <template slot-scope="scope">
            {{ scope.row.IsWebSocket }}
          </template>
        </el-table-column>
        <el-table-column label="连接名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.连接名称 }}
          </template>
        </el-table-column>
        <el-table-column label="OpcServer_MIS" align="center">
          <template slot-scope="scope">
            {{ scope.row.OpcServer_MIS }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[50, 100, 200]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      dataType: [], // 工位数组
      dataTypeValue: '', // 工位信息
      valueType: [
        {
          label: '基本变量',
          value: 8
        }, {
          label: '报警变量',
          value: 9
        }, {
          label: '质量变量',
          value: 7
        }
      ],
      valueTypeValue: '',
      total: 0, // 总条数
      pageList: 100, // 每页显示条数
      pageSize: 100, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    this.getNumber()
    this.searchTable()
  },
  methods: {
    // 初始化获取产品型号
    getNumber() {
      this.dataType = []
      request({
        url: '',
        method: 'post',
        data: {
          type: '3',
          name: `SELECT [工位号] FROM [dbo].[MES_计划BOM_工位与名称]`
        }
      }).then(response => {
        if (response.data.length) {
          for (let i = 0; i < response.data.length; i++) {
            this.dataType.push({
              label: response.data[i].工位号,
              value: response.data[i].工位号
            })
          }
        }
      })
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      let stationNumberValue_check, valueType_check
      // this.engineTypeValue ? engineTypeValue_check = 1 : (engineTypeValue_check = 0, this.engineTypeValue = '')
      this.dataTypeValue ? stationNumberValue_check = 1 : (stationNumberValue_check = 0, this.dataTypeValue = '')
      this.valueTypeValue ? valueType_check = 1 : (valueType_check = 0, this.valueTypeValue = '')
      var param = []
      param[0] = ['变量类型_ischeck', valueType_check]
      param[1] = ['变量类型', this.valueTypeValue]
      param[2] = ['工位号_ischeck', stationNumberValue_check]
      param[3] = ['工位号', this.dataTypeValue]
      param[4] = ['PageCurrent', this.pageCurrent]
      param[5] = ['PageSize', this.pageSize]
      param[6] = ['PageCount', '1111', 'int', '1']
      param[7] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', 'MES_基本变量_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}
</script>

<style scoped>
  .topDiv{
    margin-bottom: 10px;
  }
</style>
