<template>
  <div class="app-container" id="acceptDetail">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item prop="startTime">
        <el-date-picker
          v-model="queryParams.startTime"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="开始日期"
          style="width: 130px"
          @change="() => queryParams.endTime = ''"
        />
      </el-form-item>
      <el-form-item>-</el-form-item>
      <el-form-item prop="endTime">
        <el-date-picker
          v-model="queryParams.endTime"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="结束日期"
          style="width: 130px"
          :picker-options="{ disabledDate: (t) => t.getTime() < new Date(queryParams.startTime).getTime() - 86400000}"
        />
      </el-form-item>
      <el-form-item  prop="keyWord">
          <el-input
              v-model="queryParams.keyWord"
              placeholder="请输入关键词"
              clearable
              @keyup.enter.native="handleQuery"
              maxlength="20"
          />
      </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"
          size="mini"
          icon="el-icon-back"
          @click="jumpList"
          >报废台账</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出数据</el-button
        >
      </el-col>

    </el-row>

    <el-table
      v-loading="loading"
      :data="tableList"
      ref="multipleTable"
      row-key="id"
    >
      <el-table-column label="序号" align="center" width="80" type="index">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型名称" align="center" prop="typeName" :show-overflow-tooltip="true" />
      <el-table-column label="规格型号" align="center" prop="typeModelName" :show-overflow-tooltip="true" />
      <el-table-column label="计量单位" align="center" prop="unitName" :show-overflow-tooltip="true" />
      <el-table-column label="报废数量" align="center" prop="scrapNum" :show-overflow-tooltip="true" />
      <el-table-column label="报废费用(万元)" align="center" prop="totalCost" :show-overflow-tooltip="true" />
      <el-table-column label="报废类型" align="center" prop="scrapStyle" :show-overflow-tooltip="true" />
      <el-table-column label="损坏类型" align="center" prop="scrapType" :show-overflow-tooltip="true" />
      <el-table-column label="审核人" align="center" prop="auditName" :show-overflow-tooltip="true" />
      <el-table-column label="审核日期" align="center" prop="month" :show-overflow-tooltip="true" />
    </el-table>
        <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

  <script>
import { getScrapDetailsList } from '@/api/repair/scrapLedgerReview';
import { downloadFile } from "@/utils/download";
import { getToken } from "@/utils/auth";
export default {
  name: "ScrapLedgerDetail",
  data() {
    return {
      month: "",

      // 遮罩层
      loading: false,
      dialogLoading: false,
      isView: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,

      // 总条数
      total: 0,
      //表格数据
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      rowData: {},

      // 查询参数
      queryParams: {
        time:null,
        keyWord: null,
        pageNum: 1,
        pageSize: 10,
        startTime: null,
        endTime: null,
      },
    };
  },
  mounted() {
    const month = this.$route.query && this.$route.query.month;
    const isView = this.$route.query && this.$route.query.isView;
    this.month = month;
    if (isView == "true") {
      this.isView = true;
    } else {
      this.isView = false;
    }
    this.getList();
  },
  methods: {

    // 返回列表页
    jumpList() {
      const obj = { path: "/scrap/scrapLedger" };
      this.$tab.closeOpenPage(obj);
    },

    /** 查询列表 */
    getList() {
      this.loading = true;
      const params = {
          month: this.month,
          keyWord: this.queryParams.keyWord,
          startTime: this.queryParams.startTime,
          endTime: this.queryParams.endTime,
          pageSize: this.queryParams.pageSize,
          pageNum: this.queryParams.pageNum
      }

      getScrapDetailsList(params).then((response) => {
        this.tableList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.keyWord = null;
      this.queryParams.time = null;
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },


    /** 导出按钮操作 */
    handleExport() {
      const formatTime = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        return `${year}${month}${day}_${hours}${minutes}${seconds}`;
      };

      const currentTime = formatTime(new Date());
        const params = {
          month: this.month,
          keyWord: this.queryParams.keyWord,
          startTime: this.queryParams.startTime,
          endTime: this.queryParams.endTime,
      }
      this.download(
        "/material/scrap_apply_details/exportScrapDetailsList",
        { ...params },
        `报废台账明细_${currentTime}.xlsx`
      );
    },
  },
};
</script>
  <style lang="scss" scoped>
.uploadImg {
  padding-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.deviceCode {
  margin-top: 10px;
  padding-bottom: 20px;
  font-size: 18px;
}
::v-deep.el-table .fixed-width .el-button--mini {
  width: 60px !important;
  margin-bottom: 10px;
}
//隐藏图片上传框的css
::v-deep.disabled {
  .el-upload--picture-card {
    display: none;
  }
}
</style>
