<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投诉人" prop="complainName">
        <el-input
          v-model="queryParams.complainName"
          placeholder="请输入投诉人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="指派单位" prop="complainAssignEnterproseId" v-if="deptId==-2" >
        <el-select v-model="queryParams.complainAssignEnterproseId" 
          style="width: 240px" placeholder="请选择预案等级" clearable size="small">
          <el-option
            v-for = "dict in enterpriseList"
            :key = "dict.enterpriseId"
            :label = "dict.enterpriseName"
            :value = "dict.enterpriseId"
          />
        </el-select>
      </el-form-item> 
      <el-form-item label="任务状态" prop="complainStatus">
        <el-select v-model="queryParams.complainStatus"  
          style="width: 240px" placeholder="请选择任务状态" clearable size="small">
            <el-option
              v-for="dict in taskStateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="数据来源" prop="provincialDataFlag" v-if="deptId==-2">
        <el-select v-model="queryParams.provincialDataFlag"  
          style="width: 240px" placeholder="请选择数据来源" clearable size="small">
            <el-option
              v-for="dict in provincialDataFlagOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
        </el-select>
      </el-form-item> 
      
      <el-form-item label="投诉类别" prop="complainType" v-if="deptId==-2">
        <el-select v-model="queryParams.complainType"  
          style="width: 240px" placeholder="请选择投诉类别" clearable size="small"> 
            <el-option label="投诉举报" value="1"/>
            <el-option label="服务申请" value="2"/>
            <el-option label="咨询建议" value="3"/> 
        </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"
          v-if="deptId==-2"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      
      <el-col :span="1.5">
        <el-button
          type="info"
          v-if="deptId==-2"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="provincialDataAcq"
        >省厅数据获取</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          v-if="deptId==-2"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="managementSystemSetting"
        >管理制度设置</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 
    <el-table 
      v-loading="loading" 
      :data="complainDealList" 
      @selection-change="handleSelectionChange"
       @cell-mouse-enter="handleTableRowMouseEnter"
       @cell-mouse-leave="handleTableRowMouseLeave"
       @cell-click="handleTableRowClick">
      <!--<el-table-column label="投诉处置id" align="center" prop="complainDealId" />-->
      <el-table-column label="投诉人姓名" align="center" prop="complainName" >
        <template slot-scope="scope"> 
          <i v-if="scope.row.overtimeSupervision != null && scope.row.overtimeSupervision != ''" class="el-icon-star-on" style="color: red;"></i>
          <span>{{ scope.row.complainName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="投诉人电话" align="center" prop="complainPhone" />
      <el-table-column label="投诉事项" align="center" prop="complainMatter" />
      <el-table-column label="投诉类别" align="center" prop="complainType" >
        <template slot-scope="scope">
          <span v-if="scope.row.complainType == '1'">投诉举报</span>
          <span v-if="scope.row.complainType == '2'">服务申请</span>
          <span v-if="scope.row.complainType == '3'">咨询建议</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="反馈内容" align="center" prop="dealCondition" />-->
      <el-table-column label="指派单位名称" align="center" prop="complainAssignEnterproseName" >
        <template slot-scope="scope">
          <el-popover popper-class="custom-popover" 
                      v-if="scope.row.overtimeSupervision === '0' || scope.row.overtimeSupervision === '1'" 
                      trigger="hover" 
                      placement="top" 
                      :ref="'popover' + scope.row.complainDealId" >
            <p>提示: {{handlePopoverShow(scope.row.overtimeSupervision)}}</p>
            <div slot="reference" class="name-wrapper">
              <span>{{ scope.row.complainAssignEnterproseName }}</span>
            </div>
          </el-popover>
          <span v-if="scope.row.overtimeSupervision != '0' && scope.row.overtimeSupervision != '1'" >
            {{ scope.row.complainAssignEnterproseName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="指派人" align="center" prop="complainAssignMan" >
      </el-table-column> 
      <el-table-column label="任务状态" align="center" prop="complainStatus" :formatter="taskStateFormat" >
      </el-table-column>
      <el-table-column label="督办状态" align="center" prop="overtimeSupervision" :formatter="overtimeSupervisionStateFormat" >
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" align="center" prop="dealTime" width="180" >
        <!--<template slot-scope="scope">-->
          <!--<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
        <!--</template>-->
      </el-table-column>
      <el-table-column label="数据源" align="center" prop="provincialDataFlag" >
          <template slot-scope="scope">
            <span v-if="scope.row.provincialDataFlag === '0'">平台</span>
            <span v-else-if="scope.row.provincialDataFlag === '1'">省厅</span>
            <span v-else>-</span>
          </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope" >
          <el-button
            size="mini"
            v-if="scope.row.complainStatus==1"
            style="color: red"
            type="text"
            icon="el-icon-edit"
            @click.native.stop="handlefankui(scope.row)"
          >反馈</el-button>
          <el-button
            size="mini"
            v-if="scope.row.complainStatus==2 && deptId==-2"
            style="color: #30B46B"
            type="text"
            icon="el-icon-edit"
            @click.native.stop="handlegui(scope.row)"
          >归档</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="(scope.row.complainStatus==1)  && deptId==-2"
            icon="el-icon-edit"
            @click.native.stop="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click.native.stop="handleDtail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.native.stop="handleDelete(scope.row)"
          >删除</el-button>
          <el-button
            v-if="scope.row.complainStatus==1 && deptId!=-2"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.native.stop="handleEnterpriseReturn(scope.row)"
          >退回</el-button>
          <el-button
            v-if="scope.row.complainStatus==4 && deptId==-2"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.native.stop="handleTransfer(scope.row)"
          >转办</el-button>
          <!-- 归档后 再评价 -->
          <el-button
            v-if="scope.row.complainStatus==3 && deptId==-2"
            size="mini"
            type="text"
            icon="el-icon-chat-line-square"
            @click.native.stop="handleSatisfactionEvaluation(scope.row)"
          >满意度评价</el-button> 
          <el-button
            v-if="scope.row.complainStatus!=3 && deptId==-2 && 
            (scope.row.overtimeSupervision != '0' )"
            size="mini"
            type="text"
            icon="el-icon-chat-line-square"
            @click.native.stop="handleOvertimeSupervision(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"/>

    <!-- 添加或修改投诉处置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @close="handleBeforClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <div class="division">
          <div style="width: 50%;">
            <el-form-item label="投诉人姓名" prop="complainName">
              <el-input v-model="form.complainName" placeholder="请输入投诉人姓名" :disabled="readonly"/>
            </el-form-item>
            <el-form-item label="指派单位" prop="complainAssignEnterproseId" >
              <el-select style="width: 100%" v-model="form.complainAssignEnterproseName" placeholder="请选择指派单位"  @change="qiyechang" :disabled="readonly">
                <el-option
                  v-for = "dict in enterpriseList"
                  :key = "dict.enterpriseId"
                  :label = "dict.enterpriseName"
                  :value = "dict.enterpriseId"
                />
              </el-select>
            </el-form-item>
            <!-- 1-投诉举报,2-服务申请,3-咨询建议 -->
            <el-form-item label="投诉类别" prop="complainType"> 
              <el-select style="width: 100%" v-model="form.complainType" :disabled="readonly">
                <el-option label="投诉举报" value="1"/>
                <el-option label="服务申请" value="2"/>
                <el-option label="咨询建议" value="3"/>
              </el-select>
            </el-form-item> 
          </div>
          <div style="width: 50%;">
            <el-form-item label="投诉人电话" prop="complainPhone">
              <el-input v-model="form.complainPhone" placeholder="请输入投诉人电话" :disabled="readonly"/>
            </el-form-item>
            <el-form-item label="指派人" prop="complainAssignManId">
              <el-select v-model="form.complainAssignMan" placeholder="请选择指派人" clearable style = "width: 100%" @change="manChang" :disabled="readonly">
                <el-option
                  v-for = "dict in peopleList"
                  :key = "dict.id"
                  :label = "dict.nickName"
                  :value = "dict.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="所属区域" prop="township">
              <el-select style="width: 100%" v-model="form.township" placeholder="请选择所属区域" clearable size="small"  :disabled="readonly">
                <el-option
                  v-for="dict in townshipOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div> 
        <el-form-item label="投诉事项" prop="complainMatter">
          <el-input v-model="form.complainMatter" type = "textarea" placeholder="请输入投诉事项" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="反馈时间" prop="dealTime" :style="display">
          <el-date-picker clearable size="small"
                          v-model="form.dealTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择反馈时间"
                          :disabled="readonly"
                          style="width: 280px">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="反馈内容" prop="dealCondition" :style="display">
          <el-input v-model="form.dealCondition" type = "textarea" placeholder="请输入办理情况" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="转办记录" prop="transferRecord" :style="display">
          <el-input v-model="form.transferRecord" type="textarea"  placeholder="请输入转办记录" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="任务状态" :style="display" >

          <el-input v-model="form.complainStatus"  placeholder=""  :disabled="readonly"/>
          <!--<el-select v-model="form.complainStatus" placeholder="请选择任务状态"   :disabled="readonly">-->
            <!--<el-option-->
              <!--v-for="dict in taskStateOptions"-->
              <!--:key="dict.dictValue"-->
              <!--:label="dict.dictLabel"-->
              <!--:value="dict.dictValue"-->
            <!--&gt;</el-option>-->
          <!--</el-select>-->
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" :disabled="readonly"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="showDetails">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

      <!-- 转办流程 如果有的话 -->
      <div v-if="complainDealTransferList !== null && complainDealTransferList.length > 0"> 
        <el-divider content-position="left">转办流程</el-divider>
        <el-timeline>
          <el-timeline-item placement="top" :timestamp="item.sj" v-for="(item, index) in complainDealTransferList" :key="index">
            <el-card>
              <el-table :data="item.rows" border>
                <el-table-column v-for="(item, index) in item.dictList" :prop="item.indexCode" :label="item.label" :key="index" align="center"></el-table-column>
              </el-table>
            </el-card>
          </el-timeline-item>
        </el-timeline> 
      </div>
    </el-dialog>
    <!-- 督办历史记录 -->
    <el-dialog title="督办历史记录" :visible.sync="historyOvertimeSupervisionVisible" width="650px">
      <el-table :data="historyOvertimeSupervisionList">
          <el-table-column
          prop="createTime"
          label="督办创建日期"
          width="150">
        </el-table-column>
        <el-table-column
          prop="supervisionReasons"
          label="督办事由"
          width="150">
        </el-table-column>
          <el-table-column
          prop="updateTime"
          label="回复时间"
          width="150">
        </el-table-column>
        <el-table-column
          prop="concent"
          label="回复信息"
          width="150">
        </el-table-column>
      </el-table>
    </el-dialog>
<!-- 超时督办 -->
    <el-dialog title="超时督办" :visible.sync="dialogOvertimeSupervisionVisible" width="600px">
      <div style="padding-bottom:20px">
        <el-button type="info" @click="historyOvertimeSupervisionListButton">历史督办记录</el-button>
      </div>
      <el-form :model="overtimeSupervisionForm"> 
        <div class="page-header clearfix">
            <div class="leftfix">督办事由</div>
            <div class="rightfix" v-show="overtimeSupervisionForm.createTime != null && overtimeSupervisionForm.createTime !=''">
              <div>督办创建时间</div>
              <div>{{overtimeSupervisionForm.createTime}}</div>
            </div>
        </div> 
        <textarea class="inputstyle" v-model="overtimeSupervisionForm.supervisionReasons" type ="textarea" :readonly="this.supervisionReasonsStatus ? false : 'readonly'"></textarea>


        <div class="page-header clearfix" v-show="showFeedbackVisible">
            <div class="leftfix">回复</div>
            <div class="rightfix" v-show="overtimeSupervisionForm.updateTime != null && overtimeSupervisionForm.updateTime !=''">
              <div>回复时间</div>
              <div>{{overtimeSupervisionForm.updateTime}}</div>
            </div>
            <textarea class="inputstyle" v-model="overtimeSupervisionForm.concent" type ="textarea" :readonly="this.supervisionFeedbackStatus ? false : 'readonly'"></textarea>
        </div> 

        <!-- <el-form-item label="回复" v-show="showFeedbackVisible">
            <textarea class="inputstyle" v-model="overtimeSupervisionForm.concent" type ="textarea" :readonly="this.supervisionFeedbackStatus ? false : 'readonly'"></textarea>
        </el-form-item> -->
      </el-form>
      <div v-show="showFeedbackOperationVisible" slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="dialogOvertimeSupervisionVisible = false">取 消</el-button>
        <el-button type="primary"  @click="submitOvertimeSupervision">确 定</el-button>
      </div>
    </el-dialog>
    
<!-- 投诉转办 -->
    <el-dialog title="投诉转办" :visible.sync="dialogTransferVisible" width="600px">
      <el-form :model="transferForm">
        <div style="width: 100%;min-height: 100px;margin-top: -20px">
          <el-form-item label="指派单位" prop="complainAssignEnterproseId" >
            <el-select style="width: 100%" v-model="transferForm.complainAssignEnterproseName" placeholder="请选择指派单位"  @change="transferEnterpriseChang">
              <el-option
                v-for = "dict in transferEnterpriseList"
                :key = "dict.enterpriseId"
                :label = "dict.enterpriseName"
                :value = "dict.enterpriseId"
              />

            </el-select>
          </el-form-item>
          
          <el-form-item label="指派人" prop="complainAssignManId">
            <el-select v-model="transferForm.complainAssignMan" placeholder="请选择指派人" clearable style = "width: 100%" @change="transferManChang">
              <el-option
                v-for = "dict in peopleList"
                :key = "dict.id"
                :label = "dict.nickName"
                :value = "dict.id"
              />
            </el-select>
          </el-form-item> 
        </div> 
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="dialogTransferVisible = false">取 消</el-button>
        <el-button type="primary"  @click="transferSubmint">确 定</el-button>
      </div>
    </el-dialog>
<!-- 反馈内容 -->
    <el-dialog title="反馈内容" :visible.sync="dialogFormVisible" width="600px">
      <el-form :model="form2">
        <div style="width: 100%;min-height: 100px;margin-top: -20px">
          <el-form-item label="投诉事项" prop="complainMatter">
            <textarea class="inputstyle1" v-model="form2.complainMatter"  readonly></textarea>
          </el-form-item>
        </div>
        <el-form-item label="反馈" style = "margin-top: -15px;">
            <textarea class="inputstyle" v-model="form2.concent" type ="textarea" ></textarea>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary"  @click="submint2">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 退回原因描述 -->
    <el-dialog title="退回原因" :visible.sync="dialogEnterpriseReturnVisible" width="600px" @close="handleEnterpriseReturnBeforClose">
      <el-form :model="enterpriseReturnForm">
        <el-form-item label="原因描述" style = "margin-top: -15px;">
            <textarea class="inputstyle" v-model="enterpriseReturnForm.reasonConcent" type ="textarea" ></textarea>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="dialogEnterpriseReturnVisible = false">取 消</el-button>
        <el-button type="primary"  @click="EnterpriseReturnSubmint">确 定</el-button>
      </div>
    </el-dialog>
    
    <!-- 评价 -->
    <el-dialog title="满意度评价" :visible.sync="dialogEvaluateVisible" width="600px" @close="handleEvaluateReturnBeforClose">
      <el-form :model="evaluateForm">
        <el-form-item label="评分" style = "margin-top: -15px;">
            <el-rate v-model="evaluateForm.evaluateRate" :disabled="evaluateFormRateDisabled"></el-rate>
        </el-form-item>
        <el-form-item label="原因描述" style = "margin-top: -15px;">
            <textarea class="inputstyle" v-model="evaluateForm.evaluateContent" type ="textarea" :readonly="evaluateFormContentReadonly"></textarea>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;" v-show="evaluateFormFooterVisible">
        <el-button @click="dialogEvaluateVisible = false">取 消</el-button>
        <el-button type="primary"  @click="evaluateSubmint">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 管理制度设置 -->
    <el-dialog title="管理制度设置" :visible.sync="dialogManSysSetVisible" width="900px">
      <el-table :data="complainDealManSysSetList">
        <el-table-column prop="fType" label="投诉处置类型" width="120">
          <template slot-scope="scope">
            <span v-if="scope.row.fType === '1'">投诉举报</span>
            <span v-else-if="scope.row.fType === '2'">服务申请</span>
            <span v-else-if="scope.row.fType === '3'">咨询建议</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="及时办结时长">
          <template slot-scope="scope">
           <DurationSetting :duration="scope.row" @update:externalMilliseconds="handleTotalMilliseconds($event, scope.$index)"></DurationSetting>
          </template>
        </el-table-column>
        
        <el-table-column prop="fRemarks" label="备注">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.fRemarks"
              @blur="handleManSysSetRemarksEdit(scope.$index, scope.row)"
              size="small">
            </el-input>
          </template>
        </el-table-column>
      </el-table>
      
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="managementSystemSettingCancel">取 消</el-button>
        <el-button type="primary"  @click="managementSystemSettingSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComplainDeal, getComplainDeal, delComplainDeal, addComplainDeal, 
         updateComplainDeal, exportComplainDeal,getUserList,getComplainDealManSysSet,
         batchUpdateComplainDealManSysSet,addComplainTransFer,listComplainTransFer,
         addComplainEvaluate,updateComplainEvaluate,getComplainEvaluateByComplainDealId,
         getOverSuperByComplainDealIdAndStatus,addComplainDealOverSuper,
         updateComplainDealOverSuper,overtimeSupervisionFeedbackConfirmationMethod,
         historyOvertimeSupervisionListMethod } from "@/api/complainDeal/complainDeal";
import {enterpriseList,transferEnterpriseListMethod} from "@/api/system/eventInfo";
import { getUserProfile } from "@/api/system/user";
import { MessageBox } from 'element-ui'
import DurationSetting from '@/components/DurationSetting';
export default {
  name: "ComplainDeal",
  components: {
    DurationSetting
  },
  data() {
    return {
      externalMilliseconds: 0,
      //查看详情时,隐藏底部确定和取消按钮
      showDetails:true,
      //查看详情时,查看是否有 转办记录
      complainDealTransferList:[], 
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 所属乡镇字典
      townshipOptions: [],
      // 总条数
      total: 0,
      // 投诉处置表格数据
      complainDealList: [],
      enterpriseList:[],
      peopleList:[],
      transferEnterpriseList:[],
      transferPeopleList:[],
      readonly:false,
      display:"display:none",
      // 投书状态类型:1.派发中 2.反馈 3.归档
      taskStateOptions: [],
      // 数据源:0.平台自建 1.省厅获取
      provincialDataFlagOptions: [
        {
          value: '0',
          label: '平台自建数据'
        },{
          value: '1',
          label: '省厅获取数据'
        }
      ],
      // 投诉处置制度表格数据
      complainDealManSysSetList:[],
      //督办历史记录数据
      historyOvertimeSupervisionList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dialogFormVisible:false,
      dialogManSysSetVisible:false,
      dialogEnterpriseReturnVisible:false,
      dialogTransferVisible:false,
      dialogEvaluateVisible:false,
      dialogSummaryAnalysisVisible:false,
      //超时督办 是否显示弹出层
      dialogOvertimeSupervisionVisible:false,
      //督办事由 企业端只读
      supervisionReasonsStatus:true,
      //反馈 监管部门只读
      supervisionFeedbackStatus:true,
      //超时督办  反馈是否显示
      showFeedbackVisible:false,
      //超时督办  操作是否显示
      showFeedbackOperationVisible:true,
      //历史督办记录弹出层
      historyOvertimeSupervisionVisible:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        complainName: null,
        complainPhone: null,
        complainMatter: null,
        complainType:null,
        transferRecord: null,
        dealCondition: null,
        complainAssignEnterproseName: null,
        complainAssignEnterproseId: null,
        complainAssignManId: null,
        complainAssignMan: null,
        complainStatus: null,
        isDel: null,
        remarks: null
      },
      // 表单参数
      form: {
        peopleList:[],
      },
      form2:{
        complainDealId:'',
        complainMatter:'',
        concent:'',
      },
      
      overtimeSupervisionForm:{
        //自己的id
        complainDealOverSuperId:'',
        //关联id
        complainDealId:'',
        //督办事由
        supervisionReasons:'',
        //反馈
        concent:'',
        // 超时督办:0-创建,1-企业反馈,2-确认反馈,不确认时监管部门直接改成 0  默认0
        overtimeSupervision:'',
        //创建时间
        createTime:'',
        //修改时间
        updateTime:''
      },
      enterpriseReturnForm:{
        complainDealId:'',
        reasonConcent:'',
        complainAssignManId:'',
        complainAssignMan:''
      },
      
      evaluateForm:{
        complainDealEvaluateId:0,
        complainDealId:0,
        evaluateContent:'',
        evaluateRate:null
      },
      //满意度评价底部只读
      evaluateFormFooterVisible:true,
      evaluateFormContentReadonly:false,
      evaluateFormRateDisabled:false,

      defaultEvaluateForm:{
        complainDealEvaluateId:0,
        complainDealId:0,
        evaluateContent:'',
        evaluateRate:null
      },
      
      transferForm:{
        complainDealId:'', 
        complainAssignEnterproseId:'',
        complainAssignEnterproseName:'',
        complainAssignManId:'',
        complainAssignMan:''
      },
      //身份
      deptId:'',
      // 表单校验
      rules: {
        complainName: [
          { required: true, message: "投诉人不能为空", trigger: "blur" }
        ],
        complainPhone: [
          { required: true, message: "投诉人电话不能为空", trigger: "blur" }
        ],
        complainMatter: [
          { required: true, message: "投诉事项不能为空", trigger: "blur" }
        ],
        complainAssignEnterproseId: [
          { required: true, message: "指派单位不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getUser();
    this.getEnterpriseList();
    this.getDicts("task_state").then(response => {
      this.taskStateOptions = response.data;
    });
    this.getDicts("t_township").then(response => {
      this.townshipOptions = response.data;
    });
  },  
  methods: {
    //获取deptId
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.deptId = response.data.deptId;
        //console.log(this.deptId)
    });
    },
    /** 查询投诉处置列表 */
    getList() {
      this.loading = true;
      listComplainDeal(this.queryParams).then(response => {
        this.complainDealList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }, 
    //公司列表
    getEnterpriseList() {
      enterpriseList(this.queryParams).then(response => {
        this.enterpriseList = response.data;
      });
    },
    qiyechang(value){
      this.form.complainAssignMan="";
      let obj = {};
      obj = this.enterpriseList.find((item)=>{
        return item.enterpriseId === value;
      });
      this.form.complainAssignEnterproseName = obj.enterpriseName;
      this.form.complainAssignEnterproseId = value;
      getUserList(value).then(response => {
        //console.log(this.peopleList)
        this.peopleList=response.data;
      });
    },
    // 企业退回原因 对话框关闭
    handleEnterpriseReturnBeforClose() {
    },
    manChang(value){
      let obj = {};
      obj = this.peopleList.find((item)=>{
        return item.id === value;
      });
      this.form.complainAssignManId === value;
      this.form.complainAssignMan = obj.nickName;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        complainDealId: null,
        complainName: null,
        complainPhone: null,
        complainMatter: null,
        complainType:null,
        overtimeSupervision:null,
        transferRecord: null,
        dealCondition: null,
        complainAssignEnterproseName: null,
        complainAssignEnterproseId: null,
        complainAssignManId: null,
        complainAssignMan: null,
        complainStatus: "1",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDel: null,
        remarks: null,
        township: 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.complainDealId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    overtimeSupervisionStateFormat(row,column){
      if(row.overtimeSupervision === null || row.overtimeSupervision == '') {
        return '-'
      } else if (row.overtimeSupervision === '0') {
        return <p style='color: #ff7272'>督办中</p>
      } else if (row.overtimeSupervision === '1') {
        return <p style='color: #30B46B'>已回复</p>
      }
    },
    taskStateFormat(row, column) {
      var status = this.selectDictLabel(this.taskStateOptions, row.complainStatus);
      if(status=='派发中'){
        return <p style='color: #ff7272'>派发中</p>
      }else if(status=="已反馈"){
        return <p style='color: #1890ff'>已反馈</p>
      }else if(status=="已归档"){
        return <p style='color: #30B46B'>已归档</p>
      } else {
        return <p style='color: #ff0000'>企业退回</p>
      }
      return this.selectDictLabel(this.taskStateOptions, row.complainStatus);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.display="display:none";
      this.readonly = false;
      this.peopleList=[];
      this.reset();
      this.open = true;
      this.title = "添加投诉处置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.display="display:none";
      this.readonly = false;
      this.peopleList=[];
      this.reset();
      const complainDealId = row.complainDealId || this.ids
      getComplainDeal(complainDealId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改投诉处置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.complainDealId != null) {
            updateComplainDeal(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addComplainDeal(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleBeforClose() {
      if (this.readonly) {
        this.showDetails = true;
      }
      this.complainDealTransferList = [];
    },
    //详情
    handleDtail(row) {
      const complainDealId = row.complainDealId || this.ids
      //先看有没有转办记录
      listComplainTransFer(complainDealId).then(response =>{
        this.complainDealTransferList =  response.data; 
        this.showDetails = false;
        this.display="display:";
        this.readonly = true;
        this.reset();
        getComplainDeal(complainDealId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "投诉处置详情";
          var statusName = this.selectDictLabel(this.taskStateOptions, row.complainStatus);
          this.form.complainStatus=statusName; 
        }); 
      }) 
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const complainDealIds = row.complainDealId || this.ids;
      this.$confirm('是否确认删除选中的投诉处置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delComplainDeal(complainDealIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    //归档
    handlegui(row) {
      const complainDealIds = row.complainDealId || this.ids;
      this.$confirm('是否确认归档选中的投诉处置数据项?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "success"
      }).then(() => {
        var a = {"complainDealId":complainDealIds,"complainStatus":3}
        return updateComplainDeal(a);
      }).then(() => {
        this.msgSuccess("归档成功");
        this.getList();
      }).catch(() => {});
    },
    //反馈
    handlefankui(row){
      this.form2.concent="";
      this.dialogFormVisible = true;
      this.form2.complainDealId=row.complainDealId;
      this.form2.complainMatter = row.complainMatter;
    },
    //提交反馈信息
    submint2(){
      var a = {"complainDealId":this.form2.complainDealId,"complainStatus":2,"dealCondition":this.form2.concent}
      updateComplainDeal(a).then(response => {
        this.msgSuccess("修改成功");
        this.dialogFormVisible = false;
        this.getList();
      });
    },
    //管理制度 备注修改回调函数
    handleManSysSetRemarksEdit(index, row) {
      this.complainDealManSysSetList[index].fRemarks = row.fRemarks;
    },
    //管理制度取消
    managementSystemSettingCancel() {
      this.dialogManSysSetVisible = false;

    },
    //管理制度提交
    managementSystemSettingSubmit() {
      batchUpdateComplainDealManSysSet(this.complainDealManSysSetList).then(response =>{
        this.msgSuccess("管理制度修改成功");
        this.dialogManSysSetVisible = false;
      });
    },

    // 时间控件传回来的值
    handleTotalMilliseconds(manSysSetDuration,index){ 
      this.complainDealManSysSetList[index].fDay = manSysSetDuration.fDay;
      this.complainDealManSysSetList[index].fHours = manSysSetDuration.fHours;
      this.complainDealManSysSetList[index].fMinutes = manSysSetDuration.fMinutes;
      this.complainDealManSysSetList[index].fSeconds = manSysSetDuration.fSeconds;
    },
// 管理制度设置
    managementSystemSetting(){
      getComplainDealManSysSet().then(response =>{
        this.complainDealManSysSetList = response.data;
        this.dialogManSysSetVisible = true;
      })
    },
// 省厅数据获取
    provincialDataAcq(){
      this.$alert('省住建厅网站受理入口开发中,目前还无数据', '省厅数据获取', { confirmButtonText: '确定'});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有投诉处置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportComplainDeal(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },

    //企业退回
    handleEnterpriseReturn(row){
      this.dialogEnterpriseReturnVisible = true;
      this.enterpriseReturnForm.complainDealId = row.complainDealId;
      this.enterpriseReturnForm.complainAssignManId = row.complainAssignManId;
      this.enterpriseReturnForm.complainAssignMan = row.complainAssignMan;
      this.enterpriseReturnForm.reasonConcent = "";
    },
    //监管部门把企业退回的投诉 转办给其他企业
    handleTransfer(row){
      this.transferForm.complainDealId = row.complainDealId; 
      this.transferEnterpriseList = [];
      this.transferForm.complainAssignMan = "";
      transferEnterpriseListMethod(this.transferForm.complainDealId).then(response =>{
        this.transferEnterpriseList = response.data;
        this.dialogTransferVisible = true;
      })
    }, 
    transferEnterpriseChang(value){
      let obj = {};
      obj = this.transferEnterpriseList.find((item)=>{
        return item.enterpriseId === value;
      });

      this.transferForm.complainAssignEnterproseName = obj.enterpriseName;
      this.transferForm.complainAssignEnterproseId = value;
      getUserList(value).then(response => {
        //console.log(this.peopleList)
        this.peopleList=response.data;
      });
    },
    
    transferManChang(value){
      let obj = {};
      obj = this.peopleList.find((item)=>{
        return item.id === value;
      });
      this.transferForm.complainAssignManId === value;
      this.transferForm.complainAssignMan = obj.nickName;
    },
    //投诉转办 提交按钮
    transferSubmint() {
      //把这条数据的状态改成 派发中
      this.transferForm.complainStatus = '1';
      console.log(JSON.stringify(this.transferForm))
      updateComplainDeal(this.transferForm).then(response => {
        this.msgSuccess("修改成功");
        this.dialogTransferVisible = false;
        this.getList();
      });

    },
    //企业把 投诉处置退回 提交
    EnterpriseReturnSubmint() {
      addComplainTransFer(this.enterpriseReturnForm).then(response => {
        this.msgSuccess("已退回");
        this.dialogEnterpriseReturnVisible = false;
        this.getList();
      });
    },

    //查询历史督办信息展示
    historyOvertimeSupervisionListButton() {
      const complainDealId = this.overtimeSupervisionForm.complainDealId;
      const param = {
        complainDealId
      }
      historyOvertimeSupervisionListMethod(param).then(response => {
        this.historyOvertimeSupervisionList = response.data;
        this.historyOvertimeSupervisionVisible = true;
      })
    },
    //督办详情点击 table 每行
    handleTableRowClick(row, column, cell, event){ 
      if (row.overtimeSupervision === '0' || row.overtimeSupervision === '1') {
        
        const query = {
          complainDealId:row.complainDealId,
          overtimeSupervision:row.overtimeSupervision
        }
        getOverSuperByComplainDealIdAndStatus(query).then(response => {
          this.overtimeSupervisionForm = response.data;
          if(this.deptId == '-2') {
            if (this.overtimeSupervisionForm.overtimeSupervision === '1'){
              this.supervisionReasonsStatus = false;
            } else {
              this.supervisionReasonsStatus = true;
            }
            this.supervisionFeedbackStatus = false;
          } else {
            this.supervisionReasonsStatus = false;
            this.supervisionFeedbackStatus = true;
          }  
          // 判断 反馈是否需要显示
          if (this.deptId != "-2") {
            this.showFeedbackVisible =  true;
          } else if (this.deptId === "-2" && this.overtimeSupervisionForm.concent != '') {
            this.showFeedbackVisible =  true;
          } else {
            this.showFeedbackVisible =  false;
          }

          if (this.overtimeSupervisionForm.overtimeSupervision === '1') {
            this.showFeedbackOperationVisible = false
          } else {
            this.showFeedbackOperationVisible = true
          }

          this.dialogOvertimeSupervisionVisible = true;
        }) 

      }

    },
    handleTableRowMouseLeave(row, column, cell, event){ 
        if (this.$refs['popover'+row.complainDealId]) {
          this.$refs['popover'+row.complainDealId].showPopper = false
        }
    },
    handleTableRowMouseEnter(row, column, cell, event){ 
      if (this.$refs['popover'+row.complainDealId]) {
        this.$refs['popover'+row.complainDealId].showPopper = true
      }
    },
    handlePopoverShow(overtimeSupervision){
      if(overtimeSupervision === '0') {
        return '超时督办进行中,点击查看详情'
      } else if (overtimeSupervision === '1') {
        return '超时督办企业已反馈,点击查看详情'
      }
    },
    //超时督办 反馈确认 -- 经讨论不需要了
    overtimeSupervisionFeedbackConfirmation(){ 
      MessageBox.confirm('是否确认反馈?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '否定',
        type: 'warning'
      }).then(async () => {
        this.overtimeSupervisionForm.overtimeSupervision = "2"
        await overtimeSupervisionFeedbackConfirmationMethod(this.overtimeSupervisionForm);
      
        this.dialogOvertimeSupervisionVisible = false;
        this.getList();
      }).catch(async () => {
        this.overtimeSupervisionForm.overtimeSupervision = "0"
        await overtimeSupervisionFeedbackConfirmationMethod(this.overtimeSupervisionForm);  
        
        this.dialogOvertimeSupervisionVisible = false;
        this.getList();  
      });
    },
    //提交督办事由 有id就修改,没id就新增
    submitOvertimeSupervision(){
      console.log("this.overtimeSupervisionForm = " + this.overtimeSupervisionForm)
      //有就修改
      if(this.overtimeSupervisionForm.complainDealOverSuperId == null ||
      this.overtimeSupervisionForm.complainDealOverSuperId === '') {
        addComplainDealOverSuper(this.overtimeSupervisionForm).then(response => {
          this.msgSuccess("新增成功")
          this.dialogOvertimeSupervisionVisible = false;
          this.getList();
        })
      //没有就新增
      } else { 
        updateComplainDealOverSuper(this.overtimeSupervisionForm).then(response => {
          this.msgSuccess("修改成功")
          this.dialogOvertimeSupervisionVisible = false;
          this.getList();
        })
      }
    },
    //监管部门-点击超时督办 操作 按钮 
    handleOvertimeSupervision(row){
      // 说明还没创建过 超时督办,就不查数据库了 
      if (row.overtimeSupervision == null || row.overtimeSupervision === '' || row.overtimeSupervision === '1'){
        this.overtimeSupervisionForm.complainDealId = row.complainDealId;
        this.overtimeSupervisionForm.complainDealOverSuperId = '';
        this.overtimeSupervisionForm.supervisionReasons = '';
        this.overtimeSupervisionForm.concent = '';
        this.overtimeSupervisionForm.overtimeSupervision = '';
        this.overtimeSupervisionForm.createTime = '';
        this.overtimeSupervisionForm.updateTime = '';
        this.dialogOvertimeSupervisionVisible = true;
        this.showFeedbackOperationVisible = true;
        this.showFeedbackVisible =  false;
        this.supervisionReasonsStatus = true;
      // 说明创建了 超时督办了,监管部门可能要对最新的一条记录进行修改,那就也查 超时督办的 状态是0的数据。
      //  || 说明是 企业反馈了,那就也查 超时督办的 状态是0的数据。
      } else if (row.overtimeSupervision === '0') {
        const query = {
          complainDealId:row.complainDealId,
          overtimeSupervision:row.overtimeSupervision
        }
        getOverSuperByComplainDealIdAndStatus(query).then(response => {
          this.overtimeSupervisionForm = response.data;
          this.dialogOvertimeSupervisionVisible = true;
        })
      // 
      }
    },
    // 满意度评价
    handleSatisfactionEvaluation(row){
       
      this.evaluateFormFooterVisible=true,
      this.evaluateFormContentReadonly=false,
      this.evaluateFormRateDisabled=true, 

      Object.keys(this.defaultEvaluateForm).forEach(key => {  
      // 使用 key 从 defaultFormValues 中获取默认值,并赋值给 myForm 的对应字段  
        this.evaluateForm[key] = this.defaultEvaluateForm[key];  
      });  
      this.evaluateForm.complainDealId = row.complainDealId;
      getComplainEvaluateByComplainDealId(this.evaluateForm.complainDealId).then(response =>{
        const data = response.data;
        
        if (data != null) {
          this.evaluateForm = data;
        }

        if ((this.evaluateForm.evaluateContent == null || this.evaluateForm.evaluateContent ==='') && 
             this.evaluateForm.evaluateRate == null ) {
            this.evaluateFormFooterVisible=true;
            this.evaluateFormContentReadonly=false;
            this.evaluateFormRateDisabled=false;
        } else{
            this.evaluateFormFooterVisible=false;
            this.evaluateFormContentReadonly='readonly';
            this.evaluateFormRateDisabled=true;
        }

         this.dialogEvaluateVisible = true;
      })
    },
    // 满意度评价提交
    evaluateSubmint(){ 
      if (this.evaluateForm.complainDealEvaluateId != null && this.evaluateForm.complainDealEvaluateId != 0) {
        updateComplainEvaluate(this.evaluateForm).then(response => {
          this.msgSuccess("评论修改成功");
          this.dialogEvaluateVisible = false;
        })
      } else {
        addComplainEvaluate(this.evaluateForm).then(response => {
          this.msgSuccess("评论添加成功");
          this.dialogEvaluateVisible = false;
        })
      }
    },
    //关闭之前
    handleEvaluateReturnBeforClose() {

    },
  //按照 区域 和  类型 统计发生量
    drawNumberOfComplaints() {
      
    }
  },
}
</script>
<style>
  .division{
    display:flex;
    flex-direction:row;
    justify-content:flex-start;
  }
  .inputstyle{
    min-height: 200px;
    max-height: 300px;
    width: 100%;
    border-color: 0.5px #99a9bf;
    outline:none;
  }
  .inputstyle1{
    min-height: 50px;
    max-height: 200px;
    width: 100%;
    border : none;
    resize:none;
    outline:none;
  } 
.circle {
  position: absolute;
  top: 17px;
  left: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 5px;
}
.custom-popover {
  color: #f1f2f6; /* 字体颜色 */
  border: none; /* 可以设置边框样式,如果不需要则移除 */
  background-color: #f56c6c; /* 设置你想要的背景色 */
}
textarea {
  resize: none;
}
.leftfix {
      float: left;
      font-weight: bold;
  }
.rightfix {
    float: right;
}

.clearfix::after {
    content: '';
    display: block;
    clear: both;
}
</style>