<template>
  <basic-container>
    <avue-crud :option="option"
               :data="dataList"
               ref="crud"
               v-model="form"
               :page.sync="page"
               :table-loading="loading"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="primary"
                   size="small"
                   icon="el-icon-plus"
                   @click="addReceipt">新 单
        </el-button>
        <el-button size="small"
                   type="success"
                   @click.stop=""
        >复制新单
        </el-button>
        <el-button size="small"
                   type="info"
                   @click.stop="openReport()"
        >导出报表
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-edit"
          size="small"
          @click.stop="editOpen(scope.row, scope.index)"
        >编辑
        </el-button>
        <el-button
          type="text"
          icon="el-icon-delete"
          size="small"
          @click.stop="rowDel(scope.row, scope.index)"
        >删除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import option from "./configuration/receiptList.json";
  import {getList ,remove} from "@/api/financialManagement/financialManagement"

  export default {
    data() {
      return {
        loading : false,
        form: {},
        option: option,
        parentId:0,
        dataList: [{
          canem:""
        }],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
        query:{}
      }
    },
    created() {

    },
    mounted() {
      option.height = window.innerHeight - 350 ;
    },
    methods: {
      //新单打开
      addReceipt(){
        this.$router.push({
          path: "/receipt_detailsPage",
          query: {id: ''},
        });
      },
      //编辑打开
      editOpen(row, index){
        this.$router.push({
          path: "/receipt_detailsPage",
          query: {id:row.id},
        });
      },
      rowDel(row, index, done) {
        if(row.id){
          this.$confirm("确定将选择数据删除?", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(() => {
            remove(row.id).then(res =>{
              if(res.data.success){
                this.$message.success("操作成功!");
                this.onLoad(this.page);
              }
            })
          });
        }
      },
      //点击搜索按钮触发
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done()
      },
      searchReset() {
        console.log('1')
      },
      selectionChange() {
        console.log('1')
      },
      currentChange() {
        console.log('1')
      },
      sizeChange() {
        console.log('1')
      },
      refreshChange() {
        console.log('1')
      },
      onLoad(page, params = {}) {
        params.billType = "收费"
        this.loading = true
        getList(page.currentPage, page.pageSize,params).then(res =>{
          this.dataList = res.data.data.records
          this.page.total = res.data.data.total
          this.loading = false
        })
      },
    }
  }
</script>

<style scoped>

</style>
