<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="线路名称" prop="electLineName">
        <el-input
          v-model="queryParams.electLineName"
          placeholder="请输入线路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主分支名称" prop="branchName" label-width="100px">
        <el-input
          v-model="queryParams.branchName"
          placeholder="请输入主分支名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划检修超期" label-width="100px">
			<el-select
			  style="margin-right: 8px"
			  size="mini"
			  v-model="queryParams.maintenanceOverdue"
			  placeholder="请选择"
			  clearable
			>
			  <el-option label="全部" value=""> </el-option>
			  <el-option
			    v-for="item in maintenanceTimeList"
			    :key="item.parValue"
			    :label="`${item.parValue}${item.parUnitCn}`"
			    :value="`${item.parValue}|${item.parUnit}`"
			  >
			  </el-option>
			</el-select>
      </el-form-item>
      <el-form-item label="重复停电" >
		  <el-select
		    style="margin-right: 8px"
		    size="mini"
		    v-model="queryParams.repeatPowerCut"
		    placeholder="请选择"
		    clearable
		  >
		    <el-option label="全部" value=""> </el-option>
		    <el-option
		      v-for="item in repeatPowerFailureList"
		      :key="item.parValue"
		      :label="`${item.parValue}${item.parUnitCn}`"
		      :value="`${item.parValue}|${item.parUnit}`"
		    >
		    </el-option>
		  </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-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['powerdistribution:maintenance:statistics:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="maintenanceStatisticsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="事件序号" align="center" prop="eventNo" width="100" fixed >
		  <template slot-scope="scope">
		  <a @click="table_show(scope.row, scope.$index)" style="color: #00afff;cursor: pointer">{{scope.row.eventNo}}</a>
		  </template>
      </el-table-column>
      <el-table-column label="线路名称" align="center" prop="electLineName"  :show-overflow-tooltip="true" width="160" fixed />
      <!--el-table-column label="主分支名称" align="center" prop="branchName"  :show-overflow-tooltip="true" width="120" fixed/-->
      <el-table-column label="数据状态" align="center" prop="dataStatus" fixed/>
      <el-table-column label="推送状态" align="center" prop="pushStatus" fixed/>
      <el-table-column label="是否可维护" align="center" prop="isMaintainable" width="100" fixed/>
      <el-table-column label="是否纯专变" align="center" prop="isPureSpecia" width="100" fixed/>
      <el-table-column label="事件类型" align="center" prop="eventType" fixed/>
      <el-table-column label="停电起始时间" align="center" prop="powerOutageStart" width="180" fixed>
        <!--template slot-scope="scope">
          <span>{{ parseTime(scope.row.powerOutageStart, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template-->
      </el-table-column>
      <el-table-column label="停电终止时间" align="center" prop="powerOutageEnd" width="180" fixed>
        <!--template slot-scope="scope">
          <span>{{ parseTime(scope.row.powerOutageEnd, '{y}-{m}-{d}') }}</span>
        </template-->
      </el-table-column>
      <el-table-column label="停电时户数" align="center" prop="powerOutageDuringHouseholds" width="100" />
      <el-table-column label="研判停电性质" align="center" prop="powerOutageNature" width="100" />
      <el-table-column label="所属市公司" align="center" prop="city" width="150" />
      <el-table-column label="所属县公司" align="center" prop="county" width="150" />
      <el-table-column label="所属供电所" align="center" prop="station" width="150" />
      <el-table-column label="单位编码" align="center" prop="oranNo" />
      <el-table-column label="变电站名称" align="center" prop="substationName" width="100"/>
      <el-table-column label="停电户次数" align="center" prop="powerOutageHouseholds" />
      <el-table-column label="停电线次数" align="center" prop="powerOutageLine" />
      <el-table-column label="无故障持续时间" align="center" prop="faultFreeDuration" />
      <el-table-column label="奖励金额" align="center" prop="rewardAmount" >
				<template slot-scope="scope">
				  <span>{{ scope.row.rewardAmount }}/元</span>
				</template>
			</el-table-column>
     
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
	</div>
	
</template>

<script>
import recordDetails from './details'
import { listMaintenanceStatistics, getMaintenanceStatistics, delMaintenanceStatistics, addMaintenanceStatistics, updateMaintenanceStatistics } from "@/api/powerdistribution/maintenance";
import { listByParType } from "@/api/powerdistribution/par";
import { getDicts } from "@/api/system/dict/data";
export default {
  name: "MaintenanceStatistics",
  dicts: ["pdm_maintenance_time","repeat_power_failure"],
  components: {
  	recordDetails
  },
  data() {
    return {
			dialog: {
				detailsSave:false
			},
			visible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 线路检修完成情况表格数据
      maintenanceStatisticsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventNo: null,
        electLineName: null,
        branchName: null,
        dataStatus: null,
        pushStatus: null,
        isMaintainable: null,
        isPureSpecia: null,
        eventType: null,
        powerOutageStart: null,
        powerOutageEnd: null,
        powerOutageDuringHouseholds: null,
        powerOutageNature: null,
        city: null,
        county: null,
        station: null,
        oranNo: null,
        substationName: null,
        powerOutageHouseholds: null,
        powerOutageLine: null,
        faultFreeDuration: null,
        rewardAmount: null
      },
      // 表单参数
      form: {},
	  maintenanceTimeList: [],
	  maintenanceTimeList2: [],
	  repeatPowerFailureList: [],
	  maintenanceTimeDicList: [],
      // 表单校验
      rules: {
        eventNo: [
          { required: true, message: "事情序号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
	this.getParList(0);
	this.getParList(1);
  },
  methods: {
    /** 查询线路检修完成情况列表 */
    getList() {
      this.loading = true;
      listMaintenanceStatistics(this.queryParams).then(response => {
        this.maintenanceStatisticsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
	async getParList(parType) {
	  this.queryParams.parType=parType;
	  await listByParType(this.queryParams).then(response => {
	   if(parType==0){
		   this.maintenanceTimeList= response.data;
		}
	   if(parType==1)this.repeatPowerFailureList= response.data;
	  });
	
	},
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        eventNo: null,
        electLineName: null,
        branchName: null,
        dataStatus: null,
        pushStatus: null,
        isMaintainable: null,
        isPureSpecia: null,
        eventType: null,
        powerOutageStart: null,
        powerOutageEnd: null,
        powerOutageDuringHouseholds: null,
        powerOutageNature: null,
        city: null,
        county: null,
        station: null,
        oranNo: null,
        substationName: null,
        powerOutageHouseholds: null,
        powerOutageLine: null,
        faultFreeDuration: null,
        rewardAmount: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.eventNo)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加线路检修完成情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const eventNo = row.eventNo || this.ids
      getMaintenanceStatistics(eventNo).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改线路检修完成情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.eventNo != null) {
            updateMaintenanceStatistics(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMaintenanceStatistics(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const eventNos = row.eventNo || this.ids;
      this.$modal.confirm('是否确认删除线路检修完成情况编号为"' + eventNos + '"的数据项？').then(function() {
        return delMaintenanceStatistics(eventNos);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('powerdistribution/maintenance/statistics/export', {
        ...this.queryParams
      }, `maintenanceStatistics_${new Date().getTime()}.xlsx`)
    },
	//查看
	table_show(row){
		this.dialog.detailsSave = true
		this.$nextTick(() => {
			this.$refs.detailsDialog.open().setData(row)
		})
	},
  }
};
</script>
