<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="周装箱" prop="containerNumber">
        <el-input
          v-model="queryParams.containerNumber"
          placeholder="请输入周装箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位编码" prop="storeCode">
        <el-input
          v-model="queryParams.storeCode"
          placeholder="请输入库位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产任务单" prop="productionTask">
        <el-input
          v-model="queryParams.productionTask"
          placeholder="请输入生产任务单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周转箱状态" prop="containerStatus">
        <el-select v-model="queryParams.containerStatus" placeholder="周转箱状态" clearable>
          <el-option
            v-for="dict in dict.type.container_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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="['system:info:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="id" align="center" prop="id"/>
      <el-table-column label="周装箱" align="center" prop="containerNumber"/>
      <el-table-column label="周装箱状态" align="center" prop="containerStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.container_status" :value="scope.row.containerStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="周装箱装表数量" align="center" prop="qty"/>
      <el-table-column label="库位编码" align="center" prop="storeCode"/>
      <el-table-column label="开始入库时间" align="center" prop="onInstoreTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.onInstoreTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库时间" align="center" prop="instoreTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.instoreTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开始出库时间" align="center" prop="onOutstoreTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.onOutstoreTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出库时间" align="center" prop="outstoreTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outstoreTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产任务单" align="center" prop="productionTask"/>
      <el-table-column label="创建人" align="center" prop="createdBy"/>
      <el-table-column label="创建时间" align="center" prop="createdDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDt) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy"/>
      <el-table-column label="更新时间" align="center" prop="updatedDt" width="180">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updatedDt) }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="周装箱号(入库时不存在，自动增加)" prop="containerNumber">
          <el-input v-model="form.containerNumber" placeholder="请输入周装箱号(入库时不存在，自动增加)"/>
        </el-form-item>
        <el-form-item label="周装箱装表数量" prop="qty">
          <el-input v-model="form.qty" placeholder="请输入周装箱装表数量"/>
        </el-form-item>
        <el-form-item label="库位编码(iCMX-A01-05-03)" prop="storeCode">
          <el-input v-model="form.storeCode" placeholder="请输入库位编码(iCMX-A01-05-03)"/>
        </el-form-item>
        <el-form-item label="开始入库时间(人工扫描或自动扫描时间)" prop="onInstoreTime">
          <el-date-picker clearable
                          v-model="form.onInstoreTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择开始入库时间(人工扫描或自动扫描时间)"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入库时间(机器人放到库位上时间)" prop="instoreTime">
          <el-date-picker clearable
                          v-model="form.instoreTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择入库时间(机器人放到库位上时间)"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开始出库时间(机器人开始出库作业时间)" prop="onOutstoreTime">
          <el-date-picker clearable
                          v-model="form.onOutstoreTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择开始出库时间(机器人开始出库作业时间)"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出库时间(机器人取货到出库工位完成时间)" prop="outstoreTime">
          <el-date-picker clearable
                          v-model="form.outstoreTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择出库时间(机器人取货到出库工位完成时间)"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产任务单" prop="productionTask">
          <el-input v-model="form.productionTask" placeholder="请输入生产任务单"/>
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="createdDt">
          <el-date-picker clearable
                          v-model="form.createdDt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择创建时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人"/>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedDt">
          <el-date-picker clearable
                          v-model="form.updatedDt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择更新时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo,listRecordInfo, addInfo, updateInfo } from '@/api/wms/containerInfo'

export default {
  dicts: ['container_status'],
  name: 'Info',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      infoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        containerNumber: null,
        containerStatus: null,
        qty: null,
        storeCode: null,
        onInstoreTime: null,
        instoreTime: null,
        onOutstoreTime: null,
        outstoreTime: null,
        productionTask: null,
        createdBy: null,
        createdDt: null,
        updatedBy: null,
        updatedDt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      listRecordInfo(this.queryParams).then(response => {
        this.infoList = response.data.data
        this.total = response.data.recordsTotal
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        containerNumber: null,
        containerStatus: null,
        qty: null,
        storeCode: null,
        onInstoreTime: null,
        instoreTime: null,
        onOutstoreTime: null,
        outstoreTime: null,
        productionTask: null,
        createdBy: null,
        createdDt: null,
        updatedBy: null,
        updatedDt: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加【请填写功能名称】'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改【请填写功能名称】'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('container/exportExcel', {
        ...this.queryParams
      }, `周转箱列表_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
