<script>
import {
  deletedicekeMiningrecord,
  findAllMiningrecord,
  finddicekeMiningrecordById
} from "@@/apis/tables/diceke/DicekeMiningrecord.js"

export default {
  data() {
    return {
      dicekeMiningrecordQuery: null,
      updatedicekeMiningrecordform: false,
      dicekeMiningrecordform: null
    }
  },
  created() {
    // 页面渲染之前执行，一般调用methods定义的方法
    this.getList()
  },
  methods: {
    getList() {
      findAllMiningrecord().then((Response) => {
        console.log(Response)
        this.dicekeMiningrecordQuery = Response.data.dicekeMiningrecordVoList
        console.log(this.dicekeMiningrecordQuery)
      })
    },
    // 删除平盘
    removeDataById(id) {
      ElMessageBox.confirm(
        "此操作将永久删除平盘记录，是否继续？",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          deletedicekeMiningrecord(id).then(() => {
            // 删除成功
            ElMessage({
              type: "success",
              message: "删除成功!"
            })
            // 重新加载列表
            this.getList()
          })
        })
        .catch(() => {
          ElMessage({
            type: "info",
            message: "已取消删除"
          })
        })
    },
    handleEdit(id) {
      finddicekeMiningrecordById(id).then((Response) => {
        this.dicekeMiningrecordform = Response.data.dicekeMiningrecordServiceById
        this.updatedicekeMiningrecordform = true
      })
    }
  }
}
</script>

<template>
  <div class="app-container">
    <el-table :data="dicekeMiningrecordQuery" border style="width: 100%" :span-method="spanMethod">
      <!-- 表格列定义 -->
      <el-table-column prop="plateRange" label="平盘（#）" />
      <el-table-column prop="shovelCode" label="铲号（#）" />
      <el-table-column prop="totalMiningTon" label="采矿量（t）" />
      <el-table-column prop="metalTon" label="金属量（#）" />
      <el-table-column prop="miningGrade" label="块段采矿品位（%）" />
      <el-table-column prop="oxidationRate" label="块段氧化率（%）" />
      <el-table-column prop="avgGrade" label="全月平均品位（%）" />
      <el-table-column prop="dressingGrade" label="选矿平均品位（%）" />
      <el-table-column prop="avgOxidationRate" label="全月平均氧化率（%）" />
      <el-table-column prop="beizhu" label="备注" />
      <el-table-column fixed="right" label="操作" width="150" align="center">
        <template #default="scope">
          <div style="display: flex; justify-content: center; gap: 8px;">
            <el-button type="primary" text bg size="small" plain @click="handleEdit(scope.row.recordID)">
              修改
            </el-button>
            <el-button
              type="danger"
              text bg size="small"
              @click="removeDataById(scope.row.recordID)"
            >
              删除
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog v-model="updatedicekeMiningrecordform" title="修改Mo品味信息" width="500">
      <el-form :model="dicekeMiningrecordform">
        <el-form-item label="采矿量（t）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.totalMiningTon" autocomplete="off" />
        </el-form-item>
        <el-form-item label="金属量（#）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.metalTon" autocomplete="off" />
        </el-form-item>
        <el-form-item label="块段采矿品位（%）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.miningGrade" autocomplete="off" />
        </el-form-item>
        <el-form-item label="块段氧化率（%）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.oxidationRate" autocomplete="off" />
        </el-form-item>
        <el-form-item label="全月平均品位（%）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.avgGrade" autocomplete="off" />
        </el-form-item>
        <el-form-item label="选矿平均品位（%）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.dressingGrade" autocomplete="off" />
        </el-form-item>
        <el-form-item label="全月平均氧化率（%）" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.avgOxidationRate" autocomplete="off" />
        </el-form-item>
        <el-form-item label="备注" :label-width="formLabelWidth">
          <el-input v-model="dicekeMiningrecordform.beizhu" autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="updatedicekeMiningrecordform = false">
            取消
          </el-button>
          <el-button type="primary" @click="updatePlateArea">
            提交
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
