editResourcePrivateDetailsCtrl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. angular.module('push')
  2. .controller('editResourcePrivateDetailsCtrl', function ($scope, $stateParams, $ionicActionSheet, ModelService, UtilService, ResourceLibraryService, $timeout, $ionicScrollDelegate,$ionicSlideBoxDelegate) {
  3. if($scope.app){
  4. $scope.setStatusBar(0);
  5. }
  6. $scope.type = $stateParams.type;
  7. var tempdate = angular.fromJson($stateParams.resource);
  8. var recourceid = tempdate.unique;
  9. var recourcecomefrom = tempdate.source;
  10. $scope.resource = {
  11. title: tempdate.title,//名称或姓名
  12. type: tempdate.type,//1:需求,2:成果,6:企业,8:人才
  13. categoryid: tempdate.categoryid,//行或领域
  14. cperid: tempdate.cperid == undefined ? 0 : tempdate.cperid,//合作模式
  15. content: tempdate.content == undefined ? "" : tempdate.content,
  16. tel: tempdate.tel == undefined ? "" : tempdate.tel,//电话
  17. orgName: tempdate.orgName == undefined ? "" : tempdate.orgName,//单位
  18. //企业
  19. enterprisetype: tempdate.enterprisetype == undefined ? 0 : tempdate.enterprisetype,//企业类型
  20. enterprisescale: tempdate.enterprisescale == undefined ? 0 : tempdate.enterprisescale,//企业规模
  21. address: tempdate.address == undefined ? "" : tempdate.address,//地址
  22. contactor: tempdate.contactor == undefined ? "" : tempdate.contactor,//联系人
  23. //人才
  24. sex: tempdate.sex == undefined ? 0 : tempdate.sex,//性别
  25. birthday: tempdate.birthday == undefined ? "" : tempdate.birthday,//出生年月
  26. academicdegree: tempdate.academicdegree == undefined ? 0 : tempdate.academicdegree,//学位
  27. positionaltitles: tempdate.positionaltitles == undefined ? 0 : tempdate.positionaltitles,//职称
  28. email: tempdate.email == undefined ? "" : tempdate.email,//邮箱
  29. //需求
  30. capitalScale: tempdate.capitalScale == -1 ? "面议" : tempdate.capitalScale,//投入预算
  31. //成果
  32. isipr: tempdate.isipr == undefined ? 0 : tempdate.isipr,//知识产权
  33. proficiency: tempdate.proficiency == undefined ? 0 : tempdate.proficiency//成熟度
  34. };
  35. $scope.imagelist = tempdate.picturelist == undefined ? [] : tempdate.picturelist;
  36. // console.log($scope.resource);
  37. // console.log($scope.imagelist);
  38. /*选择行业*/
  39. $scope.selectCategory = function () {
  40. $ionicActionSheet.show({
  41. buttons: [
  42. {text: '<a class="action-sheet-push">汽车制造</a>'},
  43. {text: '<a class="action-sheet-push">能源及节能技术</a>'},
  44. {text: '<a class="action-sheet-push">新材料</a>'},
  45. {text: '<a class="action-sheet-push">生物与新医药</a>'},
  46. {text: '<a class="action-sheet-push">电子信息</a>'},
  47. {text: '<a class="action-sheet-push">先进制造及高端装备</a>'},
  48. {text: '<a class="action-sheet-push">资源及环境技术</a>'}
  49. ],
  50. cancelText: '取消',
  51. buttonClicked: function (index) {
  52. $scope.resource.categoryid = index + 1;
  53. return true;
  54. }
  55. });
  56. };
  57. /*选择企业类型*/
  58. $scope.selectEnterpriseType = function () {
  59. $ionicActionSheet.show({
  60. buttons: [
  61. {text: '<a class="action-sheet-push">国有企业</a>'},
  62. {text: '<a class="action-sheet-push">集体所有制企业</a>'},
  63. {text: '<a class="action-sheet-push">私营企业</a>'},
  64. {text: '<a class="action-sheet-push">股份制企业</a>'},
  65. {text: '<a class="action-sheet-push">联营企业</a>'},
  66. {text: '<a class="action-sheet-push">外商投资企业</a>'},
  67. {text: '<a class="action-sheet-push">港澳台企业</a>'},
  68. {text: '<a class="action-sheet-push">股份制企业</a>'}
  69. ],
  70. cancelText: '取消',
  71. buttonClicked: function (index) {
  72. $scope.resource.enterprisetype = index + 1;
  73. return true;
  74. }
  75. });
  76. };
  77. /*选择企业规模*/
  78. $scope.selectEnterpriseScale = function () {
  79. $ionicActionSheet.show({
  80. buttons: [
  81. {text: '<a class="action-sheet-push">少于50人</a>'},
  82. {text: '<a class="action-sheet-push">50-150人</a>'},
  83. {text: '<a class="action-sheet-push">150-500人</a>'},
  84. {text: '<a class="action-sheet-push">500-1000人</a>'},
  85. {text: '<a class="action-sheet-push">1000-5000人</a>'},
  86. {text: '<a class="action-sheet-push">5000-10000人</a>'},
  87. {text: '<a class="action-sheet-push">10000人以上</a>'}
  88. ],
  89. cancelText: '取消',
  90. buttonClicked: function (index) {
  91. $scope.resource.enterprisescale = index + 1;
  92. return true;
  93. }
  94. });
  95. };
  96. /*选择知识产权*/
  97. $scope.selectRight = function () {
  98. $ionicActionSheet.show({
  99. buttons: [
  100. {text: '<a class="action-sheet-push">有</a>'},
  101. {text: '<a class="action-sheet-push">无</a>'}
  102. ],
  103. cancelText: '取消',
  104. buttonClicked: function (index) {
  105. $scope.resource.isipr = 1 - index;
  106. return true;
  107. }
  108. });
  109. };
  110. /*选择成熟度*/
  111. $scope.selectMaturity = function () {
  112. $ionicActionSheet.show({
  113. buttons: [
  114. {text: '<a class="action-sheet-push">正在研发</a>'},
  115. {text: '<a class="action-sheet-push">已有小样</a>'},
  116. {text: '<a class="action-sheet-push">通过小试</a>'},
  117. {text: '<a class="action-sheet-push">通过中试</a>'},
  118. {text: '<a class="action-sheet-push">可以量产</a>'}
  119. ],
  120. cancelText: '取消',
  121. buttonClicked: function (index) {
  122. $scope.resource.proficiency = index + 1;
  123. return true;
  124. }
  125. });
  126. };
  127. /*选择合作模式*/
  128. $scope.selectCperid = function () {
  129. $ionicActionSheet.show({
  130. buttons: [
  131. {text: '<a class="action-sheet-push">委托开发</a>'},
  132. {text: '<a class="action-sheet-push">合作研发</a>'},
  133. {text: '<a class="action-sheet-push">成果转让</a>'},
  134. {text: '<a class="action-sheet-push">技术入股</a>'},
  135. {text: '<a class="action-sheet-push">技术咨询</a>'},
  136. {text: '<a class="action-sheet-push">其他</a>'}
  137. ],
  138. cancelText: '取消',
  139. buttonClicked: function (index) {
  140. $scope.resource.cperid = index + 1;
  141. return true;
  142. }
  143. });
  144. };
  145. /*选择性别*/
  146. $scope.selectSex = function () {
  147. $ionicActionSheet.show({
  148. buttons: [
  149. {text: '<a class="action-sheet-push">男</a>'},
  150. {text: '<a class="action-sheet-push">女</a>'}
  151. ],
  152. cancelText: '取消',
  153. buttonClicked: function (index) {
  154. $scope.resource.sex = index + 1;
  155. return true;
  156. }
  157. });
  158. };
  159. /*选择学位*/
  160. $scope.selectAcademicDegree = function () {
  161. $ionicActionSheet.show({
  162. buttons: [
  163. {text: '<a class="action-sheet-push">学士</a>'},
  164. {text: '<a class="action-sheet-push">硕士</a>'},
  165. {text: '<a class="action-sheet-push">博士</a>'},
  166. {text: '<a class="action-sheet-push">博士后</a>'},
  167. {text: '<a class="action-sheet-push">其他</a>'}
  168. ],
  169. cancelText: '取消',
  170. buttonClicked: function (index) {
  171. $scope.resource.academicdegree = index + 1;
  172. return true;
  173. }
  174. });
  175. };
  176. /*选择职称*/
  177. $scope.selectPositionalTitles = function () {
  178. $ionicActionSheet.show({
  179. buttons: [
  180. {text: '<a class="action-sheet-push">正高</a>'},
  181. {text: '<a class="action-sheet-push">副高</a>'},
  182. {text: '<a class="action-sheet-push">中级</a>'},
  183. {text: '<a class="action-sheet-push">副级</a>'},
  184. {text: '<a class="action-sheet-push">无</a>'}
  185. ],
  186. cancelText: '取消',
  187. buttonClicked: function (index) {
  188. $scope.resource.positionaltitles = index + 1;
  189. return true;
  190. }
  191. });
  192. };
  193. /*选取照片*/
  194. $scope.showPicture = function () {
  195. $ionicActionSheet.show({
  196. buttons: [
  197. {text: '<a class="action-sheet-push">拍照</a>'},
  198. {text: '<a class="action-sheet-push">从相册中添加</a>'}
  199. ],
  200. cancelText: '取消',
  201. buttonClicked: function (index) {
  202. if (index == 0) {
  203. if ($scope.imagelist.length >= 18) {
  204. UtilService.showMess("最多选取18张图片");
  205. return;
  206. }
  207. UtilService.getPicture(1).then(function (results) {
  208. $scope.imagelist.push({photo_name: results, original_name: results, source_name: results});
  209. $scope.totalImglength = 600 * $scope.imagelist.length;
  210. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  211. }, function (err) {
  212. });
  213. } else if (index == 1) {
  214. getPictures();
  215. }
  216. return true;
  217. }
  218. });
  219. };
  220. var verifyStorage = function () {
  221. window.imagePicker.verifyStorage(
  222. function (results) {
  223. if (results == "1") {
  224. getPic();
  225. }
  226. }, function (error) {
  227. }
  228. );
  229. };
  230. var getPic = function () {
  231. if ($scope.imagelist.length >= 18) {
  232. UtilService.showMess("最多选取18张图片");
  233. return;
  234. }
  235. UtilService.getPictureList(18 - $scope.imagelist.length).then(function (results) {
  236. angular.forEach(results, function (value, index) {
  237. $scope.imagelist.push({photo_name: value, original_name: value, source_name: value})
  238. });
  239. $scope.totalImglength = 600 * $scope.imagelist.length;
  240. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  241. }, function (err) {
  242. });
  243. };
  244. var getPictures = function () {
  245. if (device.platform == "Android") {
  246. verifyStorage();
  247. } else {
  248. getPic();
  249. }
  250. };
  251. var delpiclist = [];
  252. $scope.deletePhoto = function (index) {
  253. if (UtilService.isDefined($scope.imagelist[index].id)) {
  254. delpiclist.push($scope.imagelist[index].id);
  255. }
  256. $scope.imagelist.splice(index, 1);
  257. };
  258. var addpiclist = [];
  259. var uploadImages = function () {
  260. var upimages = [];
  261. angular.forEach($scope.imagelist, function (data) {
  262. if (data.photo_name.indexOf("file:") != -1) {
  263. upimages.push(data.photo_name);
  264. }
  265. });
  266. if (upimages.length > 0) {
  267. UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
  268. // console.log(response);
  269. angular.forEach(response, function (value, index) {
  270. if (value.status) {
  271. addpiclist.push({
  272. id: 0,
  273. photo_name: value.userPhoto,
  274. original_name: value.originalPhoto,
  275. source_name: value.sourcePhoto,
  276. source_size:value.source_size,
  277. title: "",
  278. moduleid: $scope.type,
  279. infoid: recourceid,
  280. infocomefrom: recourcecomefrom
  281. });
  282. }
  283. });
  284. $timeout(function () {
  285. editResource(addpiclist);
  286. }, 100);
  287. }, function () {
  288. editResource([]);
  289. })
  290. } else {
  291. editResource([]);
  292. }
  293. };
  294. // 编辑资源
  295. var editResource = function (addpiclist) {
  296. ResourceLibraryService.editResource($scope.type, recourceid, recourcecomefrom, delpiclist, addpiclist, $scope.resource).then(function (response) {
  297. // console.log(response);
  298. UtilService.showMess("编辑成功");
  299. $timeout(function () {
  300. $scope.goback();
  301. }, 1000);
  302. }, function () {
  303. UtilService.showMess("网络不给力,请重试");
  304. })
  305. };
  306. $scope.saveResource = function () {
  307. if (!UtilService.isDefined($scope.resource.title)) {
  308. if ($scope.type == '8') {
  309. UtilService.showMess("姓名不能为空");
  310. } else {
  311. UtilService.showMess("名称不能为空");
  312. }
  313. return;
  314. }
  315. if (UtilService.isDefined($scope.imagelist) && $scope.imagelist.length > 0) {
  316. uploadImages();
  317. } else {
  318. editResource([])
  319. }
  320. };
  321. //点击图片放大
  322. $scope.bigImage = false; //初始默认大图是隐藏的
  323. $scope.hideBigImage = function () {
  324. $timeout(function () {
  325. if($scope.app){
  326. $scope.setStatusBar(0);
  327. }
  328. $scope.bigImage = false;
  329. }, 400);
  330. };
  331. $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
  332. if($scope.app){
  333. $scope.setStatusBar(1);
  334. }
  335. $scope.bigImage = true; //显示大图
  336. // console.log(index);
  337. $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
  338. //图片总数量
  339. setTimeout(function () {
  340. // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
  341. // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
  342. $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10);
  343. //获取图片
  344. var imgObj = document.getElementsByClassName('bigimage');
  345. var n;
  346. for (n = 0; n < imgObj.length; n++) {
  347. // 获取图片的原始高度和宽度
  348. var oldWid = imgObj[n].naturalWidth;
  349. var oldHei = imgObj[n].naturalHeight;
  350. var screen = document.body.offsetWidth;
  351. var screenH = window.innerHeight;
  352. // console.log(oldWid/oldHei);
  353. // console.log(screen );
  354. var rate=oldWid/oldHei;
  355. if(oldWid>=screen&&oldHei>=screenH){
  356. var tw=screen;
  357. var th=tw/rate;
  358. if(th<screenH){
  359. imgObj[n].style.width = tw + 'px';
  360. imgObj[n].style.height = th + 'px';
  361. imgObj[n].style.marginTop=(screenH-th)/2+ 'px';
  362. }else{
  363. imgObj[n].style.width = screenH*rate + 'px';
  364. imgObj[n].style.height = screenH + 'px';
  365. imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
  366. }
  367. }else if(oldWid>=screen&&oldHei<=screenH){
  368. imgObj[n].style.width = screen + 'px';
  369. imgObj[n].style.height = screen/rate + 'px';
  370. imgObj[n].style.marginTop=(screenH-screen/rate)/2+ 'px';
  371. }else if(oldWid<=screen&&oldHei>=screenH){
  372. // var hh=screenH;
  373. // var ww=screenH*rate;
  374. imgObj[n].style.width = screenH*rate + 'px';
  375. imgObj[n].style.height = screenH + 'px';
  376. imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
  377. }else{
  378. imgObj[n].style.width = oldWid + 'px';
  379. imgObj[n].style.height = oldHei + 'px';
  380. imgObj[n].style.marginLeft=(screen-oldWid)/2+ 'px';
  381. imgObj[n].style.marginTop=(screenH-oldHei)/2+ 'px';
  382. }
  383. }
  384. }, 0);
  385. };
  386. //查看原图
  387. $scope.viewOldImg = function (index) {
  388. // console.log($scope.imagelist[index]);
  389. // console.log("查看原图"+index);
  390. var url = UtilService.isDefined($scope.imagelist[index].source_name) ? $scope.imagelist[index].source_name : $scope.imagelist[index].photo_name;
  391. $(".bigimage").eq(index).attr("src", $scope.imgUrl + url);
  392. $timeout(function () {
  393. $scope.imagelist[index].loadsource = true;
  394. },20);
  395. };
  396. });