<template>
  <div>
    <p-card :title="title">
      <div slot="extra">
        <div class="btns">
          <p-button type="primary" style="margin-left: 20px" @click="check">审核</p-button>
          <!-- <p-button type="primary" style="margin-left:20px" @click="split">拆分</p-button> -->
          <p-button type="primary" style="margin-left: 20px">打印</p-button>
          <p-button type="primary" style="margin-left: 20px">导出</p-button>
        </div>
      </div>
      <main-table ref="maintable" :tablecolumns="tablecolumns"></main-table>
    </p-card>
  </div>
</template>

<script>
import MainTable from "../components/mainTable";
import tablecolumns from "./config";
import { batchAdd, batchCheck } from "../api";
export default {
  data() {
    return {
      tablecolumns,
      title: "养护复检",
      ids: {},
    };
  },
  components: {
    MainTable,
  },

  //   mixins: [setwarehouse],
  methods: {
    async check() {
      let data = this.$refs.maintable.getselectedRowsfunss();
      console.log(typeof data);

      if (typeof data == "boolean") {
        this.$message.warning("请勾选数据");
        return;
      }
      if (data.length > 0) {
        let res = await batchCheck(data);
        console.log(res);
        if (res.success) {
          this.$refs.maintable.reload();
        }
      } else {
        this.$message.warning("有必填项未填!");
      }
    },
    //   getselectedRowsfun
    //拆分
    split() {
      console.log("拆分");
      let data = this.$refs.maintable.getSelectRow();
      console.log(data);
      this.ids = data;
    },
    async Makeplan() {
      let that = this;
      //        selectedRowsfun(selectedRowKeys, selectedRow) {
      //   this.selectedRow = selectedRow
      let selectedRow = this.$refs.maintable.getselectedRowsfun();
      console.log(selectedRow, "====");
      selectedRow.forEach((item) => {
        item.upkeepType = 0;
      });
      //   upkeepType
      let res = await batchAdd(selectedRow);
      console.log(res);
      if (res.success) {
        this.$success({
          title: "提示",
          // JSX support
          content: (
            <div>
              <p>生成养护记录成功!</p>
            </div>
          ),
          ok: function () {
            that.$refs.maintable.reload();
          },
        });
      } else {
        this.$exception(res);
      }
    },
  },
};
</script>

<style scoped>
.btns {
  /* width: 200px; */
  display: flex;
  justify-content: space-around;
}
</style>
