TeclcontractCtrl.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. angular.module('push')
  2. .controller('TeclcontractCtrl', function ($scope,SelfcheckService,$stateParams,UserService,$ionicPopup,CommonService,ConfigService,AccountService,
  3. $timeout,$ionicModal,$ionicActionSheet,ionicDatePicker,$ionicScrollDelegate) {
  4. $scope.data=[
  5. {
  6. info:'合同名称',
  7. ismust:true,
  8. value:'',
  9. type:1,
  10. key:'name'
  11. },{
  12. info:'合同金额(万)',
  13. ismust:true,
  14. value:'',
  15. type:2,
  16. key:'amount'
  17. },{
  18. info:'甲方名称',
  19. ismust:true,
  20. value:'',
  21. type:1,
  22. key:'firstName'
  23. },{
  24. info:'甲方联系人',
  25. ismust:true,
  26. value:'',
  27. type:1,
  28. key:'firstContact'
  29. },{
  30. info:'乙方名称',
  31. ismust:true,
  32. value:'',
  33. type:1,
  34. key:'secondName'
  35. },{
  36. info:'乙方联系人',
  37. ismust:true,
  38. value:'',
  39. type:1,
  40. key:'secondContact'
  41. },{
  42. info:'上传合同',
  43. ismust:true,
  44. value:[],
  45. type:3,
  46. key:'url'
  47. },
  48. ]
  49. $scope.status=null
  50. $scope.oninputs=function (row){
  51. $scope.TeclcontractModal.show();
  52. }
  53. //下面是录入弹框
  54. $ionicModal.fromTemplateUrl('modules/account/views/Teclcontractinput.html', {
  55. scope: $scope,
  56. backdropClickToClose:false
  57. }).then(function (modal) {
  58. $scope.TeclcontractModal = modal;
  59. });
  60. function getcontractlist(){
  61. SelfcheckService.getcontractlist({userId:UserService.id}).then(function (res){
  62. if(res.code==3350){
  63. res.data.forEach((item)=>{
  64. if(item.url){
  65. item.url = JSON.parse(item.url)
  66. }
  67. })
  68. $scope.checkList = res.data;
  69. // if(res.data.length!=0){
  70. // $scope.data.forEach((item)=>{
  71. // if(res.data[0][item.key]){
  72. // if(item.key=='url'){
  73. // item.value=JSON.parse(res.data[0][item.key])
  74. // }else {
  75. // item.value=res.data[0][item.key]
  76. // }
  77. // }
  78. // })
  79. // console.log($scope.data)
  80. // $scope.status=res.data[0].status
  81. // }
  82. }else {
  83. $ionicPopup.alert({
  84. title: '提示',
  85. template: res.message
  86. });
  87. }
  88. }).catch(function () {
  89. $ionicPopup.alert({
  90. title: '提示',
  91. template: "服务器错误"
  92. });
  93. })
  94. }getcontractlist()
  95. //验证
  96. $scope.clearNum = function(obj, attr){
  97. if(obj[attr] != obj[attr].replace(/\D/g,"")){
  98. var alertPopup = $ionicPopup.alert({
  99. template: '请输入正整数!'
  100. });
  101. alertPopup.then(function(res) {
  102. console.log('Thank you for not eating my delicious ice cream cone');
  103. });
  104. }
  105. obj[attr] = obj[attr].replace(/\D/g,"");
  106. }
  107. $scope.addImage = function (val) {
  108. var files = document.getElementById('file');
  109. files.click();
  110. $(files).unbind().on('change', function (e) {
  111. console.log(e)
  112. if(!/.(jpg|jpeg|png|JPG|pdf|PDF)$/.test(e.target.value)){
  113. $ionicPopup.alert({
  114. title: '提示',
  115. template: "图片类型必须是jpeg,jpg,png,中的一种"
  116. });
  117. return;
  118. }
  119. if (val.value.length > 9||(e.target.files.length+val.value.length)>9) {
  120. $ionicPopup.alert({
  121. title: '提示',
  122. template: '最多只能上传9个文件!'
  123. });
  124. return;
  125. }
  126. $.each(e.target.files, function (i, file) {
  127. console.log(file)
  128. $scope.showLoadingToastUtilEnd();
  129. var data = new FormData();
  130. data.append('file', file);
  131. CommonService.webUploadImage(data).then(function (res) {
  132. files.value=''
  133. $scope.hideLoadingToast();
  134. var temp = {
  135. title: res.title,
  136. sourceName: res.sourceName
  137. }
  138. val.value.push(temp);
  139. })
  140. });
  141. })
  142. return true;
  143. }
  144. //删除图片
  145. $scope.deletePhoto = function (val,index) {
  146. val.splice(index, 1);
  147. }
  148. $scope.shouBigImage = function (val) { //传递一个参数(图片的URl)
  149. window.open(ConfigService.imgurl + val.sourceName);
  150. return;
  151. };
  152. //录入
  153. function Processingdata(){
  154. var params={}
  155. for(let row of $scope.data){
  156. if(row.ismust&&(!row.value||row.value==false)){
  157. $ionicPopup.alert({
  158. template: '请输入'+row.info
  159. });
  160. return false
  161. }else {
  162. if(row.key=='url'){
  163. params[row.key]=JSON.stringify(row.value)
  164. }else {
  165. params[row.key]=row.value
  166. }
  167. }
  168. }
  169. console.log(params)
  170. return params
  171. }
  172. $scope.gotest=function (){
  173. let Processingfinal=Processingdata()
  174. if(Processingfinal){
  175. $scope.showLoadingToastUtilEnd();
  176. let pams={creater:UserService.id,...Processingfinal}
  177. console.log(pams)
  178. SelfcheckService.postcontractinsert(pams).then(function (res){
  179. $scope.hideLoadingToast();
  180. console.log(res)
  181. if(res.code==3350){
  182. CommonService.prompt('登记成功');
  183. getcontractlist()
  184. $scope.TeclcontractModal.hide()
  185. }else {
  186. $ionicPopup.alert({
  187. title: '提示',
  188. template: res.message
  189. });
  190. }
  191. }).catch(function () {
  192. $ionicPopup.alert({
  193. title: '提示',
  194. template: "服务器错误"
  195. });
  196. })
  197. }
  198. }
  199. })