<template>
  <div class="app-container">

    <div v-if="-2 == $store.state.user.enterpriseId">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input
            v-model="queryParams.enterpriseName"
            placeholder="请输入企业名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="上报时间">
          <el-date-picker
            v-model="dateRange"
            size="small"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="timeChange"
          ></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="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:day:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >删除</el-button>
        </el-col>-->
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="dayList">
        <!--<el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column label="企业名称" align="center" prop="enterpriseName"  width="180" :show-overflow-tooltip="true"/>
        <el-table-column label="天然气总气量/wm³" align="center" prop="fGasUsage" width="150"/>
        <el-table-column label="天然气城镇居民用量/wm³" align="center" prop="fUrbanGasUsage" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.fUrbanGasUsage">{{ scope.row.fUrbanGasUsage }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="天然气农村气代煤居民用量/wm³" align="center" prop="fRuralReplaceResidentsGasUsage" width="210">
          <template slot-scope="scope">
            <span v-if="scope.row.fRuralReplaceResidentsGasUsage">{{ scope.row.fRuralReplaceResidentsGasUsage }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="液化石油气总量/t" align="center" prop="fLpgUsage" width="150"/>
        <el-table-column label="液化石油气城镇居民用量/t" align="center" prop="fUrbanLpgUsage" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.fUrbanLpgUsage">{{ scope.row.fUrbanLpgUsage }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="液化石油气农村居民用量/t" align="center" prop="fRuralLpgUsage" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.fRuralLpgUsage">{{ scope.row.fRuralLpgUsage }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="上报省厅状态" align="center" prop="fGovUploadStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.fGovUploadStatus == '0'">未上报</span>
            <span v-else-if="scope.row.fGovUploadStatus == '1'">已上报</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="上报省厅日期" align="center" prop="fGovUploadTime" width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.fGovUploadTime">{{ parseTime(scope.row.fGovUploadTime, '{y}-{m}-{d} {h}:{i}') }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
           <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleDetail(scope.row)"
            >详情</el-button>
           <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>-->
            <el-button
              size="mini"
              type="text"
              @click="handleReport(scope.row)"
            >上报</el-button>
          </template>
        </el-table-column>
      </el-table>

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


    <!-- 添加或修改供需平衡-企业每日填报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业uuid" prop="fCompanyInfoId">
          <el-input v-model="form.fCompanyInfoId" placeholder="请输入企业uuid" />
        </el-form-item>
        <el-form-item label="天然气城镇居民用量" prop="fUrbanGasUsage">
          <el-input v-model="form.fUrbanGasUsage" placeholder="请输入天然气城镇居民用量" />
        </el-form-item>
        <el-form-item label="天然气农村气代煤居民用量" prop="fRuralReplaceResidentsGasUsage">
          <el-input v-model="form.fRuralReplaceResidentsGasUsage" placeholder="请输入天然气农村气代煤居民用量" />
        </el-form-item>
        <el-form-item label="天然气农村非气代煤居民用量" prop="fNoRuralReplaceResidentsGasUsage">
          <el-input v-model="form.fNoRuralReplaceResidentsGasUsage" placeholder="请输入天然气农村非气代煤居民用量" />
        </el-form-item>
        <el-form-item label="天然气工业用量" prop="fIndustrialGasUsage">
          <el-input v-model="form.fIndustrialGasUsage" placeholder="请输入天然气工业用量" />
        </el-form-item>
        <el-form-item label="天然气商业用量" prop="fCommercialGasUsage">
          <el-input v-model="form.fCommercialGasUsage" placeholder="请输入天然气商业用量" />
        </el-form-item>
        <el-form-item label="天然气公福用量" prop="fPublicGasUsage">
          <el-input v-model="form.fPublicGasUsage" placeholder="请输入天然气公福用量" />
        </el-form-item>
        <el-form-item label="天然气城市集中供热锅炉用量" prop="fCityHeatingGasUasge">
          <el-input v-model="form.fCityHeatingGasUasge" placeholder="请输入天然气城市集中供热锅炉用量" />
        </el-form-item>
        <el-form-item label="天然气汽车用户用量" prop="fCarGasUsage">
          <el-input v-model="form.fCarGasUsage" placeholder="请输入天然气汽车用户用量" />
        </el-form-item>
        <el-form-item label="出售给其他燃气企业的天然气量" prop="fSoldGasVolume">
          <el-input v-model="form.fSoldGasVolume" placeholder="请输入出售给其他燃气企业的天然气量" />
        </el-form-item>
        <el-form-item label="天然气总凄凉" prop="fGasUsage">
          <el-input v-model="form.fGasUsage" placeholder="请输入天然气总凄凉" />
        </el-form-item>
        <el-form-item label="液化石油气城镇居民用量" prop="fUrbanLpgUsage">
          <el-input v-model="form.fUrbanLpgUsage" placeholder="请输入液化石油气城镇居民用量" />
        </el-form-item>
        <el-form-item label="液化石油气农村居民用量" prop="fRuralLpgUsage">
          <el-input v-model="form.fRuralLpgUsage" placeholder="请输入液化石油气农村居民用量" />
        </el-form-item>
        <el-form-item label="液化石油气工业用量(吨)" prop="fIndustrialLpgUsage">
          <el-input v-model="form.fIndustrialLpgUsage" placeholder="请输入液化石油气工业用量(吨)" />
        </el-form-item>
        <el-form-item label="液化石油气商业用量(吨)" prop="fCommercialLpgUsage">
          <el-input v-model="form.fCommercialLpgUsage" placeholder="请输入液化石油气商业用量(吨)" />
        </el-form-item>
        <el-form-item label="液化石油气公福用量(吨)" prop="fPublicLpgUsage">
          <el-input v-model="form.fPublicLpgUsage" placeholder="请输入液化石油气公福用量(吨)" />
        </el-form-item>
        <el-form-item label="液化石油气汽车用户用量(吨)" prop="fCarLpgUsage">
          <el-input v-model="form.fCarLpgUsage" placeholder="请输入液化石油气汽车用户用量(吨)" />
        </el-form-item>
        <el-form-item label="出售或调拨给其他燃气企业液化石油气量(吨)" prop="fSoldLpgVolume">
          <el-input v-model="form.fSoldLpgVolume" placeholder="请输入出售或调拨给其他燃气企业液化石油气量(吨)" />
        </el-form-item>
        <el-form-item label="液化石油气总量(吨)" prop="fLpgUsage">
          <el-input v-model="form.fLpgUsage" placeholder="请输入液化石油气总量(吨)" />
        </el-form-item>
        <el-form-item label="记录时间，日，格式:2023-09-01" prop="fReportRecord">
          <el-input v-model="form.fReportRecord" placeholder="请输入记录时间，日，格式:2023-09-01" />
        </el-form-item>
        <el-form-item label="上报时间，日，格式:2023-09-01" prop="fReportTime">
          <el-input v-model="form.fReportTime" placeholder="请输入上报时间，日，格式:2023-09-01" />
        </el-form-item>
        <el-form-item label="创建时间 yyyy-MM-dd hh:mm:ss" prop="fCreateTime">
          <el-input v-model="form.fCreateTime" placeholder="请输入创建时间 yyyy-MM-dd hh:mm:ss" />
        </el-form-item>
        <el-form-item label="最后修改时间 yyyy-MM-dd hh:mm:ss" prop="fUpdateTime">
          <el-input v-model="form.fUpdateTime" placeholder="请输入最后修改时间 yyyy-MM-dd hh:mm:ss" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <div v-if="-2 != $store.state.user.enterpriseId" class="report-content">
      <el-row style="margin-left: -3.5px;margin-right: -3.5px">
        <el-col :span="12" style="padding: 0px 3.5px 0px 3.5px">
          <div class="report-title">
            <div class="title">上报记录</div>
          </div>
          <div class="content">
            <!-- 日历 -->
            <Calendar
              width="100%"
              v-model="reportDate"
              :scheduleData="scheduleData"
              @dateChange="dateChange"
            />
          </div>
        </el-col>

        <el-col :span="12" style="padding: 0px 3.5px 0px 3.5px">
          <div class="report-title flex-between">
            <div class="title">上报情况</div>
            <el-button
              type="primary"
              size="small"
              @click="reportInfo"
            >
              上报
            </el-button>
          </div>
          <div class="content">
            <div class="state-warp">
              <el-row>
                <el-col :span="13">
                  <div class="label-warp">状态</div>
                  <div class="value-warp">
                    <span v-if="reportForm.fReportStatus == '1'">已上报</span>
                    <span v-else>未上报</span>
                  </div>
                </el-col>
                <el-col :span="11" style="padding-left: 45px">
                  <div class="label-warp">上报时间</div>
                  <div class="value-warp">
                    <span v-if="reportForm.fReportTime">{{ reportForm.fReportTime }}</span>
                    <span v-else>暂无</span>
                  </div>
                </el-col>
              </el-row>
            </div>

            <div class="report-form" >
              <el-form ref="reportForm" label-position="top" :rules="rules" label-width="80px" :model="reportForm">
                <el-row class="el-row-table">
                  <el-col :span="12" style="padding-right: 2px">
                    <el-col :span="24" class="sort-type">
                      天然气
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="天然气总气量(万立方米)" prop="fGasUsage">
                        <el-input type="Number" v-model="reportForm.fGasUsage" placeholder="请输入天然气总气量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气农村气代煤居民用量(万立方米)" prop="fRuralReplaceResidentsGasUsage">
                        <el-input type="Number" v-model="reportForm.fRuralReplaceResidentsGasUsage" placeholder="请输入天然气农村气代煤居民用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气工业用量(万立方米)" prop="fIndustrialGasUsage">
                        <el-input type="Number" v-model="reportForm.fIndustrialGasUsage" placeholder="请输入天然气工业用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气公福用量(万立方米)" prop="fPublicGasUsage">
                        <el-input type="Number" v-model="reportForm.fPublicGasUsage" placeholder="请输入天然气公福用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气汽车用户用量(万立方米)" prop="fCarGasUsage">
                        <el-input type="Number" v-model="reportForm.fCarGasUsage" placeholder="请输入天然气汽车用户用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-col :span="24" class="sort-type">
                        石油气
                      </el-col>
                      <el-form-item label="液化石油气总量(吨)" prop="fLpgUsage">
                        <el-input type="Number" v-model="reportForm.fLpgUsage" placeholder="请输入液化石油气总量(吨)" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气农村居民用量(吨)" prop="fRuralLpgUsage">
                        <el-input type="Number" v-model="reportForm.fRuralLpgUsage" placeholder="请输入液化石油气农村居民用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气商业用量(吨)" prop="fCommercialLpgUsage">
                        <el-input type="Number" v-model="reportForm.fCommercialLpgUsage" placeholder="请输入液化石油气商业用量(吨)" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气汽车用户用量(吨)" prop="fCarLpgUsage">
                        <el-input type="Number" v-model="reportForm.fCarLpgUsage" placeholder="请输入液化石油气汽车用户用量(吨)" />
                      </el-form-item>
                    </el-col>


                  </el-col>

                  <el-col :span="12" style="padding-left: 2px;padding-right: 1px">
                    <el-col :span="24" class="sort-type">

                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="天然气城镇居民用量(万立方米)" prop="fUrbanGasUsage">
                        <el-input type="Number" v-model="reportForm.fUrbanGasUsage" placeholder="请输入天然气城镇居民用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气农村非气代煤居民用量(万立方米)" prop="fNoRuralReplaceResidentsGasUsage">
                        <el-input type="Number" v-model="reportForm.fNoRuralReplaceResidentsGasUsage" placeholder="请输入天然气农村非气代煤居民用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气商业用量(万立方米)" prop="fCommercialGasUsage">
                        <el-input type="Number" v-model="reportForm.fCommercialGasUsage" placeholder="请输入天然气商业用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="天然气城市集中供热锅炉用量(万立方米)" prop="fCityHeatingGasUasge">
                        <el-input type="Number" v-model="reportForm.fCityHeatingGasUasge" placeholder="请输入天然气城市集中供热锅炉用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="出售给其他燃气企业的天然气量(万立方米)" prop="fSoldGasVolume">
                        <el-input type="Number" v-model="reportForm.fSoldGasVolume" placeholder="请输入出售给其他燃气企业的天然气量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24" class="sort-type">
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气城镇居民用量" prop="fUrbanLpgUsage">
                        <el-input type="Number" v-model="reportForm.fUrbanLpgUsage" placeholder="请输入液化石油气城镇居民用量" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气工业用量(吨)" prop="fIndustrialLpgUsage">
                        <el-input type="Number" v-model="reportForm.fIndustrialLpgUsage" placeholder="请输入液化石油气工业用量(吨)" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="液化石油气公福用量(吨)" prop="fPublicLpgUsage">
                        <el-input type="Number" v-model="reportForm.fPublicLpgUsage" placeholder="请输入液化石油气公福用量(吨)" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">
                      <el-form-item label="出售给其他燃气企业液化石油气量(吨)" prop="fSoldLpgVolume">
                        <el-input type="Number" v-model="reportForm.fSoldLpgVolume" placeholder="请输入出售给其他燃气企业液化石油气量(吨)" />
                      </el-form-item>
                    </el-col>

                    <el-col :span="24">

                    </el-col>

                  </el-col>

                </el-row>
              </el-form>
            </div>

            <!--<div style="border: 1px solid;height: 500px"></div>-->
          </div>


        </el-col>
      </el-row>
    </div>

    <!-- 详情 -->
    <DetailInfo ref="detail"/>
  </div>
</template>

<script>
import { listDay, getDay, delDay, addDay, updateDay, exportDay, reportInfoList, getReportInfoByCompany, reportSupBalGasDayRecInfo } from "@/api/supplybalance/day";
import Calendar from "@/components/Calendar";
import moment from "moment";
import DetailInfo from "./components/DetailInfo";
export default {
  name: "Day",
  components: {
    Calendar,
    DetailInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供需平衡-企业每日填报表格数据
      dayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fCompanyInfoId: null,
        enterpriseName: null,
        beginRepDate: null,
        endRepDate: null,
      },
      // 表单参数
      form: {},
      // 所属区域字典
      townshipOptions: [],
      // 表单校验
      rules: {
        fGasUsage: [
          { required: true, message: "天然气总气量不能为空", trigger: "blur" }
        ],
        fLpgUsage: [
          { required: true, message: "液化石油气总量不能为空", trigger: "blur" }
        ],
      },
      scheduleData:[
        {date:'2024-06-19',content:'已上报'},
        {date:'2024-06-17',content:'未上报'},
        {date:'2024-06-15',content:'已上报'},
        {date:'2024-06-14',content:'已上报'}
      ],
      reportForm: {},
      reportDate: moment().format('YYYY-MM-DD'),
      dateRange: []
    };
  },
  created() {
    this.getDicts("t_township").then(response => {
      this.townshipOptions = response.data;
    });
    if(-2 == this.$store.state.user.enterpriseId){
      this.getList();
      //return;
    }
    // 获取当月开始时间
    const startOfMonth = moment().startOf('month').format('YYYY-MM-DD HH:mm:ss');
    // 获取当月结束时间
    const endOfMonth = moment().endOf('month').format('YYYY-MM-DD HH:mm:ss');
    this.currentMonthReportInfo(startOfMonth,endOfMonth);


  },
  mounted(){
    this.getReportInfo();
  },
  methods: {
    // 所属区域字典翻译
    townshipFormat(row, column) {
      return this.selectDictLabel(this.townshipOptions, row.township);
    },
    /** 查询供需平衡-企业每日填报列表 */
    getList() {
      this.loading = true;
      listDay(this.queryParams).then(response => {
        this.dayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fRepUsgDayId: null,
        fCompanyInfoId: null,
        fUrbanGasUsage: null,
        fRuralReplaceResidentsGasUsage: null,
        fNoRuralReplaceResidentsGasUsage: null,
        fIndustrialGasUsage: null,
        fCommercialGasUsage: null,
        fPublicGasUsage: null,
        fCityHeatingGasUasge: null,
        fCarGasUsage: null,
        fSoldGasVolume: null,
        fGasUsage: null,
        fUrbanLpgUsage: null,
        fRuralLpgUsage: null,
        fIndustrialLpgUsage: null,
        fCommercialLpgUsage: null,
        fPublicLpgUsage: null,
        fCarLpgUsage: null,
        fSoldLpgVolume: null,
        fLpgUsage: null,
        fReportRecord: null,
        fReportTime: null,
        fCreateTime: null,
        fUpdateTime: null
      };
      this.resetForm("form");
    },
    resetReportForm() {
      this.reportForm = {
        fRepUsgDayId: null,
        fCompanyInfoId: null,
        fUrbanGasUsage: null,
        fRuralReplaceResidentsGasUsage: null,
        fNoRuralReplaceResidentsGasUsage: null,
        fIndustrialGasUsage: null,
        fCommercialGasUsage: null,
        fPublicGasUsage: null,
        fCityHeatingGasUasge: null,
        fCarGasUsage: null,
        fSoldGasVolume: null,
        fGasUsage: null,
        fUrbanLpgUsage: null,
        fRuralLpgUsage: null,
        fIndustrialLpgUsage: null,
        fCommercialLpgUsage: null,
        fPublicLpgUsage: null,
        fCarLpgUsage: null,
        fSoldLpgVolume: null,
        fLpgUsage: null,
        fReportRecord: null,
        fReportTime: null,
        fCreateTime: null,
        fUpdateTime: null
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.dateRange != null) {
        this.queryParams.beginRepDate = this.dateRange[0];
        this.queryParams.endRepDate = this.dateRange[1];
      } else {
        this.queryParams.beginRepDate = null;
        this.queryParams.endRepDate = null;
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.queryParams.beginRepDate = null;
      this.queryParams.endRepDate = null;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fRepUsgDayId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加供需平衡-企业每日填报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fRepUsgDayId = row.fRepUsgDayId || this.ids
      getDay(fRepUsgDayId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改供需平衡-企业每日填报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fRepUsgDayId != null) {
            updateDay(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDay(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fRepUsgDayIds = row.fRepUsgDayId || this.ids;
      this.$confirm('是否确认删除供需平衡-企业每日填报编号为"' + fRepUsgDayIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDay(fRepUsgDayIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有供需平衡-企业每日填报数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportDay(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    //日期切换
    dateChange(val){
      this.resetReportForm();
      this.getReportInfo();
      if(val == 0){
        const startOfMonth = moment(this.reportDate).startOf('month').format('YYYY-MM-DD HH:mm');
        // 获取当月结束时间
        const endOfMonth = moment(this.reportDate).endOf('month').format('YYYY-MM-DD HH:mm');
        this.currentMonthReportInfo(startOfMonth,endOfMonth);
      }
    },
    reportInfo(){
      this.$refs["reportForm"].validate(valid => {
        if (valid) {
          if (this.reportForm.fRepUsgDayId != null) {
            let that = this;
            this.$confirm('当前已上报，是否确认再次上报?', "警告", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(function() {
              that.reportForm.fReportTime =  moment().format('YYYY-MM-DD HH:mm');
              that.reportForm.calendarDate = that.reportDate;
              that.reportForm.fReportStatus = '1';
              return updateDay(that.reportForm);
            }).then(() => {
              that.getReportInfo();
              that.msgSuccess("上报成功");
            }).catch(() => {});
          } else {
            this.reportForm.fReportTime =  moment().format('YYYY-MM-DD HH:mm');
            this.reportForm.fCalendarDate = this.reportDate;
            this.reportForm.fReportStatus = '1';
            addDay(this.reportForm).then(response => {
              this.msgSuccess("上报成功");
              const startOfMonth = moment(this.reportDate).startOf('month').format('YYYY-MM-DD');
              // 获取当月结束时间
              const endOfMonth = moment(this.reportDate).endOf('month').format('YYYY-MM-DD');
              this.currentMonthReportInfo(startOfMonth,endOfMonth);
              this.getReportInfo();
            });
          }
        }
      });
    },
    currentMonthReportInfo(beginCurrentMonthDate,endCurrentMonthDate){
      reportInfoList({fCompanyInfoId:this.$store.state.user.enterpriseId,beginCurrentMonthDate:beginCurrentMonthDate,endCurrentMonthDate:endCurrentMonthDate}).then(res =>{
        if(res.code == 200 && res.data){
          this.scheduleData = [];
            res.data.forEach(item =>{
              this.scheduleData.push({date:item.fCalendarDate,content:item.fReportStatus == '1'?"已上报":"未上报"})
          })
        }
      })
    },
    getReportInfo(){
      getReportInfoByCompany({companyId:this.$store.state.user.enterpriseId,calendarDate:this.reportDate}).then(res =>{
          if(res.code && res.data){
          this.reportForm = res.data;
        }
      })
    },
    //详情
    handleDetail(row){
      this.$refs.detail.getDetailInfo(row.fRepUsgDayId);
    },
    timeChange(val){
      this.queryParams.beginRepDate = val[0];
      this.queryParams.endRepDate = val[1];
    },
    //上传
    handleReport(row) {
      this.$confirm('是否确认上报日用气量编号为"' + row.fRepUsgDayId + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return reportSupBalGasDayRecInfo({fRepUsgDayId : row.fRepUsgDayId});
      }).then(() => {
        this.getList();
        this.msgSuccess("上报成功");
      }).catch(() => {});
    },
  }
};
</script>
<style scoped lang="scss">
  .report-content{
    //border: 1px solid;
    margin: auto;
    max-width: 1200px;
    padding: 30px
  }

  .report-title{
    background: rgb(241, 241, 242);
    padding: 20px 30px;
    border-radius: 3px;
  }

  .report-title .title{
    line-height: 32px;
    font-weight: 500;
  }

  .content{
    background: var(--custom-background-soft);
    box-shadow: 0 3px 14px #a9aaab80;
    border-radius: 3px;
    padding: 32px 48px;
    height: 525px;
  }

  .report-form{
    height: 84%;
    overflow-y: auto;
    &::-webkit-scrollbar {
      /* 设置滚动条宽度 */
      width: 4px;
      /* 设置滚动条背景色 */
      //background: black;
    }

    //滚动条轨道
    &::-webkit-scrollbar-track {
      background-color:transparent;
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius:2em;
    }

    //滚动条滑块
    &::-webkit-scrollbar-thumb {
      background-color: rgb(147,147,153,0.5);
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius:2em;
    }

    ::v-deep .el-form--label-top .el-form-item__label{
      padding: 0px;
      font-size: 12px;
    }

    ::v-deep .el-form-item {
      margin-bottom: 7px;
    }
  }

  .state-warp{
    border-bottom: 1px solid #d4d4d4;
    height: 54px;
    margin-top: -10px;
    padding-bottom: 8px;
    margin-bottom: 24px;
    color: var(--custom-main-text-color);
  }
  .label-warp{
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(24, 31, 67, .5);
    line-height: 20px;
  }

  .value-warp{
    font-weight: 500;
    font-size: 18px;
    line-height: 25px;
  }

  .flex-between{
    display: flex;
    justify-content: space-between;
  }

  .sort-type{
    height: 25px;
    font-weight: 600;
    margin: 0px 0px 6px 0px;
  }
</style>
