<!-- 
  filename: index.vue
  author: liubin
  date: 2023-08-25 10:27:58
  description: 包装报工
-->
<template>
  <div class="list-view-with-head" ref="pointer-loading-ref">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-input
          ref="hu"
          v-model="hu"
          placeholder="扫描HU号"
          @keydown.enter.native="handleReport"></el-input>
      </el-col>
      <el-col :span="1.5">
        <el-button @click="handleReport" type="primary" plain>报工</el-button>
      </el-col>
      <el-col :span="3">
        <el-select v-model="team" placeholder="班次" style="width: 100%">
          <el-option label="早班" value="0">早班</el-option>
          <el-option label="中班" value="1">中班</el-option>
          <el-option label="晚班" value="2">晚班</el-option>
        </el-select>
      </el-col>
    </el-row>

    <el-row style="margin-top: 18px">
      <BaseListTable
        v-if="dataList.length"
        v-loading="tableLoading"
        :table-config="tableConfig.table"
        :column-config="tableConfig.column"
        :table-data="dataList"
        :page="listQuery.page"
        :size="listQuery.limit"
        @operate-event="handleOperate"
        :refresh-layout-key="refreshLayoutKey" />
      <div style="color: #ccc; letter-spacing: 1px" v-else>暂无数据</div>
    </el-row>
  </div>
</template>

<script>
// import BaseSearchForm from "@/components/BaseSearchForm.vue";
import BaseListTable from "@/components/BaseListTable.vue";
import moment from "moment";

export default {
  name: "PackReport",
  components: { BaseListTable },
  data() {
    return {
      // hu: "40032179#300000624000000016",
      hu: "",
      team: "",
      tableLoading: false,
      tableConfig: {
        table: null,
        column: [],
      },
      dataList: [],
      listQuery: {
        page: 1,
        limit: 10,
      },
      refreshLayoutKey: Math.random(),
    };
  },
  activated() {
    this.$refs.hu.focus();
  },
  mounted() {
    this.getList();
  },
  methods: {
    handleOperate() {},

    handleReport() {},

    async getList() {
      const now = new Date();
      const [y, m, d] = [now.getFullYear(), now.getMonth(), now.getDate()];
      const today = new Date(y, m, d, 0, 0, 0).getTime();
      const { data: res } = await this.$axios({
        url: "/pms-am/pms/workReport/pageView",
        method: "post",
        data: {
          externalCode: 2,
          startTime: moment(today - 24 * 7 * 60 * 60 * 1000).format("YYYY-MM-DDTHH:mm:ss"),
          endTime: moment(today + 24 * 60 * 60 * 1000).format("YYYY-MM-DDTHH:mm:ss"),
          page: this.listQuery.page,
          limit: this.listQuery.limit,
        },
      });

      if (res.code == 0) {
        this.dataList = res.data;
      } else {
        this.$message.error(res.msg);
      }
    },

    handleReport() {
      this.$http({
        url: "/pms/workReport/packReport",
        method: "post",
        data: {
          hu: this.hu,
          team: this.team,
        },
        headers: {
          "Content-Type": "application/json",
        },
      }).then(({ data: res }) => {
        if (res.code == 0) {
          this.$message.success("报工成功");
          this.getList();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
  },
};
</script>

<style scoped>
.list-view-with-head {
  background: white;
  /* height: 100%; */
  min-height: inherit;
  border-radius: 6px;
  padding: 16px;
  box-shadow: 0 0 1.125px 0.125px rgba(0, 0, 0, 0.125);
}
</style>
