<template>
    <view>
        <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
            <block slot="backText">返回</block>
            <block slot="content">隐患整改</block>
        </cu-custom>
        <scroll-view scroll-y>
            <view class="de-card-list de-list">
                <view class="de-item">
                    <text class="text-semi">{{pd.HIDDENDESCR}}</text>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患来源</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text v-if="pd.SOURCE=='1'" class="text-semi">隐患快报</text>
                        <text v-if="pd.SOURCE=='2' || pd.SOURCE=='3'" class="text-semi">清单排查</text>
                        <text v-if="pd.SOURCE=='4'" class="text-semi">安全环保检查（监管端）</text>
                        <text v-if="pd.SOURCE=='5'" class="text-semi">安全环保检查（企业端）</text>
                    </view>
                </view>
                <view class="de-item" v-if="pd.SOURCE==2">
                    <view class="de-sub-title">
                        <text class="text-grey">风险点（单元）</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.RISK_UNIT}}</text>
                    </view>
                </view>
                <view class="de-item" v-if="pd.SOURCE==2">
                    <view class="de-sub-title">
                        <text class="text-grey">辨识部位</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.IDENTIFICATION}}</text>
                    </view>
                </view>
                <view class="de-item-sp" v-if="pd.SOURCE==2">
                    <view class="de-sub-title">
                        <text class="text-grey">存在风险</text>
                    </view>
                    <view class="de-sub-content">
                        <text class="text-semi">{{pd.RISK_DESCR}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view style="width: 200px" class="de-sub-title">
                        <text class="text-grey">隐患上报位置（经纬度）</text>
                    </view>
                    <view class="uni-flex-item text-right" v-if="pd.LONGITUDE">
                        <text class="text-semi">
                            {{ pd.LONGITUDE &&
                            pd.LONGITUDE.length>6?pd.LONGITUDE.substr(0,6):pd.LONGITUDE}},{{pd.LATITUDE &&
                            pd.LATITUDE.length>6?pd.LATITUDE.substr(0,6):pd.LATITUDE}}
                        </text>
                    </view>
                </view>
                <view class="de-item" v-if="pd.SOURCE==2">
                    <view class="de-sub-title">
                        <text class="text-grey">风险分级</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.LEVEL}}</text>
                    </view>
                </view>
                <view class="de-item-sp" v-if="pd.SOURCE==2">
                    <view class="de-sub-title">
                        <text class="text-grey">检查内容</text>
                    </view>
                    <view class="de-sub-content">
                        <text class="text-semi">{{pd.CHECK_CONTENT}}</text>
                    </view>
                </view>
                <!-- 				<view class="de-item-sp">
                                    <view class="de-sub-title">
                                        <text class="text-grey">隐患描述</text>
                                    </view>
                                    <view class="de-sub-content">
                                        <text class="text-semi">{{pd.HIDDENDESCR}}</text>
                                    </view>
                                </view> -->
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患部位</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.hregionName?pd.hregionName:pd.HIDDENPART}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患部位描述</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.POSITIONDESC}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患类型</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.HIDDENTYPENAME}}</text>
                    </view>
                </view>
                <!--<view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患类型2</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.HIDDENTYPENAME2}}</text>
                    </view>
                </view>-->
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患级别</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.editLevelName}}</text>
                    </view>
                </view>
                <view class="de-item" v-for="(item, index) in hiddenFindPeople" :key="index">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患发现人</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{item.NAME}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患发现时间</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{formatDate(pd.DISCOVERYTIME)}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">整改类型</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text v-if="pd.RECTIFICATIONTYPE=='1'" class="text-semi">立即整改</text>
                        <text v-else-if="pd.RECTIFICATIONTYPE=='2'" class="text-semi">限期整改</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">整改负责部门</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.editDeptName}}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">整改负责人</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.editUserName}}</text>
                    </view>
                </view>
                <view v-if="pd.RECTIFICATIONTYPE=='2'" class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">整改期限</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.editRectificationDeadline }}</text>
                    </view>
                </view>
                <view class="de-item">
                    <view class="de-sub-title">
                        <text class="text-grey">是否相关方</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text v-if="pd.ISRELEVANT=='1'" class="text-semi">是</text>
                        <text v-else-if="pd.ISRELEVANT=='2'" class="text-semi">否</text>
                    </view>
                </view>
                <view class="de-item-sp">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患照片</text>
                    </view>
                    <view class="de-sub-content">
                        <scroll-view scroll-x class="bg-white nav" scroll-with-animation>
                            <view class="cu-item" v-for="(item,index) in files" v-bind:key="index">
                                <view class="imgs">
                                    <image :src="baseImgPath+item.FILEPATH" :data-index="index" @click="ViewShowImage"
                                           mode=""></image>
                                </view>
                            </view>
                        </scroll-view>
                    </view>
                </view>

                <view class="de-item-sp" v-if="hiddenVideo.length>0">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患视频</text>
                    </view>
                    <view class="de-sub-content" style="background-color: #000;width: 120upx;">
                        <image src="/static/icon-apps/video.png" mode="aspectFill" @click="playVideo"
                               :data-src="baseImgPath + hiddenVideo[0].FILEPATH"
                               style="width: 120upx;height: 120upx;"></image>
                    </view>
                </view>
                <view class="de-item" @click="seeHiddenConfirm=='2'?seeHiddenConfirm='1':seeHiddenConfirm='2'">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患确认信息</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <a>查看</a>
                    </view>
                </view>
            </view>
            <div v-for="(item,index) in hiddenExamineList" :key="index" v-if="seeHiddenConfirm=='1'">
                <view class="de-card-list de-list" v-if="item.TYPE === 4 ||item.TYPE === 2||item.TYPE === 1  ">
                    <div v-if="item.TYPE === 4">
                        <view class="de-title">
                            <text  class="text-semi">隐患确认</text>
                        </view>

                        <view class="cu-form-group margin-top">
                            <view class="title">隐患级别</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.editLevelName}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">整改负责人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.editUserName}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">整改完成期限</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.spare3}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">隐患确认人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{pd.conUserName}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">隐患确认时间</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{pd.CONFIRM_TIME}}</text>
                                </view>
                            </view>
                        </view>
                    </div>
                    <div v-if="item.TYPE === 2">
                        <view class="de-title">
                            <text class="text-semi">延期信息</text>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">申请延期日期</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.CREATTIME}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">审核人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{pd.conUserName}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">延期日期</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.DELAY_TIME}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">处置方案</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.DISPOSAL_PLAN}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.DISPOSAL_FILE">
                            <view class="title">方案附件</view>
                            <view class="picker-tree-box">
                                <button class="cu-btn bg-blue" style="width: 60px" @click="downloadAppendix(item.DISPOSAL_FILE)">
                                    下载
                                </button>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">延期审核状态</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi" v-if="item.STATE===-1">待审核</text>
                                    <text class="text-semi" v-if="item.STATE===1">通过</text>
                                    <text class="text-semi" v-if="item.STATE===2">未通过</text>

                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.STATE!==-1">
                            <view class="title">审核时间</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.OPERATTIME}}</text>
                                </view>
                            </view>
                        </view>
                    </div>
                    <div v-if="item.TYPE === 1">
                        <view class="de-title">
                            <text class="text-semi">特殊处理审核信息</text>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">无法整改原因</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.EXAMINE}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top">
                            <view class="title">特殊处置审核状态</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi" v-if="item.STATE===-1">待审核</text>
                                    <text class="text-semi" v-if="item.STATE===1">不通过</text>
                                    <text class="text-semi" v-if="item.STATE===2">通过</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.STATE!==-1">
                            <view class="title">审核时间</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.OPERATTIME}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.STATE!==-1">
                            <view class="title">审核人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{pd.conUserName}}</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.STATE==1">
                            <view class="title">是否更换整改负责人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi" v-if="item.spare1==='1'">是</text>
                                    <text class="text-semi" v-else>否</text>
                                </view>
                            </view>
                        </view>
                        <view class="cu-form-group margin-top" v-if="item.spare1=='1'">
                            <view class="title">整改负责人</view>
                            <view class="picker-tree-box">
                                <view class="uni-flex-item text-right">
                                    <text class="text-semi">{{item.NEWRECTIFICATIONOR}}</text>
                                </view>
                            </view>
                        </view>
                    </div>
                </view>

            </div>
            <view class="cu-form-group margin-top">
                <view class="title text-hui">是否正常整改</view>
                <radio-group class="selected">
                    <view class="group mr20">
                        <radio class='radio' value="1" :checked="IS_NORMAL=='1'" @click="radioNormal('1')"></radio>
                        <text>是</text>
                    </view>
                    <view class="group">
                        <radio class='radio' value="0" :checked="IS_NORMAL=='2'" @click="radioNormal('2')"></radio>
                        <text>否</text>
                    </view>
                </radio-group>
            </view>
            <view class="cu-form-textarea margin-top" v-if="IS_NORMAL=='2'">
                <view class="cu-form-title text-grey">无法整改原因</view>
                <textarea maxlength="-1" v-model="pd.disposalPlan" placeholder="请输入无法整改原因"></textarea>
            </view>
            <view class="de-card-list de-list" v-if="IS_NORMAL=='1'">
                <view class="de-title">
                    <text class="text-semi">隐患整改</text>
                </view>
                <view class="cu-form-textarea" style="border: none;">
                    <view class="cu-form-title text-grey">隐患整改</view>
                    <textarea maxlength="-1" @input="textareaAInput" placeholder="请对隐患整改详细描述(必填项)"></textarea>
                </view>
                <view class="cu-form-group bb">
                    <view class="title">整改日期</view>
                    <!-- <picker mode="date" :value="RECTIFICATIONTIME" start="2015-09-01" :end="date" @change="changeDate"> -->
                    <!--    <view class="picker"> -->
                    <!--        {{RECTIFICATIONTIME==''?'请选择':RECTIFICATIONTIME}} -->
                    <!--    </view> -->
                    <!-- </picker> -->
					<uni-datetime-picker type="datetime" v-model="RECTIFICATIONTIME" @change="changeDate" />
					<!-- <ruiDatePicker start="2015-09-01" fields="minute" :value="RECTIFICATIONTIME || '请选择'" @change="changeDate"></ruiDatePicker> -->
                </view>

                <view class="cu-form-textarea">
                    <view class="cu-form-title">投入资金（元）：</view>
                    <textarea v-model="INVEST_FUNDS" placeholder="请填写投入资金" type="number"></textarea>
                </view>
                <view class="cu-bar bg-white">
                    <view class="action">
                        整改后照片
                    </view>
                    <view class="action">
                        {{imgList.length}}/4
                    </view>
                </view>
                <view class="cu-form-group">
                    <view class="grid col-4 grid-square flex-sub">
                        <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
                              :data-url="imgList[index]">
                            <image :src="imgList[index]" mode="aspectFill"></image>
                            <view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
                                <text class='cuIcon-close'></text>
                            </view>
                        </view>
                        <view class="solids" @tap="ChooseImage" v-if="imgList.length<4">
                            <text class='cuIcon-cameraadd'></text>
                        </view>
                    </view>
                </view>
                <view class="add_pard_box">
                    <view class="add_pard_btns">
                        <view class="add_pard_b">
                            <button class="cu-btn round bg-blue" @click="addOther">添加</button>
                        </view>
                    </view>
                    <view class="add_pard_item" v-for="(item,index) of other">
                        <view class="add_pard_del" v-if="index>0" @click="removeOther(index)">
                            <text class="cuIcon-roundclosefill text-red f40"></text>
                        </view>
                        <view class="cu-form-group">
                            <view class="title">验收部门</view>
                            <view class="picker-tree-box">
                                <view class="picker-tree" @tap="showYsTree(index)">
                                    {{other[index].DEPARTMENT_NAME?other[index].DEPARTMENT_NAME:'请选择'}}
                                </view>
                            </view>
                            <tki-tree :ref="'tkiTree'+index"
                                      :selectParent=true
                                      :range="treeNode"
                                      rangeKey="name"
                                      @confirm="ystreeConfirm($event,index)"></tki-tree>
                        </view>
                        <view class="cu-form-group">
                            <view class="title">验收人</view>
                            <picker @change="PickerYsr($event,index)" :value="other[index].index"
                                    @click="haveUser(otherUserList[index])"
                                    :disabled="otherUserList[index] ==null || otherUserList[index].length==0"
                                    :range="otherUserList[index]" range-key="NAME">
                                <view class="picker">
                                    {{other[index].USER_NAME?other[index].USER_NAME:'请选择'}}
                                </view>
                            </picker>
                        </view>
                    </view>
                </view>

                <view class="cu-form-group">
                    <view class="title text-hui">是否有整改方案</view>
                    <radio-group class="selected">
                        <view class="group mr20">
                            <radio class='radio' value="1" :checked="HAVESCHEME==='1'" @click="radio('1')"></radio>
                            <text>是</text>
                        </view>
                        <view class="group">
                            <radio class='radio' value="0" :checked="HAVESCHEME==='0'" @click="radio('0')"></radio>
                            <text>否</text>
                        </view>
                    </radio-group>
                </view>
                <view class="de-item" v-if="HAVESCHEME=='1'">
                    <view class="de-sub-title">
                        <text class="text-grey">排查日期</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.CREATTIME}}</text>
                    </view>
                </view>
                <view class="de-item" v-if="HAVESCHEME=='1'">
                    <view class="de-sub-title">
                        <text class="text-grey">隐患清单</text>
                    </view>
                    <view class="uni-flex-item text-right">
                        <text class="text-semi">{{pd.LIST_NAME}}</text>
                    </view>
                </view>

                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">治理标准</view>
                    <textarea maxlength="-1" v-model="pd.GOVERNSTANDARDS" placeholder="请输入治理标准"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">治理方法</view>
                    <textarea maxlength="-1" v-model="pd.GOVERNMETHOD" placeholder="请输入治理方法"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">经费落实</view>
                    <textarea maxlength="-1" v-model="pd.EXPENDITURE" placeholder="请输入经费落实"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">负责人员</view>
                    <textarea maxlength="-1" v-model="pd.PRINCIPAL" placeholder="请输入负责人员"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">工时安排</view>
                    <textarea maxlength="-1" v-model="pd.PROGRAMMING" placeholder="请输入工时安排"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">时限要求</view>
                    <textarea maxlength="-1" v-model="pd.TIMELIMITFOR" placeholder="请输入时限要求"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">工作要求</view>
                    <textarea maxlength="-1" v-model="pd.JOBREQUIREMENT" placeholder="请输入工作要求"></textarea>
                </view>
                <view class="cu-form-textarea" v-if="HAVESCHEME=='1'">
                    <view class="cu-form-title text-grey">其他事项</view>
                    <textarea maxlength="-1" v-model="pd.OTHERBUSINESS" placeholder="请输入其他事项"></textarea>
                </view>
                <view class="cu-bar bg-white" v-if="HAVESCHEME=='1'">
                    <view class="action">
                        方案照片
                    </view>
                    <view class="action">
                        {{imgList_fa.length}}/4
                    </view>
                </view>
                <view class="cu-form-group" v-if="HAVESCHEME=='1'">
                    <view class="grid col-4 grid-square flex-sub">
                        <view class="bg-img" v-for="(item,index) in imgList_fa" :key="index" @tap="ViewImage_fa"
                              :data-url="imgList_fa[index]">
                            <image :src="imgList_fa[index]" mode="aspectFill"></image>
                            <view class="cu-tag bg-red" @tap.stop="DelImg_fa" :data-index="index">
                                <text class='cuIcon-close'></text>
                            </view>
                        </view>
                        <view class="solids" @tap="ChooseImage_fa" v-if="imgList_fa.length<4">
                            <text class='cuIcon-cameraadd'></text>
                        </view>
                    </view>
                </view>
                <!--				<view class="cu-form-textarea">-->
                <!--					<l-file ref="lFile" @up-success="onSuccess"></l-file>-->
                <!--					<view class="cu-form-title text-grey">隐患描述1</view>-->
                <!--					<button @tap="onUpload">上传</button>-->
                <!--				</view>-->
            </view>

            <view class="padding flex flex-direction bf">
                <button class="cu-btn bg-green margin-tb-sm lg" @click="goSubmit()">提 交</button>
            </view>
            <view class="cu-tabbar-height"></view>
        </scroll-view>
        <view :class="['cu-modal',{'show':modalShow}]" v-if="modalShow">
            <view class="cu-dialog">
                <view class="cu-bar bg-white justify-end">
                    <view class="content">播放视频</view>
                    <view class="action" @tap="modalShow = false">
                        <text class="cuIcon-close text-red"></text>
                    </view>
                </view>
                <video :src="videoSrc" :autoplay="true"></video>
                <view class="cu-bar bg-white justify-end">
                    <view class="action">
                        <button class="cu-btn line-green text-green" @click="modalShow = false">关闭</button>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    import {
        basePath, corpinfoId, loginSession, loginUser, baseImgPath, formatDate
    } from '@/common/tool.js';
    import lFile from '@/components/l-file/l-file.vue'
    import tkiTree from "@/components/select-tree/select-tree.vue"
import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue'

    export default {
        components: {
            tkiTree, lFile,ruiDatePicker
        },
        data() {
            return {
                date: '',
                RECTIFICATIONTIME: '',
                imgList: [],
                imgList_fa: [],
                id: '',
                pd: [],
                files: [],
                RECTIFYDESCR: '',
                INVEST_FUNDS: '',
                basePath: basePath,
                baseImgPath: baseImgPath,
                HAVESCHEME: '0',
                HIDDENSCHEME_ID: '',
                treeNode: [],//部门下拉数据
                uindex: -1,
                IS_NORMAL: 1,
                rectificationUserList: [],
                other: [{"DEPARTMENT_ID": '', "USER_ID": '', "DEPARTMENT_NAME": '', "USER_NAME": '', index: -1}],//其他验收人员
                otherUserList: [],
                modalShow: false,
                hiddenVideo: [],
                videoSrc: '',
                hiddenExamineList: [],
                hiddenFindPeople: [], //隐患发现人
                seeHiddenConfirm: '2'
            }
        },
        onLoad(e) {
            this.id = e.id;
            // let now = new Date();
            // this.date = formatDate(now, 'yyyy-MM-dd');

            this.getData();
            this.getDept();
            loginSession();
        },
        // filters: {
        // 	formatDate(time) {
        // 		time = time * 1
        // 		let date = new Date(time)
        // 		return formatDate(date, 'yyyy-MM-dd hh:mm')
        // 	}
        // },
        methods: {
            getData() {
                var _this = this;
                uni.showLoading({
                    title: '请稍候'
                })
                uni.request({
                    url: basePath + '/app/hidden/goEdit',
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        HIDDEN_ID: _this.id,
                    },
                    success: (res) => {
                        if ("success" == res.data.result) {
                            uni.hideLoading();
                            _this.pd = res.data.pd; //参数map
                            _this.files = res.data.hImgs;
                            _this.hiddenVideo = res.data.hiddenVideo
                            _this.hiddenFindPeople = res.data.hiddenFindPeople
                            _this.hiddenExamineList = res.data.hiddenExa

                        } else if ("exception" == data.result) {
                            uni.showToast({
                                title: '错误',
                                duration: 2000
                            });
                        }
                    }
                });
            },
            //图片上传
            ChooseImage() {
                var _this = this;
                uni.chooseImage({
                    count: 4, //默认9
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['camera', 'album'], //从相册选择
                    success: (res) => {
                        if (this.imgList.length != 0) {
                            this.imgList = this.imgList.concat(res.tempFilePaths)
                        } else {
                            this.imgList = res.tempFilePaths
                        }
                    }
                });
            },
            ViewImage(e) {
                uni.previewImage({
                    urls: this.imgList,
                    current: e.currentTarget.dataset.url
                });
            },
            DelImg(e) {
                uni.showModal({
                    title: '双控平台',
                    content: '确定要删除这张图片吗？',
                    cancelColor: "#000000",
                    cancelText: '取消',
                    confirmText: '确定',
                    success: res => {
                        if (res.confirm) {
                            this.imgList.splice(e.currentTarget.dataset.index, 1)
                        }
                    }
                })
            },
            //图片上传
            ChooseImage_fa() {
                var _this = this;
                uni.chooseImage({
                    count: 4, //默认9
                    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
                    sourceType: ['camera', 'album'], //从相册选择
                    success: (res) => {
                        if (this.imgList_fa.length != 0) {
                            this.imgList_fa = this.imgList_fa.concat(res.tempFilePaths)
                        } else {
                            this.imgList_fa = res.tempFilePaths
                        }
                    }
                });
            },
            ViewImage_fa(e) {
                uni.previewImage({
                    urls: this.imgList_fa,
                    current: e.currentTarget.dataset.url
                });
            },
            DelImg_fa(e) {
                uni.showModal({
                    title: '双控平台',
                    content: '确定要删除这张图片吗？',
                    cancelColor: "#000000",
                    cancelText: '取消',
                    confirmText: '确定',
                    success: res => {
                        if (res.confirm) {
                            this.imgList_fa.splice(e.currentTarget.dataset.index, 1)
                        }
                    }
                })
            },
            textareaAInput(e) {
                this.RECTIFYDESCR = e.detail.value
            },
            goSubmit() {
                var _this = this;
                if (_this.IS_NORMAL == 1) {
                    if (!_this.RECTIFYDESCR) {
                        uni.showToast({
                            icon: 'none',
                            title: '请填整改描述',
                            duration: 1500
                        });
                        return;
                    }
                    if (!_this.RECTIFICATIONTIME) {
                        uni.showToast({
                            icon: 'none',
                            title: '请选择整改时间',
                            duration: 1500
                        });
                        return;
                    }
                    if (_this.imgList.length <= 0) {
                        uni.showToast({
                            icon: 'none',
                            title: '请上传整改后照片',
                            duration: 1500
                        });
                        return;
                    }
                    if (!_this.INVEST_FUNDS) {
                        uni.showToast({
                            icon: 'none',
                            title: '请输入投入资金',
                            duration: 1500
                        });
                        return;
                    }

                    if (this.HAVESCHEME == 1) {
                        if (this.pd.GOVERNSTANDARDS == '' || this.pd.GOVERNSTANDARDS == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入治理标准要求',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.GOVERNMETHOD == '' || this.pd.GOVERNMETHOD == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入治理方法',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.EXPENDITURE == '' || this.pd.EXPENDITURE == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入经费和物资的落实',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.PRINCIPAL == '' || this.pd.PRINCIPAL == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入负责治理人员',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.PROGRAMMING == '' || this.pd.PROGRAMMING == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入工时安排',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.TIMELIMITFOR == '' || this.pd.TIMELIMITFOR == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入时限要求',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.JOBREQUIREMENT == '' || this.pd.JOBREQUIREMENT == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入工作要求',
                                duration: 1500
                            });
                            return;
                        }
                        if (this.pd.OTHERBUSINESS == '' || this.pd.OTHERBUSINESS == undefined) {
                            uni.showToast({
                                icon: 'none',
                                title: '请输入其他事项',
                                duration: 1500
                            });
                            return;
                        }
                        if (_this.imgList_fa.length <= 0) {
                            uni.showToast({
                                icon: 'none',
                                title: '请上传方案照片',
                                duration: 1500
                            });
                            return;
                        }
                    }
                    if (!_this.other[0].USER_ID) {
                        uni.showToast({
                            icon: 'none',
                            title: '请添加验收人',
                            duration: 1500
                        });
                        return;
                    }
                    new Promise((resolve, reject) => {
                        _this.submit().then(() => {
                            resolve();
                        })
                    }).then(() => {
                        var fileList = [];
                        for (var i = 0; i < _this.imgList.length; i++) {
                            var file = {};
                            file.type = 4;
                            file.filePath = _this.imgList[i];
                            file.FOREIGN_KEY = _this.id;
                            fileList.push(file);
                        }
                        if (_this.HAVESCHEME == 1) {
                            for (var i = 0; i < _this.imgList_fa.length; i++) {
                                var file = {};
                                file.type = 8;
                                file.filePath = _this.imgList_fa[i];
                                file.FOREIGN_KEY = _this.HIDDENSCHEME_ID;
                                fileList.push(file);
                            }
                        }
                        var m = 0;
                        _this.uploadImg(fileList, m).then(() => {
                            resolve();
                        })
                    }).then(() => {
                        uni.showToast({
                            icon: 'none',
                            title: '提交成功',
                            duration: 1500
                        });
                        setTimeout(function () {
                            var pages = getCurrentPages();	// 获取当前页面栈
                            var prePage = pages[pages.length - 2];	// 上一个页面
                            prePage.$vm.initflag = true;    // A 页面 init方法 为true
                            uni.navigateBack({});
                            uni.hideLoading();
                        }, 1500);
                    })
                } else if (_this.IS_NORMAL == 2) {
                    if (!_this.pd.disposalPlan) {
                        uni.showToast({
                            icon: 'none',
                            title: '请输入无法整改原因',
                            duration: 1500
                        });
                        return;
                    }

                    uni.request({
                        url: basePath + "//app/hiddenexamine/special", //提交接口
                        method: 'POST',
                        dataType: 'json',
                        header: {
                            'Content-type': 'application/x-www-form-urlencoded'
                        },
                        data: {
                            disposalPlan: _this.pd.disposalPlan,
                            HIDDEN_ID: _this.id,
                            USER_ID: loginUser.USER_ID,
                            USERNAME: loginUser.NAME
                        },
                        success: (res) => {
                            uni.hideLoading();
                            if ("success" == res.data.result) {
                                uni.showToast({
                                    icon: 'none',
                                    title: '提交成功',
                                    duration: 1500
                                });
                                setTimeout(function () {
                                    var pages = getCurrentPages();	// 获取当前页面栈
                                    var prePage = pages[pages.length - 2];	// 上一个页面
                                    prePage.$vm.initflag = true;    // A 页面 init方法 为true
                                    uni.navigateBack({});
                                    uni.hideLoading();
                                }, 1500);
                            } else {
                                uni.showToast({
                                    title: '错误',
                                    duration: 2000
                                });
                            }
                        }
                    });
                }
            },
            uploadImg(tempFilePaths, i) {
                return new Promise((resolve, reject) => {
                    var _this = this;
                    if (tempFilePaths.length == 0) {
                        resolve();
                    }
                    uni.showLoading({
                        title: '上传中'
                    })
                    uni.uploadFile({
                        url: basePath + '/app/imgfiles/add',
                        filePath: tempFilePaths[i].filePath,
                        name: 'FFILE',

                        formData: {
                            'FOREIGN_KEY': tempFilePaths[i].FOREIGN_KEY,
                            'TYPE': tempFilePaths[i].type
                        },
                        success: (res) => {
                            i++;
                            if (tempFilePaths.length > i) {
                                _this.uploadImg(tempFilePaths, i);
                            } else {
                                uni.hideLoading();
                                resolve();
                            }
                        },
                        fail: (err) => {
                            uni.hideLoading();
                            uni.showModal({
                                content: err.errMsg,
                                showCancel: false
                            });
                        }
                    })
                })
            },

            uploadImg_fa(tempFilePaths, i) {
                var _this = this;
                uni.showLoading({
                    title: '上传中'
                })
                uni.uploadFile({
                    url: basePath + '/app/imgfiles/add',
                    filePath: tempFilePaths[i],
                    name: 'FFILE',

                    formData: {
                        'FOREIGN_KEY': _this.HIDDENSCHEME_ID,
                        'TYPE': '8'
                    },
                    success: (res) => {
                        i++;
                        if (tempFilePaths.length > i) {
                            _this.uploadImg(tempFilePaths, i);
                        } else {
                            if (_this.HAVESCHEME == '1') {
                                _this.onUpload()
                            } else {
                                uni.showToast({
                                    icon: 'none',
                                    title: '提交成功',
                                    duration: 1500
                                });
                                setTimeout(function () {
                                    var pages = getCurrentPages();	// 获取当前页面栈
                                    var prePage = pages[pages.length - 2];	// 上一个页面
                                    prePage.$vm.initflag = true;    // A 页面 init方法 为true
                                    uni.navigateBack({});
                                    uni.hideLoading();
                                }, 1500);
                            }


                        }
                    },
                    fail: (err) => {
                        uni.hideLoading();
                        console.log('uploadImage fail', err);
                        uni.showModal({
                            content: err.errMsg,
                            showCancel: false
                        });
                    }
                })
            },
            submit() {
                return new Promise((resolve, reject) => {
                    var _this = this;
                    uni.request({
                        url: basePath + "/app/hidden/rectify", //提交接口
                        method: 'POST',
                        dataType: 'json',
                        header: {
                            'Content-type': 'application/x-www-form-urlencoded'
                        },
                        data: {
                            RECTIFICATIONTIME: _this.RECTIFICATIONTIME,
                            RECTIFYDESCR: _this.RECTIFYDESCR,
                            HAVESCHEME: _this.HAVESCHEME,
                            // RECTIFICATIONDEPT:_this.pd.RECTIFICATIONDEPT,
                            // RECTIFICATIONOR:_this.pd.RECTIFICATIONOR,
                            USER_ID: loginUser.USER_ID,
                            CORPINFO_ID: corpinfoId,
                            HIDDEN_ID: _this.id,
                            INVEST_FUNDS: _this.INVEST_FUNDS,
                            SCREENINGDATE: _this.pd.CREATTIME ? _this.pd.CREATTIME : '',
                            LISTNAME: _this.pd.LIST_NAME ? _this.pd.LIST_NAME : '',
                            GOVERNSTANDARDS: _this.pd.GOVERNSTANDARDS ? _this.pd.GOVERNSTANDARDS : '',
                            GOVERNMETHOD: _this.pd.GOVERNMETHOD ? _this.pd.GOVERNMETHOD : '',
                            EXPENDITURE: _this.pd.EXPENDITURE ? _this.pd.EXPENDITURE : '',
                            PRINCIPAL: _this.pd.PRINCIPAL ? _this.pd.PRINCIPAL : '',
                            PROGRAMMING: _this.pd.PROGRAMMING ? _this.pd.PROGRAMMING : '',
                            TIMELIMITFOR: _this.pd.TIMELIMITFOR ? _this.pd.TIMELIMITFOR : '',
                            JOBREQUIREMENT: _this.pd.JOBREQUIREMENT ? _this.pd.JOBREQUIREMENT : '',
                            OTHERBUSINESS: _this.pd.OTHERBUSINESS ? _this.pd.OTHERBUSINESS : '',
                            OTHER: JSON.stringify(_this.other)
                        },
                        success: (res) => {
                            uni.hideLoading();
                            if ("success" == res.data.result) {
                                _this.HIDDENSCHEME_ID = res.data.HIDDENSCHEME_ID
                                resolve();
                            } else {
                                uni.showToast({
                                    title: '错误',
                                    duration: 2000
                                });
                                reject();
                            }

                        }
                    });
                })
            },
            haveUser(e) {
                if (e == null || e.length == 0) {
                    uni.showToast({
                        icon: "none",
                        title: '请先选择有人员的部门',
                        duration: 2000
                    });
                }
                console.info(1)
            },
            onUpload() {
                return new Promise((resolve, reject) => {
                    this.$refs.lFile.upload({
                        // #ifdef APP-PLUS
                        // nvue页面使用时请查阅nvue获取当前webview的api，当前示例为vue窗口
                        currentWebview: this.$mp.page.$getAppWebview(),
                        // #endif
                        //非真实地址，记得更换,调试时ios有跨域，需要后端开启跨域并且接口地址不要使用http://localhost/
                        url: basePath + "/app/hidden/rectify1?HIDDENSCHEME_ID=" + this.HIDDENSCHEME_ID,
                        //默认file,上传文件的key
                        name: 'file',
                        // header:{
                        // 	'Content-type':'application/x-www-form-urlencoded'
                        // },
                        //...其他参数
                    });
                    resolve();
                })
            },
            onSuccess(res) {
                return new Promise((resolve, reject) => {
                    resolve();
                })


            },
            getDept() {
                var _this = this;
                uni.request({
                    url: basePath + '/app/sys/listTree',//部门下拉接口
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                        CORPINFO_ID: corpinfoId,
                    },
                    success: (res) => {
                        if ("success" == res.data.result) {
                            _this.treeNode = eval(res.data.zTreeNodes);
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                duration: 2000
                            });
                        }
                    }
                });
            },
            // 确定回调事件
            zgtreeConfirm(e) {
                this.pd.RECTIFICATIONDEPT = e[0].id;
                this.pd.RECTIFICATIONDEPTNAME = e[0].name;
                this.uindex = -1;
                this.pd.RECTIFICATIONOR = '';
                this.pd.RECTIFICATIONORNAME = '';
                this.$forceUpdate();//强制刷新
                this.getUserList(this.pd.RECTIFICATIONDEPT);
            },
            // 显示树形选择器
            showZgTree() {
                this.$refs.tkiTree._show();
            },

            // 确定回调事件
            ystreeConfirm(e, index) {
                this.other[index].DEPARTMENT_ID = e[0].id;
                this.other[index].DEPARTMENT_NAME = e[0].name;
                this.other[index].USER_ID = '';
                this.other[index].USER_NAME = '';
                this.other[index].index = -1;
                this.getUserList(this.other[index].DEPARTMENT_ID, index);
                this.$forceUpdate();//强制刷新
            },
            // 显示树形选择器
            showYsTree(index) {
                let ref = 'tkiTree' + index;
                this.$refs['tkiTree' + index][0]._show();
            },
            //根据主键ID获取数据
            addOther: function () {
                var _this = this;
                let o = {"DEPARTMENT_ID": '', "USER_ID": '', "DEPARTMENT_NAME": '', "USER_NAME": '', index: -1};
                _this.other.push(o);
                let index = _this.other.length - 1;
                _this.otherUserList[index] = [];
            },
            removeOther: function (index) {
                this.other.splice(index, 1);
                this.otherUserList.splice(index, 1);
            },
            //获取人员列表
            getUserList(DEPARTMENT_ID, i) {
                //发送 post 请求
                var _this = this;
                uni.request({
                    method: 'POST',
                    dataType: 'json',
                    header: {
                        'Content-type': 'application/x-www-form-urlencoded'
                    },
                    url: basePath + '/app/sys/listUser',
                    data: {
                        DEPARTMENT_ID: DEPARTMENT_ID, NOMAIN: '1',
                        LOGINUSERID: loginUser.USER_ID,
                        NOSELF: '1',
                        tm: new Date().getTime()
                    },
                    success: function (res) {
                        if ("success" == res.data.result) {
                            if (i > -1) {
                                _this.otherUserList[i] = [];
                                _this.otherUserList[i] = res.data.userList;
                                _this.$forceUpdate();//强制刷新
                            } else {
                                _this.rectificationUserList = res.data.userList;
                            }
                        } else {
                            uni.showToast({
                                title: res.data.message,
                                duration: 2000
                            });
                        }
                    }
                })
            },
            PickerZgr(e) {
                this.uindex = e.detail.value;
                this.pd.RECTIFICATIONOR = this.rectificationUserList[this.uindex].USER_ID;
                this.pd.RECTIFICATIONORNAME = this.rectificationUserList[this.uindex].NAME;
                this.$forceUpdate();//强制刷新
            },
            PickerYsr(e, index) {
                this.other[index].index = e.detail.value;
                this.other[index].USER_ID = this.otherUserList[index][e.detail.value] ? this.otherUserList[index][e.detail.value].USER_ID : '';
                this.other[index].USER_NAME = this.otherUserList[index][e.detail.value] ? this.otherUserList[index][e.detail.value].NAME : '';
                this.$forceUpdate();//强制刷新
            },
            radio(e) {
                this.HAVESCHEME = e
            },
            radioNormal(e) {
                this.IS_NORMAL = e
            },
            changeDate(e) {
                this.RECTIFICATIONTIME = e.detail.value
            },
            formatDate(time) {
                let date = new Date(time)
                return formatDate(date, 'yyyy-MM-dd hh:mm')
            },
            downloadAppendix(DISPOSAL_FILE) {
                plus.runtime.openURL(this.baseImgPath + DISPOSAL_FILE, function (res) {
                    console.log(res);
                });
            },
            ViewShowImage(e) {
                let files = [];
                for (var i = 0; i < this.files.length; i++) {
                    files.push(baseImgPath + this.files[i].FILEPATH)
                }
                uni.previewImage({
                    urls: files,
                    current: e.currentTarget.dataset.index
                });
            },
            playVideo(e) {
                this.videoSrc = e.currentTarget.dataset.src
                this.modalShow = true
            }
        }
    }
</script>

<style>
    .bb {
        border-top: 1upx solid #f1f1f1;
        border-bottom: 1upx solid #f1f1f1;
    }

    .cu-bar .action:first-child {
        font-size: 26upx
    }

    .cu-form-title {
        padding: 20upx 0;
    }

    .cu-form-textarea {
        background-color: #ffffff;
        padding: 1upx 30upx 20upx;
        min-height: 100upx;
        border-bottom: 1px solid #f1f1f1;
    }

    .cu-form-textarea textarea {
        height: 4.6em;
        width: 100%;
        line-height: 1.2em;
        flex: 1;
        font-size: 28upx;
        padding: 0;
    }

    .cu-form-group {
        padding: 0upx 25upx;
    }

    .cu-form-group picker .picker {
        line-height: 76upx;
    }

    .cu-form-group .title {
        font-size: 28upx;
        /* line-height: 76upx; */
        color: #888;
    }

    .cu-form-group uni-picker::after {
        top: -11upx;
    }

    .selected {
        display: flex;
        align-items: center;
    }

    .selected .radio {
        transform: scale(0.5);
        margin-right: 10upx;
    }

    .bf .cu-btn {
        border-radius: 0;
        width: 100%;
        height: 84upx;
        font-weight: bold;
    }

    .group {
        display: flex;
        align-items: center;
    }
</style>
