<script>
import {
  findAllMiningglossApi,
  deletedicekeMininglossApi,
  finddicekeMiningrecordById,
  findLossByMonthApi,
  updatedicekeMininglossApi,
  savedicekeMininglossApi,
} from "@@/apis/tables/diceke/LossDepletionReport.ts";
import { getSpecificDate } from "@@/utils/datetime";
export default {
  data() {
    return {
      date: "",
      tableList: [],
      dialogVisible: false,
      lossReportForm: {},
    };
  },
  created() {
    // 页面渲染之前执行，一般调用methods定义的方法
    this.getList();
  },
  methods: {
    //获取列表
    async getList() {
      const res = await findAllMiningglossApi();
      this.tableList = res.data.dicekeMininglossVoList;
    },
    //按月查询
    async getMouthLoss() {
      let data = getSpecificDate(this.date);
      const res = await findLossByMonthApi(data);
    },
    removeDataById(id) {
      ElMessageBox.confirm("此操作将永久删除降水量记录，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deletedicekeMininglossApi(id).then(() => {
            // 删除成功
            ElMessage({
              type: "success",
              message: "删除成功!",
            });
            // 重新加载列表
            this.getList();
          });
        })
        .catch(() => {
          ElMessage({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //修改
    handleEdit(id) {
      this.dialogVisible = true;
    },
    //修改提交
    lossReportSub() {},
  },
};
</script>

<template>
  <div class="app-container">
    <div style="margin-bottom: 20px">
      <el-date-picker v-model="date" type="month" placeholder="选择年月">
      </el-date-picker>
      <el-button
        type="primary"
        size="mini"
        style="margin-left: 20px"
        @click="getMouthLoss"
        >查询</el-button
      >
    </div>
    <el-table
      :data="tableList"
      border
      style="width: 100%"
      :span-method="spanMethod"
      :header-align="center"
      :cell-style="rowStyle"
    >
      <!-- 表格列定义 -->
      <el-table-column align="center" prop="plateRange" label="平盘(m)" />
      <el-table-column align="center" prop="shovelCode" label="电铲(#)" />
      <el-table-column align="center" prop="strippingAndTotalMiningTon" label="实采总量(t)" />
      <el-table-column align="center" prop="wasteRockTon" label="采下废石(%)" />
      <el-table-column align="center" prop="dilutionRate" label="贫化率(%)" />
      <el-table-column align="center" prop="strippingAndTotalMiningTon" label="圈定矿量(t)" />
      <el-table-column align="center" prop="amount" label="损失矿量(t)" />
      <el-table-column align="center" prop="lossRate" label="损失率(%)" />
      <el-table-column
        align="center"
        prop="allocationTon"
        label="配矿配矿量(t)"
      />
      <el-table-column align="center" prop="month" label="月份" />
      <el-table-column align="center" fixed="right" label="操作" width="300">
        <template #default="scope">
          <div style="display: flex; justify-content: center; gap: 8px">
            <el-button
              type="primary"
              size="small"
              icon="Edit"
              @click="handleEdit(scope.row.lossID)"
            >
              修改
            </el-button>
            <el-button
              type="danger"
              size="small"
              icon="Delete"
              @click="removeDataById(scope.row.lossID)"
            >
              删除
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog v-model="dialogVisible" title="修改损失和贫化信息" width="500">
      <!-- <el-form :model="lossReportForm">
        <el-form-item label="降水量" :label-width="formLabelWidth">
          <el-input v-model="lossReportForm.amount" autocomplete="off" />
        </el-form-item>

        <el-form-item label="月份" :label-width="formLabelWidth">
          <el-date-picker
            v-model="lossReportForm.monthDate"
            type="datetime"
            placeholder="选择月份"
          />
        </el-form-item>
      </el-form> -->
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogVisible = false"> 取消 </el-button>
          <el-button type="primary" @click="lossReportSub"> 提交 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
