<template>
  <div class="app-container">
    <el-button
      icon="el-icon-back"
      size="mini"
      style="margin-bottom: 10px"
      @click="goback"
    >
      返回
    </el-button>
    <div class="top flex-b">
      <div class="l top-item bb">
        <div class="t">{{ taskDetailData.title }}</div>
        <div class="m bb">
          <span class="sl">任务起止时间</span>
          <span class="sr">{{ taskDetailData.startTime }} ~ {{ taskDetailData.endTime }}</span>
        </div>
        <div class="b bb flex">
          <div class="bl flex" v-if="taskDetailData.type == 1">
            <div class="l">安检小区或村数</div>
            <div class="r">{{ taskDetailData.coummunityNum }}</div>
          </div>
          <div class="br flex">
            <div class="l">安检总户数</div>
            <div class="r">{{ taskDetailData.totalInspectNum }}</div>
          </div>
        </div>
      </div>
      <div class="m top-item bb">
        <div class="t">任务进度</div>
        <div class="b flex-b bb">
          <div v-for="item in itemDataA" :key="item.label" class="bottom-item">
            <div
              :style="{
                background: `url(${item.src}) no-repeat center`,
                color: item.color,
              }"
              class="imgbg"
            >
              {{ item.label }}
            </div>
            <div :style="{ color: item.color }" class="num">{{ item.val }}</div>
          </div>
        </div>
      </div>
      <div class="r top-item bb">
        <div class="t">隐患信息</div>
        <div class="flex-b m bb">
          <div>存在隐患</div>
          <div class="n">{{ taskInspectDangerDetailData.totalDangerNum }}</div>
        </div>
        <div class="b bb flex">
          <div class="bl flex">
            <div class="l">已解决隐患数</div>
            <div class="r">{{ taskInspectDangerDetailData.dealNum ? taskInspectDangerDetailData.dealNum : 0 }}</div>
          </div>
          <div class="br flex">
            <div class="l">未解决隐患数</div>
            <div class="r">{{ taskInspectDangerDetailData.toDoNum ? taskInspectDangerDetailData.toDoNum : 0}}</div>
          </div>
        </div>
      </div>
    </div>
    <!--搜索 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
      style="margin-top: 10px"
    >
      <el-form-item label="单位名称" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="联系人" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入联系人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="安检状态" prop="inspectStatus">
        <el-select
          v-model="queryParams.inspectStatus"
          clearable
          size="small"
          palceholder="请选择安检状态"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="未安检" value="-1" />
          <el-option label="到访不遇" value="0" />
          <el-option label="拒绝安检" value="1" />
          <el-option label="已安检" value="2" />
          <el-option label="燃气停用" value="3" />
        </el-select>
      </el-form-item>

      <el-form-item label="安检人" prop="inspector">
        <el-input
          v-model="queryParams.inspector"
          placeholder="请输入安检人"
          clearable
          size="small"
          @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="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="batchExportLoading"
          @click="handleBatchInspectExport"
        >安检单导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="industryDetailInfo">
      <el-table-column label="单位名称" align="center" prop="company" :show-overflow-tooltip="true"/>
     <!-- <el-table-column label="用户编号" align="center" prop="usernum"/>-->
      <el-table-column label="联系人" align="center" prop="username" :show-overflow-tooltip="true"/>
      <el-table-column label="联系方式" align="center" prop="phone"/>
      <el-table-column label="所属区域" align="center" prop="countyName" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ scope.row.countyName ? scope.row.countyName : ""
          }}{{ scope.row.streetName ? scope.row.streetName : "" }}
        </template>
      </el-table-column>
      <el-table-column
        label="通气状态"
        align="center"
        prop="status"
        :show-overflow-tooltip="true"
        :formatter="statusFormat"
      />
      <!--<el-table-column label="街道/乡镇" align="center" prop="streetName" width="120" :show-overflow-tooltip="true"/>-->
      <el-table-column
        label="安检状态"
        align="center"
        prop="inspectStatus"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span style="color: #f56c6c" v-if="scope.row.inspectStatus == -1"
            >未安检</span
          >
          <span style="color: purple" v-if="scope.row.inspectStatus == 0"
            >到访不遇</span
          >
          <span style="color: yellow" v-if="scope.row.inspectStatus == 1"
            >拒绝安检</span
          >
          <span style="color: #1ab394" v-if="scope.row.inspectStatus == 2"
            >已安检</span
          >
          <span style="color: #1ab394" v-if="scope.row.inspectStatus == 3">燃气停用</span>
        </template>
      </el-table-column>
      <el-table-column
        label="安检人"
        align="center"
        prop="inspector"
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column label="满意度" align="center" prop="satisfy" width="100" :show-overflow-tooltip="true">
        <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="inspectSign" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.inspectSign == 0">未签字</span>
          <span v-if="scope.row.inspectSign == 1">已签字</span>
        </template>
      </el-table-column>-->
      <el-table-column
        label="安检时间"
        align="center"
        prop="inspectTime"
        width="150"
        :show-overflow-tooltip="true"
      />
      <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-document"
            @click="handleDetail(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"
    />

    <!-- 工业用户安检详情 -->
    <IndustryTaskInspectInfo ref="industryTaskInspectInfo" />

    <ExportInspect ref="exportInspect"/>

  </div>
</template>

<script>
import { getIndustryInspectInfo } from "@/api/baseinfo/industry";
import IndustryTaskInspectInfo from "./components/IndustryTaskInspectInfo";
import imgA from "@/assets/ajImg/imgA.png";
import imgB from "@/assets/ajImg/imgB.png";
import imgC from "@/assets/ajImg/imgC.png";
import { taskDetailInfo, taskInspectDetailInfo, taskInspectDangerDetailInfo } from "@/api/checktask/task";
import ExportInspect from "../inspect/ExportInspect";
export default {
  name: "industry-detail",
  components: {
    IndustryTaskInspectInfo,
    ExportInspect
  },

  data() {
    return {
      open: false,
      total: 0,
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId: null,
        company: null,
        username: null,
        usernum: null,
        inspectStatus: null,
        inspectSign: null,
        inspector: null,
      },
      batchExportLoading: false,
      itemDataA: [
        {
          label: "未安检",
          val: 2109,
          src: imgA,
          color: "#2167E5",
        },
        {
          label: "到访不遇",
          val: 21,
          src: imgA,
          color: "#2167E5",
        },
        {
          label: "拒绝安检",
          val: 3,
          src: imgB,
          color: "#E22121",
        },
        {
          label: "燃气停用",
          val: 4,
          src: imgA,
          color: "#2167E5",
        },
        {
          label: "已安检",
          val: 1209,
          src: imgC,
          color: "#08932D",
        },
      ],
      industryDetailInfo: [],
      statusOptions: [],
      taskDetailData:{},
      taskInspectDangerDetailData:{}
    };
  },
  created() {
    this.queryParams.taskId = this.$route.query.taskId;
    this.queryParams.type = this.$route.query.type;
    this.queryParams.taskType = this.$route.query.checkType;
    this.getList();
    this.getDicts("t_user_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.taskDetail();
    this.taskInspectDetail();
    this.taskInspectDangerDetail();
  },
  methods: {
    /* //初始化工业用户安检信息
      getDetailInfo(taskId){
        this.queryParams.taskId = taskId;
        this.getList();
      },*/
    //工业用户安检信息列表
    getList() {
      this.loading = true;
      getIndustryInspectInfo(this.queryParams).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.industryDetailInfo = res.rows;
          this.total = res.total;
          this.open = true;
        }
      });
    },
    taskDetail(){
      taskDetailInfo({taskId:this.$route.query.taskId}).then(res =>{
        if(res.code == 200){
           this.taskDetailData = res.data;
        }
      })
    },
    taskInspectDetail(){
      taskInspectDetailInfo({taskId:this.$route.query.taskId,type:this.$route.query.type,taskType: this.$route.query.checkType}).then(res =>{
        if(res.code == 200){
          let data = res.data;
          this.itemDataA[0].val = data.noInspectNum;
          this.itemDataA[1].val = data.missNum;
          this.itemDataA[2].val = data.refuseNum;
          this.itemDataA[3].val = data.beforeNum;
          this.itemDataA[4].val = data.inspectNum;
        }
      })
    },
    taskInspectDangerDetail(){
      taskInspectDangerDetailInfo({taskId:this.$route.query.taskId}).then(res =>{
        if(res.code == 200){
          this.taskInspectDangerDetailData = res.data;
        }
      })
    },
    //搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    goback() {
      this.$router.back()
    },
    //详情
    handleDetail(row) {
      if (!row.inspector) {
        this.$message.error("该用户未进行安检");
        return;
      }
      this.$refs.industryTaskInspectInfo.queryParams.taskId =
        this.$route.query.taskId;
      this.$refs.industryTaskInspectInfo.queryParams.receiveId = row.id;
      this.$refs.industryTaskInspectInfo.checkType =
        this.$route.query.checkType;
      this.$refs.industryTaskInspectInfo.initInfoList();
    },
    // 开通状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    handleBatchInspectExport(){
      let query = {...this.queryParams}
      query.nickName = this.queryParams.inspector;
      query.companyName = this.queryParams.company;
      this.$refs.exportInspect.init(query);
    }
  },
};
</script>

<style lang="scss" scoped>
.top {
  height: 200px;
  .top-item {
    width: 490px;
    height: 180px;
    border-radius: 3px;
    border: 1px solid #eeeeee;
    box-shadow: 0px 0px 24px 0px rgba(0, 0, 0, 0.08);
    padding-top: 32px;
    padding-left: 30px;
    color: #1b63df;

    .t {
      font-size: 20px;
      margin-bottom: 21px;
      font-weight: 800;
    }
    &.l {
      .m {
        height: 40px;
        border-radius: 20px;
        background: #eef5ff;
        line-height: 42px;
        padding-left: 38px;
        font-size: 16px;
        margin-right: 34px;

        margin-bottom: 19px;
        .sl {
          font-size: 14px;
          margin-right: 40px;
        }
        .sr {
          font-size: 16px;
          letter-spacing: 1px;
        }
      }
      .b {
        padding-left: 17px;

        .bl,
        .br {
          margin-right: 72px;
          align-items: center;
          .l {
            font-size: 14px;
            margin-right: 16px;
          }
          .r {
            font-size: 16px;
            font-weight: 800;
          }
        }
        .br {
          margin-right: 0;
        }
      }
    }
    &.m {
      width: 570px;
      padding-right: 34px;
      .t {
        margin-bottom: 17px;
      }
      .b {
        .bottom-item {
          .imgbg {
            width: 80px;
            height: 56px;
            text-align: center;
            line-height: 56px;
            font-weight: 600;
            font-size: 14px;
            margin-bottom: 8px;
          }
          .num {
            text-align: center;
            font-weight: 800;
          }
        }
      }
    }
    &.r {
      padding-right: 34px;
      .m {
        height: 40px;
        background: rgba(255, 214, 214, 0.24);
        margin-bottom: 18px;
        color: #e22121;
        line-height: 40px;
        padding: 0 25px;
        .n {
          font-weight: 800;
        }
      }
      .b {
        padding-left: 17px;
        color: #e22121;

        .bl,
        .br {
          margin-right: 72px;
          align-items: center;
          .l {
            font-size: 14px;
            margin-right: 16px;
          }
          .r {
            font-size: 16px;
            font-weight: 800;
          }
        }
        .br {
          margin-right: 0;
        }
      }
    }
  }
}
</style>
