<template>
  <view class="content">
    <view  class="flex-between card custom-padding">
      <text>考评状态: </text>
      <text @click="showTree('evaluationStateTree')">{{ searchForm.stateName || '请选择' }}</text>
      <tki-tree ref="evaluationStateTree" :range="evaluationStateTreeList" rangeKey="name" @confirm="confirmTree($event,'evaluationStateTreeList')"/>
    </view>
    <view  class="flex-between card  custom-padding">
      <text>本人是否考评: </text>
      <text @click="showTree('ifIAmEvaluatedTree')">{{ searchForm.userIsName || '请选择' }}</text>
      <tki-tree ref="ifIAmEvaluatedTree" :range="ifIAmEvaluatedTreeList" rangeKey="name" @confirm="confirmTree($event,'ifIAmEvaluatedTreeList')"/>
    </view>
    <view class="flex-between search card">
      <u--input
          class="ml-10"
          prefixIcon="search"
          placeholder="请输入隐患发现人"
          border="surround"
          v-model="searchForm.KEYWORDS"
          clearable
          shape="circle"
      ></u--input>
      <u-button class="bth-mini ml-10" type="success" text="确定" @click="resetList"></u-button>
    </view>
    <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view>
          <view class="flex-between mt-10 main-title">
            <text>
              隐患来源:
              <template v-if="item.SOURCE == 1">隐患快报</template>
              <template v-if="item.SOURCE == 2 || item.SOURCE == 3">清单排查</template>
              <template v-if="item.SOURCE == 4">安全环保检查(监管端)</template>
              <template v-if="item.SOURCE == 5">安全环保检查(企业端)</template>
              <template v-if="item.SOURCE == 6">消防检查</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>隐患描述:{{ item.HIDDENDESCR }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>隐患发现人:{{ item.CREATOR_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>隐患状态:已验收</text>
            <text>隐患发现时间:{{ item.DISCOVERYTIME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>已考评组成员:{{ item.CHECK_USER }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>待考评组成员:{{ item.UN_CHECK_USER }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>
              考评结果:
              <template v-if="item.CHECK_COUNT !== 5">考核未完成</template>
              <template v-else>
                <template v-if="item.CHECK_COUNT > 2">考核合格</template>
                <template v-else>考核不合格</template>
              </template>
            </text>
          </view>
          <view class="flex-end mt-10">
            <u-button type="default" text="查看隐患详情" size="mini" class="bth-mini btn-hidden-detail-bg margin-value" @click="fnViewHidden(item.HIDDEN_ID)"></u-button>
            <u-button type="default" text="考评详情" size="mini" class="bth-mini btn-eval-detail-bg margin-value" @click="fnEvaluation(item.HIDDEN_ID,item.SOURCE, item.CREATOR,'view')"></u-button>
            <u-button v-if="isEvaluationShowButton(item.UN_CHECK_USER_ID)" type="default" text="考评" size="mini" class="bth-mini btn-eval-bg margin-value" @click="fnEvaluation(item.HIDDEN_ID, item.SOURCE, item.CREATOR,'edit')"></u-button>
            <u-button v-if="USER_ID=='1'" type="default" text="重置考评" size="mini" class="bth-mini btn-reset-bg" @click="fnDelvaluation(item)"></u-button>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
    <u-popup :show="evaluationAndDetailShow" @close="evaluationAndDetailShow = false" mode="right" :closeOnClickOverlay="false" :customStyle="{width:'85vw',overflowY:'auto'}">
      <view class="card">
        <u-list @scrolltolower="scrolltolower" v-if="evaluationDialog.list.length > 0" height="auto">
          <u-list-item v-for="(value, index) in evaluationDialog.list" :key="index">
            <view>
              <view class="flex-between mt-10 subtitle">
                <text>考评人员:{{ value.USER_NAME }}</text>
              </view>
              <view class="flex-between mt-10 subtitle">
                <text>考评时间:{{ value.CREATTIME ? value.CREATTIME : "暂未考评" }}</text>
              </view>
              <view class="flex-between mt-10 subtitle">
                <text>
                  是否符合:
                  <template v-if="value.RESULT === 1">符合</template>
                  <template v-if="value.RESULT === 2">不符合</template>
                  <template v-if="!value.RESULT">未考评</template>
                </text>
              </view>
              <view class="flex-between mt-10 subtitle"  v-if="value.RESULT === 2" :key="value.CONFIG_USER_ID">
                <text>不符合原因:{{ value.DESCR }}</text>
              </view>
            </view>
          </u-list-item>
        </u-list>
        <empty v-else></empty>
        <u-cell-group :border="false">
          <u-cell v-show="addShowOrHidden" class="flex-none">
            <view slot="title" class="title">考评人员:</view>
            <view slot="value" class="mt-10">
              <u--input v-model="evaluationDialog.form.USER_NAME" disabled="true"></u--input>
            </view>
          </u-cell>
          <u-cell v-show="addShowOrHidden">
            <view slot="title" class="title required">是否符合:</view>
              <view slot="value">
                <text @click="showTree('tree')">{{ evaluationDialog.form.NAME || '请选择' }}</text>
                <tki-tree ref="tree" :range="hiddenTypeTreeList" rangeKey="name" @confirm="confirmTree($event,'isIfTrueTreeList')"/>
              </view>
          </u-cell>
          <u-cell v-show="isdescr"  class="flex-none">
            <view slot="title" class="title required">不符合原因:</view>
            <view slot="value" class="mt-10">
              <u--textarea v-model="evaluationDialog.form.DESCR" placeholder="请输入不符合原因"></u--textarea>
            </view>
          </u-cell>
          <u-cell class="flex-none" :border="false">
            <view slot="value" class="flex-between">
              <u-button type="info" text="关闭" class="bth" @click="evaluationAndDetailClose"></u-button>
              <u-button v-show="addShowOrHidden" type="primary" text="保存" class="bth ml-10" @click="evaluationAndDetailSave"></u-button>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </u-popup>
    <u-popup :show="hiddenDetailShow" @close="hiddenDetailShow = false" mode="right" :closeOnClickOverlay="false" :customStyle="{width:'85vw',overflowY:'auto'}">
      <view class="card">
        <view class="view-title">
          <u--text text="隐患信息" bold></u--text>
        </view>
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">隐患来源</view>
            <view slot="value">
              <template v-if="pd.SOURCE=='1'">
                隐患快报
              </template>
              <template v-else-if="pd.SOURCE=='2'">
                清单排查
              </template>
              <template v-else-if="pd.SOURCE=='3'">
                清单排查
              </template>
              <template v-else-if="pd.SOURCE=='4'">
                安全环保检查(监管端)
              </template>
              <template v-else-if="pd.SOURCE=='5'">
                安全环保检查(企业端)
              </template>
              <template v-else-if="pd.SOURCE=='6'">
                消防检查
              </template>
            </view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">隐患描述</view>
            <view slot="value" class="mt-10 u-line-5">{{ pd.HIDDENDESCR }}</view>
          </u-cell>
          <template v-if="pd.SOURCE=='2'">
            <u-cell>
              <view slot="title" class="title">风险点(单元)</view>
              <view slot="value">{{ pd.RISK_UNIT }}</view>
            </u-cell>
            <u-cell>
              <view slot="title" class="title">辨识部位</view>
              <view slot="value">{{ pd.IDENTIFICATION }}</view>
            </u-cell>
            <u-cell>
              <view slot="title" class="title">存在风险</view>
              <view slot="value">{{ pd.RISK_DESCR }}</view>
            </u-cell>
            <u-cell>
              <view slot="title" class="title">风险分级</view>
              <view slot="value">{{ pd.LEVEL }}</view>
            </u-cell>
            <u-cell>
              <view slot="title" class="title">检查内容</view>
              <view slot="value">{{ pd.CHECK_CONTENT }}</view>
            </u-cell>
          </template>
          <u-cell>
            <view slot="title" class="title">隐患级别</view>
            <view slot="value">{{ pd.editLevelName || pd.HIDDENLEVELNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患类型</view>
            <view slot="value">{{ pd.HIDDENTYPENAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患状态</view>
            <view slot="value">
              <template v-if="pd.STATE=='1'">
                未整改
              </template>
              <template v-else-if="pd.STATE=='2'">
                已整改
              </template>
              <template v-else-if="pd.STATE=='3'">
                已整改
              </template>
              <template v-else-if="pd.STATE=='4'">
                已验收
              </template>
              <template v-else-if="pd.STATE=='5'">
                忽略隐患
              </template>
              <template v-else-if="pd.STATE=='6'">
                重大隐患
              </template>
              <template v-else-if="pd.STATE=='7'">
                待处理的特殊隐患
              </template>
              <template v-else-if="pd.STATE=='8'">
                已处理的特殊隐患
              </template>
              <template v-else-if="pd.STATE=='-1'">
                已超期
              </template>
              <template v-else-if="pd.STATE=='-2'">
                待确认
              </template>
              <template v-else-if="pd.STATE=='10'">
                验收打回
              </template>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患部位</view>
            <view slot="value">{{ pd.hregionName?pd.hregionName:pd.HIDDENPART }}</view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">隐患上报位置</view>
            <view slot="value" class="mt-10">
              <view>经度:{{ pd.LONGITUDE }}</view>
              <view>纬度:{{ pd.LATITUDE }}</view>
            </view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">隐患位置描述</view>
            <view slot="value" class="mt-10">{{ pd.POSITIONDESC }}</view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">隐患图片</view>
            <view slot="value" class="mt-10">
              <u-row>
                <u-col span="3" v-for="(item,index) in hImgs" :key="item.id">
                  <u--image :showLoading="true" :src="item.src" width="80px" height="80px"
                            @click="previewImage(hImgs, item)"></u--image>
                </u-col>
              </u-row>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患发现人</view>
            <view slot="value" class="mt-10">{{ pd.CREATORNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患发现时间</view>
            <view slot="value" class="mt-10">{{ pd.DISCOVERYTIME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改类型</view>
            <view slot="value">
              <template v-if="pd.RECTIFICATIONTYPE=='1'">
                立即整改
              </template>
              <template v-else-if="pd.RECTIFICATIONTYPE=='2'">
                限期整改
              </template>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改负责部门</view>
            <view slot="value" class="mt-10">{{ pd.oldDeptName ?pd.oldDeptName :pd.RECTIFICATIONDEPTNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改负责人</view>
            <view slot="value" class="mt-10">{{ pd.oldUserName || pd.RECTIFICATIONORNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">是否相关方</view>
            <view slot="value" class="mt-10">{{ pd.ISRELEVANT=='1'?'是':'否' }}</view>
          </u-cell>
          <u-cell v-if="videoUrl">
            <view slot="title" class="title">隐患视频</view>
            <view slot="value">
              <u-icon name="play-circle-fill" size="30" @click="modalShow = true"></u-icon>
            </view>
          </u-cell>
          <u-modal :show="modalShow" title="视频播放" confirmText="关闭" @confirm="modalShow = false">
            <view>
              <video v-if="modalShow" :src="videoUrl" :autoplay="true"></video>
            </view>
          </u-modal>
          <u-cell v-if="pd.RECTIFICATIONTYPE=='2'">
            <view slot="title" class="title">整改期限</view>
            <view slot="value">{{ pd.RECTIFICATIONDEADLINE }}</view>
          </u-cell>
          <template v-if="repulsecause">
            <u-cell class="flex-none">
              <view slot="title" class="title">打回原因</view>
              <view slot="value" class="mt-10">
                <u-row>
                  <u-col span="3" v-for="(item,index) in repulsecause" :key="item.USER_ID">
                    {{ item.REPULSE_CAUSE }}
                  </u-col>
                </u-row>
              </view>
            </u-cell>
            <u-cell class="flex-none">
              <view slot="title" class="title">打回时间</view>
              <view slot="value" class="mt-10">
                <u-row>
                  <u-col span="3" v-for="(item,index) in repulsecause" :key="item.USER_ID">
                    {{ item.OPERATTIME }}
                  </u-col>
                </u-row>
              </view>
            </u-cell>
          </template>
        </u-cell-group>
      </view>
      <view class="card">
        <view class="view-title">
          <u--text text="确认信息" bold></u--text>
        </view>
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title">隐患级别</view>
            <view slot="value">{{ pd.HIDDENLEVELNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改负责人</view>
            <view slot="value">{{ pd.RECTIFICATIONORNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改完成期限</view>
            <view slot="value">{{ pd.RECTIFICATIONDEADLINE }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">隐患确认人</view>
            <view slot="value">{{ pd.conUserName }}</view>
          </u-cell>
          <u-cell v-if="pd.STATE != '-2'">
            <view slot="title" class="title">隐患确认时间</view>
            <view slot="value">{{ pd.CONFIRM_TIME }}</view>
          </u-cell>
        </u-cell-group>
      </view>

      <view  v-show="pd.STATE>=2 && pd.STATE <16" class="card">
        <view class="view-title">
          <u--text text="整改信息" bold></u--text>
        </view>
        <u-cell-group :border="false">
          <u-cell class="flex-none">
            <view slot="title" class="title">整改描述</view>
            <view slot="value" class="mt-10 u-line-5">{{ pd.RECTIFYDESCR }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改部门</view>
            <view slot="value">{{ pd.RECTIFICATIONDEPTNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改人</view>
            <view slot="value">{{ pd.RECTIFICATIONORNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改时间</view>
            <view slot="value">{{ pd.RECTIFICATIONTIME }}</view>
          </u-cell>
          <u-cell v-if="pd.STATE != '-2'">
            <view slot="title" class="title">投入资金</view>
            <view slot="value">{{ pd.INVESTMENT_FUNDS }}元</view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">整改后图片</view>
            <view slot="value" class="mt-10">
              <u-row>
                <u-col span="3" v-for="(item,index) in rImgs" :key="index">
                  <u--image :showLoading="true" :src="item" width="80px" height="80px"
                            @click="previewImage(rImgs, item)"></u--image>
                </u-col>
              </u-row>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">整改方案</view>
            <view slot="value">
              <template v-if="pd.HAVESCHEME==0">
                无
              </template>
              <template v-else-if="pd.HAVESCHEME==1">
                有
              </template>
            </view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">排查日期</view>
            <view slot="value">{{ hs.SCREENINGDATE }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">治理标准要求</view>
            <view slot="value">{{ hs.GOVERNSTANDARDS }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">治理方法</view>
            <view slot="value">{{ hs.GOVERNMETHOD }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">经费和物资的落实</view>
            <view slot="value">{{ hs.EXPENDITURE }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">负责治理人员</view>
            <view slot="value">{{ hs.PRINCIPAL }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">工时安排</view>
            <view slot="value">{{ hs.PROGRAMMING }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">时限要求</view>
            <view slot="value">{{ hs.TIMELIMITFOR }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">工作要求</view>
            <view slot="value">{{ hs.JOBREQUIREMENT }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1">
            <view slot="title" class="title">其他事项</view>
            <view slot="value">{{ hs.OTHERBUSINESS }}</view>
          </u-cell>
          <u-cell v-if="hs && pd.HAVESCHEME==1" class="flex-none">
            <view slot="title" class="title">方案图片</view>
            <view slot="value" class="mt-10">
              <u-row>
                <u-col span="3" v-for="(item,index) in sImgs" :key="index">
                  <u--image :showLoading="true" :src="item" width="80px" height="80px"
                            @click="previewImage(sImgs, item)"></u--image>
                </u-col>
              </u-row>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
      <view v-show="pd.STATE ==4 || pd.RECTIFICATIONTYPE=='1'" class="card">
        <view class="view-title">
          <u--text text="验收信息" bold></u--text>
        </view>
        <template v-if="pd.RECTIFICATIONTYPE!='1'">
        <u-cell-group v-for="(data) in checkList" :key="data.value" :border="false">
          <u-cell class="flex-none">
            <view slot="title" class="title">验收描述</view>
            <view slot="value" class="mt-10 u-line-5">{{ data.CHECKDESCR }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">是否合格</view>
            <view slot="value">
              <template v-if="data.STATUS=='1'">
                是
              </template>
              <template v-else-if="data.STATUS=='0'">
                否
              </template>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">验收部门</view>
            <view slot="value">{{ data.CHECKDEPTNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">验收人</view>
            <view slot="value">{{ data.CHECKORNAME }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">验收时间</view>
            <view slot="value">{{ data.CHECK_TIME }}</view>
          </u-cell>
          <u-cell class="flex-none">
            <view slot="title" class="title">验收图片</view>
            <view slot="value" class="mt-10">
              <u-row>
                <u-col span="3" v-for="(item,index) in cImgs" :key="index">
                  <u--image :showLoading="true" :src="item" width="80px" height="80px"
                            @click="previewImage(cImgs, item)"></u--image>
                </u-col>
              </u-row>
            </view>
          </u-cell>
        </u-cell-group>
        </template>
        <template v-if="pd.RECTIFICATIONTYPE=='1'">
          <u-cell-group :border="false">
            <u-cell>
              <view slot="title" class="title">验收人</view>
              <view slot="value">{{ pd.CHECKORNAME }}</view>
            </u-cell>
          </u-cell-group>
        </template>
      </view>
      <view class="card">
        <u-cell-group :border="false">
          <u-cell class="flex-none" :border="false">
            <view slot="value" class="flex-between">
              <u-button type="info" text="关闭" class="bth" @click="hiddenDetailPopClose"></u-button>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </u-popup>
  </view>
</template>
<script>
import {getEvaluationList} from "../../../api";
import {goEvaluationEdit} from "../../../api";
import {evaluationAddRecord} from "../../../api";
import {findHiddenDetailMessage} from "../../../api";
// import UviewUi from "../../../uni_modules/uview-ui/components/uview-ui/uview-ui.vue";
// import UText from "../../../uni_modules/uview-ui/components/u-text/u-text.vue";
export default {
  // components: {UText, UviewUi},
  data() {
    return {
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
      HIDDENTYPE: '',
      hiddendescr: '',
      DEPARTMENT_ID: '',
      SOURCE: '',
      EVALUATIONCONFIG_ID: '',
      CORPINFO_ID: '',
      TYPE: '',
      USER_ID: '',
      // 下面是考评弹窗使用到的相关属性
      evaluationAndDetailShow: false,
      evaluationDialog: { // 考评弹窗
        visible: false,
        type: '',
        HIDDEN_ID: '',
        SOURCE: '',
        CREATOR: '',
        form: {
          EVALUATIONCONFIGINFO_ID: '',
          USER_NAME: '',
          DESCR: '',
          RESULT: 0,
          NAME: ''
        },
        list: []
      },
      hiddenTypeTreeList: [
        {
          id: 1,
          name: '符合'
        },
        {
          id: 2,
          name: '不符合'
        }
      ],
      evaluationStateTreeList: [
        {
          id: 0,
          name: '请选择'
        },
        {
          id: 1,
          name: '是'
        },
        {
          id: 2,
          name: '否'
        },
        {
          id: 3,
          name: '考评合格'
        },
        {
          id: 4,
          name: '考评不合格'
        }
      ],
      ifIAmEvaluatedTreeList: [
        {
          id: 0,
          name: '请选择'
        },
        {
          id: 1,
          name: '是'
        },
        {
          id: 2,
          name: '否'
        }
      ],
      selectedTreeValue: '',
      isdescr: false, // 刚一开始不显示不符合原因的输入框
      addShowOrHidden: true, // 添加考评的表单默认为显示
      // 下面是隐患详情弹窗使用到的相关数据
      hiddenDetailShow: false, // 隐患详情的弹窗默认不显示
      pd: {},
      videoUrl: '', // 视频地址
      hImgs: [],
      repulsecause: [],
      rImgs: [],
      cImgs: [],
      sImgs: [],
      hs: {},
      checkList: [],
      modalShow: false, //是否播放视频
      searchForm: {
        KEYWORDS: '',
        STATE: '',
        stateName: '',
        hiddendescr: '',
        userIs: '',
        userIsName: ''
      },
    }
  },
  onLoad(event) {
    this.CORPINFO_ID = event.CORPINFO_ID
    this.EVALUATIONCONFIG_ID = event.EVALUATIONCONFIG_ID
    this.TYPE = event.TYPE
    this.resetList()
  },
  computed: {
    userInfo() {
      this.USER_ID = this.$store.getters.getUserInfo.USER_ID
      return this.$store.getters.getUserInfo
    }
  },
  methods: {
    async getData(){
      let resData = await getEvaluationList({
        ...this.searchForm,
        showCount: this.pageSize,
        currentPage: this.currentPage,
        USER_ID: this.userInfo.USER_ID, // 获取当前用户的ID
        HIDDENTYPE: this.HIDDENTYPE,
        hiddendescr: this.hiddendescr,
        DEPARTMENT_ID:  this.DEPARTMENT_ID,
        SOURCE: this.SOURCE,
        EVALUATIONCONFIG_ID: this.EVALUATIONCONFIG_ID,
        CORPINFO_ID: this.CORPINFO_ID,
        SELECT_CORPINFO_ID: this.CORPINFO_ID,
        TYPE: this.TYPE
      });
      this.list = [...this.list,...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    resetList() {
      this.pageSize= 10
      this.currentPage= 1
      this.list = []
      console.info(this.searchForm)
      this.getData()
    },
    scrolltolower() {
      this.currentPage++;
      if(this.totalPage >= this.currentPage) this.getData();
    },
    isEvaluationShowButton(UN_CHECK_USER_ID) {
      if (!UN_CHECK_USER_ID) return false
      else {
        return UN_CHECK_USER_ID.split(',').indexOf(this.USER_ID) !== -1
      }
    },
    fnEvaluationDialogChangeShow() {
      this.evaluationDialog.visible = !this.evaluationDialog.visible
    },
    fnEvaluation(HIDDEN_ID, SOURCE, CREATOR, type) { // 考评
      this.evaluationDialog.HIDDEN_ID = HIDDEN_ID
      this.evaluationDialog.SOURCE = SOURCE
      this.evaluationDialog.CREATOR = CREATOR
      this.evaluationDialog.type = type
      this.evaluationDialog.list = []
      this.fnEvaluationDialogChangeShow()
      this.isdescr = false;
      if(type === 'view'){
        this.addShowOrHidden = false;
      }else {
        this.addShowOrHidden = true;
      }
      this.getDialogData(HIDDEN_ID, type);
      this.evaluationAndDetailShow = true;
    },
    async getDialogData(HIDDEN_ID, type){
      let resultData = await goEvaluationEdit({
        HIDDEN_ID,
        EVALUATIONCONFIG_ID: this.EVALUATIONCONFIG_ID
      });
      const list = []
      for (let i = 0; i < resultData.varList.length; i++) {
        if (type === 'edit') {
          if (resultData.varList[i].CONFIG_USER_ID !== this.USER_ID) { //非当前登陆用户
            list.push(resultData.varList[i])
          } else { // 当前登陆用户
            this.evaluationDialog.form.EVALUATIONCONFIGINFO_ID = resultData.varList[i].CONFIG_EVALUATIONCONFIGINFO_ID
            this.evaluationDialog.form.USER_NAME = resultData.varList[i].USER_NAME
            this.evaluationDialog.form.DESCR = ''
            this.evaluationDialog.form.RESULT = 0
          }
        } else {
          list.push(resultData.varList[i])
        }
      }
      this.evaluationDialog.list = list
    },
    evaluationAndDetailClose() {
      this.evaluationAndDetailShow = false
    },
    evaluationAndDetailSave() {
      if(!this.evaluationDialog.form.NAME){
        uni.showToast({
          title: '请先选择是否符合',
          icon: 'none',
          duration: 2000
        });
        return;
      }
      if(this.isdescr){
        if(!this.evaluationDialog.form.DESCR){
          uni.showToast({
            title: '请输入不符合原因',
            icon: 'none',
            duration: 2000
          });
          return;
        }
      }
      this.saveDialogData()
      this.evaluationAndDetailClose()
    },
    async saveDialogData(){
      let resultData = await evaluationAddRecord({
        CORPINFO_ID: this.CORPINFO_ID,
        HIDDENTYPE: this.TYPE,
        EVALUATIONCONFIG_ID: this.EVALUATIONCONFIG_ID,
        SOURCE: this.evaluationDialog.SOURCE,
        USER_ID: this.evaluationDialog.CREATOR,
        LOGIN_USER_ID: this.userInfo.USER_ID,
        LOGIN_USER_NAME: this.userInfo.USERNAME,
        HIDDEN_ID: this.evaluationDialog.HIDDEN_ID,
        ...this.evaluationDialog.form
      });
      if (resultData.result === 'success') {
        uni.showToast({
          title: '考评成功',
          icon: 'none',
          duration: 2000
        });
        this.resetList()
      }else {
        uni.showToast({
          title: '考评失败',
          icon: 'none',
          duration: 2000
        });
      }
    },
    showTree(ref, type) {
      if (this.disabled) return;
      if (type === 'arr') this.$refs[ref][0]._show();
      else this.$refs[ref]._show()
    },
    confirmTree(e, list, index) {
      if (list === 'isIfTrueTreeList') {
        for (let i = 0; i < e.length; i++) {
          this.evaluationDialog.form.RESULT = e[i].id
          this.evaluationDialog.form.NAME = e[i].name
          if (e[i].name === '不符合'){
            this.isdescr = true
          } else {
            this.isdescr = false
          }
        }
      } else if (list === 'evaluationStateTreeList') {
        for (let i = 0; i < e.length; i++) {
          if (e[i].name === '请选择' && e[i].id === 0){
            this.searchForm.STATE = ''
            this.searchForm.stateName = ''
          } else {
            this.searchForm.STATE = e[i].id
            this.searchForm.stateName = e[i].name
          }
        }
      } else if (list === 'ifIAmEvaluatedTreeList') {
        for (let i = 0; i < e.length; i++) {
          if (e[i].name === '请选择' && e[i].id === 0) {
            this.searchForm.userIs = ''
            this.searchForm.userIsName = ''
          } else {
            this.searchForm.userIs = e[i].id
            this.searchForm.userIsName = e[i].name
          }
        }
      }
    },
    fnViewHidden(HIDDEN_ID) {
      this.hiddenDetailShow = true
      this.HIDDEN_ID = HIDDEN_ID
      this.getHiddenDetailData()
    },
    hiddenDetailPopClose() {
      this.hiddenDetailShow = false
    },
    async getHiddenDetailData() {
      let hiddenData = await findHiddenDetailMessage({HIDDEN_ID: this.HIDDEN_ID});
      this.pd = hiddenData.pd
      this.hs = hiddenData.hs
      this.checkList = hiddenData.checkList
      this.repulsecause = hiddenData.repulsecause
      if (hiddenData.hiddenVideo.length > 0){
        this.videoUrl = this.$store.state.filePath + hiddenData.hiddenVideo[0].FILEPATH
      } else {
        this.videoUrl = ''
      }
      hiddenData.hiddenExa && hiddenData.hiddenExa.forEach(item => {
        if (item.TYPE == 4) {
          this.pd.oldUserName = item.editUserName
          this.pd.oldDeptName = item.editDeptName
          this.pd.oldLevelName = item.editLevelName
          this.pd.oldRectificationDeadline = item.editRectificationDeadline
        }
      })
      this.clearImages()
      // 隐患图片
      if(hiddenData.hImgs.length > 0){
        for (let i = 0; i < hiddenData.hImgs.length; i++) {
          const filePath = this.$store.state.filePath + hiddenData.hImgs[i].FILEPATH;
          const id = hiddenData.hImgs[i].IMGFILES_ID;
          this.hImgs.push({ src: filePath, id: id });
        }
      }
      // 验收图片
      if(hiddenData.cImgs.length > 0){
        for (let i = 0; i < hiddenData.cImgs.length; i++) {
          this.cImgs.push(this.$store.state.filePath + hiddenData.cImgs[i].FILEPATH)
        }
      }
      // 整改后图片
      if(hiddenData.rImgs.length > 0){
        for (let i = 0; i < hiddenData.rImgs.length; i++) {
          this.rImgs.push(this.$store.state.filePath + hiddenData.rImgs[i].FILEPATH)
        }
      }
      // 方案图片
      if(hiddenData.sImgs.length > 0){
        for (let i = 0; i < hiddenData.sImgs.length; i++) {
          this.sImgs.push(this.$store.state.filePath + hiddenData.sImgs[i].FILEPATH)
        }
      }
    },
    previewImage(list, current) {
      uni.previewImage({
        urls: list,
        current
      });
    },
    clearImages() {
      this.hImgs = []
      this.cImgs = []
      this.rImgs = []
      this.sImgs = []
    },
  }
}
</script>
<style scoped lang="scss">
  .btn-hidden-detail-bg {
    background-color: #9fa7bc;
    color: white;
  }
  .btn-eval-detail-bg {
    background-color: #007aff;
    color: white;
  }
  .btn-eval-bg {
    background-color: #07bb07;
    color: white;
  }
  .btn-reset-bg {
    background-color: #777aff;
    color: white;
  }
  .margin-value {
    margin-right: 5rpx;
  }
  .custom-padding {
    padding-left: 20px;
  }
</style>