<!--
 * @Description: 
 * @Author: shipeng
 * @Date: 2025-06-10 预定报表开发 替换 日报表
-->
<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="60px">
        <el-form-item label="日期" required>
          <el-date-picker
            v-model="queryParams.performDate"
            @change="dateChange"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="场次" v-if="!multiPerformDate" label-width="55px">
            <el-select
            v-model="queryParams.timeId"
            placeholder="场次"
            @change="getList"
            clearable
            style="width: 100%"
            >
            <el-option
                v-for="dict in pagePerformTimeList"
                :key="dict.id"
                :label="dict.timeSnapshot+'('+dict.performTimeStart+'-'+dict.performTimeEnd+')'"
                :value="dict.id"
            />
            </el-select>
        </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"  style="margin-left: 0; margin-top: 10px">
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-download"
          :disabled="dataList.length === 0"
          v-hasPermi="['daily:daily:downloadExcel']"
          @click="handleExport"
          v-loading.fullscreen.lock="handleExportLoading"
          element-loading-text="正在拼命生成数据中..."
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.5)"
        >导出excel</el-button>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table ref="tables" v-loading="loading" :data="dataList" max-height="650px" border>
        <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
        <!-- <el-table-column label="剧目名称" align="center" prop="performName" />
        <el-table-column label="票务名称" align="center" prop="goodsName" /> -->
        <el-table-column label="场次日期" align="center" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.performDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="场次" align="center" width="110">
          <template slot-scope="scope">
            <span>{{ scope.row.performTimeStart }} -- {{ scope.row.performTimeEnd }}</span>
          </template>
        </el-table-column>
         <el-table-column label="座位类型" align="center" prop="seatTypeName" width="120" />
         <el-table-column label="窗口" align="center" prop="winTotal" />
         <el-table-column label="小程序" align="center"  prop="microAppTotal" />
         <el-table-column label="分销" align="center"  prop="retailTotal" />
         <el-table-column label="自助机" align="center"  prop="selfTotal" />
         <el-table-column label="直客小计" align="center"  prop="directSaleTotal" />
         <el-table-column label="美团" align="center"  prop="meituanTotal" />
         <el-table-column label="抖音" align="center"  prop="duoyinTotal" />
         <el-table-column label="携程" align="center"  prop="xiechenTotal" />
         <el-table-column label="猫眼" align="center"  prop="maoyanTotal" />
         <el-table-column label="OTA小计" align="center"  prop="otaSaleTotal" />
         <el-table-column label="大客户" align="center"  prop="maxCustomerSaleTotal" />
         <el-table-column label="旅行社&红培" align="center"  prop="travelAgencySaleTotal" />
         <el-table-column label="研学" align="center"  prop="studySaleTotal" />
         <el-table-column label="党校" align="center"  prop="partySchoolSaleTotal" />
         <el-table-column label="团购小计" align="center"  prop="groupBuyTotal" />
         <el-table-column label="合计" align="center"  prop="buySaleTotal" />
         <el-table-column label="推广票" align="center"  prop="promotionTicketSaleTotal" />
         <el-table-column label="总计" align="center"  prop="saleTotal" />

      </el-table>
  
    </div>
  </template>
  
  <script>
  
  import { bookingReportCount, bookingReportCountExport } from '@/api/statisticalReport/statistics'
  import { exportExcel } from '@/utils/exportexcel'
  import { seatPricePageList } from '@/api/distribution/ticketMr'
  import { pagePerformTimeList } from "@/api/schedulingMr/schedulingMr"
  import moment from "moment"
  export default {
    name: "Daily",
    dicts: [],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        responseData: {},
  
        // 是否显示弹出层
        open: false,
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: {
          // pageNum: 1,
          // pageSize: 10,
        },
        visibleStatus: false,
        newObj: {},
        visibleType: '',
        handleExportLoading: false,
        tableData: {},
        ticketList: [],
        seatList: [],
        multiPerformDate:false,
        pagePerformTimeList: [], // 场次列表
      };
    },
    created() {
      // this.$set(this.queryParams,'performDate',moment().format("yyyy-MM-DD"));
      this.$set(this.queryParams,'performDate',moment().add(1, 'days').format('YYYY-MM-DD'));
      this.pagePerformTimeListFun(this.performDate)
      this.getList();
    //   this.ticketListApi();
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        if(this.queryParams.time){
          this.queryParams.performStartDate = this.queryParams.time[0];
          this.queryParams.performEndDate = this.queryParams.time[1];
        }
        bookingReportCount(this.addDateRange(this.queryParams, this.dateRange))
        .then(response => {
            // this.responseData = response.data;
            
            this.dataList = response.data.rows||[];
            this.total = response.data.total||0;
            this.loading = false;
          }
        ).catch(()=>{
          this.loading = false;
        });
      },
      /** 票务列表查询 */
      ticketListApi() {
        this.ticketList = []
        seatPricePageList(this.addDateRange({pageNum: 1, pageSize: 100}))
          .then(response => {
            let ticketItemList = []
            response.data.rows.forEach(item => {
              if(ticketItemList.indexOf(item.goodsId) == -1){
                this.ticketList.push(item);
                ticketItemList.push(item.goodsId);
              }
            })
          });
      },
      /** 座位类型列表 */
      getSeatTypeList(obj) {
        seatPricePageList(this.addDateRange({pageNum: 1, pageSize: 100, goodsId: obj.goodsId}))
          .then(response => {
            let ticketList = []
            response.data.rows.forEach(item => {
              if(ticketList.indexOf(item.seatTypeId) == -1){
                this.seatList.push(item);
                ticketList.push(item.seatTypeId);
              }
            })
          });
      },
      // 取消按钮
      cancel() {
        this.open = false;
      },
      // 票务改变事件
      goodsChangeEven() {
        this.seatList = [];
        this.$set(this.queryParams, 'seatTypeId', '');
        let selectMap = {goodsId: this.queryParams.goodsId}
        this.getSeatTypeList(selectMap);
      },
      /** 搜索按钮操作 */
      handleQuery() {
        // this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.seatList = [];
        this.$set(this.queryParams, 'time', '');
        this.$set(this.queryParams, 'performStartDate', '');
        this.$set(this.queryParams, 'performEndDate', '');
        this.$set(this.queryParams, 'goodsId', '');
        this.$set(this.queryParams, 'seatTypeId', '');
        this.$set(this.queryParams, 'timeId', '');
        // this.queryParams.pageNum = 1;
        // this.$set(this.queryParams,'performDate',moment().format("yyyy-MM-DD"));
        this.$set(this.queryParams,'performDate',moment().add(1, 'days').format('YYYY-MM-DD'));
        this.handleQuery();
      },
      dateChange(e){
        this.queryParams.timeId = '';
        this.pagePerformTimeListFun(e)
      },
      async pagePerformTimeListFun(value) {
            // console.log('value',value);
            try {
                let { data,code } = await pagePerformTimeList({
                performDate: this.queryParams.performDate,
                pageNum: 1,
                pageSize: 999
                })
                this.pagePerformTimeList = [].concat(data.rows);
                // if(data.rows[0]){
                //   this.queryParams.timeId = data.rows[0].id;
                // }
                // this.getList();
            } catch (error) {
                console.log('pagePerformTimeListFun error',error);
            }
        },
      /**
       * 导出报表
       * @date 2022-10-24
       * @returns {any}
       */
      handleExport() {
        this.$confirm('您确定要导出当前查询的数据吗？', '提示', {
          confirmButtonText: '确定 ',
          cancelButtonText: '取消 ',
          type: 'warning'
        })
          .then(() => {
            this.handleExportLoading = true;
            // const { pageNum, pageSize} = this.params;
            let postMap = {}
            for (let key in this.queryParams) {
              if(key != 'pageNum' && key != 'pageSize'){
                postMap[key] = this.queryParams[key]
              }
            }
            bookingReportCountExport(postMap)
              .then((res) => {
                exportExcel(res, '预定报表', '.xlsx');
                this.handleExportLoading = false;
              })
              .catch(() => {
                this.handleExportLoading = false;
              });
          })
          .catch(() => {
            this.$message.info('您已取消导出！');
          });
      },
    }
  };
  </script>
  <style lang="scss" scoped>
  </style>