<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">标准JPH:</span>
        <el-input-number v-model="标准JPH" label="标准JPH"></el-input-number>
        <span style="margin-left: 10px">滚动文本:</span>
        <el-input v-model="滚动文本" placeholder="请输入滚动文本" style="width: 600px;"></el-input>
        <el-button type="primary" plain size="small" icon="el-icon-s-tools" style="margin-left: 5px"
          @click="saveData();">保存配置</el-button>
        <!--        <el-button type="success" plain icon="el-icon-document-copy" size="small" @click="copyData('form4')">复制</el-button>-->
      </div>
    </el-card>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      dataType: [], // 工位数组
      dataTypeValue: '', // 工位信息
      标准JPH: 0,
      滚动文本: '',
      valueType: [
        {
          label: '基本变量',
          value: 8
        }, {
          label: '报警变量',
          value: 9
        }, {
          label: '质量变量',
          value: 7
        }
      ],
      valueTypeValue: '9',
      alarmType: [],
      alarmTypeValue: '',
      dialogFormVisible: false,
      dialogFormVisible4: false,
      form4: {
        engineTypeValue: ''
      },
      rules4: { // 订单下发验证
        engineTypeValue: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      title: '',
      form: {
        tagID: '',
        stationNo: '',
        measurementItems: '',
        valueName: ''
      },
      rules: { // 表单验证规则
      },
      total: 0, // 总条数
      pageList: 50, // 每页显示条数
      pageSize: 50, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    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) {
          this.dataTypeValue = response.data[0].工位号
          for (let i = 0; i < response.data.length; i++) {
            this.dataType.push({
              label: response.data[i].工位号,
              value: response.data[i].工位号
            })
          }
        }
      }).then(() => {
        this.searchTable()
      })
    }, // 初始化获取报警类型
    getAlarmType() {
      this.alarmType = []
      request({
        url: '',
        method: 'post',
        data: {
          type: '3',
          name: `SELECT [ID], [报警类型] FROM [dbo].[MES_基本变量_报警类型]`
        }
      }).then(response => {
        if (response.data.length) {
          // console.log(response.data, 'response.data')
          for (let i = 0; i < response.data.length; i++) {
            this.alarmType.push({
              label: response.data[i].报警类型,
              value: response.data[i].报警类型
            })
          }
        }
      })
    },
    searchTable() {
      var param = []
      var Data = this.CreateData('11', 'TV_新看板关键数据_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
          this.标准JPH = response.data[0].标准JPH
          this.滚动文本 = response.data[0].滚动消息
        }
      })
    },
    saveData() {
      var param = []
      param[0] = ['标准JPH', this.标准JPH]
      param[1] = ['滚动文本', this.滚动文本]
      var Data = this.CreateData('12', 'TV_新看板关键数据_写入', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.searchTable()
        } else {
          this.$message.error('修改失败！')
        }
      })
    },
    editShiftTable(row) {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.form.tagID = row.TagID
      this.form.measurementItems = row.测量位置
      this.form.stationNo = row.工位号
      this.form.valueName = row.测量项目
      this.title = '编辑'
      this.dialogFormVisible = true
    },
    submitAdd1() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          var param = []
          param[0] = ['工位号', this.form.stationNo]
          param[1] = ['TagID', this.form.tagID]
          param[2] = ['测量项目', this.form.measurementItems]
          param[3] = ['变量类型名称', this.form.valueName]
          var Data = this.CreateData('12', '基础数据_报警变量维护_编辑', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.searchTable()
            } else {
              this.$message.error('修改失败！')
            }
          })
          this.dialogFormVisible = false
        } else {
          return false
        }
      })
    },
    callOff() {
      this.dialogFormVisible = false
    },
    copyData(formName) {
      if (this.tableData.length) {
        if (this.$refs[formName] !== undefined) {
          this.$refs[formName].resetFields()
        }
        this.dialogFormVisible4 = true
      } else {
        this.$message({
          message: '暂无可复制的数据！',
          type: 'error'
        })
      }
    },
    callOff4() {
      this.dialogFormVisible4 = false
    },
    submitAdd4() {
      var param = []
      param[0] = ['原始工位号', this.dataTypeValue]
      param[1] = ['复制工位号', this.form4.engineTypeValue]
      var Data = this.CreateData('12', '基础数据_报警变量维护_复制', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.dataTypeValue = this.form4.engineTypeValue
          this.searchTable()
          this.dialogFormVisible4 = false
        } else {
          this.$message.error('修改失败！')
        }
      })
      this.dialogFormVisible = 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>
