<template>
  <el-dialog
    title="安检记录"
    :visible.sync="open"
    width="1400px"
    append-to-body
    destroy-on-close
    :close-on-click-modal="false"
  >
    <el-row>
      <div class="top-title">{{ $parent.taskDetailData.title }}</div>
      <div class="user-title">用户信息</div>
      <el-col>
        <el-row class="container flex bb">
          <el-form label-width="100px">
            <el-col :span="8">
              <el-form-item label="单位名称">
                <span>{{ industryDetailInfo.company || "-" }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="信用代码">
                <span>{{ industryDetailInfo.contract || "-" }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="用户姓名">
                <span>{{ industryDetailInfo.username || "-" }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话">
                <span>{{ industryDetailInfo.phone || "-" }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="用户编号">
                <span>{{ industryDetailInfo.usernum || "-" }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="用气设施">
                <span>{{ typeFormat(this.industryDetailInfo) || "-" }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="所属区域">
                <span
                  v-if="
                    industryDetailInfo.countyName ||
                    industryDetailInfo.streetName ||
                    industryDetailInfo.villageName
                  "
                  >{{ industryDetailInfo.countyName
                  }}{{ industryDetailInfo.streetName
                  }}{{ industryDetailInfo.villageName }}</span
                >
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="通气状态">
                <span>{{ statusFormat(this.industryDetailInfo) || "-" }}</span>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="开户时间">
                <span v-if="industryDetailInfo.createTime">{{
                  industryDetailInfo.createTime
                }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="具体地址">
                <span v-if="industryDetailInfo.address">{{
                  industryDetailInfo.address
                }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>

        <!-- <div style="font-size: 20px; margin: 10px 0px 10px 0px">安检列表</div> -->

        <!-- 安检列表 -->
      </el-col>

      <!-- <el-col :span="10">
        <div
          id="map"
          style="width: 100%; height: 500px; border: 1px solid"
        ></div>
      </el-col> -->
    </el-row>
    <div class="table flex-b">
      <div class="l">
        <el-table v-loading="loading" :data="taskInspectList" :height="240">
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column
            label="安检时间"
            align="center"
            prop="createTime"
            width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="有无隐患"
            align="center"
            prop="danger"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.danger == 1">有</span>
              <span v-else>无</span>
            </template>
          </el-table-column>
          <!-- <el-table-column
            label="安检状态"
            align="center"
            prop="status"
            width="100"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0">到访不遇风</span>
              <span v-if="scope.row.status == 1">拒绝安检</span>
              <span v-if="scope.row.status == 2">已检测</span>
              <span v-if="scope.row.status == 3">表前已检测</span>
            </template>
          </el-table-column> -->

          <!-- <el-table-column label="满意度" align="center" prop="satisfy">
            <template slot-scope="scope">
              <span v-if="scope.row.satisfy == 1">不满意</span>
              <span v-if="scope.row.satisfy == 2">一般</span>
              <span v-if="scope.row.satisfy == 3">满意</span>
            </template>
          </el-table-column>-->
          <el-table-column label="签字状态" align="center" prop="sign">
            <template slot-scope="scope">
              <span v-if="scope.row.sign == 0">未签字</span>
              <span v-if="scope.row.sign == 1">已签字</span>
            </template>
          </el-table-column>
          <el-table-column
            label="安检人"
            align="center"
            prop="memberName"
            :show-overflow-tooltip="true"
          />

          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="250"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                v-if="scope.row.status != 0"
                @click="handleDetail(scope.row)"
                >检查表</el-button
              >
              <el-button
                size="mini"
                type="text"
                v-if="scope.row.status == 0"
                @click="handlePicture(scope.row)"
                >不遇图片</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="handleLocation(scope.row)"
                >位置</el-button
              >

              <el-button
                size="mini"
                type="text"
                v-if="scope.row.danger == 1"
                @click="handleDanger(scope.row)"
                >隐患</el-button
              >

              <el-button
                size="mini"
                type="text"
                v-if="scope.row.status == 2 || scope.row.status == 3"
                @click="handleCover(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"
          :pageSizes="[5, 10, 20, 30, 50]"
          @pagination="getTaskInspectInfoList"
        />
      </div>
      <div class="r">
        <div id="map"></div>
      </div>
    </div>

    <!-- 详情 -->
    <IndustryRecordDetail ref="industryRecordDetail" />

    <!-- 隐患信息 -->
    <el-dialog
      title="隐患记录"
      :visible.sync="dangerDetailOpen"
      width="1000px"
      append-to-body
      destroy-on-close
    >
      <!-- 隐患信息 -->
      <DangerDetailInfo ref="dangerDetail" />
    </el-dialog>

    <!-- 到访不遇图片 -->
    <el-image
      ref="viewImage"
      :src="imageUrl"
      v-show="false"
      :preview-src-list="imageUrlList"
      :z-index="9999"
    ></el-image>

    <!-- 表封照片 -->
    <CoverPhotoView ref="cover" />
  </el-dialog>
</template>

<script>
import { listInspect, getInspect } from "@/api/checktask/inspect";
import { getIndustry } from "@/api/baseinfo/industry";
import { EditorMap } from "@/utils/mapClass/map";
import { mapGetters } from "vuex";
import IndustryRecordDetail from "./IndustryRecordDetail";
import DangerDetailInfo from "./DangerDetailInfo";
import CoverPhotoView from "./CoverPhotoView";
import { listDanger } from "@/api/checktask/danger";
export default {
  name: "industry-task-inspect-info",
  components: {
    IndustryRecordDetail,
    DangerDetailInfo,
    CoverPhotoView,
  },
  data() {
    return {
      open: false,
      taskInspectList: [],
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        taskId: null,
        receiveId: null,
      },
      loading: false,
      gaoMap: null,
      checkType: null,
      dangerDetailOpen: false,
      industryDetailInfo: {},
      // 用气场景字典
      typeOptions: [],
      // 开通状态字典
      statusOptions: [],
      imageUrl: null,
      imageUrlList: [],
    };
  },
  methods: {
    //初始化信息
    initInfoList() {
      this.open = true;
      this.$nextTick(() => {
        this.initMap();
        this.initDictInfo();
        this.getIndustryInfo();
        this.getTaskInspectInfoList();
      });
    },
    //字典数据初始化
    initDictInfo() {
      this.getDicts("t_user_scene").then((response) => {
        this.typeOptions = response.data;
      });
      this.getDicts("t_user_status").then((response) => {
        this.statusOptions = response.data;
      });
    },
    //初始化安检列表
    getTaskInspectInfoList() {
      this.loading = true;
      listInspect(this.queryParams).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.taskInspectList = res.rows;
          this.total = res.total;
          this.addLocation({
            longitude: this.taskInspectList[0].longitude,
            latitude: this.taskInspectList[0].latitude,
            nickName: this.taskInspectList[0].createTime,
            iconType: "industryTaskInspect",
          });
        }
      });
    },
    //详情
    handleDetail(row) {
      getInspect(row.id).then((res) => {
        if (res.code == 200 && res.data) {
          if (!res.data.content) return this.$message.error("未查到安检信息！");
          this.$refs.industryRecordDetail.checkType = this.checkType;
          this.$refs.industryRecordDetail.inspectInfo = res.data;
          this.$refs.industryRecordDetail.open = true;
        } else {
          this.$message.error("未查到安检信息！");
        }
      });
    },
    //位置
    handleLocation(row) {
      this.addLocation({
        longitude: row.longitude,
        latitude: row.latitude,
        nickName: row.createTime,
        iconType: "industryTaskInspect",
      });
    },
    //地图初始化
    initMap() {
      const path = eval(this.systemSetting.map_center);
      this.gaoMap = new EditorMap(
        "map",
        {
          center: path,
          zoom: 12,
        },
        this
      );
    },
    //位置上图
    addLocation(data) {
      this.gaoMap.allDevice["industryTaskInspect"]?.forEach((item) => {
        this.gaoMap.map.remove(item);
      });
      this.gaoMap.control = 2;
      this.gaoMap.addDevice(data, null);
      this.gaoMap.map.panTo([data.longitude, data.latitude]);
    },
    //隐患
    handleDanger(row) {
      listDanger({
        pageNum: 1,
        pageSize: 99999,
        inspectId: row.id,
        type: 3,
      }).then((response) => {
        if (
          response.code != 200 ||
          response.rows == null ||
          response.rows.length == 0
        ) {
          this.$message.error("未查到隐患信息！");
          return;
        }
        this.dangerDetailOpen = true;
        this.$nextTick(() => {
          this.$refs.dangerDetail.getList(response);
        });
      });
    },
    //工业用户信息
    getIndustryInfo() {
      getIndustry(this.queryParams.receiveId).then((res) => {
        if (res.code == 200) {
          this.industryDetailInfo = res.data;
          this.gaoMap.control = 2;
          this.gaoMap.addDevice(
            {
              longitude: res.data.longitude,
              latitude: res.data.latitude,
              nickName: res.data.username,
              iconType: "19",
            },
            null
          );
          this.gaoMap.map.panTo([res.data.longitude, res.data.latitude]);
        }
      });
    },
    // 用气场景字典翻译
    typeFormat(row, column) {
      if (row.type == undefined) {
        return "";
      }
      var str = "";
      for (var tp of row.type.split(",")) {
        str += this.selectDictLabel(this.typeOptions, tp) + "、";
      }
      return str.substr(0, str.length - 1);
      //return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 开通状态字典翻译
    statusFormat(row) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    //查看图片
    handlePicture(row) {
      if (!row.meterData) return this.$message.error("未查询到到访不遇图片");
      this.imageUrl = row.meterData.split(",")[0];
      this.imageUrlList = row.meterData.split(",");

      this.$refs.viewImage.showViewer = true;
    },
    //表封照片
    handleCover(row) {
      if (!row.meterImg) return this.$message.error("未查询到图片");
      this.$refs.cover.viewCoverPhoto(row.meterImg);
    },
  },
  computed: {
    ...mapGetters(["systemSetting"]),
  },
};
</script>

<style scoped lang="scss">
.inspect-record-info {
  padding-right: 10px;
  /* height: 750px;
    overflow-y: auto;
    padding-right: 10px;
    &::-webkit-scrollbar {
      width: 3px;
      background:  #dfe4ed;
      position: absolute;
      top: 0;
    }
    &::-webkit-scrollbar-thumb {
      !*滚动条里面小方块*!
      // border-radius: 10px;
      // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
      background: #cccccc;
      border-radius: 5px;
    }*/
}
::v-deep .el-col-8 {
  height: 40px;
}
::v-deep .el-form-item {
  margin-bottom: 0 !important;
}
::v-deep .el-table::before {
  height: 0;
}
.top-title {
  text-align: center;
  font-size: 20px;
  margin-bottom: 14px;
}
.user-title {
  color: #226aed;
  font-size: 16px;
  margin-bottom: 16px;
}
.container {
  background: #f9f9f9;
  margin-bottom: 32px;
  padding: 10px 0;
  width: 100%;
}
.table {
  height: 300px;
  .l {
    width: 850px;
    margin-right: 20px;
  }
  .r {
    flex: 1;
    height: 100%;
    #map {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
