<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{pd.TRANSPORTVEHICLE}}车辆行车三检日志</block>
		</cu-custom>
		<scroll-view scroll-y>
			<view class="wui-form-list">
				<view  class="cu-form-group">
				  <view class="title">
					<text>运单编号</text>
				  </view>
				  <view>
					<text>{{pd.WAYBILLNUMBER}}</text>
				  </view>
				</view>
				<view class="cu-form-group">
					<view class="title">运单状态</view>
					<view>
						<text>已完成</text>
					</view>
				</view>
				<view class="wui-form-list">
					<view class="wui-sub-title">
						<text>运输任务</text>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>运输车辆</text>
						</view>
						<view>
							<text>{{pd.TRANSPORTVEHICLE}}</text>
						</view>
					</view>
					<view  class="cu-form-group" v-if="pd.PLATE_NUMBER">
						<view class="title">
							<text>挂车车牌号</text>
						</view>
						<view>
							<text>{{pd.TRUCKCART}}</text>
						</view>
					</view>
					<view  class="cu-form-group" v-if="pd.VIN">
						<view class="title">
							<text>车架号</text>
						</view>
						<view>
							<text>{{pd.VIN}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>从业人员</text>
						</view>
						<view>
							<text>{{pd.NAME}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>联系电话</text>
						</view>
						<view>
							<text>{{pd.PHONE}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>发车时间</text>
						</view>
						<view>
							<text>{{pd.STARTTIME}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>发车地点</text>
						</view>
						<view>
							<text>{{pd.ORIGIN_NAME}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>收车时间</text>
						</view>
						<view>
							<text>{{pd.STOPTIME}}</text>
						</view>
					</view>
					<view  class="cu-form-group">
						<view class="title">
							<text>收车地点</text>
						</view>
						<view>
							<text>{{pd.DESTINATION_NAME}}</text>
						</view>
					</view>
				</view>
<!--				<view class="wui-form-list">
					<view class="wui-sub-title">
						<text>行车安全问询</text>
					</view>
					<view>
						<view class="check-items" v-for="(item,index) in commitmentList" :key="item.DRIVINGCOMMITMENT_ID">
							<view  class="cu-form-group">{{item.INQUIRYCONTENT}}</view>
						</view>
					</view>
				</view>-->

				<view class="wui-form-list">
					<view class="wui-sub-title">
						<text>排查项</text>
					</view>
				</view>

        <view class="check-items" v-for="(item,index) in list2" :key="item.CHECKTYPE_ID">
          <view class="wui-sub-title">行车安全问询:</view>
          <view class="title" v-for="(item1,index1) in item.pd1Children" :key="index1">
            <view class="title" v-for="(item2,index2) in commitmentList" :key="index2">
              <view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
                <text>承诺项:</text>
              </view>
              <view>
                <view>{{ item2.INQUIRYCONTENT }}</view>
              </view>
              <view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
                <text>承诺说明:</text>
              </view>
              <view>
                <view>{{ item2.REMARK?item2.REMARK:'无' }}</view>
              </view>
              <view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
                <text>是否合格:</text>
              </view>
              <view>{{item2.STATUS === '0'? "合格":item2.STATUS === '1'?"不合格": "不涉及"}}</view>
            </view>
            <view>
              <view style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
                <view class="cu-form-group" >
                  <view class="title">检查人签字</view>
                </view>
                <view class="cu-item" style="border-bottom: 1px solid  #e3e3e3">
                  <view class="imgs" style="display: flex;justify-content: space-between;align-items: flex-end;padding: 20upx 50upx;">
                    <image :src="baseImgPath + item1.SIGN_PATH" :data-index="index" @click="ViewShowImage(baseImgPath + item1.SIGN_PATH)"
                           mode="" style="width: 200upx;height: 200upx;"></image>
                    <text> {{item1.SIGN_TIME}}</text>
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
				<view class="check-items" v-for="(item,index) in list" :key="item.CHECKTYPE_ID" v-if="item.CHECKTYPE_NAME !== '待承诺'">
					<view class="wui-sub-title">{{item.CHECKTYPE_NAME}}检查：</view>
					<view class="title" v-for="(item1,index1) in item.pd1Children" :key="index1">
						<view class="title" v-for="(item2,index2) in item1.pd2Children" :key="index2">
							<view class="title"  style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
								<text>检查项名称:</text>
							</view>
							<view>{{item2.CHECKITEMNAME}}</view>
							<view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
								<text>检查项说明:</text>
							</view>
							<view>{{item2.REMARKS}}</view>
							<view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
								<text>出车说明:</text>
							</view>
							<view>{{item2.REMARK?item2.REMARK:'无'}}</view>
              <view class="title" style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
                <text>是否合格:</text>
              </view>
              <view>{{item2.STATUS === '0'? "合格":"不合格"}}</view>
						</view>

						<view>
              <view style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee"  v-if="item.CHECKTYPE_NAME !== '待承诺'">
								<view class="cu-form-group">
									<view class="title">检查图片</view>
								</view>
								<view class="cu-item" style="border-bottom: 1px solid  #e3e3e3">
									<view class="imgs" style="display: flex;justify-content: space-between;align-items: flex-end;padding: 20upx 50upx;">
										<image v-for="(item3,index3) in item1.IMG_PATH.split(',')" :key="index3" :src="baseImgPath + item3" :data-index="index" @click="ViewShowImage(baseImgPath + item3)"
											   mode="" style="width: 200upx;height: 200upx;"></image>
									</view>
								</view>
							</view>
						</view>
						<view>
							<view style="border-bottom: 1px solid #eeeeee;  border-top: 1px solid #eeeeee">
								<view class="cu-form-group" >
									<view class="title">检查人签字</view>
								</view>
								<view class="cu-item" style="border-bottom: 1px solid  #e3e3e3">
									<view class="imgs" style="display: flex;justify-content: space-between;align-items: flex-end;padding: 20upx 50upx;">
										<image :src="baseImgPath + item1.SIGN_PATH" :data-index="index" @click="ViewShowImage(baseImgPath + item1.SIGN_PATH)"
											   mode="" style="width: 200upx;height: 200upx;"></image>
										<text> {{item1.SIGN_TIME}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		basePath,
		baseImgPath,
		corpinfoId,
      loginUser
	} from '@/common/tool.js';
	export default {
		data() {
			return {
				noClick: true,
				date: '',
				RECTIFICATIONTIME: '',
				imgList: [],
				id: '',
				pd: [],
				hs: [],
				files: [],
				list:[],
        list2:[],
				commitmentList:[],
				videoList: [],
				checkList: [],
				CHECKDESCR: '',
				basePath: basePath,
				baseImgPath: baseImgPath,
				ISQUALIFIED: '1',
        modalShow: false,
        videoSrc: '',
			}
		},
		onLoad(e) {
			this.id = e.listId;
			// let now = new Date();
			// this.date = formatDate(now, 'yyyy-MM-dd');
			this.getData();
		},
		// filters: {
		// 	formatDate(time) {
		// 		time = time * 1
		// 		let date = new Date(time)
		// 		return formatDate(date, 'yyyy-MM-dd hh:mm')
		// 	}
		// },
		methods: {
      fullScreenHandler(e) {
        if (uni.getSystemInfoSync().platform == "ios") { return }
      },
			getData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/waybillregistration/getDetail',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						WAYBILLREGISTRATION_ID: _this.id,
						CORPINFO_ID:loginUser.CORPINFO_ID,
						USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if ("success" == res.data.result) {
              console.log(res)
							uni.hideLoading();
							_this.pd = res.data.pd; //参数map
							_this.commitmentList = res.data.commitmentList; //参数map
							_this.list = res.data.pd.varList
              _this.list2 = res.data.pd.varList2
						} 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)
						}
					}
				})
			},
			textareaAInput(e) {
				this.CHECKDESCR = e.detail.value
			},
			goSubmit() {
				var _this = this;
				if (!_this.CHECKDESCR) {
					uni.showToast({
						icon: 'none',
						title: '请填验收描述',
						duration: 1500
					});
					return;
				}
				if (_this.imgList.length <= 0) {
					uni.showToast({
						icon: 'none',
						title: '请上传验收照片',
						duration: 1500
					});
					return;
				}
				var i = 0;
				_this.uploadImg(_this.imgList, i);
			},

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

					formData: {
						'FOREIGN_KEY': _this.id,
						'TYPE': '5',
            CORPINFO_ID: loginUser.CORPINFO_ID,
            USER_ID: loginUser.USER_ID,
					},
					success: (res) => {
						i++;
						if (tempFilePaths.length > i) {
							_this.uploadImg(tempFilePaths, i);
						} else {
							_this.submit();
						}
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showModal({
							content: err.errMsg,
							showCancel: false
						});
					}
				})
			},
			submit() {
				var _this = this;
				uni.request({
					url: basePath + "/app/hidden/check", //提交接口
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						ISQUALIFIED: _this.ISQUALIFIED,
						CHECKDESCR: _this.CHECKDESCR,
						HIDDEN_ID: _this.id,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					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
							});
						}

					}
				});
			},
			changeDate(e) {
				this.RECTIFICATIONTIME = e.detail.value
			},
			radio(e) {
				this.ISQUALIFIED = e
			},

			ViewShowImage(url) {
				let files = [];
				files.push(url)
				uni.previewImage({
					urls: files,
					current: 0
				});
			},
			ViewShowImages(imgs, index) {
				let files = [];
				for (var i = 0; i < imgs.length; i++) {
					files.push(baseImgPath + imgs[i].FILEPATH)
				}
				uni.previewImage({
					urls: files,
					current: index
				});
			},
			goToOpen(e) {
				var url = e;
				plus.runtime.openURL(url, function(res) {
					console.log(res);
				});


				// uni.navigateTo({
				// 	url: '/pages/application/safety-production-account/organization-personnel/web-view?link=' + url
				// });
			},
      playVideo(e) {
        this.videoSrc = e.currentTarget.dataset.src
        this.modalShow = true
      }
		}
	}
</script>

<style>

</style>
