<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>
      </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">
            {{ 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" 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.orderCode" clearable size="small" placeholder="订货号" style="width: 200px;"/>
        </el-form-item>
        <el-form-item label="位置名称" prop="位置名称" style="display: inline-block">
          <el-select v-model="form.positionCode" 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 v-model="form.miniPartType" clearable size="small" placeholder="小机型号" style="width: 200px;"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="系列" prop="系列" style="display: inline-block">-->
<!--          <el-input v-model="form.series" clearable size="small" placeholder="系列" style="width: 200px;"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="类别" prop="类别" style="display: inline-block">-->
<!--          <el-input v-model="form.category" clearable size="small" placeholder="类别" style="width: 200px;"/>-->
<!--        </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: [], // 日志类型数组
      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:'',
        orderCode:'',  // 订货号
        positionCode:'', // 打印位置
        miniPartType:'', // 小机型
        series:'',  // 系列
        category:''  // 类别
      },
      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.getDataType()
    this.searchTable()
  },
  methods: {
    // 初始化获取日志类型
    getDataType() {
      this.dataType = []
      var param = []
      var Data = this.CreateData('11', '潍柴_打印位置_基本表_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (const item of response.data) {
          this.dataType.push({
            label: item.打印位置,
            value: item.传递编号
          })
        }
      })
    },
    addData(){
      this.dialogFormVisible1 = true
      this.form.orderCode = ''
      this.form.positionCode = ''
      this.form.miniPartType = ''
      this.form.series = ''
      this.form.category = ''
      this.formTitle = '增加关联'
    },
    submitAdd1(){
      if(!this.form.orderCode){
        this.$message.error("请填写订货号后提交！")
        return
      }
      var param = []
      param[0] = ['订货号', this.form.orderCode]
      param[1] = ['传递编号', this.form.positionCode]
      param[2] = ['小机型号', this.form.miniPartType]
      param[3] = ['系列', this.form.series]
      param[4] = ['类别', this.form.category]
      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.orderCode ){
        this.$message.error("请填写订货号后提交！")
        return
      }
      var param = []
      param[0] = ['订货号', this.form.orderCode]
      param[1] = ['传递编号', this.form.positionCode]
      param[2] = ['小机型号', this.form.miniPartType]
      param[3] = ['系列', this.form.series]
      param[4] = ['类别', this.form.category]
      param[5] = ['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.orderCode = row.订货号
      this.form.positionCode = row.传递编号
      this.form.miniPartType = row.小机型
      this.form.series = row.系列
      this.form.category = 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 => {
        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
      })
    },
    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>
