<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="serialNo">
        <el-input
          v-model="queryParams.serialNo"
          placeholder="请输入称重编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="plateNo">
        <el-input
          v-model="queryParams.plateNo"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运输单位" prop="transportUnit">
        <el-input
          v-model="queryParams.transportUnit"
          placeholder="请输入运输单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货单位" prop="forwardingUnit">
        <el-input
          v-model="queryParams.forwardingUnit"
          placeholder="请输入发货单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货单位" prop="consigneeUnit">
        <el-input
          v-model="queryParams.consigneeUnit"
          placeholder="请输入收货单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货物名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入货物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货物规格" prop="goodsSpec">
        <el-input
          v-model="queryParams.goodsSpec"
          placeholder="请输入货物规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛重" prop="grossWeight">
        <el-input
          v-model="queryParams.grossWeight"
          placeholder="请输入毛重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="皮重" prop="tareWeight">
        <el-input
          v-model="queryParams.tareWeight"
          placeholder="请输入皮重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="净重" prop="netWeight">
        <el-input
          v-model="queryParams.netWeight"
          placeholder="请输入净重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扣重" prop="buckleWeight">
        <el-input
          v-model="queryParams.buckleWeight"
          placeholder="请输入扣重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实重" prop="actualWeight">
        <el-input
          v-model="queryParams.actualWeight"
          placeholder="请输入实重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <!-- <el-form-item label="毛重时间" prop="grossTime">
        <el-date-picker clearable
          v-model="queryParams.grossTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择毛重时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="皮重时间" prop="tareTime">
        <el-date-picker clearable
          v-model="queryParams.tareTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择皮重时间">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="毛重时间">
            <el-date-picker clearable
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
           <el-form-item label="皮重时间">
            <el-date-picker clearable
              v-model="dateRange2"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
      <!-- <el-form-item label="重量单位" prop="weightUnit">
        <el-input
          v-model="queryParams.weightUnit"
          placeholder="请输入重量单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="unitPrice">
        <el-input
          v-model="queryParams.unitPrice"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额" prop="sumAmt">
        <el-input
          v-model="queryParams.sumAmt"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="过磅类型" prop="weightType">
        <el-input
          v-model="queryParams.weightType"
          placeholder="请输入过磅类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卡号" prop="cardno">
        <el-input
          v-model="queryParams.cardno"
          placeholder="请输入卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛重磅号" prop="grossStation">
        <el-input
          v-model="queryParams.grossStation"
          placeholder="请输入毛重磅号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="皮重磅号" prop="tareStation">
        <el-input
          v-model="queryParams.tareStation"
          placeholder="请输入皮重磅号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毛重人员" prop="grossMan">
        <el-input
          v-model="queryParams.grossMan"
          placeholder="请输入毛重人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="皮重人员" prop="tareMan">
        <el-input
          v-model="queryParams.tareMan"
          placeholder="请输入皮重人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="一次时间" prop="firstTime">
        <el-date-picker clearable
          v-model="queryParams.firstTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择一次时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="二次时间" prop="secondTime">
        <el-date-picker clearable
          v-model="queryParams.secondTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择二次时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="打印次数" prop="printNum">
        <el-input
          v-model="queryParams.printNum"
          placeholder="请输入打印次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['weighbridge:weightInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['weighbridge:weightInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['weighbridge:weightInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['weighbridge:weightInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="weightInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="称重编号" align="center" prop="serialNo" />
      <el-table-column label="车牌号" align="center" prop="plateNo" />
      <el-table-column label="运输单位" align="center" prop="transportUnit" />
      <el-table-column label="发货单位" align="center" prop="forwardingUnit" />
      <el-table-column label="收货单位" align="center" prop="consigneeUnit" />
      <el-table-column label="货物名称" align="center" prop="goodsName" />
      <el-table-column label="货物规格" align="center" prop="goodsSpec" />
      <el-table-column label="毛重" align="center" prop="grossWeight" />
      <el-table-column label="皮重" align="center" prop="tareWeight" />
      <el-table-column label="净重" align="center" prop="netWeight" />
      <el-table-column label="扣重" align="center" prop="buckleWeight" />
      <el-table-column label="实重" align="center" prop="actualWeight" />
      <el-table-column label="重量单位" align="center" prop="weightUnit" />
      <el-table-column label="单价" align="center" prop="unitPrice" />
      <el-table-column label="金额" align="center" prop="sumAmt" />
      <el-table-column label="过磅类型" align="center" prop="weightType" />
      <el-table-column label="卡号" align="center" prop="cardno" />
      <el-table-column label="毛重磅号" align="center" prop="grossStation" />
      <el-table-column label="皮重磅号" align="center" prop="tareStation" />
      <el-table-column label="毛重人员" align="center" prop="grossMan" />
      <el-table-column label="皮重人员" align="center" prop="tareMan" />
      <el-table-column label="毛重时间" align="center" prop="grossTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.grossTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="皮重时间" align="center" prop="tareTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tareTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="一次时间" align="center" prop="firstTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="二次时间" align="center" prop="secondTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.secondTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打印次数" align="center" prop="printNum" />
      <el-table-column label="云端上传" align="center" prop="isUploadCloud" />
      <el-table-column label="数据日志" align="center" prop="dataLog" />
      <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="['weighbridge:weightInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['weighbridge:weightInfo: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="称重编号" prop="serialNo">
          <el-input v-model="form.serialNo" placeholder="请输入称重编号" />
        </el-form-item>
        <el-form-item label="车牌号" prop="plateNo">
          <el-input v-model="form.plateNo" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="运输单位" prop="transportUnit">
          <el-input v-model="form.transportUnit" placeholder="请输入运输单位" />
        </el-form-item>
        <el-form-item label="发货单位" prop="forwardingUnit">
          <el-input v-model="form.forwardingUnit" placeholder="请输入发货单位" />
        </el-form-item>
        <el-form-item label="收货单位" prop="consigneeUnit">
          <el-input v-model="form.consigneeUnit" placeholder="请输入收货单位" />
        </el-form-item>
        <el-form-item label="货物名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="请输入货物名称" />
        </el-form-item>
        <el-form-item label="货物规格" prop="goodsSpec">
          <el-input v-model="form.goodsSpec" placeholder="请输入货物规格" />
        </el-form-item>
        <el-form-item label="毛重" prop="grossWeight">
          <el-input v-model="form.grossWeight" placeholder="请输入毛重" />
        </el-form-item>
        <el-form-item label="皮重" prop="tareWeight">
          <el-input v-model="form.tareWeight" placeholder="请输入皮重" />
        </el-form-item>
        <el-form-item label="净重" prop="netWeight">
          <el-input v-model="form.netWeight" placeholder="请输入净重" />
        </el-form-item>
        <el-form-item label="扣重" prop="buckleWeight">
          <el-input v-model="form.buckleWeight" placeholder="请输入扣重" />
        </el-form-item>
        <el-form-item label="实重" prop="actualWeight">
          <el-input v-model="form.actualWeight" placeholder="请输入实重" />
        </el-form-item>
        <el-form-item label="重量单位" prop="weightUnit">
          <el-input v-model="form.weightUnit" placeholder="请输入重量单位" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="金额" prop="sumAmt">
          <el-input v-model="form.sumAmt" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="过磅类型" prop="weightType">
          <el-input v-model="form.weightType" placeholder="请输入过磅类型" />
        </el-form-item>
        <el-form-item label="卡号" prop="cardno">
          <el-input v-model="form.cardno" placeholder="请输入卡号" />
        </el-form-item>
        <el-form-item label="毛重磅号" prop="grossStation">
          <el-input v-model="form.grossStation" placeholder="请输入毛重磅号" />
        </el-form-item>
        <el-form-item label="皮重磅号" prop="tareStation">
          <el-input v-model="form.tareStation" placeholder="请输入皮重磅号" />
        </el-form-item>
        <el-form-item label="毛重人员" prop="grossMan">
          <el-input v-model="form.grossMan" placeholder="请输入毛重人员" />
        </el-form-item>
        <el-form-item label="皮重人员" prop="tareMan">
          <el-input v-model="form.tareMan" placeholder="请输入皮重人员" />
        </el-form-item>
        <el-form-item label="毛重时间" prop="grossTime">
          <el-date-picker clearable
            v-model="form.grossTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择毛重时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="皮重时间" prop="tareTime">
          <el-date-picker clearable
            v-model="form.tareTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择皮重时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="一次时间" prop="firstTime">
          <el-date-picker clearable
            v-model="form.firstTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择一次时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="二次时间" prop="secondTime">
          <el-date-picker clearable
            v-model="form.secondTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择二次时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="打印次数" prop="printNum">
          <el-input v-model="form.printNum" placeholder="请输入打印次数" />
        </el-form-item>
        <el-form-item label="云端上传" prop="isUploadCloud">
          <el-input v-model="form.isUploadCloud" placeholder="请输入云端上传" />
        </el-form-item>
        <el-form-item label="数据日志" prop="dataLog">
          <el-input v-model="form.dataLog" 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 { listWeightInfo, getWeightInfo, delWeightInfo, addWeightInfo, updateWeightInfo } from "@/api/weighbridge/weightInfo";

export default {
  name: "WeightInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 称重单表格数据
      weightInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNo: null,
        plateNo: null,
        transportUnit: null,
        forwardingUnit: null,
        consigneeUnit: null,
        goodsName: null,
        goodsSpec: null,
        grossWeight: null,
        tareWeight: null,
        netWeight: null,
        buckleWeight: null,
        actualWeight: null,
        weightUnit: null,
        unitPrice: null,
        sumAmt: null,
        weightType: null,
        cardno: null,
        grossStation: null,
        tareStation: null,
        grossMan: null,
        tareMan: null,
        grossTime: null,
        tareTime: null,
        firstTime: null,
        secondTime: null,
        updateTime: null,
        printNum: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 日期范围
      dateRange: [],
      // 日期范围
      dateRange2: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询称重单列表 */
    getList() {
      this.loading = true;
      listWeightInfo(this.addDateRange(this.queryParams, this.dateRange, this.dateRange2)).then(response => {
        this.weightInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        serialNo: null,
        plateNo: null,
        transportUnit: null,
        forwardingUnit: null,
        consigneeUnit: null,
        goodsName: null,
        goodsSpec: null,
        grossWeight: null,
        tareWeight: null,
        netWeight: null,
        buckleWeight: null,
        actualWeight: null,
        weightUnit: null,
        unitPrice: null,
        sumAmt: null,
        weightType: null,
        cardno: null,
        grossStation: null,
        tareStation: null,
        grossMan: null,
        tareMan: null,
        grossTime: null,
        tareTime: null,
        firstTime: null,
        secondTime: null,
        updateTime: null,
        printNum: null,
        isUploadCloud: null,
        dataLog: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
       this.dateRange = [];
       this.dateRange2 = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.serialNo)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加称重单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const serialNo = row.serialNo || this.ids
      getWeightInfo(serialNo).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改称重单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.serialNo != null) {
            updateWeightInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWeightInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const serialNos = row.serialNo || this.ids;
      this.$modal.confirm('是否确认删除称重单编号为"' + serialNos + '"的数据项？').then(function() {
        return delWeightInfo(serialNos);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('weighbridge/weightInfo/export', {
        ...this.queryParams
      }, `weightInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
