<template>
  <basic-container>
    <div>
      <Card class="cardTitle">
        <p>
          <el-button type="primary" @click="backPage" style="width: 80px;"
            >返回</el-button
          >
        </p>
      </Card>

      <avue-crud
        style="width:100%;margin-top:15px;"
        :data="tableData"
        :option="option"
        :page.sync="page"
        :table-loading="tableLoading"
        @on-load="getList"
        @size-change="sizeChange"
        @current-change="currentChange"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            type="text"
            size="small"
            icon="el-icon-view"
            :disabled="scope.row.status > 1"
            @click="agreeBtn(scope.row, scope.index)"
            >同意
          </el-button>

          <el-button
            type="text"
            size="small"
            icon="el-icon-view"
            :disabled="scope.row.status > 1"
            @click="refuseBtn(scope.row, scope.index)"
            >拒绝
          </el-button>
        </template>
      </avue-crud>
    </div>
  </basic-container>
</template>

<script>
import { receiptApprovalData } from "@/const/crud/specialTask/patientEdu/approval";

import {
  getPage,
  approvalStatus,
  updateZZ
} from "@/api/assignPoints/currency/approval";

export default {
  name: "receiptApproval",
  data() {
    return {
      tableData: [],
      option: receiptApprovalData,
      page: {
        pageSize: 10,
        pagerCount: 5
      },
      tableLoading: false,
      searchForm: {}
    };
  },
  mounted() {},
  methods: {
    // 初始化页面
    getList(page, params) {
      this.tableLoading = true;
      getPage(
        Object.assign(
          {
            packageId: this.$route.query.id,
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.tableData = [];
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },

    // 返回按钮
    backPage() {
      this.$store.commit("ADD_PATIENT_EDU_TYPE", "second");
      this.$router.$avueRouter.closeTag();
      this.$router.push({ path: "/admin/specialTask/patientEdu/index" });
    },

    // 同意按钮
    agreeBtn(row) {
      this.$confirm("是否同意?", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning"
      })
        .then(() => {
          let arg = {
            packageId: row.packageId,
            id: row.id,
            status: 2
          };
          approvalStatus(arg)
            .then(data => {
              this.$message.success("同意成功");
              this.getList(this.page);
            })
            .catch(() => {
              this.$message.error("请求异常");
            });
        })
        .catch(() => {
          //this.$message.error("请求异常");
        });
    },

    // 拒绝按钮
    refuseBtn(row) {
      let arg = {
        packageId: row.packageId,
        id: row.id,
        status: 3
      };
      approvalStatus(arg)
        .then(data => {
          this.$message.success("拒绝成功");
          this.getList(this.page);
        })
        .catch(() => {
          this.$message.error("请求异常");
        });
    },

    // 取消按钮
    cancelBtn() {
      this.enableForm = {};
    },
    // 分页查询
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    }
  }
};
</script>
