<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
<!--        <span style="margin-left: 10px">订货号：</span>-->
<!--        <el-input v-model="orderCode" placeholder="订货号" clearable size="small" style="width: 250px; margin-left: 5px"/>-->
<!--        <span style="margin-left: 10px">时间：</span>-->
<!--        <el-date-picker-->
<!--          :clearable="false"‘、’】-->
<!--          v-model="dateTime"-->
<!--          size="small"-->
<!--          type="daterange"-->
<!--          align="center"-->
<!--          style="width: 240px;"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          format="yyyy-MM-dd"-->
<!--          range-separator="～"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"/>-->
        <el-button
          type="primary"
          plain
          size="small"
          icon="el-icon-search"
          style="margin-left: 5px"
          @click="pageSize=50;pageCurrent=1;searchTable()">查询
        </el-button>
      <el-button type="success" plain icon="el-icon-document-copy" size="small" @click="addData()">增加</el-button>
        <span style="color: red">当机型包含多种特征码时，则使用优先级最大的特征码机型</span>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        size="mini"
        height="740"
        center
        style="width: 80%">

        <el-table-column width="60" label="序号" type="index" align="center"/>
        <el-table-column label="特征码" width="200px" 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">
            <span v-if="scope.row.机型编号 == 1">12T</span>
            <span v-if="scope.row.机型编号 == 2">13L</span>
            <span v-if="scope.row.机型编号 == 3">H1</span>
            <span v-if="scope.row.机型编号 == 4">WP10</span>
          </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" width="170">
          <template slot-scope="scope">
            {{ scope.row.操作时间 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="170">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-delete" style="color: #ff9a02" @click="update(scope.row)">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" style="color: red" @click="deleteData(scope.row)">删除</el-button>
          </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>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible1" :title="formTitle" center style="min-height: 200px" width="400px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="110px">
        <el-form-item label="特征码" prop="特征码" style="display: inline-block">
          <el-input v-model="form.code" clearable size="small" placeholder="特征码" style="width: 200px;"/>
        </el-form-item>
        <el-form-item label="机型类型" prop="机型类型" style="display: inline-block">
          <el-select v-model="form.engineTypeCode" placeholder="机型类型" size="small" style="width: 200px">
            <el-option v-for="item in dataType" :label="item.label" :value="item.value" size="mini" />
          </el-select>
        </el-form-item>
        <el-form-item label="优先级" prop="优先级" style="display: inline-block">
          <el-input-number v-model="form.order" :min="1" :max="100" label="优先级" style="width: 200px"></el-input-number>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible1 = false">取消</el-button>
        <el-button v-if="formTitle == '增加机型'" type="primary" size="small" @click="submitAdd1('form')">确定</el-button>
        <el-button v-if="formTitle == '修改机型'" type="primary" size="small" @click="submitUpdate('form')">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      tableData: [],
      dataType: [
        {label:'12T',value:1},
        {label:'13L',value:2},
        {label:'H1',value:3},
        {label:'WP10',value:4},
      ], // 日志类型数组
      dataTypeValue: '', // 日志类型
      valueType: [],
      valueTypeValue: '',
      parentId: '',
      orderCode:'',
      parentList: [],
      alarmType: [],
      alarmTypeValue: '',
      dateTime: '', // 时间
      dialogFormVisible: false,
      dialogFormVisible4: false,
      form4: {
        engineTypeValue: ''
      },
      rules4: { // 订单下发验证
        engineTypeValue: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      title: '',
      form: {
        id:'',
        code:'',  // 特征码
        engineTypeCode:'', // 机型编号
        order:'', // 优先级
      },
      formTitle:'', // 修改框标题
      rules: { // 表单验证规则
      },
      total: 0, // 总条数
      pageList: 50, // 每页显示条数
      pageSize: 50, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      dialogFormVisible1:false,
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date() // 修改数据date
    year = new Date().getFullYear()
    month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
    day = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
    audiTime = year + '-' + month + '-' + day
    console.log(audiTime, 'audiTime')
    this.dateTime = [audiTime, audiTime]
    this.searchTable()
  },
  methods: {
    addData(){
      this.dialogFormVisible1 = true
      this.form.code = ''
      this.form.engineTypeCode = ''
      this.form.order = ''
      this.formTitle = '增加机型'
    },
    submitAdd1(){
      if(!this.form.code || !this.form.engineTypeCode || !this.form.order){
        this.$message.error("请填写完善信息后提交！")
        return
      }
      var param = []
      param[0] = ['特征码', this.form.code]
      param[1] = ['机型编号', this.form.engineTypeCode]
      param[2] = ['优先级', this.form.order]
      var Data = this.CreateData('11', '潍柴_缸体机型码_基本表_增加', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result == 1) {
          this.$message.success("添加成功！")
          this.dialogFormVisible1 = false
          this.searchTable()
        }
      })
    },
    submitUpdate(){
      if(!this.form.code || !this.form.engineTypeCode || !this.form.order){
        this.$message.error("请填写完善信息后提交！")
        return
      }
      var param = []
      param[0] = ['特征码', this.form.code]
      param[1] = ['机型编号', this.form.engineTypeCode]
      param[2] = ['优先级', this.form.order]
      param[3] = ['Id', this.form.id]
      var Data = this.CreateData('11', '潍柴_缸体机型码_基本表_修改', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result == 1) {
          this.$message.success("添加成功！")
          this.dialogFormVisible1 = false
          this.searchTable()
        }
      })
    },
    update(row){
      this.form.id = row.Id
      this.form.code = row.特征码
      this.form.engineTypeCode = row.机型编号
      this.form.order = row.优先级
      this.dialogFormVisible1 = true
      this.formTitle = '修改机型'
    },
    deleteData(row){
      this.$confirm('此操作将永久删除该机型特征，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['id', row.Id]
        var Data = this.CreateData('11', '潍柴_缸体机型码_基本表_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result == 1) {
            this.$message.success("删除成功！")
            this.searchTable()
          }
        })
      })
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      // param[0] = ['订货号', this.orderCode]
      // param[1] = ['PageCurrent', this.pageCurrent]
      // param[2] = ['PageSize', this.pageSize]
      // param[3] = ['PageCount', '1111', 'int', '1']
      // param[4] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', '潍柴_缸体机型码_基本表_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableData = response.data
        }
        // this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    callOff() {
      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>
