<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>
					</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" 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_POSITION}}</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}}</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.CREATORNAME}}</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.CREATTIME}}</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">整改类型</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 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.RECTIFICATIONDEADLINE}}</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="cu-form-group margin-top">
					<view class="title">隐患级别</view>
					忽略隐患
				</view>
        <view class="cu-form-group">
          <view class="title">隐患确认时间：</view>
        </view>
        <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" disabled :checked="pd.IS_NORMAL=='1'"></radio>
              <text>是</text>
            </view>
            <view class="group">
              <radio class='radio'  value="2" disabled :checked="pd.IS_NORMAL=='2'"></radio>
              <text>否</text>
            </view>
          </radio-group>
        </view>
        <block v-if="pd.IS_NORMAL=='1'">
          <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" disabled :checked="pd.IS_POSTPONE=='1'"></radio>
                <text>是</text>
              </view>
              <view class="group">
                <radio class='radio'  value="2" disabled :checked="pd.IS_POSTPONE=='2'"></radio>
                <text>否</text>
              </view>
            </radio-group>
          </view>
          <block v-if="pd.IS_POSTPONE=='2'">
            <view class="cu-form-group">
              <view class="title">隐患整改时间：</view>
              {{ pd.RECTIFICATIONTIME }}
            </view>
            <view class="cu-form-group">
              <view class="title">整改描述：</view>
             <textarea disabled v-model="pd.RECTIFYDESCR" placeholder="请填写整改描述"></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>
              </view>
            </view>
            <view class="cu-form-group">
              <view class="title">投入资金（元）：</view>
              <textarea disabled v-model="pd.INVEST_FUNDS" placeholder="请填写投入资金" type="number"></textarea>
            </view>
            <view class="cu-form-group margin-top">
              <view class="title text-hui">整改方案</view>
              <radio-group class="selected">
                <view class="group mr20">
                  <radio class='radio'  disabled value="1" :checked="pd.HAVESCHEME=='1'"></radio>
                  <text>是</text>
                </view>
                <view class="group">
                  <radio class='radio'  disabled value="2" :checked="pd.HAVESCHEME=='2'"></radio>
                  <text>否</text>
                </view>
              </radio-group>
            </view>
            <block v-if="pd.HAVESCHEME=='1'">
              <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.CREATTIME}}</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.LIST_NAME}}</text>
                </view>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">治理标准</view>
                <textarea maxlength="-1" disabled v-model="pd.GOVERNSTANDARDS" placeholder="请输入治理标准"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">治理方法</view>
                <textarea maxlength="-1" disabled v-model="pd.GOVERNMETHOD" placeholder="请输入治理方法"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">经费落实</view>
                <textarea maxlength="-1" disabled v-model="pd.EXPENDITURE" placeholder="请输入经费落实"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">负责人员</view>
                <textarea maxlength="-1" disabled v-model="pd.PRINCIPAL" placeholder="请输入负责人员"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">工时安排</view>
                <textarea maxlength="-1" disabled v-model="pd.PROGRAMMING" placeholder="请输入工时安排"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">时限要求</view>
                <textarea maxlength="-1" disabled v-model="pd.TIMELIMITFOR" placeholder="请输入时限要求"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">工作要求</view>
                <textarea maxlength="-1" disabled v-model="pd.JOBREQUIREMENT" placeholder="请输入工作要求"></textarea>
              </view>
              <view class="cu-form-textarea">
                <view class="cu-form-title text-grey">其他事项</view>
                <textarea maxlength="-1" disabled v-model="pd.OTHERBUSINESS" placeholder="请输入其他事项"></textarea>
              </view>
              <view class="cu-bar bg-white">
                <view class="action">
                  方案照片
                </view>
                <view class="action">
                  {{imgList_fa.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_fa" :key="index" @tap="ViewImage_fa" :data-url="imgList_fa[index]">
                    <image :src="imgList_fa[index]" mode="aspectFill"></image>
                  </view>
                </view>
              </view>
              <view class="add_pard_box">
                <view class="add_pard_item" v-for="(item,index) of other">
                  <view class="cu-form-group">
                    <view class="title">验收部门</view>
                    <view class="picker-tree-box">
                      {{other[index].DEPARTMENT_NAME}}
                    </view>
                    <view class="cu-form-group">
                      <view class="title">验收人</view>
                      {{other[index].USER_NAME}}
                    </view>
                  </view>
                </view>
              </view>
            </block>
          </block>
          <block v-if="pd.IS_POSTPONE=='1'">
            <view class="cu-form-group">
              <view class="title">延期时间：</view>
              {{ pd.DELAY_TIME }}
            </view>
            <view class="cu-form-textarea">
              <view class="cu-form-title text-grey">临时措施</view>
              <textarea maxlength="-1" disabled v-model="pd.TEMPORARY_MEASURES" placeholder="请输入临时措施"></textarea>
            </view>
          </block>
        </block>
        <view class="cu-form-textarea" v-if="pd.IS_NORMAL=='2'">
          <view class="cu-form-title text-grey">无法整改原因</view>
          <textarea maxlength="-1" disabled v-model="pd.REASON" placeholder="请输入无法整改原因"></textarea>
        </view>
        <view class="cu-form-group margin-top">
          <view class="title text-hui">延期审核</view>
          <radio-group class="selected">
            <view class="group mr20">
              <radio class='radio' disabled value="1" :checked="pd.POSTPONE_AUDIT=='1'"></radio>
              <text>通过</text>
            </view>
            <view class="group">
              <radio class='radio' disabled value="2" :checked="pd.POSTPONE_AUDIT=='2'"></radio>
              <text>不通过</text>
            </view>
          </radio-group>
        </view>
        <view class="cu-form-group" v-if="pd.POSTPONE_AUDIT=='1'">
          <view class="title">限期整改时间：</view>
          {{ pd.DELAYED_RECTIFICATION_TIME }}
        </view>
        <view class="cu-form-group margin-top">
          <view class="title text-hui">验收结果</view>
          <radio-group class="selected">
            <view class="group mr20">
              <radio class='radio' disabled value="1" :checked="pd.ACCEPTANCE_RESULTS=='1'" @click="radioAcceptanceResults('1')"></radio>
              <text>通过</text>
            </view>
            <view class="group">
              <radio class='radio' disabled value="2" :checked="pd.ACCEPTANCE_RESULTS=='2'" @click="radioAcceptanceResults('2')"></radio>
              <text>不通过</text>
            </view>
          </radio-group>
        </view>
        <view class="cu-form-group">
          <view class="title">验收人：</view>
          {{ pd.ACCEPTOR_PEOPLE }}
        </view>
        <view class="cu-form-group">
          <view class="title">验收时间：</view>
          {{ pd.ACCEPTOR_TIME }}
        </view>
			</view>
      <view class="cu-bar btn-group" style="margin-top: 30upx;">
        <button class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goback)">返回</button>
        <button class="cu-btn bg-blue margin-tb-sm lg" @click="$noMultipleClicks(submit)">提交</button>
      </view>
			<view class="cu-tabbar-height"></view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		basePath,baseImgPath,corpinfoId,loginUser,formatDate
	} from '@/common/tool.js';
  import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue';
  import tkiTree from "@/components/select-tree/select-tree.vue"
	export default {
    components: {
      ruiDatePicker,
      tkiTree
    },
		data() {
			return {
				noClick: true,
				date: '',
				RECTIFICATIONTIME: '',
				imgList: [],
        imgList_fa: [],
				id: '',
				pd: [],
				hs: [],
				files: [],
				files2: [],
				files3: [],
				files4: [],
				checkList: [],
        other: [],
				CHECKDESCR: '',
				basePath:basePath,
				baseImgPath,
				ISQUALIFIED:'1',
				levelList :[],
        treeNode :[],
        otherUserList :[],
        principalList :[],
				lindex: -1,
        todayDate: formatDate(new Date(), 'yyyy-MM-dd hh:mm'),
			}
		},
		onLoad(e) {
      this.pd.ACCEPTOR_PEOPLE = loginUser.USER_NAME
      this.pd.ACCEPTOR_TIME = formatDate(new Date(), 'yyyy-MM-dd hh:mm')
			this.id = e.id;
			this.getData();
      this.getDept();
		},

		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.hs = res.data.hs; //参数map
							_this.files = res.data.hImgs;
							_this.files2 = res.data.rImgs;
							//_this.files3 = res.data.cImgs;
							_this.files4 = res.data.sImgs;
							_this.checkList = res.data.checkList;
						} else if ("exception" === res.data.result) {
							uni.showToast({
								title: '错误',
								duration: 2000
							});
						}
					}
				});
			},

			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},


			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
				});
			},
      radioNormal(e){
        this.$set(this.pd,'IS_NORMAL',e)
      },
      radioPostpone(e){
        this.$set(this.pd,'IS_POSTPONE',e)
      },
      radioHavescheme(e){
        this.$set(this.pd,'HAVESCHEME',e)
      },
      changeDELAYED_RECTIFICATION_TIME(e){
        this.pd.DELAYED_RECTIFICATION_TIME = e
      },
      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
              });
            }
          }
        });
      },
      getUserList(list,DEPARTMENT_ID) {
        //发送 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, NOMAIN:'1',
            tm: new Date().getTime()
          },
          success: function (res) {
            if ("success" == res.data.result) {
              _this[list] = res.data.userList;
            } else {
              uni.showToast({
                title: res.data.message,
                duration: 2000
              });
            }
          }
        })
      },
      ViewImage_fa(e) {
        uni.previewImage({
          urls: this.imgList_fa,
          current: e.currentTarget.dataset.url
        });
      },
      radioPostponeAudit(){
        this.$set(this.pd,'POSTPONEAudit',e)
      },
      radioAcceptanceResults(){
        this.$set(this.pd,'ACCEPTANCE_RESULTS',e)
      },
      radioReplacePrincipal(){
        this.$set(this.pd,'REPLACE_PRINCIPAL',e)
      },
      showZgTree(ref) {
        this.$refs[ref]._show();
      },
      zgtreeConfirm(e,list) {
        if(list === "principalList"){
          this.form.PRINCIPAL_DEPARTMENT_ID = e[0].id;
          this.form.PRINCIPAL_DEPARTMENT_NAME = e[0].name;
          this.form.PRINCIPAL_INDEX = '';
          this.form.PRINCIPAL_ID = '';
          this.form.PRINCIPAL_NAME = '';
        }
        this.getUserList(list,e[0].id);
      },
      zgtreeCancel(e) {
        this.isUps = false;
      },
      principalChange(e){
        this.pd.PRINCIPAL_INDEX = e.detail.value;
        this.pd.PRINCIPAL_ID = this.principalList[e.detail.value].USER_ID;
        this.pd.PRINCIPAL_NAME = this.principalList[e.detail.value].USERNAME;
      },
      submit() {
        var _this = this;
        let required = true
        if(!this.pd.ACCEPTANCE_RESULTS){
          uni.showToast({
            icon: 'none',
            title: '请选择验收结果',
            duration: 1500
          });
          required = false
        }
        if (!required) {
          return
        }
        uni.showLoading({
          title: '请稍候'
        })
        uni.request({
          url: basePath + "/app/hotworkapplication/" + _this.msg,
          method: 'POST',
          dataType: 'json',
          header: {
            'Content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            ...this.pd,
            CORPINFO_ID:corpinfoId,
            USER_ID:loginUser.USER_ID,
          },
          success: (res) => {
            uni.showToast({
              icon: 'none',
              title: '提交成功',
              duration: 2000
            });
            _this.goback()
          },
          fail: (err) => {
            uni.hideLoading();
            uni.showModal({
              content: err.errMsg,
              showCancel: false
            });
          }
        })
      },
			goback() {
				uni.navigateBack({
					delta: 1
				});
				uni.hideLoading();
			}
		}
	}
</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;
	}

	.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;
	}

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

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