<template>
  <div class="app-container" id="">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="关键字" prop="keyWord">
        <el-input
          v-model="queryParams.keyWord"
          placeholder="请输入关键字"
          clearable
          :maxlength="20"
          style="width: 240px"
        />
      </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="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="tableList" :max-height="650">
      <el-table-column
        label="序号"
        align="center"
        type="index"
        :index="indexContinuation(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column label="项目部名称" align="center" prop="proCenter" />
      <el-table-column label="工程名称" align="center" prop="proName">
        <template v-slot="{ row }">
          <span @click="openProDetails(row)" style="color: #409eff; cursor: pointer">{{ row.proName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总保有量" align="center" prop="allNum" width="180" />
    </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 { getProTotalListApi } from '@/api/materialsStation'
export default {
  name: '',
  dicts: [],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 主表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyWord: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    async getList() {
      this.loading = true
      const params = {
        keyWord: this.queryParams.keyWord,
        pageSize: this.queryParams.pageSize,
        pageNum: this.queryParams.pageNum
      }
      try {
        const res = await getProTotalListApi(params)
        this.tableList = res.data.rows || []
        this.total = res.data.total || 0
        console.log('🚀 ~ getList ~ this.tableList:', this.tableList)
      } catch (error) {
        console.log('🚀 ~ getList ~ error:', error)
      } finally {
        this.loading = false
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'material/material_maMachine/exportTotalList',
        {
          ...this.queryParams
        },
        `工器具台账_${new Date().getTime()}.xlsx`
      )
    },
    // 工程详情
    openProDetails(row) {
      this.$router.push({
        path: '/materialsStation/equipment/equipmentRecord/proDetails',
        query: {
          proId: row.proId,
          proCenter: row.proCenter
        }
      })
    }
  }
}
</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>
