<template>
    <div class="app-container" id="">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
        <el-form-item prop="deptName">
            <el-select v-model="queryParams.deptName" placeholder="请选择分公司" clearable style="width: 240px">
                <el-option
                    v-for="item in impUnitNameList"
                    :key="item.impUnitName"
                    :label="item.impUnitName"
                    :value="item.impUnitName"
                ></el-option>
            </el-select>
        </el-form-item>
        <el-form-item prop="proName">
            <el-input
                v-model="queryParams.proName"
                placeholder="请输入工程名称"
                clearable :maxlength="20"
                style="width: 220px"
            />
        </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-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                >导出</el-button
            >
        </el-form-item>
      </el-form>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      <el-table v-loading="loading" :data="tableList" border>
          <el-table-column label="序号" align="center" width="80" type="index">
                <template scope="scope">
                    <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index+1 }}</span>
                </template>
          </el-table-column>

          <el-table-column label="分公司" align="center" prop="deptName" :show-overflow-tooltip="true" width="400px"/>
          <el-table-column label="工程名称" align="center" prop="proName" :show-overflow-tooltip="true"/>>
      </el-table>
      <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          @pagination="getList"
      />
    </div>
</template>

<script>
import {getFinishNoReturnListApi } from '@/api/stquery/stquery';
import {getImpUnitNameListApi,} from '@/api/back/index.js'
export default {
    name: 'FinishNoReturn',
    dicts: [],
    data() {
        return {
            // 遮罩层
            loading: false,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 主表格数据
            tableList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                deptName: null, //分公司
                proName: null, //物资名称
            },
            impUnitNameList: [], //分公司
        }
    },
    created() {
        this.getImpUnitNameList()
        this.getList()
    },
    methods: {
      // 分公司下拉
      async getImpUnitNameList () {
          try {
              const res = await getImpUnitNameListApi()
              this.impUnitNameList = res.data
          } catch (error) {
              console.log('🚀 ~ error:', error)
          }
      }, 


      // 获取列表
      async getList() {
          this.loading = true
          const params = {
                deptName: this.queryParams.deptName,
                proName: this.queryParams.proName,
                pageSize: this.queryParams.pageSize,
                pageNum: this.queryParams.pageNum
            }
          const res = await getFinishNoReturnListApi(params)
          this.loading = false
          if(res.data.rows.length>0){
            this.tableList = res.data.rows;
          }else{
            this.tableList=[]
          }
          this.total = res.data.total;
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1
          this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.deptName = null, //分公司
        this.queryParams.proName = null, //物资名称
        this.queryParams.pageNum = 1
        this.resetForm('queryForm')
        this.handleQuery()
      },
      /** 导出按钮操作 */
      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 params = {
            deptName: this.queryParams.deptName,
            proName: this.queryParams.proName,
            pageSize: this.queryParams.pageSize,
            pageNum: this.queryParams.pageNum
        }
        const currentTime = formatTime(new Date());
          this.download(
              'material/complex_query/exportFinishNoReturnList',
              {
                  ...params,
              },
              `综合查询_工程竣工未归还记录_${currentTime}.xlsx`,
          )
      },
    },
}
</script>
<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
    width: 60px !important;
    margin-bottom: 10px;
}
.clickText {
  color: #02a7f0;
  cursor: pointer;
}
</style>
