<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="任务标题" prop="workTitle">
        <el-input
          v-model="queryParams.workTitle"
          placeholder="请输入任务标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="任务类型" prop="workType">-->
        <!--<el-select v-model="queryParams.workType" placeholder="请选择任务类型" clearable size="small">-->
          <!--<el-option label="入户安检" value="1" />-->
          <!--<el-option label="巡检" value="2" />-->
          <!--&lt;!&ndash;<el-option label="报警巡查" value="3" />&ndash;&gt;-->
          <!--&lt;!&ndash;<el-option label="其他" value="4" />&ndash;&gt;-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <el-form-item label="任务状态" prop="workStatus">
        <el-select v-model="queryParams.workStatus" placeholder="请选择任务状态" clearable size="small">
          <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="timeType">
        <el-select v-model="queryParams.timeType">
          <el-option label="日" value="1"></el-option>
          <el-option label="周" value="2"></el-option>
          <el-option label="月" value="3"></el-option>
          <el-option label="年" value="4"></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-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--plain-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-if="roleType != 'inpector'"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-if="roleType != 'inpector'"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div id="chars" class="chars"></div>
    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="任务标题" align="center" prop="workTitle">
        <template slot-scope="scope">
          <span style="margin-left: 10px;display: inline-block">{{ scope.row.workTitle }}</span>
          <el-popover
            placement="right"
            title="督办信息"
            width="350"
            trigger="click"
            v-if="null!=scope.row.supervisorInfoList">
            <div class="timeline">
              <el-timeline>
                <el-timeline-item
                  v-for="(activity, index) in scope.row.supervisorInfoList"
                  :key="index"
                  :timestamp="activity.createTime">
                  {{activity.supervisorContent}}
                </el-timeline-item>
              </el-timeline>
            </div>
            <!--<el-button slot="reference">click 激活</el-button>-->
            <div style="display:inline-block;position:relative" slot="reference">
              <img src="@/assets/image/start.svg" style="position:absolute;top:-15px;left:0;width: 20px;height: 20px"/>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="任务类型" align="center" prop="workType">
        <template slot-scope="scope">
          <span v-if="scope.row.workType == 1">入户安检</span>
          <span v-if="scope.row.workType == 2">巡检</span>
          <!-- <span v-if="scope.row.workType == 3">报警巡查</span>-->
          <!--<span v-if="scope.row.workType == 4">其他</span>-->
        </template>
      </el-table-column>
      <!-- <el-table-column label="任务内容" align="center" prop="workContent" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="创建单位" align="center" prop="workCreateEnterpriseName" />
      <el-table-column label="执行单位" align="center" prop="workAssignEnterproseName" />
      <el-table-column label="执行人" align="center" prop="workAssignMan" />
      <el-table-column label="任务状态" align="center" prop="workStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.workStatus == 0" style="color: #ff7272">派发中</span>
          <span v-if="scope.row.workStatus == 1" style="color: #ffba00">已接单</span>
          <span v-if="scope.row.workStatus == 2" style="color: #1890ff">已反馈</span>
          <span v-if="scope.row.workStatus == 3" style="color: #30B46B">已归档</span>
        </template>
      </el-table-column>>

      <el-table-column label="截止日期" align="center" prop="expiryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expiryDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</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="workDetail(scope.row)"
            key="detail"
          >详情</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="800px" @closed="dialogClose" @open="dialogOpen" :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="任务标题" prop="workTitle">
              <el-input v-model="form.workTitle" placeholder="请输入任务标题" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="任务类型" prop="workType">
              <el-select v-model="form.workType" placeholder="请选择任务类型" style="width: 100%" :disabled="isDetail">
                <el-option label="入户安检" value="1" />
                <el-option label="巡检" value="2" />
                <!--<el-option label="报警巡查" value="3" />-->
                <!--<el-option label="其他" value="4" />-->
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="任务内容" prop="workContent">
              <!--<editor v-model="form.workContent" :min-height="192" :readOnly="!s"/>-->
              <editor v-if="isOpen" v-model="form.workContent" :min-height="192" :readOnly="isDetail"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="执行单位" prop="workAssignEnterproseId">
              <!--<el-input v-model="form.workAssignEnterproseName" placeholder="请输入执行单位名称" />-->
              <el-select v-model="form.workAssignEnterproseId" placeholder="请选择执行单位名称" style="width: 100%" @change="selectworkAssignEnterprose($event)" :disabled="isDetail || isEnterproser">
                <el-option
                  v-for="item in enterprises"
                  :key="item.enterpriseId"
                  :label="item.enterpriseName"
                  :value="item.enterpriseId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="执行人" prop="workAssignMan">
              <!--<el-input v-model="form.workAssignManId" placeholder="请输入执行人" />-->
              <el-select v-model="form.workAssignManId" placeholder="请输入执行人" style="width: 100%" @change="selectInspection($event,'edit')" :disabled="isDetail" clearable>
                <el-option
                  v-for="item in inspectors"
                  :key="item.userId "
                  :label="item.nickName"
                  :value="item.userId "
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11" v-show="isDetail">
            <el-form-item label="创建单位" prop="workCreateEnterpriseName">
              <el-input v-model="form.workCreateEnterpriseName" placeholder="请输入创建单位名称" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
          <!--<el-col :span="12">-->
          <!--<el-form-item label="巡检时间" prop="inspectionDate" v-show="form.workType=='2'">-->
          <!--<el-date-picker clearable size="small"-->
          <!--v-model="form.inspectionDate"-->
          <!--type="date"-->
          <!--value-format="yyyy-MM-dd HH:mm:ss"-->
          <!--placeholder="选择巡检时间" style="width: 100%" :disabled="isDetail">-->
          <!--</el-date-picker>-->
          <!--</el-form-item>-->
          <!--</el-col>-->
        </el-row>
        <el-row v-if="isDetail && form.workStatus >1">
          <el-col :span="23">
            <el-form-item label="巡线范围" prop="inspectionRoute">
              <el-input v-model="form.inspectionRoute" type="textarea" placeholder="请输入巡检路线" :disabled="isDetail" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="isDetail && form.workStatus >1">
          <el-col :span="23">
            <el-form-item label="处理结果" prop="problemDescription" >
              <el-input v-model="form.problemDescription" type="textarea" placeholder="请输入问题描述" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="23">
            <el-form-item label="反馈图片" prop="iconUrl" v-show="isDetail && (form.workStatus =='2' || form.workStatus =='3') && form.iconUrl !='' && form.iconUrl != null">
              <!--<MyFileUpload
                listType="picture-card"
                @resFun="getFileInfo"
                @remove="listRemove"
                :fileArr="fileList"
                :readOnly= "isDetail"
              />
              <el-input v-show="false" disabled v-model="form.iconUrl"></el-input>-->
              <div style="width: 20%;" v-for="item in imageArr">
                <el-image :src="item" :preview-src-list="[item]" style="width: auto;height: auto;" :z-index= "3000"></el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row  v-if="isDetail && form.workStatus >1">
          <el-col :span="23" >
            <el-form-item label="整改方案" prop="rectificationPlan" v-show="form.workType=='1' ">
              <el-input v-model="form.rectificationPlan" type="textarea" placeholder="请输入整改方案" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="isDetail && form.workStatus >1" >
          <el-col :span="23" >
            <el-form-item label="整改结果" prop="rectificationResult" v-show="form.workType =='1'">
              <el-input v-model="form.rectificationResult" type="textarea" placeholder="请输入整改结果" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="责任单位" prop="responsibleUnit">
              <el-input v-model="form.responsibleUnit" placeholder="请输入责任单位" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="责任人员" prop="responsiblePerson">
              <el-input v-model="form.responsiblePerson" placeholder="请输入责任人员" :disabled="isDetail"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="截止日期" prop="expiryDate">
              <el-date-picker clearable size="small"
                              v-model="form.expiryDate"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择截止日期" style="width: 100%" :disabled="isDetail">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div v-if="supervisorList.length > 0 && isDetail">
        <div class="hiddenInfo">督办信息</div>
        <el-timeline ref="timeline">
          <el-timeline-item
            v-for="(activity, index) in supervisorList"
            :key="index"
            :timestamp="activity.createTime"
            v-show='index>1?false:true'>
            <el-card>
              {{activity.supervisorContent}}
            </el-card>
          </el-timeline-item>
        </el-timeline>
        <div style="width: 95%;position: relative;" @click="changeDisplay()" v-if="supervisorList.length >2">
          <!-- <el-button type="primary"> -->
          <i class="el-icon-arrow-down" v-if="isDisplay==false"
             style="margin-left: 100px;color: #909399;font-size: 14px;">
            <span style="text-decoration:underline">显示全部</span>
          </i>
          <i class="el-icon-arrow-up" v-else style="color: #909399;font-size: 14px;margin-left: 100px;">
            <span style="text-decoration:underline">收起</span>
          </i>
          <!-- </el-button> -->

        </div>
      </div>
      <div v-if="hiddenInfoList.length > 0">
        <div class="hiddenInfo">隐患信息</div>
        <HiddenTrouble
          :hiddenList="hiddenInfoList"/>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!isDetail">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder,orderCount } from "@/api/operationMonitor/order";
  import { hiddenTroubleList } from "@/api/operationMonitor/hiddenTrouble"
  import { addSupervisorInfo, supervisorInfoList } from "@/api/operationMonitor/supervisor"
  import Editor from '@/components/Editor';
  import MyFileUpload from '@/components/MyFileUpload';
  import { enterpriseLists } from "@/api/regulation/info";
  import { getInspectionUsers } from "@/api/system/user";
  import ScrollPane from "../../../layout/components/TagsView/ScrollPane";
  export default {
    name: "Order",
    components: {
      ScrollPane,
      Editor,
      MyFileUpload
    },
    data() {
      const validateHiddenFeedInfo = (rule, value, callback) => {
        if (this.$refs.hiddenChild.checkChildData()) {
          callback(new Error("隐患信息不能为空！"));
        } else {
          callback();
        }
      };
      return {
        isOpen:false,
        imageArr:[],
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        detailDialogVisible: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 燃气任务表格数据
        orderList: [
          {activities:[]}
        ],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //企业选项
        enterprises: [],
        //巡检员
        inspectors:[],
        // 上传文件列表
        fileList: [],
        //详情
        isDetail: false,
        //是否为企业用户
        isEnterproser: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          timeType:'',
          workTitle: null,
          workType: 2,
          workContent: null,
          workCreateEnterpriseName: null,
          workCreateEnterpriseId: null,
          workAssignEnterproseName: null,
          workAssignEnterproseId: null,
          workAssignManId: null,
          workAssignMan: null,
          workStatus: null,
          inspectionDate: null,
          inspectionRoute: null,
          problemDescription: null,
          iconUrl: null,
          rectificationPlan: null,
          rectificationResult: null,
          responsibleUnit: null,
          responsiblePerson: null,
          expiryDate: null,
          isDel: null,
          remarks: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          workTitle: [
            { required: true, message: "任务标题", trigger: "blur" }
          ],
          workType: [
            { required: true, message: "任务类型", trigger: "blur" }
          ],
          workContent: [
            { required: true, message: "任务内容", trigger: "blur" }
          ],
          workAssignEnterproseId: [
            { required: true, message: "执行单位", trigger: "blur" }
          ],
          expiryDate: [
            { required: true, message: "截止时间", trigger: "blur" }
          ]
        },
        //任务下发表单校验
        workRules: {
          workAssignEnterproseId: [
            { required: true, message: "执行单位", trigger: "blur" }
          ],
          workAssignMan: [
            { required: true, message: "执行人", trigger: "blur" }
          ]
        },
        //反馈校验
        feedBookRules: {
          iconUrl: [
            { required: true, message: "反馈图片", trigger: "change" }
          ],
          rectificationResult:[
            { required: true, message: "反馈信息", trigger: "blur" }
          ]
        },
        roleType: "zhengfu",
        workForm:{},
        workOpen: false,
        feedBookForm: {
          iconUrl: "",
          hiddenList:[]
        },
        feedBookOpen: false,
        //详情隐患信息
        hiddenInfoList:[],
        hiddenFeedOpen:false,
        hiddenFeedForm:{
          hiddenList:[]
        },
        //反馈校验
        hiddenFeedRules: {
          hiddenInfo: [
            { type: "array", validator: validateHiddenFeedInfo, required: true }
          ]
        },
        //督办form
        supervisorForm: {},
        //督办弹框
        supervisorOpen: false,
        //督办校验
        supervisorRules:{
          supervisorContent: [
            { required: true, message: "督办内容", trigger: "blur" }
          ]
        },
        supervisorList:[],
        isDisplay: false,
        showAndHide: false
      };
    },
    created() {
      window.func=()=>{
        this.isDetail =!this.isDetail;
      }
      this.getList();
      let enterpriseId = this.$store.state.user.enterpriseId;
      let post = this.$store.state.user.posts.find(item => item.postCode === "se");
      if(-2 != enterpriseId){
        if(post && this.$store.state.user.posts.length <=1){
          this.roleType = "inpector";
        }else if(post && this.$store.state.user.posts.length >1){
          this.roleType = "doubleRole";
        }else{
          this.roleType = "enterprise";
        }
      }

    },
    methods: {

      dialogClose(){
        this.isOpen=false;
      },
      dialogOpen(){
        this.isOpen=true;
      },
      /** 查询燃气任务列表 */
      getList() {
        this.loading = true;
        listOrder(this.queryParams).then(response => {
          this.orderList = response.rows;
        this.charsStar();
        /* const param = response.rows;
         param.forEach(item =>{
           this.supervisorData(item);
         })
         this.orderList = param;
         console.log(this.orderList,"fdsfdsfdfdsfd========")*/
        this.total = response.total;
        this.loading = false;
      });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          workId: null,
          workTitle: null,
          workType: null,
          workContent: null,
          workCreateEnterpriseName: null,
          workCreateEnterpriseId: null,
          workAssignEnterproseName: null,
          workAssignEnterproseId: null,
          workAssignManId: null,
          workAssignMan: null,
          workStatus: "0",
          inspectionDate: null,
          inspectionRoute: null,
          problemDescription: null,
          iconUrl: null,
          rectificationPlan: null,
          rectificationResult: null,
          responsibleUnit: null,
          responsiblePerson: null,
          expiryDate: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          isDel: null,
          remarks: 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.workId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.isDetail = false;
        this.title = "添加巡检巡查任务";
        this.getEnterpriseLists();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const workId = row.workId || this.ids
        this.isDetail = false;
        getOrder(workId).then(response => {
          this.form = response.data;
        this.open = true;
        this.title = "修改燃气任务";
        this.getHiddenInfos({workId : workId});
        this.getEnterpriseLists();
        this.getInspectionUserList(response.data.workAssignEnterproseId);
      });

      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.workId != null) {
              updateOrder(this.form).then(response => {
                this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
            } else {
              addOrder(this.form).then(response => {
                this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const workIds = row.workId || this.ids;
        this.$confirm('是否确认删除燃气任务名称为"' + row.workTitle + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          //return delOrder(workIds);
          updateOrder({workId: workIds,isDel: '1'})
        }).then(() => {
          this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有燃气任务数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
        return exportOrder(queryParams);
      }).then(response => {
          this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
      },
      getFileInfo(res){
        this.feedBookForm.iconUrl = res.url;
        //this.$set(this.feedBookForm,'iconUrl',res.url)
      },
      listRemove(e) {
        this.form.iconUrl = "";
        this.fileList = [];
      },
      showPicture(row){
        this.$refs['a'+row.workId].showViewer = true;
      },
      //执行单位
      getEnterpriseLists(){
        const param = {};
        this.judgeOperateType(param);
        enterpriseLists(param).then(response => {
          this.enterprises = response.rows;
      });
      },
      //根据用户角色和操作类型设置执行人是否可选
      judgeOperateType(param){
        if(this.roleType != "zhengfu"){
          param.enterpriseId = this.$store.state.user.enterpriseId;
          if(this.title == "添加巡检巡查任务"){
            this.form.workAssignEnterproseId = this.$store.state.user.enterpriseId;
            this.isEnterproser = true;
          }
          if(this.title == "任务下发"){
            this.isEnterproser = true;
          }
          this.getInspectionUserList(this.$store.state.user.enterpriseId);
        }
      },
      //获取巡检员
      getInspectionUserList(enterpriseId){
        getInspectionUsers(enterpriseId,"se").then(response =>{
          this.inspectors = response.data;
      })
      },
      //选择执行单位
      selectworkAssignEnterprose(enterpriseId){
        this.form.workAssignManId = "";
        this.workForm.workAssignManId = "";
        this.workForm.workAssignMan="";
        this.form.workAssignMan = "";
        this.getInspectionUserList(enterpriseId);
        let enterpriseName = this.enterprises.find(val=>val.enterpriseId == enterpriseId).enterpriseName;
        this.form.workAssignEnterproseName = enterpriseName;
      },
      //获取执行人
      selectInspection(userId,type){
        if(userId){
          let nickName = this.inspectors.find(val=>val.userId == userId).nickName;
          if("edit" == type){
            this.form.workAssignMan = nickName;
          }else{
            this.workForm.workAssignMan = nickName;
          }
        }else{
          if("edit" == type){
            this.form.workAssignMan = "";
          }else{
            this.workForm.workAssignMan = "";
          }
        }
      },
      /*//选择任务类型
      selectWorkType(workType){
        if("2" == workType){
          this.inspectorInfoIsShow = true;
        }else{
          this.inspectorInfoIsShow = false;
        }
      },*/
      //详情
      workDetail(row){
        getOrder(row.workId).then(response => {
          this.isDetail=true;
        this.open = true;
        this.title = "燃气任务详情";
        this.form = response.data;
        this.imageArr = this.form.iconUrl.split(",");
        /*if(this.form.workStatus == '2' || this.form.workStatus == '3'){
          const param = {};
          param.workId = this.form.workId;

        }*/
        //查询隐患信息
        this.getHiddenInfos({workId : this.form.workId});
        this.getEnterpriseLists();
        this.getInspectionUserList(response.data.workAssignEnterproseId);
        this.supervisorData(this.form.workId);
      });
      },

      //接单
      takingOrder(row){
        this.$confirm('是否确认接单?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.workForm = {};
        this.workForm.workId = row.workId;
        this.workForm.workStatus = '1';
        if (this.workForm.workId != null) {
          updateOrder(this.workForm);
        }
      }).then(response => {
          this.getList();
        this.msgSuccess("接单成功");
      }).catch(() => {});
      },
      //反馈
      feedbookWork(row){
        this.title = "反馈信息";
        this.feedBookOpen = true;
        //this.feedBookForm = {};
        this.feedBookForm.workId = row.workId;
        this.feedBookForm.workTitle = row.workTitle;
        this.feedBookForm.workType = row.workType;
        /*if(row.iconUrl){
          this.feedBookForm.iconUrl = row.iconUrl;
        }*/
        /*if(row.rectificationPlan){
          this.feedBookForm.rectificationPlan =  row.rectificationPlan;
        }
        if(row.rectificationResult){
          this.feedBookForm.rectificationResult =  row.rectificationResult;
        }*/
        //this.feedBookForm = row;
        this.getEnterpriseLists();
      },
      //归档
      sortWork(row){
        this.$confirm('是否确认归档?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.workForm = {};
        this.workForm.workId = row.workId;
        this.workForm.workStatus = '3';
        if (this.workForm.workId != null) {
          updateOrder(this.workForm);
        }
      }).then(response => {
          this.getList();
        this.msgSuccess("归档成功");
      }).catch(() => {});
      },


      //获取隐患信息
      getHiddenInfos(param){
        hiddenTroubleList(param).then(res =>{
          this.hiddenInfoList = res.data;
        /*this.hiddenInfoList.forEach(item=>{
          item.reportPersonName = item.reportPerson;
        })*/
      });
      },
      //隐患信息反馈
      hiddenFeed(row){
        this.title = "隐患反馈信息";
        this.hiddenFeedOpen = true;
        this.hiddenFeedForm.workId = row.workId;
        this.hiddenFeedForm.workTitle = row.workTitle;
        this.hiddenFeedForm.workType = row.workType;
      },

      //督办
      supervisor(row){
        this.title = "任务督办";
        this.supervisorOpen = true;
        this.supervisorForm.workId = row.workId;
        this.supervisorForm.workTitle = row.workTitle;
        this.supervisorForm.workType = row.workType;
      },

      //督办取消
      cancelSupervisor(){
        this.supervisorOpen = false;
        this.supervisorForm = {};
      },
      //查询督办时间线
      supervisorData(workId){
        supervisorInfoList({workId: workId}).then(res =>{
          this.supervisorList = res.data;
      });
      },
      charsOption(dataX, dataY) {
        return {
          title: {
            text: "巡检巡查信息统计图",
          },
          legend: {},
          tooltip: {
            show: true,
            trigger: "item",
            // formatter: "{b}:设备总数;{c},在线:{c},离线:{e},报警:{f}",
            formatter: (params, ticket) => {

            return `巡检次数 ${params.data}`;
      },
        position: function (point, params, dom, rect, size) {
          // 固定在顶部
          return [point[0] + 20, point[1]];
        },
      },
        xAxis: {
          data: dataX,
            axisLabel: {
            interval: 0,
              rotate: 40,
              fontSize: "10",
          },
        },
        yAxis: {
          itemWidth: 10,
        },
        series: [
          {
            type: "bar",
            data: dataY,
            barMaxWidth: 100,
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  position: "top",
                  textStyle: {
                    color: "gray",
                    fontSize: 12,
                  },
                },
              },
            },
          },
        ],
      };
      },
      charsStar() {
        orderCount(this.queryParams).then((res) => {
          console.log("res", res);
        const dataX = res.data.map((item) => {
          return item.timeType;
      });
        const dataY = res.data.map((item) => {
          return item.countNum;
      });
        // const dataX = [1,2,3,4,5,6];
        // const dataY = [150,243,158,365,258,55];
        console.log(dataX, dataY);
        this.myChart = this.$echarts.init(document.getElementById("chars"));

        const option = this.charsOption(dataX, dataY);
        this.myChart.setOption(option);
      });
      },
      // 点击按钮显示隐藏
      changeDisplay() {
        this.isDisplay = !this.isDisplay
        let $timeline = this.$refs.timeline;
        if (!this.showAndHide) {
          for (let i = 0; i < $timeline.$children.length; i++) {
            if (i > 1) {
              $timeline.$children[i].$el.style.display = "block";
            }
          }
          this.showAndHide = true;
        } else {
          for (let i = 0; i < $timeline.$children.length; i++) {
            if (i > 1) {
              $timeline.$children[i].$el.style.display = "none";
            }
          }
          this.showAndHide = false;
        }


        //$timeline.toggleRowExpansion(row,true)
      }
    }
  };
</script>
<style lang="scss" scoped>
  .hiddenInfo{
    font-weight: 700;
    font-size: 18px;
    margin-left: 12px;
    margin-bottom: 9px;
  }
  .timeline{
    width: 330px;
    height: 240px;
    padding: 15px;
    overflow-y: auto;
    &::-webkit-scrollbar {
      width: 5px;
      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;
    }
  }
  .chars {
    width: 100%;
    height: 300px;
    text-align: center;
    line-height: 20;
    font-size: 10px;
    // background: red;
  }
</style>
