'use strict'; angular.module('atomic.veeker') .controller('PeaceLiveHomeCtr', function ($rootScope, $scope, $state, $stateParams, $ionicLoading,CONFIG,Upload, ModalService,$timeout, $window, $location, indentEntity, FastInsuranceService, locationEntity, OrderCache, $ionicPopup,$ionicModal,SchemeService,CarImages) { //允许用户复制的代码 stop_browser_behavior: false self.touchStart = function(e) { self.startCoordinates = getPointerCoordinates(e); if ( ionic.tap.ignoreScrollStart(e) ) { return; } if( ionic.tap.containsOrIsTextInput(e.target) ) { // do not start if the target is a text input // if there is a touchmove on this input, then we can start the scroll self.__hasStarted = false; return; } self.__isSelectable = true; self.__enableScrollY = true; self.__hasStarted = true; self.doTouchStart(e.touches, e.timeStamp); // e.preventDefault(); }; //允许用户复制的代码结束 var vm = $scope.vm = {}; var indentInfo = indentEntity || {}; vm.pageTitle = '订单主页'; vm.detailsState = $stateParams.state; vm.ordersState = 'orders'; vm.isShare = $stateParams.isShare; vm.settleIndentInfo = settleIndentInfo; vm.back = back; vm.goToSign = goToSign; // $scope.CarImages = CarImages; initIndentInfo(); // 返回 function back() { $state.go('home'); } // 结算 function settleIndentInfo() { var validateResult = validateInput(); var delay = 1500; if (validateResult[1]) { $ionicLoading.show({ template: '  正在结算,请稍后...' }); FastInsuranceService.settleOrderFee(indentInfo, function (res) { $ionicLoading.hide(); OrderCache.resetOrder(indentInfo.id); $timeout(function () { $state.go('clientPayFee', { indentId: $stateParams.indentId, state: 'peaceLiveHome', isShare: vm.isShare, date: (new Date()).getTime() }); }); }, function (error) { $ionicLoading.hide(); if (error.headers) { var msg = error.headers('errorMessage'); if (msg) { msg = decodeURI(msg); $rootScope.showMessage(msg, 3000); } else { $rootScope.showMessage('结算失败!', delay); } } else { $rootScope.showMessage('结算失败!', delay); } }); } else { $rootScope.showMessage(validateResult[0], delay); } } // 校验相关项是否合法 function validateInput() { var vmIndentInfo = vm.indentInfo; var now = new Date(); now.setDate(now.getDate() + 1); if (indentInfo.indentStatus != 'TOPAY') { return ['订单状态必须是已核保待缴费!', false]; } if (vmIndentInfo.startDate < (new Date(now.toLocaleDateString()))) { return ['保险起期不能早于或等于今天!', false]; } if (!vmIndentInfo.signImgSrc) { return ['请完善电子签名信息!', false]; } return ['校验通过!', true]; } // 初始化indentInfo function initIndentInfo() { if (indentInfo.orders) { var order = indentInfo.orders[0]; var orderItem = order.orderItems[0]; if (order.orderStatus == 'TOPAY' && indentInfo.payLock == 1) { $scope.isPaing = true; } var imgSrc = '', address = ''; if (indentInfo.signature_path) { imgSrc = "/api/attachment/download?filename=" + encodeURI(indentInfo.signature_path) + '&type=sign'; } if (locationEntity) { address = locationEntity.fullName + order.situation; } vm.indentInfo = { id: indentInfo.id, totalFee: indentInfo.indentFee.toFixed(2), productName: order.product.name, productType: order.product.productType, startDate: new Date(orderItem.startDate), endDate: new Date(orderItem.endDate), portion: orderItem.insuranceScores, buyPersonName: order.buyPersonName, cardType: order.buyCardType, cardNo: order.buyPersonCard, phone: order.buyPersonPhone, email: order.buyPersonEmail, location: address, signImgSrc: imgSrc, careerName: order.careerName, inputPhone: order.inputPhone, birthday: (order.buyPersonBirthday && (new Date(order.buyPersonBirthday))), licensePlateNumber: order.jsryyItem }; if (vm.indentInfo.productType == 'FEICHE_TWO') { vm.detailsState = 'accidentDetails'; vm.ordersState = 'RFDOrders'; } if(order.jsryyItem) { vm.detailsState = 'driverInsurance'; } wxShare(order.product.code); } } // 微信分享 function wxShare(productCode) { $window.wx.ready(function () { $window.wx.showOptionMenu(); var prefix = 'vktest'; if ($location.host().indexOf('vktest') == -1) { prefix = 'vk'; } var url = "http://" + prefix + ".zhufengic.com/wx/index/COMMONPRODUCT?productCode=" + productCode; var shareLink = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + $rootScope.wxShareConfig.appid + "&redirect_uri=" + encodeURIComponent(url) + "&response_type=code&scope=snsapi_userinfo&state=" + $rootScope.account.openId + "#wechat_redirect"; var imgUrl = 'http://' + prefix + '.zhufengic.com/mobile/www/images/ionic.png'; $window.wx.onMenuShareTimeline({ title: '家财险-产品详情', // 分享标题 link: shareLink, // 分享链接 imgUrl: imgUrl }); $window.wx.onMenuShareAppMessage({ title: '家财险-产品详情', desc: '家财险-产品详情', link: shareLink, imgUrl: imgUrl, type: 'link' }); }); $window.wx.error(function (res) { // alert(res.errMsg); }); } // 取消支付提示信息 function validatePaing() { var flag = false; if ($scope.isPaing) { $ionicPopup.alert({ title: '提示', template: '当前订单状态为支付中,不允许修改订单信息,如需修改请在缴费页面进行取消支付操作!', okText: '确定' }); } else { flag = true; } return flag; } // 跳转到电子签名 function goToSign() { if (validatePaing()) { $state.go('sign', {indentId: vm.indentInfo.id, state: 'peaceLiveHome', isShare: vm.isShare}); } } //非车险新加影响上传功能(2018-04-26) initUploadInfo(); // 弹出框名称 var objModal = { video: 'videoModal', carImage: 'carImageModal', customer: 'customerModal', product: 'productModal', car: 'carModal', special: 'special', imageHistory: 'imageHistoryModal', article: 'articleModal', schemeDetails: 'schemeDetails' }; // 影像上传弹出框 ModalService.initModal($scope, $ionicModal, 'scripts/atomic_veeker/household/peaceLive/videoUpload/list.html', objModal.video); $scope.openVideoModal = function () { ModalService.openModal(objModal.video); }; $scope.closeVideoModal = function () { ModalService.closeModal(objModal.video); }; // 身份证弹出框 $scope.openCarImageModal = function () { var uploadType = 'BEIBAOXIANZJ'; $scope.carModalTitle = '身份证'; $scope.images = []; ModalService.initModal($scope, $ionicModal, 'scripts/atomic_veeker/scheme/videoUpload/car-image.html', objModal.carImage); getRecentImage(indentInfo.orders[0].id, uploadType); ModalService.openModal(objModal.carImage); }; $scope.closeCarImageModal = function () { ModalService.closeModal(objModal.carImage); }; $scope.openImageHistoryModal = function () { var uploadType = 'BEIBAOXIANZJ'; ModalService.initModal($scope, $ionicModal, 'scripts/atomic_veeker/scheme/videoUpload/image-history.html', objModal.imageHistory); getImageHistory(indentInfo.orders[0].id, uploadType); ModalService.openModal(objModal.imageHistory); }; $scope.closeImageHistoryModal = function () { ModalService.closeModal(objModal.imageHistory); }; // 获取最近上传的影像图片 function getRecentImage(orderId, type) { $rootScope.showLoadingText('加载中'); SchemeService.getRecentImage({orderId: orderId, type: type}, function (res) { $rootScope.hideLoadingText(); if (res.file) { $scope[type + 'Src'] = "/api/attachment/download?filename=" + encodeURI(res.file) + '&type=' + res.filePath; } }, function (error) { $rootScope.hideLoadingText(); $log.debug(error); }); } // 获取历史影像资料 function getImageHistory(orderId, type) { $rootScope.showLoadingText('加载中'); SchemeService.getImageHistory({orderId: orderId, type: type}, function (res) { if (res) { $scope.imageList = []; angular.forEach(res, function (item) { var tmpSrc = "/api/attachment/download?filename=" + encodeURI(item.file) + '&type=' + item.filePath; $scope.imageList.push({src: tmpSrc}); }); $rootScope.hideLoadingText(); ModalService.openModal(objModal.imageHistory); } else { $rootScope.hideLoadingText(); $rootScope.showMessage('暂无历史影像数据!'); } }, function (error) { $rootScope.hideLoadingText(); $log.debug(error); }); } $scope.images = []; $scope.uploadImages = function (files) { if ($scope.images.length >= 10) { $rootScope.showMessage('每次最多上传10张图片!'); return; } Upload.base64DataUrl(files).then(function (urls) { for (var i = 0; i < files.length; i++) { var file = files[i]; $scope.images.push({src: urls[i], file: file}); } }); }; $scope.deleteImages = function (index) { $scope.images.splice(index, 1); }; $scope.uploadFiles = function () { if (!$scope.images.length) { $rootScope.showMessage('请选择您要上传的图片!'); return; } var files = []; angular.forEach($scope.images, function (item) { files.push(item.file); }); unloadCarFile(files, $scope.carFileObj); }; // 上传文件 function unloadCarFile(files, fileObj) { if (files && files.length) { if (files.length > 10) { $rootScope.showMessage('每次最多上传10张图片!'); return; } var dataType = 'BEIBAOXIANZJ'; var fileCount = 0; for (var i = 0; i < files.length; i++) { $rootScope.showLoadingText('正在上传第' + (fileCount + 1) + '张'); var file = files[i]; var options = { width: 640, height: 640, type: 'image/*', restoreExif: false }; Upload.resize(file, options).then(function (resizedFile) { Upload.upload({ url: '/api/attachment/upload', data: { "Content-Type": resizedFile.type != '' ? resizedFile.type : 'application/octet-stream', name: resizedFile.name, type: dataType, indentId: indentInfo.orders[0].indentId }, file: resizedFile }).progress(function (evt) { if (!fileObj.isUploading) { fileObj.isUploading = true; } fileObj.progressPercentage = parseInt(100 * evt.loaded / evt.total); }).success(function (data, status, headers, config) { fileObj.isUploading = false; fileObj.isDownloaded = true; fileObj.hasUpload = true; fileObj.progressPercentage = 0; var params = { id: '', file: data.file, filePath: dataType, orderId: indentInfo.orders[0].id, type: dataType, veekerId: $rootScope.account.veeker.id, status: '', businessNo: indentInfo.orders[0].insuranceApplicationNo, marks: '' }; SchemeService.uploadImage(params, function () { fileCount++; $rootScope.showLoadingText('正在上传第' + (fileCount + 1) + '张'); if (fileCount == files.length) { $rootScope.hideLoadingText(); $rootScope.showMessage("上传成功!", 1500); getRecentImage(indentInfo.orders[0].id, params.type); $scope.showIDTip = true; } }, function (error) { $rootScope.hideLoadingText(); $scope.showIDTip = false; var msg = error.headers('errorMessage'); if (msg) { msg = decodeURI(msg); $rootScope.showMessage(msg); } else { $rootScope.showMessage("上传失败,请重新上传!", 1500); } }); }).error(function (data, status, headers, config) { $rootScope.hideLoadingText(); var msg = headers('errorMessage'); if (msg) { msg = decodeURI(msg); $rootScope.showMessage(msg); } else { $rootScope.showMessage("上传失败,请重新上传!", 1500); } fileObj.isUploading = false; fileObj.isDownloaded = false; }); }); } } } // 初始化身份证上传信息 function initUploadInfo() { // 验车照 $scope.carFileObj = { key: 'CHECKCAR', isUploading: false, isDownloaded: false, progressPercentage: 0, hasUpload: false }; //被保险人身份证正面 $scope.insuredFrontFileObj = { key: CONFIG.ATTACH_INSURED_IDCARD_FRONT, isUploading: false, isDownloaded: false, progressPercentage: 0, hasUpload: false }; //被保险人身份证反面 $scope.insuredBackFileObj = { key: CONFIG.ATTACH_INSURED_IDCARD_BACK, isUploading: false, isDownloaded: false, progressPercentage: 0, hasUpload: false }; $scope.downloadFile = {}; $scope.previewFile = {}; initDownloadFile(); } function initDownloadFile() { var fileObjArray = ['insuredFront', 'insuredBack']; angular.forEach(fileObjArray, function (item) { var fileObj = $scope[item + 'FileObj']; var key = fileObj.key; $scope.downloadFile[key] = getAttachmentFile(key, fileObj); }); } // 获取文件类型 function getAttachmentFile(type, fileObj) { var array = CarImages.filter(function (item) { item.file = item.filePath; item.type = item.type; return item.type == type; }); if (array.length && fileObj) { fileObj.hasUpload = true; } return array[0] || {}; } });