<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="planCode" label-width="120">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入月计划编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    
      </el-form-item>
    
      </el-form-item>
      <el-form-item label="区县单位" prop="county">
        <el-input
          v-model="queryParams.county"
          placeholder="请输入区县单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供电所" prop="station">
        <el-input
          v-model="queryParams.station"
          placeholder="请输入所属供电所"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="线路编号" prop="lineCode">
        <el-input
          v-model="queryParams.lineCode"
          placeholder="请输入线路编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="线路名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入线路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="success"
          plain
          icon="el-icon-upload"
          size="mini"
          :disabled="single"
          @click=""
          v-hasPermi="['powerdistribution:process:edit']"
        >人工上传</el-button>
      </el-col>
     
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload"
          size="mini"
		   :disabled="maintenancePalan"
          @click=""
          v-hasPermi="['powerdistribution:process:export']"
        >上传检修方案</el-button>
      </el-col>
	  <el-col :span="1.5">
	    <el-button
	      type="danger"
	      plain
	      icon="el-icon-upload"
	      size="mini"
		   :disabled="maintenancePalan"
	      @click=""
	      v-hasPermi="['powerdistribution:process:export']"
	    >上传审批单</el-button>
	  </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="processList" @selection-change="handleSelectionChange"
	    :row-class-name="getRowClassName"
	>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="月计划编号" align="center" prop="planCode"  width="150">
		  <template slot-scope="scope">
				<a @click="table_show(scope.row, scope.$index)" style="color:blue;cursor:pointer">{{scope.row.planCode}}</a>
		  </template>
	  </el-table-column>
      <el-table-column label="停电设备数" align="center" prop="powerOutageDevices" />
      <el-table-column label="月计划时户数" align="center" prop="perHourHouseholdsM" />
      <el-table-column label="周计划时户数" align="center" prop="perHourHouseholdsW" />
      <el-table-column label="市州单位" align="center" prop="city" width="150" />
      <el-table-column label="区县单位" align="center" prop="county" width="180"/>
      <el-table-column label="供电服务站/所" align="center" prop="station" width="120" :show-overflow-tooltip="true"/>
      <el-table-column label="线路编号" align="center" prop="lineCode"  width="120"/>
      <el-table-column label="线路名称" align="center" prop="lineName" width="130" />
	  <el-table-column label="人工计划时户数" align="center" prop="perHourHouseholdsArtif" />
	  <el-table-column label="是否超目标" align="center">
		  <template slot-scope="scope">
		  		<el-tag type="warning" effect="dark"  v-if="scope.row.perHourHouseholdsArtif>scope.row.perHourHouseholdsM">超目标</el-tag>
		  		<el-tag type="success" effect="dark"  v-else>正常</el-tag>
		  </template>
	  </el-table-column>
      <el-table-column label="申报单位" align="center" prop="declarAgency"  width="150"/>
      <el-table-column label="检修方案" align="center" prop="isMaintenance">
		  <template slot-scope="scope">
		  		<span v-if="scope.row.isMaintenance=='1'">待上传</span>
		  		<span type="info" effect="dark"  v-if="scope.row.isMaintenance=='0'">不需要</span>
				<span type="success" effect="dark"  v-if="scope.row.isMaintenance=='2'">已上传</span>
		  </template>
	  </el-table-column>
      <el-table-column label="审批单" align="center" prop="isApprove">
		  <template slot-scope="scope">
		  		<span v-if="scope.row.isApprove=='1'">待上传</span>
		  		<span type="info" effect="dark"  v-if="scope.row.isApprove=='0'">不需要</span>
		  		<span type="success" effect="dark"  v-if="scope.row.isApprove=='2'">已上传</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)"
            v-hasPermi="['powerdistribution:process:edit']"
          >修改</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"
    />

    <!-- 添加或修改检修计划全流程管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="月计划编号" prop="planCode">
          <el-input v-model="form.planCode" placeholder="请输入月计划编号"  readonly/>
        </el-form-item>
		<el-row :gutter="24">
			<el-col :lg="12">
				<el-form-item label="停电设备数" prop="powerOutageDevices">
				  <el-input-number v-model="form.powerOutageDevices" placeholder="请输入月计划停电设备数" min="0"/>
				</el-form-item>
			</el-col>
			<el-col :lg="12">
        <el-form-item label="时户数" prop="perHourHouseholdsM">
				<el-input-number v-model="form.perHourHouseholdsM" placeholder="请输入月计划时户数" min="0"/>
        </el-form-item>
		</el-col>
		</el-row>
        <el-row :gutter="24">
			<el-col :lg="12">
        <el-form-item label="所属市公司" prop="city">
          <el-input v-model="form.city" placeholder="请输入所属市公司" readonly/>
        </el-form-item>
			</el-col>
		<el-col :lg="12">
        <el-form-item label="所属县公司" prop="county">
          <el-input v-model="form.county" placeholder="请输入所属县公司" readonly/>
        </el-form-item>
			</el-col>
		</el-row>
		<el-row :gutter="24">
			<el-col :lg="12">
        <el-form-item label="所属供电所" prop="station">
          <el-input v-model="form.station" placeholder="请输入所属供电所" readonly/>
        </el-form-item>
			</el-col>
		<el-col :lg="12">
		<el-form-item label="申报单位" prop="declarAgency">
		  <el-input v-model="form.declarAgency" placeholder="请输入申报单位" readonly/>
		</el-form-item>
			</el-col>
		</el-row>
		<el-row :gutter="24">
			<el-col :lg="12">
        <el-form-item label="线路编号" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入线路编号" readonly/>
        </el-form-item>
			</el-col>
		<el-col :lg="12">
        <el-form-item label="线路名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入线路名称" readonly/>
        </el-form-item>
			</el-col>
       	</el-row>
      </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>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
  </div>
</template>

<script>
import { listProcess, getProcess, delProcess, addProcess, updateProcess } from "@/api/powerdistribution/process";
import recordDetails from './details'
export default {
  name: "Process",
  components: {
  	recordDetails
  },
  data() {
    return {
		dialog: {
			detailsSave:false
		},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
	  
	  // 检修计划
	  maintenancePalan: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检修计划全流程管理表格数据
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planCode: null,
        powerOutageDevices: null,
        perHourHouseholdsM: null,
        perHourHouseholdsW: null,
        city: null,
        county: null,
        station: null,
        lineCode: null,
        lineName: null,
        perHourHouseholdsArtif: null,
        declarAgency: null,
        isMaintenance: null,
        isApprove: null,
        maintenanceFilePath: null,
        approveFilePath: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询检修计划全流程管理列表 */
    getList() {
      this.loading = true;
      listProcess(this.queryParams).then(response => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        planCode: null,
        powerOutageDevices: null,
        perHourHouseholdsM: null,
        perHourHouseholdsW: null,
        city: null,
        county: null,
        station: null,
        lineCode: null,
        lineName: null,
        perHourHouseholdsArtif: null,
        declarAgency: null,
        isMaintenance: null,
        isApprove: null,
        maintenanceFilePath: null,
        approveFilePath: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
	  if(selection.length==1 && selection[0].isMaintenance>0){
		   this.maintenancePalan=false;
	  }else{
		   this.maintenancePalan=true;
	  }

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加检修计划全流程管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProcess(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改时户数/停电设备数";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProcess(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProcess(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除检修计划全流程管理编号为"' + ids + '"的数据项？').then(function() {
        return delProcess(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('powerdistribution/process/export', {
        ...this.queryParams
      }, `process_${new Date().getTime()}.xlsx`)
    },
	//查看
	table_show(row){
		this.dialog.detailsSave = true
		this.$nextTick(() => {
			this.$refs.detailsDialog.open().setData(row)
		})
	},
	    getRowClassName({ row }) {
	      // 根据row的某些属性决定是否高亮
	      if (row.perHourHouseholdsM-row.perHourHouseholdsW!=0) {
	        return 'highlight-row';
	      }
	      return '';
	    }
  }
};
</script>
<style>
/* 通过自定义类名添加高亮样式 */
.highlight-row {
  background-color: #ff0000; /* 浅绿色背景色 */
  color: #ff0000; /* 绿色文字 */
}
</style>