<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="出库时间">
        <el-date-picker
          v-model="daterangeOutTime"
          size="small"
          style="width: 340px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></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-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          :loading="exportLoading"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['canteen:scck:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="list">
      <el-table-column label="就餐地名" align="center" prop="placeName" />
      <el-table-column label="总金额" align="center" prop="total" />
      <el-table-column label="统计开始时间" align="center" prop="beginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="统计结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listPlaceIncome} from "@/api/report/report";
  import user from "@/store/modules/user";

  export default {
    name: "PlaceIncome",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 显示搜索条件
        showSearch: true,
        daterangeOutTime: [],
        // 总条数
        total: 0,
        // 食材出库表格数据
        list: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          beginTime: null,
          endTime: null,
          jgid: null,
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询食材出库列表 */
      getList() {
        this.queryParams.jgid =  user.state.organ;
        this.loading = true;
        this.queryParams.params = {};
        if (null != this.daterangeOutTime && '' != this.daterangeOutTime) {
          this.queryParams.beginTime = this.daterangeOutTime[0];
          this.queryParams.endTime = this.daterangeOutTime[1];
        }else{
          this.queryParams.beginTime = null;
          this.queryParams.endTime = null;
        }
        listPlaceIncome(this.queryParams).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeOutTime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有食材出库数据项？').then(() => {
          this.exportLoading = true;
          return exportScck(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>
