<template>
  <div class="app-container preinstall">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="入仓时间" prop="warehousingTime">
        <el-date-picker v-model="queryParams.warehousingTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item label="始发地" prop="startWarehouseId">
        <el-select v-model="queryParams.startWarehouseId" placeholder="请选择始发地" clearable size="small">
          <el-option v-for="item in exportWarehouseList" :label="item.titleZh" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目的地" prop="destWarehouseId">
        <el-select v-model="queryParams.destWarehouseId" placeholder="请选择目的地">
          <el-option v-for="item in importWarehouseList" :label="item.titleZh" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择状态" clearable size="small">
          <el-option v-for="item in stateOps" :label="item.label" :value="item.value" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="备案" prop="filing">
        <el-select v-model="queryParams.filing" placeholder="请选择备案" clearable size="small">
          <el-option v-for="item in filingOps" :label="item.label" :value="item.value" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报关方式" prop="declarationMethod">
        <el-select v-model="queryParams.declarationMethod" placeholder="请选择报关方式" clearable size="small">
          <el-option v-for="item in declarationMethodOps" :label="item.label" :value="item.value" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单号码" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单号码" clearable />
      </el-form-item>
      <el-form-item label="已预装单号" prop="preinstalledNo">
        <el-input v-model="queryParams.preinstalledNo" placeholder="请输入已预装单号" clearable />
      </el-form-item>
      <el-form-item label="品名" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入品名" clearable />
      </el-form-item>
      <el-form-item label="重货比" prop="ratioMin">
        <el-input v-model="queryParams.ratioMin" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label="" prop="ratioMax">
        <el-input v-model="queryParams.ratioMax" placeholder="请输入" clearable />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索已预装订单</el-button>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索待预装订单</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 表格 -->
    <el-card style="margin-top: 15px">
      <el-row class="preinstall-title">
        <div>
          <p>自编号：</p>
          <p>111</p>
        </div>
        <div>
          <p>柜号：</p>
          <p>111</p>
        </div>
        <div>
          <p>容量：</p>
          <p>111</p>
        </div>
        <div>
          <p>始发地：</p>
          <p>111</p>
        </div>
        <div>
          <p>目的地：</p>
          <p>111</p>
        </div>
      </el-row>
      <el-row class="preinstall-table">
        <!-- 已预装订单 -->
        <el-col :span="12">
          <el-row class="preinstall-title">
            <div class="table-label">已预装订单</div>
            <div>
              <p>总计：</p>
              <p>111</p>
            </div>
            <div class="red-label">
              <p>可预装方数：</p>
              <p>111</p>
            </div>
            <div class="red-label">
              <p>重量：</p>
              <p>111</p>
            </div>
            <div class="table-button">
              <el-button type="success" size="small">增加</el-button>
            </div>
          </el-row>
          <el-row class="preinstall-title">
            <div>
              <p>第一部分</p>
              <p>111</p>
            </div>
            <div class="table-button">
              <el-button type="danger" size="small">删除部分</el-button>
              <el-button type="danger" size="small">删除订单</el-button>
              <el-button type="primary" size="small">收起</el-button>
            </div>
          </el-row>
          <el-table v-loading="loading" :data="list">
            <el-table-column type="selection" width="55" />
            <el-table-column label="订单号" align="center" prop="selfNo" />
            <el-table-column label="目的地" align="center" prop="cubNo" />
            <el-table-column label="入仓时间" align="center" prop="cabinetId" />
            <el-table-column label="品名" align="center" prop="transportType" />
            <el-table-column label="箱数" align="center" prop="squareNumber" />
            <el-table-column label="体积/重量/重货比" align="center" prop="weight" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button type="primary" size="small">操作</el-button>
                <el-button type="primary" size="small">操作</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
        <!-- 待预装订单 -->
        <el-col :span="12">
          <el-row class="preinstall-title">
            <div class="table-label">待预装订单</div>
            <div class="preinstall-title preinstalled">
              <div class="red-label">
                <p>筛选后待预装数量：</p>
                <p>111</p>
              </div>
              <div class="red-label">
                <p>方数：</p>
                <p>111</p>
              </div>
              <div class="red-label">
                <p>重量：</p>
                <p>111</p>
              </div>
            </div>
          </el-row>
          <el-row>
            <el-row class="preinstall-title order-title">
              <div>
                <p>EC11111</p>
              </div>
              <div>
                <p>发往：</p>
                <p>111</p>
              </div>
              <div>
                <p>海运拼仓</p>
              </div>
              <div>
                <p>入仓时间</p>
                <p>111</p>
              </div>
              <div>
                <p>重货比</p>
                <p>111</p>
              </div>
              <div class="table-button">
                <el-button type="primary" size="small">预装</el-button>
              </div>
            </el-row>
            <el-table v-loading="loading" :data="list">
              <el-table-column type="index" label="序号" width="50" />
              <el-table-column label="品名" align="center" prop="selfNo" />
              <el-table-column label="备案" align="center" prop="cubNo" />
              <el-table-column label="箱数" align="center" prop="cabinetId" />
              <el-table-column label="体积/重量" align="center" prop="transportType" />
              <el-table-column label="报关方式" align="center" prop="squareNumber" />
              <el-table-column label="包装类型" align="center" prop="weight" />
              <el-table-column label="材质" align="center" prop="boxStatus" />
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button type="primary" size="small">预装</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-col>
      </el-row>
    </el-card>

    <!-- 操作员 -->
    <el-row style="margin-top: 15px">
      <el-row>
        <el-form ref="operatorForm" :model="operatorData" size="small" :inline="true" label-width="120px" :rules="rules">
          <el-form-item label="目的地操作员" prop="operator">
            <el-select v-model="operatorData.operator" placeholder="请选择目的地操作员" clearable size="small">
            </el-select>
          </el-form-item>
        </el-form>
      </el-row>
      <el-row style="margin-top: 10px">
        <el-button type="primary" @click="onSubmit">提交申请</el-button>
      </el-row>
    </el-row>
  </div>
</template>

<script>
import { DICT_TYPE } from "@/utils/dict";
import { getWarehouseList } from "@/api/ecw/warehouse";

export default {
  name: "preinstall",
  components: {},
  data() {
    return {
      // 状态
      stateOps: [
        { value: "1", label: "拆单" },
        { value: "2", label: "关联单" },
      ],
      // 备案
      filingOps: this.getDictDatas(DICT_TYPE.COMMISSION_PRODUCT_APPROVAL),
      // 报关方式
      declarationMethodOps: this.getDictDatas(DICT_TYPE.ECW_CUSTOMS_TYPE),
      // 仓库
      warehouseList: [],
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出货列表
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
      },
      // 目的地操作员
      operatorData: {
        operator: null,
      },
      rules: {
        operator: [
          { required: true, message: "请选择目的地操作员", trigger: "change" },
        ],
      },
    };
  },
  computed: {
    // 始发地
    exportWarehouseList() {
      return this.warehouseList.filter(
        (item) => item.tradeType == "2" || item.type == "3"
      );
    },
    // 目的地
    importWarehouseList() {
      return this.warehouseList.filter(
        (item) => item.tradeType == "1" || item.type == "3"
      );
    },
  },
  created() {
    getWarehouseList().then((res) => (this.warehouseList = res.data));
    // this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = { ...this.queryParams };
      // 执行查询
      getboxPage(params).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleCommand(row, command) {
      switch (command) {
        case "sea":
          this.$router.push("/boxSea/shippingSea/" + row.id);
          break;

        case "edit":
          break;

        case "delete":
          break;
      }
    },
    /** 提交 */
    onSubmit() {
      this.$refs["operatorForm"].validate((valid) => {
        if (valid) {
          alert("submit!");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.preinstall {
  p {
    margin: 0;
  }
  .preinstall-title {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    padding: 0 10px;

    &.preinstalled {
      flex: 1;
      display: flex;
      justify-content: flex-end;
      > div {
        display: flex;
      }
    }

    &.order-title {
      margin-bottom: 0px;
      background-color: #e6ebf5;
      height: 45px;
    }

    > div {
      display: flex;
      margin-right: 10px;
    }

    .table-label {
      font-size: 14px;
    }
    .red-label {
      color: red;
    }
    .table-button {
      flex: 1;
      margin: 0;
      display: flex;
      justify-content: flex-end;
    }
  }
  .preinstall-table {
    display: flex;
    > div {
      border: 1px solid #e6ebf5;
      padding: 10px 0px;
    }
    > div:first-child {
      margin-right: 10px;
    }
  }
}
</style>
