recordProductInfoCtrl.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. angular.module('push')
  2. .controller('recordProductInfoCtrl', function ($scope,$stateParams,dataToolsService,UtilService,ConstantService, $timeout,
  3. $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. remark: "",// 备注
  43. userModel: {
  44. userid: 0 // 用户id
  45. },
  46. organizationInfo: {
  47. id: 0,
  48. orgtype: ConstantService.UNITTYPE_10104,//机构类型
  49. name: "",
  50. about: "",// 机构简介
  51. contact: "",
  52. contactnum: "",
  53. categoryid: "",
  54. categoryname: "",
  55. rdinstitutiontype: 0,// 企业研发机构等级
  56. rdinstitutiontypename: "",// 企业研发机构等级
  57. ishigh: 0,// 是否高企
  58. logo: "",// 企业logo
  59. high:true,
  60. ishighInfo:"是",
  61. images: "",// 传到后台的图片json
  62. delimages: "",// 删除的图片
  63. imagelist: []// app端图片插件进行传递的变量
  64. }
  65. };
  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.produceInfoList = [{
  82. id: 0,
  83. connid: 0,
  84. companyid: 0,
  85. creator: 0,
  86. updater: 0,
  87. remark: "",// 备注
  88. productname: "",// 产品名称
  89. productdescription: "",//产品描述
  90. productFromUnit:""//产品的所属单位
  91. }];
  92. //添加、删除更多一般产品
  93. $scope.AddOrDelProductInfo = function (ind) {
  94. if (ind == 0) {
  95. $scope.produceInfoList.push({
  96. id: 0,
  97. connid: 0,
  98. companyid: 0,
  99. creator: 0,
  100. updater: 0,
  101. remark: "",// 备注
  102. productname: "",// 产品名称
  103. productdescription: "",//产品描述
  104. productFromUnit:""//产品的所属单位
  105. });
  106. } else {
  107. if ($scope.produceInfoList[ind].id != 0) {
  108. $scope.produceInfoList.push($scope.produceInfoList[ind].id);
  109. }
  110. $scope.produceInfoList.splice(ind, 1);
  111. }
  112. };
  113. // 清空列表中的id,置为0
  114. var clearIdinList = function (datalist) {
  115. if(UtilService.isDefined(datalist) && datalist.length > 0){
  116. angular.forEach(datalist, function (value, index) {
  117. value.id = 0;
  118. });
  119. }
  120. }
  121. // 编辑时获取走访详情
  122. var getPublicResourceList = function () {
  123. //TODO
  124. $scope.connid = $stateParams.connid;
  125. // $scope.connid = 179;
  126. dataToolsService.getConnectioninfoDetailByConnid($scope.connid).then(function (response) {
  127. console.log("============编辑时获取走访详情==================");
  128. // 基本信息
  129. $scope.connEnterpriseModuleModel = response.data;
  130. $scope.produceInfoList = $scope.connEnterpriseModuleModel.productLkList;
  131. // 复制并新增时,清空所有的id
  132. if($scope.isedit == 2){
  133. $scope.connEnterpriseModuleModel.id = 0;
  134. clearIdinList($scope.produceInfoList);
  135. }
  136. }, function () {
  137. });
  138. };
  139. // 编辑时才获取
  140. if($scope.isedit == 1){
  141. getPublicResourceList();
  142. }else
  143. if($scope.isedit == 0){
  144. // 新增时 默认模版id
  145. $scope.connEnterpriseModuleModel.templettype = $stateParams.pageid;
  146. }else
  147. if($scope.isedit == 2){
  148. // 复制并新增时 默认模版id
  149. getPublicResourceList();
  150. }
  151. //关联相关企业
  152. $scope.isRelateUl = false;
  153. $scope.queryLikeName = function () {
  154. if ($scope.connEnterpriseModuleModel.orgname.length == 0) {
  155. $scope.companylist = [];
  156. $scope.isRelateUl = false;
  157. return;
  158. }
  159. // 全部置空
  160. $scope.connEnterpriseModuleModel.organizationInfo.id = 0;
  161. $scope.connEnterpriseModuleModel.orglogo = "";
  162. $scope.connEnterpriseModuleModel.orgcontact = "";
  163. $scope.connEnterpriseModuleModel.orgcontactnum = "";
  164. $scope.connEnterpriseModuleModel.categoryid = 0;
  165. $scope.connEnterpriseModuleModel.categoryname = "";
  166. $scope.connEnterpriseModuleModel.orggradecode = 0;
  167. $scope.connEnterpriseModuleModel.rdinstitutiontypename = "";
  168. $scope.connEnterpriseModuleModel.ishigh = 0;
  169. $scope.connEnterpriseModuleModel.ishighInfo="否";
  170. $scope.connEnterpriseModuleModel.high=false;
  171. $scope.connEnterpriseModuleModel.remark="";
  172. $scope.rolePageModel.orgtype = ConstantService.UNITTYPE_10104;// 默认机构类型:企业
  173. dataToolsService.getOrganizationModelByOrgname($scope.connEnterpriseModuleModel.orgname).then(function (response) {
  174. $scope.companylist = response.data;
  175. $scope.isRelateUl = true;
  176. }, function () {
  177. })
  178. };
  179. //选中企业
  180. $scope.setCompanyName = function (organizationInfo) {
  181. //<b style='color:red;font-weight: normal;'>亚</b>
  182. organizationInfo.name = organizationInfo.name.replace("<b style='color:red;font-weight: normal;'>", "");
  183. organizationInfo.name = organizationInfo.name.replace("</b>", "");
  184. $scope.connEnterpriseModuleModel.organizationInfo.id = organizationInfo.id;
  185. $scope.connEnterpriseModuleModel.orgname = organizationInfo.name;
  186. $scope.connEnterpriseModuleModel.orglogo = organizationInfo.logo;
  187. $scope.connEnterpriseModuleModel.orgcontact = organizationInfo.contact;
  188. $scope.connEnterpriseModuleModel.orgcontactnum = organizationInfo.contactnum;
  189. $scope.rolePageModel.orgtype = organizationInfo.orgtype;// 取得选中的机构类型
  190. $scope.connEnterpriseModuleModel.categoryid = organizationInfo.categoryid;
  191. $scope.connEnterpriseModuleModel.categoryname = organizationInfo.categoryname;
  192. $scope.connEnterpriseModuleModel.orggradecode = organizationInfo.rdinstitutiontype;
  193. $scope.connEnterpriseModuleModel.rdinstitutiontypename = organizationInfo.rdinstitutiontypename;
  194. $scope.connEnterpriseModuleModel.ishigh = organizationInfo.ishigh;
  195. if($scope.connEnterpriseModuleModel.ishigh==1){
  196. $scope.connEnterpriseModuleModel.ishighInfo="是";
  197. $scope.connEnterpriseModuleModel.high=true;
  198. }else if($scope.connEnterpriseModuleModel.ishigh==0){
  199. $scope.connEnterpriseModuleModel.ishighInfo="否";
  200. $scope.connEnterpriseModuleModel.high=false;
  201. }
  202. $scope.isRelateUl = false;
  203. };
  204. // 保存企业信息
  205. var saveInfo = function () {
  206. // 产品信息
  207. if ($scope.produceInfoList.length > 0) {
  208. angular.forEach($scope.produceInfoList, function (produceInfoList, $index) {
  209. if (!UtilService.isDefined($scope.produceInfoList[$index].productname)
  210. && !UtilService.isDefined($scope.produceInfoList[$index].productdescription)) {
  211. $scope.produceInfoList.splice($index, 1);
  212. }
  213. });
  214. }
  215. // 保存走访基本信息
  216. $scope.connEnterpriseModuleModel.userModel.userid = UserService.id;
  217. // 走访履历表中需记录机构信息
  218. $scope.connEnterpriseModuleModel.organizationInfo.name = $scope.connEnterpriseModuleModel.orgname;
  219. $scope.connEnterpriseModuleModel.title = $scope.connEnterpriseModuleModel.organizationInfo.name;
  220. $scope.connEnterpriseModuleModel.templettype = $scope.rolePageModel.id;
  221. $scope.connEnterpriseModuleModel.organizationInfo.logo = $scope.connEnterpriseModuleModel.orglogo;// 企业logo
  222. $scope.connEnterpriseModuleModel.organizationInfo.about = $scope.connEnterpriseModuleModel.orgcontent;// 企业logo
  223. $scope.connEnterpriseModuleModel.orgtype = $scope.rolePageModel.orgtype;// 机构类型
  224. $scope.connEnterpriseModuleModel.organizationInfo.orgtype = $scope.rolePageModel.orgtype;// 机构类型
  225. $scope.connEnterpriseModuleModel.organizationInfo.contact = $scope.connEnterpriseModuleModel.orgcontact;
  226. $scope.connEnterpriseModuleModel.organizationInfo.contactnum = $scope.connEnterpriseModuleModel.orgcontactnum;
  227. $scope.connEnterpriseModuleModel.organizationInfo.categoryid = $scope.connEnterpriseModuleModel.categoryid;
  228. $scope.connEnterpriseModuleModel.organizationInfo.categoryname = $scope.connEnterpriseModuleModel.categoryname;
  229. $scope.connEnterpriseModuleModel.organizationInfo.rdinstitutiontype = $scope.connEnterpriseModuleModel.orggradecode;// 企业研发机构等级
  230. $scope.connEnterpriseModuleModel.organizationInfo.ishigh = $scope.connEnterpriseModuleModel.ishigh;// 是否高企
  231. // 传参格式
  232. $scope.requestModel.data = $scope.connEnterpriseModuleModel;
  233. $scope.requestModel.node = UserService.node;
  234. dataToolsService.saveOrganizationInfo($scope.requestModel).then(function (response) {
  235. // console.log(response);
  236. if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){
  237. UtilService.showMess("添加成功");
  238. $timeout(function () {
  239. // 保存走访基本信息 后保存其他内容
  240. // 取得记录id
  241. var connid = response.data.id;
  242. $scope.connEnterpriseModuleModel.id = connid;
  243. // 取得机构id
  244. var orgid = response.data.organizationInfo.id;
  245. $scope.connEnterpriseModuleModel.organizationInfo.id = orgid;
  246. // 保存公司产品
  247. if ($scope.produceInfoList.length > 0) {
  248. angular.forEach($scope.produceInfoList, function (value, index) {
  249. value.connid = $scope.connEnterpriseModuleModel.id;
  250. value.companyid = $scope.connEnterpriseModuleModel.organizationInfo.id;
  251. value.creator = UserService.id;
  252. value.updater = UserService.id;
  253. });
  254. // 传参格式
  255. $scope.requestModel.data = $scope.produceInfoList;
  256. $scope.requestModel.node = UserService.node;
  257. dataToolsService.insertOrUpdateCompanyProduct($scope.requestModel).then(function (response) {
  258. }, function () {
  259. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  260. });
  261. }
  262. // 添加成功后跳入我的录入
  263. $scope.go("recordInfoAccount");
  264. }, 500);
  265. } else {
  266. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  267. }
  268. $scope.hideLoadingToast();
  269. saveflg = 0;
  270. }, function () {
  271. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  272. $scope.hideLoadingToast();
  273. saveflg = 0;
  274. });
  275. };
  276. var saveflg = 0;//只允许保存触发一次,多次触发无效,默认未提交
  277. $scope.saveCompanyProduct=function () {
  278. // 产品信息
  279. if (!UtilService.isDefined($scope.connEnterpriseModuleModel.orgname)) {
  280. UtilService.showMess("请填写单位名称");
  281. return;
  282. }
  283. if ($scope.connEnterpriseModuleModel.orgname.length > 50) {
  284. UtilService.showMess("单位名称不能超过50个字");
  285. return;
  286. }
  287. if (saveflg != 0) {
  288. return;
  289. }
  290. var result = 1;
  291. // 产品信息
  292. if ($scope.produceInfoList.length > 0) {
  293. angular.forEach($scope.produceInfoList, function (produceInfoList,index) {
  294. if (!UtilService.isDefined($scope.produceInfoList[index].productname)
  295. || $scope.produceInfoList[index].productname.length == 0) {
  296. result = 2;
  297. }
  298. if (result == 1 && $scope.produceInfoList[index].productname.length > 255) {
  299. result = 0;
  300. }
  301. if (result == 1 && UtilService.isDefined($scope.produceInfoList[index].remark) && $scope.produceInfoList[index].remark.length > 1000) {
  302. result = 3;
  303. }
  304. });
  305. if(result == 2){
  306. UtilService.showMess("请填写产品名称");
  307. saveflg = 0;
  308. return;
  309. }
  310. else
  311. if(result == 0){
  312. UtilService.showMess("产品名称不能超过255个字");
  313. saveflg = 0;
  314. return;
  315. }
  316. else
  317. if(result == 3){
  318. UtilService.showMess("产品备注不能超过1000个字");
  319. saveflg = 0;
  320. return;
  321. }
  322. $scope.showLoadingToast();
  323. saveInfo();
  324. saveflg = 1;
  325. // console.log($scope.produceInfoList);
  326. }
  327. };
  328. //进入资源详情
  329. $scope.jumpResourceDetail = function (company) {
  330. // 先预设信息
  331. $scope.setCompanyName(company);
  332. // 再跳转到资源详情页
  333. $scope.go('resourceCommonDetailsPage', {
  334. recourceid: company.resourcelibrary.id,
  335. recourcetype: company.resourcelibrary.restype,
  336. recourcecomefrom: company.resourcelibrary.comefrom,
  337. creator: company.resourcelibrary.creator
  338. });
  339. };
  340. });