<template>
  <div class="app-container">
    <el-card>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
        <el-form-item label="业务日期" prop="timeRange">
          <el-date-picker
            v-model="queryParams.timeRange"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </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="success" icon="el-icon-download" size="mini" @click="handleExportExcel">导出Excel</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <br />
    <el-card>
      <el-table border stripe  v-loading="loading" ref="multipleTable" :data="disposalList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="物料编码" align="center"  width="150" prop=""/>
        <el-table-column label="物料名称" align="center"  width="150" prop=""/>
        <el-table-column label="基本单位数量" align="center"  width="150" prop=""/>
        <el-table-column label="计量单位" align="center"  width="150" prop=""/>
        <el-table-column label="辅助单位数量" align="center"  width="150" prop=""/>
        <el-table-column label="辅助计量单位" align="center"  width="150" prop=""/>
        <el-table-column label="指导价" align="center"  width="150" prop=""/>
        <el-table-column label="成本单价" align="center"  width="150" prop=""/>
        <el-table-column label="成本金额" align="center"  width="150" prop=""/>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>
<script>
import { formatMoney } from "../../../utils";
export default {
  name: "dayCostTable",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      disposalList: [],
      // 弹出层标题
      title: "",
      isView:false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productionPlantName: null,
        timeRange: null,
        startTime: null,
        endTime: null,
      },
      pickerOptions: {
        disabledDate(time) {
          // 获取当前日期
          const today = new Date();
          today.setHours(0, 0, 0, 0); // 将时间设置为当天的 00:00:00

          // 禁用今天之后的日期
          return time.getTime() > today.getTime();
        }
      },
      // 表单参数
      form: {},
      rules: {},
      productionPlantList: [
        {
          value: '001',
          label: '常规生产车间'
        }
      ]
    }
  },
  watch: {
    "queryParams.timeRange": {
      handler(newVal) {
        if (newVal) {
          this.queryParams.startTime = newVal[0]
          this.queryParams.endTime = newVal[1]
        } else {
          this.queryParams.startTime = null
          this.queryParams.endTime = null
        }
      },
      deep: true
    },
  },
  created() {
    this.getList();
  },
  methods: {
    getMoney(val) {
      return formatMoney(val)
    },
    goNext(event, nextRef) {
      event.preventDefault();
      this.$refs[nextRef].focus();
    },
    /** 查询检验项目列表 */
    getList() {
      // (this.queryParams).then(res => {
      // this.disposalList = res.data.records;
      // this.total = res.data.total;
      //   this.loading = false;
      // })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        productionPlantName: null,
        timeRange: null,
        startTime: null,
        endTime: null,
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isView = false;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      // (params).then(res => {
      //   this.form = res.data;
      //   this.open = true;
      //   this.isView = false;
      //   this.title = "编辑"
      // })
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      // (params).then(res => {
      //   this.form = res.data;
      //   this.open = true;
      //   this.isView = true;
      //   this.title = "查看"
      // })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        // dealReason: null,
        // dealWay: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            // 编辑
            // (this.form).then(res => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // })
          } else {
            // 新增
            // (this.form).then(response => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      let params = {
        ids: ids
      }
      // (params).then(res => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // })
    },
    /** 删除按钮操作 */
    handleDeleteAll() {
      const ids = this.ids;
      this.$modal.confirm('确定要删除这条数据吗？').then(() => {
        let params = {
          ids: ids.join(',')
        }
        // (params).then(res => {
        //   this.getList();
        //   this.$modal.msgSuccess("删除成功");
        //   this.$refs.multipleTable.clearSelection();
        // })
      })
    },
    handleExportExcel() {
      this.$modal.confirm('确定要导出Excel吗？').then(() => {
        let params = {
          ids: ids.join(',')
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
