recordDemandInfoCtrl.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. angular.module('push')
  2. .controller('recordDemandInfoCtrl', function ($scope,$stateParams,dataToolsService,UtilService,ConstantService,
  3. $timeout,$ionicActionSheet,UserService) {
  4. // 对应的是0新增/1编辑
  5. $scope.isedit = $stateParams.isedit;
  6. if($scope.isedit == 0){
  7. $scope.pagetitle = "录入需求信息";
  8. }else
  9. if($scope.isedit == 1){
  10. $scope.pagetitle = "编辑需求信息";
  11. $timeout(function () {
  12. $("#orgname").prop("disabled", true);
  13. },300);
  14. }else
  15. // 复制并新建
  16. if($scope.isedit == 2){
  17. $scope.pagetitle = "复制并新建需求信息";
  18. $timeout(function () {
  19. $("#orgname").prop("disabled", true);
  20. },300);
  21. }
  22. //企业基本信息
  23. $scope.connEnterpriseModuleModel = {
  24. id: 0,
  25. userid: 0,
  26. usercomefrom: "",
  27. claid: 0,// 选中的文件夹id
  28. taskid: 0,// 任务id
  29. yearsetupid: 0,
  30. yearsetupname: "",
  31. templettype: $stateParams.pageid,// 模板id
  32. orgname: "",
  33. orglogo: "",// 企业logo
  34. orgtype: ConstantService.UNITTYPE_10104,//机构类型:默认企业
  35. orgcontent: "",// 企业简介
  36. orgcontact: "",
  37. orgcontactnum: "",
  38. categoryid: "",
  39. categoryname: "",
  40. orggradecode: 0,// 企业研发机构等级
  41. ishigh: 0,// 是否高企
  42. userModel: {
  43. userid: 0 // 用户id
  44. },
  45. organizationInfo: {
  46. id: 0,
  47. orgtype: ConstantService.UNITTYPE_10104,//机构类型
  48. name: "",
  49. about: "",// 机构简介
  50. contact: "",
  51. contactnum: "",
  52. categoryid: "",
  53. categoryname: "",
  54. rdinstitutiontype: 0,// 企业研发机构等级
  55. rdinstitutiontypename: "",// 企业研发机构等级
  56. ishigh: 0,// 是否高企
  57. logo: "",// 企业logo
  58. high:true,
  59. ishighInfo:"是",
  60. images: "",// 传到后台的图片json
  61. delimages: "",// 删除的图片
  62. imagelist: []// app端图片插件进行传递的变量
  63. }
  64. };
  65. $scope.deldemandInfo = "";
  66. // 保存基本信息需要的格式
  67. $scope.requestModel= {
  68. data: {},
  69. node: ""
  70. };
  71. // 获取走访录入界面的传参
  72. $scope.rolePageModel=
  73. {
  74. //TODO
  75. id: $stateParams.pageid,// 模版id
  76. orgtype: ConstantService.UNITTYPE_10104// 走访对应的机构类型
  77. // id: 2,// 模版id
  78. // orgtype: 2,// 模版id
  79. };
  80. //需求信息
  81. $scope.demandInfoList = [{
  82. id: 0,
  83. connid: 0,
  84. companyid: 0,
  85. creator: 0,
  86. updater: 0,
  87. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  88. techtype: 0,
  89. techtypename: "",
  90. techrequirementname: "",
  91. cooperationmodel: "",
  92. cooperationmodelname: "",// 合作模式名称
  93. capitalScale: 0,
  94. techrequirementdetail: "",
  95. remark: "",// 备注
  96. techrequirementsolution: "",// 问题解决方案
  97. images: "", // 图片
  98. }];
  99. //添加、删除更多需求信息
  100. $scope.AddOrDelDemandInfo = function (ind) {
  101. if (ind == 0) {
  102. $scope.demandInfoList.push({
  103. id: 0,
  104. connid: 0,
  105. companyid: 0,
  106. creator: 0,
  107. updater: 0,
  108. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  109. techtype: 0,
  110. techtypename: "",
  111. techrequirementname: "",
  112. cooperationmodel: "",
  113. cooperationmodelname: "",// 合作模式名称
  114. capitalScale: 0,
  115. techrequirementdetail: "",
  116. remark: "",// 备注
  117. techrequirementsolution: "",// 问题解决方案
  118. images: "", // 图片
  119. });
  120. } else {
  121. if ($scope.demandInfoList[ind].id != 0) {
  122. deldemandInfo.push($scope.demandInfoList[ind].id);
  123. }
  124. $scope.demandInfoList.splice(ind, 1);
  125. }
  126. };
  127. // 清空列表中的id,置为0
  128. var clearIdinList = function (datalist) {
  129. if(UtilService.isDefined(datalist) && datalist.length > 0){
  130. angular.forEach(datalist, function (value, index) {
  131. value.id = 0;
  132. });
  133. }
  134. }
  135. // 编辑时获取走访详情
  136. var getPublicResourceList = function () {
  137. //TODO
  138. $scope.connid = $stateParams.connid;
  139. // $scope.connid = 179;
  140. dataToolsService.getConnectioninfoDetailByConnid($scope.connid).then(function (response) {
  141. console.log("============编辑时获取走访详情==================");
  142. console.log(response);
  143. // 基本信息
  144. $scope.connEnterpriseModuleModel = response.data;
  145. if($scope.connEnterpriseModuleModel.ishigh==1){
  146. $scope.connEnterpriseModuleModel.ishighInfo="是";
  147. $scope.connEnterpriseModuleModel.high=true;
  148. }else if($scope.connEnterpriseModuleModel.ishigh==0){
  149. $scope.connEnterpriseModuleModel.ishighInfo="否";
  150. $scope.connEnterpriseModuleModel.high=false;
  151. }
  152. $scope.demandInfoList = $scope.connEnterpriseModuleModel.techrequirementLkList;
  153. // 复制并新增时,清空所有的id
  154. if($scope.isedit == 2){
  155. $scope.connEnterpriseModuleModel.id = 0;
  156. clearIdinList($scope.demandInfoList);
  157. }
  158. }, function () {
  159. });
  160. };
  161. // 编辑时才获取
  162. if($scope.isedit == 1){
  163. getPublicResourceList();
  164. }else
  165. if($scope.isedit == 0){
  166. // 新增时 默认模版id
  167. $scope.connEnterpriseModuleModel.templettype = $stateParams.pageid;
  168. }
  169. else
  170. if($scope.isedit == 2){
  171. // 复制并新增时 默认模版id
  172. getPublicResourceList();
  173. }
  174. //关联相关企业
  175. $scope.isRelateUl = false;
  176. $scope.queryLikeName = function () {
  177. if ($scope.connEnterpriseModuleModel.orgname.length == 0) {
  178. $scope.companylist = [];
  179. $scope.isRelateUl = false;
  180. return;
  181. }
  182. // 全部置空
  183. $scope.connEnterpriseModuleModel.organizationInfo.id = 0;
  184. $scope.connEnterpriseModuleModel.orglogo = "";
  185. $scope.connEnterpriseModuleModel.orgcontact = "";
  186. $scope.connEnterpriseModuleModel.orgcontactnum = "";
  187. $scope.connEnterpriseModuleModel.categoryid = 0;
  188. $scope.connEnterpriseModuleModel.categoryname = "";
  189. $scope.connEnterpriseModuleModel.orggradecode = 0;
  190. $scope.connEnterpriseModuleModel.rdinstitutiontypename = "";
  191. $scope.connEnterpriseModuleModel.ishigh = 0;
  192. $scope.connEnterpriseModuleModel.ishighInfo="否";
  193. $scope.connEnterpriseModuleModel.high=false;
  194. $scope.connEnterpriseModuleModel.remark="";
  195. $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10104;// 默认机构类型:企业
  196. dataToolsService.getOrganizationModelByOrgname($scope.connEnterpriseModuleModel.orgname).then(function (response) {
  197. console.log(response);
  198. $scope.companylist = response.data;
  199. $scope.isRelateUl = true;
  200. }, function () {
  201. })
  202. };
  203. //选中企业
  204. $scope.setCompanyName = function (organizationInfo) {
  205. //<b style='color:red;font-weight: normal;'>亚</b>
  206. organizationInfo.name = organizationInfo.name.replace("<b style='color:red;font-weight: normal;'>", "");
  207. organizationInfo.name = organizationInfo.name.replace("</b>", "");
  208. $scope.connEnterpriseModuleModel.organizationInfo.id = organizationInfo.id;
  209. $scope.connEnterpriseModuleModel.orgname = organizationInfo.name;
  210. $scope.connEnterpriseModuleModel.orglogo = organizationInfo.logo;
  211. $scope.connEnterpriseModuleModel.orgcontact = organizationInfo.contact;
  212. $scope.connEnterpriseModuleModel.orgcontactnum = organizationInfo.contactnum;
  213. $scope.rolePageModel.orgtype = organizationInfo.orgtype;// 取得选中的机构类型
  214. $scope.connEnterpriseModuleModel.categoryid = organizationInfo.categoryid;
  215. $scope.connEnterpriseModuleModel.categoryname = organizationInfo.categoryname;
  216. $scope.connEnterpriseModuleModel.orggradecode = organizationInfo.rdinstitutiontype;
  217. $scope.connEnterpriseModuleModel.rdinstitutiontypename = organizationInfo.rdinstitutiontypename;
  218. $scope.connEnterpriseModuleModel.ishigh = organizationInfo.ishigh;
  219. if($scope.connEnterpriseModuleModel.ishigh==1){
  220. $scope.connEnterpriseModuleModel.ishighInfo="是";
  221. $scope.connEnterpriseModuleModel.high=true;
  222. }else if($scope.connEnterpriseModuleModel.ishigh==0){
  223. $scope.connEnterpriseModuleModel.ishighInfo="否";
  224. $scope.connEnterpriseModuleModel.high=false;
  225. }
  226. $scope.isRelateUl = false;
  227. };
  228. // 获取需求的合作模式列表
  229. var cooperationmodelbuttons = [];
  230. var getCooperationmodelList = function () {
  231. dataToolsService.getTypeEntryListByTypeName("cooperationmodel").then(function (response) {
  232. if (UtilService.isDefined(response.data) && response.data.length > 0) {
  233. angular.forEach(response.data, function (value, index) {
  234. var temphtml = {
  235. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  236. cooperationmodel: value.itemvalue,
  237. cooperationmodelname: value.itemkey
  238. };
  239. cooperationmodelbuttons.push(temphtml);
  240. });
  241. // console.log(cooperationmodelbuttons);
  242. }
  243. }, function () {
  244. })
  245. };
  246. getCooperationmodelList();
  247. // 获取需求的需求类型列表
  248. var techtypebuttons = [];
  249. var getTechtypeList = function () {
  250. dataToolsService.getTypeEntryListByTypeName("techtype").then(function (response) {
  251. if (UtilService.isDefined(response.data) && response.data.length > 0) {
  252. angular.forEach(response.data, function (value, index) {
  253. var temphtml = {
  254. text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
  255. techtype: value.itemvalue,
  256. techtypename: value.itemkey
  257. };
  258. techtypebuttons.push(temphtml);
  259. });
  260. // console.log(cooperationmodelbuttons);
  261. }
  262. }, function () {
  263. })
  264. };
  265. getTechtypeList();
  266. //选择需求的合作模式列表
  267. $scope.showCooperationmodelStatus = function (ind) {
  268. $ionicActionSheet.show({
  269. buttons: cooperationmodelbuttons,
  270. cancelText: '取消',
  271. buttonClicked: function (index) {
  272. $scope.demandInfoList[ind].cooperationmodel = cooperationmodelbuttons[index].cooperationmodel;
  273. $scope.demandInfoList[ind].cooperationmodelname = cooperationmodelbuttons[index].cooperationmodelname;
  274. return true;
  275. }
  276. });
  277. };
  278. //选择需求的需求类型
  279. $scope.showTechtype = function (ind) {
  280. $ionicActionSheet.show({
  281. buttons: techtypebuttons,
  282. cancelText: '取消',
  283. buttonClicked: function (index) {
  284. $scope.demandInfoList[ind].techtype = techtypebuttons[index].techtype;
  285. $scope.demandInfoList[ind].techtypename = techtypebuttons[index].techtypename;
  286. return true;
  287. }
  288. });
  289. };
  290. // 保存企业信息
  291. var saveInfo = function () {
  292. // 需求信息
  293. if ($scope.demandInfoList.length > 0) {
  294. angular.forEach($scope.demandInfoList, function (demandInfoList, $index) {
  295. if (!UtilService.isDefined($scope.demandInfoList[$index].techrequirementname)
  296. && !UtilService.isDefined($scope.demandInfoList[$index].techrequirementdetail)) {
  297. $scope.demandInfoList.splice($index, 1);
  298. }
  299. });
  300. }
  301. // 保存走访基本信息
  302. $scope.connEnterpriseModuleModel.userModel.userid = UserService.id;
  303. // 走访履历表中需记录机构信息
  304. $scope.connEnterpriseModuleModel.organizationInfo.name = $scope.connEnterpriseModuleModel.orgname;
  305. $scope.connEnterpriseModuleModel.title = $scope.connEnterpriseModuleModel.organizationInfo.name;
  306. $scope.connEnterpriseModuleModel.templettype = $scope.rolePageModel.id;
  307. $scope.connEnterpriseModuleModel.organizationInfo.logo = $scope.connEnterpriseModuleModel.orglogo;// 企业logo
  308. $scope.connEnterpriseModuleModel.organizationInfo.about = $scope.connEnterpriseModuleModel.orgcontent;// 企业logo
  309. $scope.connEnterpriseModuleModel.orgtype = $scope.rolePageModel.orgtype;// 机构类型
  310. $scope.connEnterpriseModuleModel.organizationInfo.orgtype = $scope.rolePageModel.orgtype;// 机构类型
  311. $scope.connEnterpriseModuleModel.organizationInfo.contact = $scope.connEnterpriseModuleModel.orgcontact;
  312. $scope.connEnterpriseModuleModel.organizationInfo.contactnum = $scope.connEnterpriseModuleModel.orgcontactnum;
  313. $scope.connEnterpriseModuleModel.organizationInfo.categoryid = $scope.connEnterpriseModuleModel.categoryid;
  314. $scope.connEnterpriseModuleModel.organizationInfo.categoryname = $scope.connEnterpriseModuleModel.categoryname;
  315. $scope.connEnterpriseModuleModel.organizationInfo.rdinstitutiontype = $scope.connEnterpriseModuleModel.orggradecode;// 企业研发机构等级
  316. $scope.connEnterpriseModuleModel.organizationInfo.ishigh = $scope.connEnterpriseModuleModel.ishigh;// 是否高企
  317. // 传参格式
  318. $scope.requestModel.data = $scope.connEnterpriseModuleModel;
  319. $scope.requestModel.node = UserService.node;
  320. dataToolsService.saveOrganizationInfo($scope.requestModel).then(function (response) {
  321. // console.log(response);
  322. if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){
  323. UtilService.showMess("添加成功");
  324. $timeout(function () {
  325. // 保存走访基本信息 后保存其他内容
  326. // 取得记录id
  327. var connid = response.data.id;
  328. $scope.connEnterpriseModuleModel.id = connid;
  329. // 取得机构id
  330. var orgid = response.data.organizationInfo.id;
  331. $scope.connEnterpriseModuleModel.organizationInfo.id = orgid;
  332. // 保存公司需求
  333. if ($scope.demandInfoList.length > 0) {
  334. angular.forEach($scope.demandInfoList, function (value, index) {
  335. value.connid = $scope.connEnterpriseModuleModel.id;
  336. value.companyid = $scope.connEnterpriseModuleModel.organizationInfo.id;
  337. value.creator = UserService.id;
  338. value.updater = UserService.id;
  339. });
  340. // 传参格式
  341. $scope.requestModel.data = $scope.demandInfoList;
  342. $scope.requestModel.node = UserService.node;
  343. dataToolsService.insertOrUpdateCompanyTechrequirement($scope.requestModel).then(function (response) {
  344. }, function () {
  345. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  346. });
  347. }
  348. // 添加成功后跳入我的录入
  349. $scope.go("recordInfoAccount");
  350. }, 500);
  351. } else {
  352. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  353. }
  354. $scope.hideLoadingToast();
  355. saveflg = 0;
  356. }, function () {
  357. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  358. $scope.hideLoadingToast();
  359. saveflg = 0;
  360. });
  361. };
  362. var saveflg = 0;//只允许保存触发一次,多次触发无效,默认未提交
  363. $scope.saveDemandInfo=function () {
  364. // 需求信息
  365. if (!UtilService.isDefined($scope.connEnterpriseModuleModel.orgname)) {
  366. UtilService.showMess("请填写单位名称");
  367. return;
  368. }
  369. if ($scope.connEnterpriseModuleModel.orgname.length > 50) {
  370. UtilService.showMess("单位名称不能超过50个字");
  371. return;
  372. }
  373. if (saveflg != 0) {
  374. return;
  375. }
  376. var result = 1;
  377. // 需求信息
  378. if ($scope.demandInfoList.length > 0) {
  379. angular.forEach($scope.demandInfoList, function (demandInfoList,index) {
  380. if (!UtilService.isDefined($scope.demandInfoList[index].techrequirementname)
  381. || $scope.demandInfoList[index].techrequirementname.length == 0) {
  382. result = 2;
  383. }
  384. if (result == 1 && $scope.demandInfoList[index].techrequirementname.length > 255) {
  385. result = 0;
  386. }
  387. if (result == 1 && UtilService.isDefined($scope.demandInfoList[index].remark) && $scope.demandInfoList[index].remark.length > 1000) {
  388. result = 3;
  389. }
  390. });
  391. if(result == 0){
  392. UtilService.showMess("需求名称不能超过255个字");
  393. saveflg = 0;
  394. return;
  395. }else
  396. if(result == 2){
  397. UtilService.showMess("需求名称不能为空");
  398. saveflg = 0;
  399. return;
  400. }else
  401. if(result == 3){
  402. UtilService.showMess("需求备注不能超过1000个字");
  403. saveflg = 0;
  404. return;
  405. }
  406. $scope.showLoadingToast();
  407. saveInfo();
  408. console.log($scope.demandInfoList);
  409. saveflg = 1;
  410. }
  411. };
  412. //进入资源详情
  413. $scope.jumpResourceDetail = function (company) {
  414. // 先预设信息
  415. $scope.setCompanyName(company);
  416. // 再跳转到资源详情页
  417. $scope.go('resourceCommonDetailsPage', {
  418. recourceid: company.resourcelibrary.id,
  419. recourcetype: company.resourcelibrary.restype,
  420. recourcecomefrom: company.resourcelibrary.comefrom,
  421. creator: company.resourcelibrary.creator
  422. });
  423. };
  424. });