angular.module('push') .controller('TeclcontractCtrl', function ($scope,SelfcheckService,$stateParams,UserService,$ionicPopup,CommonService,ConfigService,AccountService, $timeout,$ionicModal,$ionicActionSheet,ionicDatePicker,$ionicScrollDelegate) { $scope.data=[ { info:'合同名称', ismust:true, value:'', type:1, key:'name' },{ info:'合同金额(万)', ismust:true, value:'', type:2, key:'amount' },{ info:'甲方名称', ismust:true, value:'', type:1, key:'firstName' },{ info:'甲方联系人', ismust:true, value:'', type:1, key:'firstContact' },{ info:'乙方名称', ismust:true, value:'', type:1, key:'secondName' },{ info:'乙方联系人', ismust:true, value:'', type:1, key:'secondContact' },{ info:'上传合同', ismust:true, value:[], type:3, key:'url' }, ] $scope.status=null $scope.oninputs=function (row){ $scope.TeclcontractModal.show(); } //下面是录入弹框 $ionicModal.fromTemplateUrl('modules/account/views/Teclcontractinput.html', { scope: $scope, backdropClickToClose:false }).then(function (modal) { $scope.TeclcontractModal = modal; }); function getcontractlist(){ SelfcheckService.getcontractlist({userId:UserService.id}).then(function (res){ if(res.code==3350){ res.data.forEach((item)=>{ if(item.url){ item.url = JSON.parse(item.url) } }) $scope.checkList = res.data; // if(res.data.length!=0){ // $scope.data.forEach((item)=>{ // if(res.data[0][item.key]){ // if(item.key=='url'){ // item.value=JSON.parse(res.data[0][item.key]) // }else { // item.value=res.data[0][item.key] // } // } // }) // console.log($scope.data) // $scope.status=res.data[0].status // } }else { $ionicPopup.alert({ title: '提示', template: res.message }); } }).catch(function () { $ionicPopup.alert({ title: '提示', template: "服务器错误" }); }) }getcontractlist() //验证 $scope.clearNum = function(obj, attr){ if(obj[attr] != obj[attr].replace(/\D/g,"")){ var alertPopup = $ionicPopup.alert({ template: '请输入正整数!' }); alertPopup.then(function(res) { console.log('Thank you for not eating my delicious ice cream cone'); }); } obj[attr] = obj[attr].replace(/\D/g,""); } $scope.addImage = function (val) { var files = document.getElementById('file'); files.click(); $(files).unbind().on('change', function (e) { console.log(e) if(!/.(jpg|jpeg|png|JPG|pdf|PDF)$/.test(e.target.value)){ $ionicPopup.alert({ title: '提示', template: "图片类型必须是jpeg,jpg,png,中的一种" }); return; } if (val.value.length > 9||(e.target.files.length+val.value.length)>9) { $ionicPopup.alert({ title: '提示', template: '最多只能上传9个文件!' }); return; } $.each(e.target.files, function (i, file) { console.log(file) $scope.showLoadingToastUtilEnd(); var data = new FormData(); data.append('file', file); CommonService.webUploadImage(data).then(function (res) { files.value='' $scope.hideLoadingToast(); var temp = { title: res.title, sourceName: res.sourceName } val.value.push(temp); }) }); }) return true; } //删除图片 $scope.deletePhoto = function (val,index) { val.splice(index, 1); } $scope.shouBigImage = function (val) { //传递一个参数(图片的URl) window.open(ConfigService.imgurl + val.sourceName); return; }; //录入 function Processingdata(){ var params={} for(let row of $scope.data){ if(row.ismust&&(!row.value||row.value==false)){ $ionicPopup.alert({ template: '请输入'+row.info }); return false }else { if(row.key=='url'){ params[row.key]=JSON.stringify(row.value) }else { params[row.key]=row.value } } } console.log(params) return params } $scope.gotest=function (){ let Processingfinal=Processingdata() if(Processingfinal){ $scope.showLoadingToastUtilEnd(); let pams={creater:UserService.id,...Processingfinal} console.log(pams) SelfcheckService.postcontractinsert(pams).then(function (res){ $scope.hideLoadingToast(); console.log(res) if(res.code==3350){ CommonService.prompt('登记成功'); getcontractlist() $scope.TeclcontractModal.hide() }else { $ionicPopup.alert({ title: '提示', template: res.message }); } }).catch(function () { $ionicPopup.alert({ title: '提示', template: "服务器错误" }); }) } } })