<template>
  <ContainerQuery>
    <div slot="left">
      <el-button size="small" type="primary">打印</el-button>
      <el-button size="small" type="primary">导出</el-button>
    </div>
    <div slot="more">
      <el-tabs
        v-model="top_time"
        style="position: absolute; top: 70px; left: 180px"
        @tab-click="pageChange(1)"
      >
        <el-tab-pane label="昨日" name="yesterday"></el-tab-pane>
        <el-tab-pane label="今日" name="today"></el-tab-pane>
        <el-tab-pane label="本周" name="beforweek"></el-tab-pane>
        <el-tab-pane label="本月" name="nowmonth"></el-tab-pane>
        <el-tab-pane label="上月" name="permonth"></el-tab-pane>
        <el-tab-pane label="近三月" name="preday"></el-tab-pane>
        <el-tab-pane label="本年" name="nowyear"></el-tab-pane>
      </el-tabs>
    </div>
    <div slot="more">
      <el-form inline size="small">
        <el-form-item>
          <el-input
            v-model="keyword"
            style="width: 220px"
            placeholder="单据编号"
            clearable
            @keyup.enter.native="pageChange(1)"
            @clear="pageChange(1)"
          >
            <el-button slot="append" @click="pageChange(1)">
              <i class="el-icon-search"></i>
            </el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="originId"
            style="width: 220px"
            placeholder="来源订单"
            clearable
            @keyup.enter.native="pageChange(1)"
            @clear="pageChange(1)"
          >
            <el-button slot="append" @click="pageChange(1)">
              <i class="el-icon-search"></i>
            </el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="time"
            clearable
            type="daterange"
            value-format="timestamp"
            range-separator="-"
            start-placeholder="下单开始日期"
            end-placeholder="下单结束日期"
            @change="orderDate"
          ></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-input
            v-model="warehouseName"
            placeholder="拣货仓库"
            style="width: 150px"
          >
            <i
              slot="suffix"
              class="el-input__icon el-icon-search"
              @click="warehouse_show = true"
            ></i>
          </el-input>
        </el-form-item>
        <!--        <el-form-item>-->
        <!--          <RegionSelect-->
        <!--            v-model="region"-->
        <!--            size="small"-->
        <!--            clearable-->
        <!--            check-strictly-->
        <!--            placeholder="区域"-->
        <!--            style="width: 150px"-->
        <!--            @change="regionChange"-->
        <!--          />-->
        <!--        </el-form-item>-->
        <el-form-item>
          <SelectCustomer
            v-model="customer_name"
            placeholder="拣货人"
            @clear="customerClear"
            @change="customerSel"
          />
        </el-form-item>

        <el-form-item>
          <SelectCustomer
            v-model="customer_name2"
            placeholder="往来单位"
            @clear="customerClear2"
            @change="customerSel2"
          />
        </el-form-item>
        <el-form-item>
          <SelectCustomer
            v-model="customer_name3"
            placeholder="经手人"
            @clear="customerClear3"
            @change="customerSel3"
          />
        </el-form-item>
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="keyword"-->
        <!--            style="width: 220px"-->
        <!--            placeholder="收货人"-->
        <!--            clearable-->
        <!--            @keyup.enter.native="pageChange(1)"-->
        <!--            @clear="pageChange(1)"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="pageChange(1)">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="keyword"-->
        <!--            style="width: 220px"-->
        <!--            placeholder="联系电话"-->
        <!--            clearable-->
        <!--            @keyup.enter.native="pageChange(1)"-->
        <!--            @clear="pageChange(1)"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="pageChange(1)">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="keyword"-->
        <!--            style="width: 220px"-->
        <!--            placeholder="收货地址"-->
        <!--            clearable-->
        <!--            @keyup.enter.native="pageChange(1)"-->
        <!--            @clear="pageChange(1)"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="pageChange(1)">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="warehouseName"-->
        <!--            placeholder="集货拉"-->
        <!--            style="width: 150px"-->
        <!--          >-->
        <!--            <i-->
        <!--              slot="suffix"-->
        <!--              class="el-input__icon el-icon-search"-->
        <!--              @click="warehouse_show = true"-->
        <!--            ></i>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-select-->
        <!--            v-model="Return"-->
        <!--            style="width: 150px"-->
        <!--            multiple-->
        <!--            placeholder="产生方式"-->
        <!--            @change="pageChange(1)"-->
        <!--          >-->
        <!--            <el-option-->
        <!--              v-for="item in Return_status"-->
        <!--              :key="item.value"-->
        <!--              :label="item.label"-->
        <!--              :value="item.value"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="keyword"-->
        <!--            style="width: 220px"-->
        <!--            placeholder="收货地址"-->
        <!--            clearable-->
        <!--            @keyup.enter.native="pageChange(1)"-->
        <!--            @clear="pageChange(1)"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="pageChange(1)">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-select-->
        <!--            v-model="Return"-->
        <!--            style="width: 150px"-->
        <!--            multiple-->
        <!--            placeholder="产生方式"-->
        <!--            @change="pageChange(1)"-->
        <!--          >-->
        <!--            <el-option-->
        <!--              v-for="item in Return_status"-->
        <!--              :key="item.value"-->
        <!--              :label="item.label"-->
        <!--              :value="item.value"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            v-model="keyword"-->
        <!--            style="width: 220px"-->
        <!--            placeholder="配送线路"-->
        <!--            clearable-->
        <!--            @keyup.enter.native="pageChange(1)"-->
        <!--            @clear="pageChange(1)"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="pageChange(1)">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item>-->
        <!--          <el-select-->
        <!--            v-model="Return"-->
        <!--            style="width: 150px"-->
        <!--            multiple-->
        <!--            placeholder="配送方式"-->
        <!--            @change="pageChange(1)"-->
        <!--          >-->
        <!--            <el-option-->
        <!--              v-for="item in Return_status"-->
        <!--              :key="item.value"-->
        <!--              :label="item.label"-->
        <!--              :value="item.value"-->
        <!--            ></el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
      </el-form>
      <!--    选择仓库-->
      <WarehouseModel
        v-if="warehouse_show"
        :is-check="false"
        :is-show="warehouse_show"
        @confirm="selWarehouse"
        @cancel="warehouse_show = false"
      />
    </div>
    <vxe-table
      ref="xTable"
      :data="tableData"
      @checkbox-all="checkboxChangeEvent"
      @checkbox-change="checkboxChangeEvent"
    >
      <vxe-table-column type="checkbox" width="60"></vxe-table-column>
      <vxe-table-column field="sex" title="单据日期" width="150">
        <template #default="{ row }">
          {{ $_common.formatDate(row.createTime) }}
        </template>
      </vxe-table-column>
      <vxe-table-column
        field="no"
        title="单据编号"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="personnelName"
        title="拣货人"
        width="150"
      ></vxe-table-column>
      <vxe-table-column field="originNo" title="来源订单" width="200">
        <template #default="{ row }">
          <span
            class="click-div"
            @click="
              $router.push({
                path: `/order/manageO/OrderDetails/${row.personnel}/${row.originId}`,
              })
            "
          >
            {{ row.originNo }}
          </span>
        </template>
      </vxe-table-column>
      <vxe-table-column
        field="age"
        title="拣货仓库"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="currentUnit"
        title="往来单位"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="sort"
        title="排序"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="number"
        title="数量"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="goodsLine"
        title="商品行数"
        width="150"
      ></vxe-table-column>
      <vxe-table-column
        field="managerName"
        title="订单经手人"
        width="150"
      ></vxe-table-column>
      <vxe-table-column width="180" fixed="right" field="name" title="操作">
        <template #default="{ row }">
          <el-button type="text" size="mini">取消</el-button>
          <el-button
            type="text"
            size="mini"
            @click="
              $router.push(`/stock/OrdersForShipment/pickingList/${row.id}`)
            "
          >
            修改
          </el-button>
          <el-button type="text" size="mini">完成拣货</el-button>
        </template>
      </vxe-table-column>
    </vxe-table>
    <FooterPage
      :page-size="pageSize"
      :total-page.sync="total"
      :current-page.sync="page"
      @pageChange="pageChange"
      @sizeChange="sizeChange"
    >
      <div slot="btn-div" class="foot-btn-div">
        <span class="batch-checkbox">
          <vxe-checkbox
            v-model="checkedAll"
            :indeterminate="isIndeterminate"
            @change="checkAllChange"
          ></vxe-checkbox>
        </span>
        <el-button size="mini">分配拣货员</el-button>
        <el-button size="mini">批量打印</el-button>
        <el-button size="mini">批量完成</el-button>
        <el-button size="mini">批量取消</el-button>
        <el-button size="mini">商品汇总</el-button>
      </div>
    </FooterPage>
  </ContainerQuery>
</template>
<script>
  import SelectCustomer from "@/component/common/SelectCustomer.vue";
  import WarehouseModel from "@/component/common/WarehouseModel.vue";
  import RegionSelect from "@/component/common/RegionSelectJSON";
  import { getAllPicking } from "@/api/Stock";
  export default {
    components: {
      SelectCustomer,
      WarehouseModel,
      // RegionSelect,
    },
    data() {
      return {
        keyword: "",
        top_time: "today",
        customer_name: "",
        customer_name2: "",
        customer_name3: "",
        customerId: "",
        time: "",
        start: "",
        end: "",
        Return: "",
        region: "",
        Return_status: [],
        warehouseName: "",
        warehouse_show: false,
        warehouseId: "",
        tableData: [],
        page: 1,
        pageSize: 10,
        total: 0,
        checkedAll: false,
        records: [],
        provinceCode: "",
        cityCode: "",
        districtCode: "",
        originId: "",
        personnelName: "",
        managerName: "",
        currentUnit: "",
        isIndeterminate: false,
      };
    },
    created() {
      this.getAllPicking();
    },
    methods: {
      pageChange(val) {
        this.page = val;
        this.getAllPicking();
      },
      sizeChange(val) {
        this.pageSize = val;
        this.pageChange(1);
      },
      selTopType() {},
      customerClear() {
        this.personnelName = "";
        this.customer_name = "";
        this.pageChange(1);
      },
      customerClear2() {
        this.currentUnit = "";
        this.customer_name2 = "";
        this.pageChange(1);
      },
      customerClear3() {
        this.managerName = "";
        this.customer_name3 = "";
        this.pageChange(1);
      },
      // 选择拣货人
      customerSel(val, list) {
        this.personnelName = list[0].id;
        this.pageChange(1);
      },
      //选择往来单位
      customerSel2(val, list) {
        this.currentUnit = list[0].id;
        this.pageChange(1);
      },
      //选择经手人
      customerSel3(val, list) {
        this.managerName = list[0].id;
        this.pageChange(1);
      },
      //  时间
      orderDate(val) {
        if (val && val.length) {
          this.start = val[0] / 1000;
          this.end = val[1] / 1000 + 86399;
        } else {
          this.start = "";
          this.end = "";
        }
        this.pageChange(1);
      },
      selWarehouse(row) {
        this.warehouseName = row[0].warehouseName;
        this.warehouseId = row[0].id;
        this.pageChange(1);
      },
      checkboxChangeEvent({ records }) {
        this.checkedAll = this.$refs.xTable.isAllCheckboxChecked();
        this.isIndeterminate = this.$refs.xTable.isAllCheckboxChecked();
        this.records = records;
      },
      checkAllChange() {
        this.$refs.xTable.setAllCheckboxRow(this.checkedAll);
        this.records = this.$refs.xTable.getCheckboxRecords();
      },
      // 选择区域
      regionChange(val) {
        this.provinceCode = val[0];
        this.cityCode = val[1];
        this.districtCode = val[2];
        this.pageChange(1);
      },
      async getAllPicking() {
        const { data, pageTotal } = await getAllPicking({
          page: this.page,
          pageSize: this.pageSize,
          no: this.keyword,
          start: this.start,
          end: this.end,
          originNo: this.originId,
          personnel: this.personnelName,
          currentUnitId: this.currentUnit,
          managerId: this.managerName,
          timeName: this.top_time,
        });
        this.tableData = data;
        this.total = pageTotal;
      },
    },
  };
</script>
<style></style>
