<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产线" prop="productLineCode">
        <el-select v-model="queryParams.productLineCode" placeholder="请选择产线">
          <el-option
            v-for="item in productLineList"
            :key="item.productLineCode"
            :label="item.productLineName"
            :value="item.productLineCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="枪编号" prop="gunCode">
        <el-input
          v-model="queryParams.gunCode"
          placeholder="请输入枪编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="系统状态：0-关；1-开" prop="systemStatus">-->
      <!--        <el-select v-model="queryParams.systemStatus" placeholder="请选择系统状态：0-关；1-开" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.sys_normal_disable"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="起止时间">
        <el-date-picker
          v-model="daterangeBeginTime"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['report:lastShotRecord:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="lastShotRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="objId" v-if="columns[0].visible"/>
      <el-table-column label="产线编号" align="center" prop="productLineCode" v-if="columns[3].visible"/>
      <el-table-column label="产线名称" align="center" prop="productLineName" v-if="columns[29].visible"/>
      <el-table-column label="工位编号" align="center" prop="stationNumber" v-if="columns[4].visible"/>
      <el-table-column label="工位名称" align="center" prop="stationName" v-if="columns[30].visible"/>
      <el-table-column label="所属系统" align="center" prop="system" v-if="columns[1].visible"/>
      <el-table-column label="枪编号" align="center" prop="gunCode" v-if="columns[2].visible"/>
      <el-table-column label="枪注料工位号" align="center" prop="pourNu" v-if="columns[13].visible"/>
      <el-table-column label="枪总产量" align="center" prop="totalYield" v-if="columns[25].visible"/>

      <el-table-column label="枪设定注料重量" align="center" prop="setWeight" v-if="columns[15].visible"/>
      <el-table-column label="枪实际注料重量" align="center" prop="pourWeight" v-if="columns[17].visible"/>

      <el-table-column label="枪POL注料温度" align="center" prop="polTemp" v-if="columns[5].visible"/>
      <el-table-column label="枪POL注料压力" align="center" prop="polHp" v-if="columns[6].visible"/>
      <el-table-column label="枪POL注料流量" align="center" prop="polVol" v-if="columns[7].visible"/>
      <el-table-column label="枪POL原料用量" align="center" prop="polUsage" v-if="columns[8].visible"/>
      <el-table-column label="枪ISO注料温度" align="center" prop="isoTemp" v-if="columns[9].visible"/>
      <el-table-column label="枪ISO注料压力" align="center" prop="isoHp" v-if="columns[10].visible"/>
      <el-table-column label="枪ISO注料流量" align="center" prop="isoVol" v-if="columns[11].visible"/>
      <el-table-column label="枪ISO原料用量" align="center" prop="isoUsage" v-if="columns[12].visible"/>

      <el-table-column label="枪设定注料时间" align="center" prop="setTime" v-if="columns[14].visible"/>
      <el-table-column label="枪中压循环时间" align="center" prop="mpTime" v-if="columns[19].visible"/>
      <el-table-column label="枪高压循环时间" align="center" prop="hpTime" v-if="columns[20].visible"/>
      <el-table-column label="枪设定注料比例" align="center" prop="setRatio" v-if="columns[16].visible"/>
      <el-table-column label="枪实际注料比例" align="center" prop="pourRatio" v-if="columns[18].visible"/>
      <el-table-column label="枪液压压力" align="center" prop="hydrPress" v-if="columns[21].visible"/>
      <el-table-column label="枪液压温度" align="center" prop="hydrTemp" v-if="columns[22].visible"/>
      <el-table-column label="枪开枪时间" align="center" prop="mixpistOn" v-if="columns[23].visible"/>
      <el-table-column label="枪关枪时间" align="center" prop="mixpistOff" v-if="columns[24].visible"/>

      <el-table-column label="枪注料结束信号" align="center" prop="pourEnd" v-if="columns[26].visible"/>
      <el-table-column label="记录时间" align="center" prop="createTime" width="180" v-if="columns[27].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="系统状态" align="center" prop="systemStatus" v-if="columns[28].visible">
        <!--        <template slot-scope="scope">-->
        <!--          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.systemStatus"/>-->
        <!--        </template>-->
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {
  listLastShotRecord,
  getLastShotRecord,
  delLastShotRecord,
  addLastShotRecord,
  updateLastShotRecord
} from '@/api/report/lastShotRecord'
import { findProductLineList } from '@//api/base/productLine'
import { parseTime } from '@//utils/ruoyi'

export default {
  name: 'LastShotRecord',
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 箱体发泡注料记录报表表格数据
      lastShotRecordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 类型 1-箱体 2-门体
      type: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        system: null,
        gunCode: null,
        productLineCode: 'CX_02',
        stationNumber: null,
        polTemp: null,
        polHp: null,
        polVol: null,
        polUsage: null,
        isoTemp: null,
        isoHp: null,
        isoVol: null,
        isoUsage: null,
        pourNu: null,
        setTime: null,
        setWeight: null,
        setRatio: null,
        pourWeight: null,
        pourRatio: null,
        mpTime: null,
        hpTime: null,
        hydrPress: null,
        hydrTemp: null,
        mixpistOn: null,
        mixpistOff: null,
        totalYield: null,
        pourEnd: null,
        systemStatus: null
      },
      // 表单参数
      form: {},
      // 更新时间时间范围
      daterangeBeginTime: [],
      // 表单校验
      rules: {},
      columns: [
        { key: 0, label: `主键`, visible: false },
        { key: 1, label: `所属系统`, visible: true },
        { key: 2, label: `枪编号`, visible: true },
        { key: 3, label: `产线编号`, visible: false },
        { key: 4, label: `工位编号`, visible: false },
        { key: 5, label: `枪POL注料温度`, visible: true },
        { key: 6, label: `枪POL注料压力`, visible: true },
        { key: 7, label: `枪POL注料流量`, visible: true },
        { key: 8, label: `枪POL原料用量`, visible: true },
        { key: 9, label: `枪ISO注料温度`, visible: true },
        { key: 10, label: `枪ISO注料压力`, visible: true },
        { key: 11, label: `枪ISO注料流量`, visible: true },
        { key: 12, label: `枪ISO原料用量`, visible: true },
        { key: 13, label: `枪注料工位号`, visible: true },
        { key: 14, label: `枪设定注料时间`, visible: true },
        { key: 15, label: `枪设定注料重量`, visible: true },
        { key: 16, label: `枪设定注料比例`, visible: true },
        { key: 17, label: `枪实际注料重量`, visible: true },
        { key: 18, label: `枪实际注料比例`, visible: true },
        { key: 19, label: `枪中压循环时间`, visible: true },
        { key: 20, label: `枪高压循环时间`, visible: true },
        { key: 21, label: `枪液压压力`, visible: true },
        { key: 22, label: `枪液压温度`, visible: true },
        { key: 23, label: `枪开枪时间`, visible: true },
        { key: 24, label: `枪关枪时间`, visible: true },
        { key: 25, label: `枪总产量`, visible: true },
        { key: 26, label: `枪注料结束信号`, visible: false },
        { key: 27, label: `创建时间`, visible: true },
        { key: 28, label: `系统状态`, visible: false },
        { key: 29, label: `产线名称`, visible: true },
        { key: 30, label: `工位名称`, visible: true }
      ],
      // 产线选项
      productLineList: []
    }
  },
  created() {
    findProductLineList({ productLineType: 1 }).then(response => {
      this.productLineList = response.data
    })

    this.type = this.$route.query.type;

    const nowDate = parseTime(new Date(), '{y}-{m}-{d}')
    this.daterangeBeginTime[0] = nowDate + ' 00:00:00'
    this.daterangeBeginTime[1] = nowDate + ' 23:59:59'
    this.getList()
  },
  methods: {
    /** 查询门体、箱体发泡注料记录报表列表 */
    getList() {
      if (null != this.daterangeBeginTime && '' != this.daterangeBeginTime) {
        this.queryParams.beginBeginTime = this.daterangeBeginTime[0]
        this.queryParams.endBeginTime = this.daterangeBeginTime[1]
      } else {
        this.queryParams.beginBeginTime = null
        this.queryParams.endBeginTime = null
      }
      //查询门体 2
      if (this.type === '2'){
        this.queryParams.stationNumber = '1020'
      }
      //查询箱体 1
      if (this.type === '1' && this.queryParams.productLineCode === 'CX_02'){
        this.queryParams.stationNumber = '1005'
      }
      //查询箱体 1
      if (this.type === '1' && this.queryParams.productLineCode === 'CX_01'){
        this.queryParams.stationNumber = '1105'
      }

      this.loading = true
      listLastShotRecord(this.queryParams).then(response => {
        this.lastShotRecordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.daterangeBeginTime = []
      this.form = {
        objId: null,
        system: null,
        gunCode: null,
        productLineCode: null,
        stationNumber: null,
        polTemp: null,
        polHp: null,
        polVol: null,
        polUsage: null,
        isoTemp: null,
        isoHp: null,
        isoVol: null,
        isoUsage: null,
        pourNu: null,
        setTime: null,
        setWeight: null,
        setRatio: null,
        pourWeight: null,
        pourRatio: null,
        mpTime: null,
        hpTime: null,
        hydrPress: null,
        hydrTemp: null,
        mixpistOn: null,
        mixpistOff: null,
        totalYield: null,
        pourEnd: null,
        createTime: null,
        systemStatus: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.objId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加箱体发泡注料记录报表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const objId = row.objId || this.ids
      getLastShotRecord(objId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改箱体发泡注料记录报表'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.objId != null) {
            updateLastShotRecord(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addLastShotRecord(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const objIds = row.objId || this.ids
      this.$modal.confirm('是否确认删除箱体发泡注料记录报表编号为"' + objIds + '"的数据项？').then(function() {
        return delLastShotRecord(objIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('report/lastShotRecord/export', {
        ...this.queryParams
      }, `lastShotRecord_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
