<template>
    <el-dialog title="阀井目录" :visible.sync="show" width="1100px" append-to-body>
      <el-tabs  v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="阀井目录" name="1">
          <el-form :model="queryParams" ref="queryForm" :inline="true">
            <el-form-item label="阀井名称" prop="valveWellName">
              <el-input
                v-model="queryParams.valveWellName"
                placeholder="请输入阀井名称"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="位置" prop="position">
              <el-input
                v-model="queryParams.position"
                placeholder="请输入位置"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="时间范围" prop="createTimes">
              <el-date-picker
                v-model="queryParams.createTimes"
                type="datetimerange"
                :picker-options="pickerOptions"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                align="right">
              </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-button @click="getData">选择</el-button>
            </el-form-item>
          </el-form>
          <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序列" width="70">
              <template slot-scope="scope">
                {{(queryParams1.pageNum-1)*queryParams1.pageSize+scope.$index+1}}
              </template>
            </el-table-column>
            <el-table-column label="阀井名称" align="center" prop="valveWellName" />
            <el-table-column label="位置" align="center" prop="position" />
            <el-table-column label="经度" align="center" prop="longitude" />
            <el-table-column label="纬度" align="center" prop="latitude" />
            <el-table-column label="控制区域" align="center" prop="remark" />
            <el-table-column label="行政区" align="center" prop="district" >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.district" :value="scope.row.district"/>
              </template>
            </el-table-column>
            <el-table-column label="队伍" align="center" prop="team" />
            <el-table-column label="阀头形状" align="center" prop="valveHeadShape" />
            <el-table-column label="阀井深度(米)" align="center" prop="valveWellDepth" />
            <el-table-column label="井盖代别" align="center" prop="manholeCoverInstead" />
            <el-table-column label="积水情况" align="center" prop="waterCondition" />
            <el-table-column label="压力等级" align="center" prop="pressureRating" />
            <el-table-column label="是否需要下井才能开关阀门" align="center" prop="isXyxjcnkg" />
            <el-table-column label="备注" align="center" prop="remarks" show-overflow-tooltip/>
          </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </el-tab-pane>
        <el-tab-pane label="我管理的" name="2">
          <el-table v-loading="loading1" :data="myList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序列" width="70">
              <template slot-scope="scope">
                {{(queryParams.pageNum-1)*queryParams.pageSize+scope.$index+1}}
              </template>
            </el-table-column>
            <el-table-column label="阀井名称" align="center" prop="valveWellName" />
            <el-table-column label="位置" align="center" prop="position" />
            <el-table-column label="经度" align="center" prop="longitude" />
            <el-table-column label="纬度" align="center" prop="latitude" />
            <el-table-column label="控制区域" align="center" prop="remark" />
            <el-table-column label="行政区" align="center" prop="district" >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.district" :value="scope.row.district"/>
              </template>
            </el-table-column>
            <el-table-column label="队伍" align="center" prop="team" />
            <el-table-column label="阀头形状" align="center" prop="valveHeadShape" />
            <el-table-column label="阀井深度(米)" align="center" prop="valveWellDepth" />
            <el-table-column label="井盖代别" align="center" prop="manholeCoverInstead" />
            <el-table-column label="积水情况" align="center" prop="waterCondition" />
            <el-table-column label="压力等级" align="center" prop="pressureRating" />
            <el-table-column label="是否需要下井才能开关阀门" align="center" prop="isXyxjcnkg" />
            <el-table-column label="备注" align="center" prop="remarks" show-overflow-tooltip/>
            <el-table-column label="操作" align="center" fixed>
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                >删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total1>0"
            :total="total1"
            :page.sync="queryParams1.pageNum"
            :limit.sync="queryParams1.pageSize"
            @pagination="getlist"
          />
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeF')">关 闭</el-button>
      </div>
    </el-dialog>
</template>


<script>
import {addNetworkRelation, listNetworkRelation, myListArea} from "@/api/gas/networkRelation";
import Cookies from 'js-cookie'
import {listArea} from "@/api/gas/area";
import {addValvewellRelation, delValvewellRelation, myListValveWell} from "@/api/gas/valvewellRelation";
import {listValveWellPosition} from "@/api/gas/valveWellPosition";
import {delRegulatorBoxRelation} from "@/api/gas/regulatorBoxRelation";
export default {
  name: "vw",
  dicts: ['district'],
  data() {
    return {
      activeName:'1',
      show:false,
      // 遮罩层
      loading: false,
      loading1: false,
      total: 0,
      total1: 0,
      list: [],
      myList: [],
      title: "",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        valveWellName: undefined,
        jobNum:undefined,
        position: undefined,
        longitude: undefined,
        latitude: undefined,
        createTimes:[]
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      queryParams1: {
        pageNum: 1,
        pageSize: 10,
        jobNum:undefined,
        valveWellName: undefined,
        position: undefined,
        longitude: undefined,
        latitude: undefined,
        createTimes:[]
      },
      ids:[],
      workerListSelect:[],
      jobNum:undefined,
    };
  },
  beforeDestroy() {
    this.list = []
    this.ids = []
  },created() {
  },
  methods: {
    handleDelete(row) {
      const ids = row.id;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(() => {
        this.loading1 = true;
        return delValvewellRelation(ids,this.jobNum);
      }).then(() => {
        this.loading1 = false;
        this.getlist();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading1 = false;
      });
    },
    getlist(){
      this.loading1 = true;
      myListValveWell(this.queryParams1).then(response => {
        this.myList = response.rows;
        this.total1 = response.total;
        this.loading1 = false;
      });
    },
    handleClick(tab,event){
      if (this.activeName=='2'){
        this.queryParams1.pageNum=1
        this.queryParams1.jobNum=this.jobNum
        this.getlist()
      }else {
        this.queryParams.pageNum=1;
        this.queryParams.jobNum=this.jobNum
        this.getList();
      }
    },
    getData(){
      this.loading1=true
      let entity = {ids:[],jobNum:this.jobNum};
      entity.ids = this.ids;
      addValvewellRelation(entity).then(res=>{
        if (res.code===200){
          this.$msgbox.alert('添加成功')
          this.loading1=false
          this.getList()
        }
      }).catch(e=>{
        this.loading1=false
        this.getList()
      })
    },
    init(user){
      if (!user) return;
      console.log(user)
      this.show=true
      this.jobNum = user.id
      this.getList(user)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.createTimes = [];
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      console.log(this.ids
      )
    },
    /** 查询调压箱管理列表 */
    getList(user) {
      this.loading = true;
      this.queryParams.jobNum=this.jobNum
      listValveWellPosition(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  }
};
</script>
