<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="PID,对应主表id" prop="fPid">
        <el-input
          v-model="queryParams.fPid"
          placeholder="请输入PID,对应主表id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行号，针对pid顺序排列，1，2，3，4，" prop="fLineno">
        <el-input
          v-model="queryParams.fLineno"
          placeholder="请输入行号，针对pid顺序排列，1，2，3，4，"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货物品名，存储id 显示名称	t_goods 中的no或 name，模糊查找选择后，存储f_id，显示name" prop="fGoodsid">
        <el-select v-model="queryParams.fGoodsid" placeholder="请选择货物品名，存储id 显示名称	t_goods 中的no或 name，模糊查找选择后，存储f_id，显示name" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="入库库区，存储库区ID,显示仓库 库位 库区，t_warehouse_area中的f_id" prop="fWarehouselocid">
        <el-select v-model="queryParams.fWarehouselocid" placeholder="请选择入库库区，存储库区ID,显示仓库 库位 库区，t_warehouse_area中的f_id" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="入" prop="fBsdate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.fBsdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择入">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="箱量" prop="fCntqty">
        <el-input
          v-model="queryParams.fCntqty"
          placeholder="请输入箱量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="箱型,20GP 4OGP" prop="fCntrtype">
        <el-select v-model="queryParams.fCntrtype" placeholder="请选择箱型,20GP 4OGP" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划件数" prop="fPlanqty">
        <el-input
          v-model="queryParams.fPlanqty"
          placeholder="请输入计划件数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划尺码" prop="fPlanvolumn">
        <el-input
          v-model="queryParams.fPlanvolumn"
          placeholder="请输入计划尺码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划毛重" prop="fPlangrossweight">
        <el-input
          v-model="queryParams.fPlangrossweight"
          placeholder="请输入计划毛重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划净重" prop="fPlannetweight">
        <el-input
          v-model="queryParams.fPlannetweight"
          placeholder="请输入计划净重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="件数" prop="fQty">
        <el-input
          v-model="queryParams.fQty"
          placeholder="请输入件数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="尺码" prop="fVolumn">
        <el-input
          v-model="queryParams.fVolumn"
          placeholder="请输入尺码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛重" prop="fGrossweight">
        <el-input
          v-model="queryParams.fGrossweight"
          placeholder="请输入毛重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净重" prop="fNetweight">
        <el-input
          v-model="queryParams.fNetweight"
          placeholder="请输入净重"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="箱号" prop="fCntrno">
        <el-input
          v-model="queryParams.fCntrno"
          placeholder="请输入箱号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车号" prop="fTruckno">
        <el-input
          v-model="queryParams.fTruckno"
          placeholder="请输入车号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态,N 入" prop="fBillstatus">
        <el-select v-model="queryParams.fBillstatus" placeholder="请选择状态,N 入" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" 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="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['warehouseBusiness:warehousebillsitems:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['warehouseBusiness:warehousebillsitems:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['warehouseBusiness:warehousebillsitems:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['warehouseBusiness:warehousebillsitems:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warehousebillsitemsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="状态,N 入" align="center" prop="fId" />
      <el-table-column label="PID,对应主表id" align="center" prop="fPid" />
      <el-table-column label="行号，针对pid顺序排列，1，2，3，4，" align="center" prop="fLineno" />
      <el-table-column label="货物品名，存储id 显示名称	t_goods 中的no或 name，模糊查找选择后，存储f_id，显示name" align="center" prop="fGoodsid" />
      <el-table-column label="入库库区，存储库区ID,显示仓库 库位 库区，t_warehouse_area中的f_id" align="center" prop="fWarehouselocid" />
      <el-table-column label="入" align="center" prop="fBsdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fBsdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="箱量" align="center" prop="fCntqty" />
      <el-table-column label="箱型,20GP 4OGP" align="center" prop="fCntrtype" />
      <el-table-column label="计划件数" align="center" prop="fPlanqty" />
      <el-table-column label="计划尺码" align="center" prop="fPlanvolumn" />
      <el-table-column label="计划毛重" align="center" prop="fPlangrossweight" />
      <el-table-column label="计划净重" align="center" prop="fPlannetweight" />
      <el-table-column label="件数" align="center" prop="fQty" />
      <el-table-column label="尺码" align="center" prop="fVolumn" />
      <el-table-column label="毛重" align="center" prop="fGrossweight" />
      <el-table-column label="净重" align="center" prop="fNetweight" />
      <el-table-column label="箱号" align="center" prop="fCntrno" />
      <el-table-column label="车号" align="center" prop="fTruckno" />
      <el-table-column label="状态,N 入" align="center" prop="fBillstatus" />
      <el-table-column label="备注" align="center" prop="remark" />
      <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="['warehouseBusiness:warehousebillsitems:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['warehouseBusiness:warehousebillsitems:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :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="PID,对应主表id" prop="fPid">
          <el-input v-model="form.fPid" placeholder="请输入PID,对应主表id" />
        </el-form-item>
        <el-form-item label="行号，针对pid顺序排列，1，2，3，4，" prop="fLineno">
          <el-input v-model="form.fLineno" placeholder="请输入行号，针对pid顺序排列，1，2，3，4，" />
        </el-form-item>
        <el-form-item label="货物品名，存储id 显示名称	t_goods 中的no或 name，模糊查找选择后，存储f_id，显示name" prop="fGoodsid">
          <el-select v-model="form.fGoodsid" placeholder="请选择货物品名，存储id 显示名称	t_goods 中的no或 name，模糊查找选择后，存储f_id，显示name">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="入库库区，存储库区ID,显示仓库 库位 库区，t_warehouse_area中的f_id" prop="fWarehouselocid">
          <el-select v-model="form.fWarehouselocid" placeholder="请选择入库库区，存储库区ID,显示仓库 库位 库区，t_warehouse_area中的f_id">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="入" prop="fBsdate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.fBsdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择入">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="箱量" prop="fCntqty">
          <el-input v-model="form.fCntqty" placeholder="请输入箱量" />
        </el-form-item>
        <el-form-item label="箱型,20GP 4OGP" prop="fCntrtype">
          <el-select v-model="form.fCntrtype" placeholder="请选择箱型,20GP 4OGP">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="计划件数" prop="fPlanqty">
          <el-input v-model="form.fPlanqty" placeholder="请输入计划件数" />
        </el-form-item>
        <el-form-item label="计划尺码" prop="fPlanvolumn">
          <el-input v-model="form.fPlanvolumn" placeholder="请输入计划尺码" />
        </el-form-item>
        <el-form-item label="计划毛重" prop="fPlangrossweight">
          <el-input v-model="form.fPlangrossweight" placeholder="请输入计划毛重" />
        </el-form-item>
        <el-form-item label="计划净重" prop="fPlannetweight">
          <el-input v-model="form.fPlannetweight" placeholder="请输入计划净重" />
        </el-form-item>
        <el-form-item label="件数" prop="fQty">
          <el-input v-model="form.fQty" placeholder="请输入件数" />
        </el-form-item>
        <el-form-item label="尺码" prop="fVolumn">
          <el-input v-model="form.fVolumn" placeholder="请输入尺码" />
        </el-form-item>
        <el-form-item label="毛重" prop="fGrossweight">
          <el-input v-model="form.fGrossweight" placeholder="请输入毛重" />
        </el-form-item>
        <el-form-item label="净重" prop="fNetweight">
          <el-input v-model="form.fNetweight" placeholder="请输入净重" />
        </el-form-item>
        <el-form-item label="箱号" prop="fCntrno">
          <el-input v-model="form.fCntrno" placeholder="请输入箱号" />
        </el-form-item>
        <el-form-item label="车号" prop="fTruckno">
          <el-input v-model="form.fTruckno" placeholder="请输入车号" />
        </el-form-item>
        <el-form-item label="状态,N 入">
          <el-radio-group v-model="form.fBillstatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除状态" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </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 { listWarehousebillsitems, getWarehousebillsitems, delWarehousebillsitems, addWarehousebillsitems, updateWarehousebillsitems, exportWarehousebillsitems } from "@/api/warehouseBusiness/warehousebillsitems";

export default {
  name: "Warehousebillsitems",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓库明细从表表格数据
      warehousebillsitemsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fPid: null,
        fLineno: null,
        fGoodsid: null,
        fWarehouselocid: null,
        fBsdate: null,
        fCntqty: null,
        fCntrtype: null,
        fPlanqty: null,
        fPlanvolumn: null,
        fPlangrossweight: null,
        fPlannetweight: null,
        fQty: null,
        fVolumn: null,
        fGrossweight: null,
        fNetweight: null,
        fCntrno: null,
        fTruckno: null,
        fBillstatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fBillstatus: [
          { required: true, message: "状态,N 入不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询仓库明细从表列表 */
    getList() {
      this.loading = true;
      listWarehousebillsitems(this.queryParams).then(response => {
        this.warehousebillsitemsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fId: null,
        fPid: null,
        fLineno: null,
        fGoodsid: null,
        fWarehouselocid: null,
        fBsdate: null,
        fCntqty: null,
        fCntrtype: null,
        fPlanqty: null,
        fPlanvolumn: null,
        fPlangrossweight: null,
        fPlannetweight: null,
        fQty: null,
        fVolumn: null,
        fGrossweight: null,
        fNetweight: null,
        fCntrno: null,
        fTruckno: null,
        fBillstatus: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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.fId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加仓库明细从表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fId = row.fId || this.ids
      getWarehousebillsitems(fId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改仓库明细从表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fId != null) {
            updateWarehousebillsitems(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWarehousebillsitems(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fIds = row.fId || this.ids;
      this.$confirm('是否确认删除仓库明细从表编号为"' + fIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWarehousebillsitems(fIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有仓库明细从表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWarehousebillsitems(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
