tools.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. import { message,Timeline,Select } from 'antd';
  2. import React from 'react';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import {
  6. patentTypeList,
  7. patentStateList,
  8. patentFieldList,
  9. technicalSourceList,
  10. catagoryList,
  11. intellectualGetList,
  12. conversionFormList,
  13. annualReportStateList,
  14. cognizanceStateList,
  15. technologyStateList,
  16. copyrightStateList,
  17. auditStatusList,
  18. vocations
  19. } from './dataDic.js';
  20. import { provinceList } from './DicProvinceList.js';
  21. import { techFieldList } from './DicTechFieldList.js'
  22. module.exports = {
  23. addressInit: function (_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea) {
  24. var cmbProvince = document.getElementById(_cmbProvince);
  25. var cmbCity = document.getElementById(_cmbCity);
  26. var cmbArea = document.getElementById(_cmbArea);
  27. function cmbSelect(cmb, str) {
  28. for (var i = 0; i < cmb.options.length; i++) {
  29. if (cmb.options[i].value == str) {
  30. cmb.selectedIndex = i;
  31. return;
  32. }
  33. }
  34. }
  35. function cmbAddOption(cmb, str, obj) {
  36. var option = document.createElement("OPTION");
  37. cmb.options.add(option);
  38. option.innerText = str;
  39. option.value = str;
  40. option.obj = obj;
  41. }
  42. function changeCity() {
  43. cmbArea.options.length = 0;
  44. if (cmbCity.selectedIndex == -1) return;
  45. var item = cmbCity.options[cmbCity.selectedIndex].obj;
  46. for (var i = 0; i < item.areaList.length; i++) {
  47. cmbAddOption(cmbArea, item.areaList[i], null);
  48. }
  49. cmbSelect(cmbArea, defaultArea);
  50. }
  51. function changeProvince() {
  52. cmbCity.options.length = 0;
  53. cmbCity.onchange = null;
  54. if (cmbProvince.selectedIndex == -1) return;
  55. var item = cmbProvince.options[cmbProvince.selectedIndex].obj;
  56. for (var i = 0; i < item.cityList.length; i++) {
  57. cmbAddOption(cmbCity, item.cityList[i].name, item.cityList[i]);
  58. }
  59. cmbSelect(cmbCity, defaultCity);
  60. changeCity();
  61. cmbCity.onchange = changeCity;
  62. }
  63. for (var i = 0; i < provinceList.length; i++) {
  64. cmbAddOption(cmbProvince, provinceList[i].name, provinceList[i]);
  65. }
  66. cmbSelect(cmbProvince, defaultProvince);
  67. changeProvince();
  68. cmbProvince.onchange = changeProvince;
  69. },
  70. provinceSelect() {
  71. let option = [];
  72. provinceList.map(function (item, i) {
  73. if ( item.cityList.length ) {
  74. let cityArr = [];
  75. item.cityList.map(function(city,n){
  76. if ( city.areaList.length ) {
  77. let areaArr = [];
  78. city.areaList.map(function(area,j){
  79. areaArr.push({
  80. value:area,
  81. label:area
  82. });
  83. });
  84. cityArr.push({
  85. value:city.name,
  86. label:city.name,
  87. children:areaArr
  88. });
  89. } else {
  90. cityArr.push({
  91. value:city.name,
  92. label:city.name
  93. });
  94. };
  95. });
  96. option.push({
  97. value:item.name,
  98. label:item.name,
  99. children:cityArr
  100. });
  101. } else {
  102. option.push({
  103. value:item.name,
  104. label:item.name
  105. });
  106. };
  107. });
  108. return option;
  109. },
  110. splitUrl: function (string, i, url) {
  111. let theList = [];
  112. let theArr = [];
  113. if (string) {
  114. theArr = string.split(i);
  115. theArr.map(function (item, i) {
  116. theList.push({
  117. uid: -i,
  118. url: url + item,
  119. response: {
  120. data: item
  121. }
  122. });
  123. });
  124. }
  125. return theList;
  126. },
  127. getBase64: function (img, callback) {
  128. const reader = new FileReader();
  129. reader.addEventListener('load', () => callback(reader.result));
  130. reader.readAsDataURL(img);
  131. },
  132. beforeUpload: function (file) {
  133. // debugger
  134. // const isJPG = file.type === 'image/jpeg/document';
  135. // if (!isJPG) {
  136. // message.error('You can only upload JPG file!');
  137. // }
  138. // const isLt2M = file.size / 1024 / 1024 < 2;
  139. // if (!isLt2M) {
  140. // message.error('Image must smaller than 2MB!');
  141. // }
  142. // return isJPG && isLt2M;
  143. },
  144. beforeUploadFile: function (file) {
  145. // debugger
  146. // const isJPG = file.type === 'image/jpeg/document';
  147. // if (!isJPG) {
  148. // message.error('You can only upload JPG file!');
  149. // }
  150. // const isLt2M = file.size / 1024 / 1024 < 2;
  151. // if (!isLt2M) {
  152. // message.error('Image must smaller than 2MB!');
  153. // }
  154. // return isJPG && isLt2M;
  155. },
  156. getTime: function (e, t) {
  157. if (e && !t) {
  158. var d = new Date(e);
  159. d = d.getFullYear() + "-" +
  160. ((d.getMonth() + 1) < 9 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + "-" +
  161. (d.getDate() < 9 ? '0' + d.getDate() : d.getDate()) + " ";
  162. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  163. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  164. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  165. return d;
  166. } else if (e && t) {
  167. var d1 = new Date(e);
  168. var d2 = new Date(e);
  169. d2 = d2.setMonth(d1.getMonth() + t);
  170. d2 = new Date(d2)
  171. d2 = d2.getFullYear() + "-" +
  172. ((d2.getMonth() + 1) < 9 ? '0' + (d2.getMonth() + 1) : (d2.getMonth() + 1)) + "-" +
  173. (d2.getDate() < 9 ? '0' + d2.getDate() : d2.getDate()) + " ";
  174. return d2;
  175. } else {
  176. return '';
  177. }
  178. },
  179. getPatentType: function (e) {
  180. if (e) {
  181. let theType = '';
  182. patentTypeList.map(function (item) {
  183. if (item.value == e) {
  184. theType = item.key;
  185. };
  186. });
  187. return theType;
  188. }
  189. },
  190. getPatentState: function (e) {
  191. if (e) {
  192. let theState = '';
  193. patentStateList.map(function (item) {
  194. if (item.value == e) {
  195. theState = item.key;
  196. };
  197. });
  198. return theState;
  199. }
  200. },
  201. getPatentField: function (e) {
  202. if (e) {
  203. let theState = '';
  204. patentFieldList.map(function (item) {
  205. if (item.value == e) {
  206. theState = item.key;
  207. };
  208. });
  209. return theState;
  210. }
  211. },
  212. getTechnicalSource: function (e) {
  213. if (e) {
  214. let theSource = '';
  215. technicalSourceList.map(function (item) {
  216. if (item.value == e) {
  217. theSource = item.key;
  218. };
  219. });
  220. return theSource;
  221. }
  222. },
  223. getTechField: function (field1, field2, field3) {
  224. let fieldList = [];
  225. for (let i = 0; i < techFieldList.length; i++) {
  226. fieldList.push({
  227. value: techFieldList[i].value,
  228. label: techFieldList[i].label
  229. });
  230. if (techFieldList[i].children) {
  231. for (let j = 0; j < techFieldList[i].children.length; j++) {
  232. fieldList.push({
  233. value: techFieldList[i].children[j].value,
  234. label: techFieldList[i].children[j].label
  235. });
  236. if (techFieldList[i].children[j].children) {
  237. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  238. fieldList.push({
  239. value: techFieldList[i].children[j].children[n].value,
  240. label: techFieldList[i].children[j].children[n].label
  241. });
  242. }
  243. };
  244. };
  245. }
  246. };
  247. fieldList.sort(function (a, b) {
  248. return a.value - b.value
  249. });
  250. let fieldKey = "";
  251. fieldList.map(function (item) {
  252. if (field1 == item.value) {
  253. fieldKey = item.label;
  254. };
  255. if (field2 == item.value) {
  256. fieldKey = fieldKey + "/" + item.label;
  257. };
  258. if (field3 == item.value) {
  259. fieldKey = fieldKey + "/" + item.label;
  260. };
  261. });
  262. return fieldKey;
  263. },
  264. getCatagory: function (e) {
  265. if (e) {
  266. let theType = '';
  267. catagoryList.map(function (item) {
  268. if (item.value == e) {
  269. theType = item.key;
  270. };
  271. });
  272. return theType;
  273. }
  274. },
  275. getIntellectualObtainWay: function (e) {
  276. if (e) {
  277. let theType = '';
  278. intellectualGetList.map(function (item) {
  279. if (item.value == e) {
  280. theType = item.key;
  281. };
  282. });
  283. return theType;
  284. }
  285. },
  286. getConversionForm: function (e) {
  287. if (e) {
  288. let theType = '';
  289. conversionFormList.map(function (item) {
  290. if (item.value == e) {
  291. theType = item.key;
  292. };
  293. });
  294. return theType;
  295. }
  296. },
  297. getAnnualReportState: function (e) {
  298. if (e) {
  299. let theType = '';
  300. annualReportStateList.map(function (item) {
  301. if (item.value == e) {
  302. theType = item.key;
  303. };
  304. });
  305. return theType;
  306. }
  307. },
  308. getCognizanceState: function (e) {
  309. if (e) {
  310. let theType = '';
  311. cognizanceStateList.map(function (item) {
  312. if (item.value == e) {
  313. theType = item.key;
  314. };
  315. });
  316. return theType;
  317. }
  318. },
  319. getTechnologyState: function (e) {
  320. if (e) {
  321. let theType = '';
  322. technologyStateList.map(function (item) {
  323. if (item.value == e) {
  324. theType = item.key;
  325. };
  326. });
  327. return theType;
  328. }
  329. },
  330. //显示用户认证状态
  331. getAuditState: function (e) {
  332. if (e) {
  333. let theType = '';
  334. auditStatusList.map(function (item) {
  335. if (item.value == e) {
  336. theType = item.key;
  337. };
  338. });
  339. return theType;
  340. }
  341. },
  342. getCopyrightState: function (e) {
  343. if (e) {
  344. let theType = '';
  345. copyrightStateList.map(function (item) {
  346. if (item.value == e) {
  347. theType = item.key;
  348. };
  349. });
  350. return theType;
  351. }
  352. },
  353. downloadFile: function (path, fileName) {
  354. window.open(globalConfig.context + '/open/downloadFile?path=' + path + '&fileName=' + fileName)
  355. },
  356. techDownloadFile: function (url, id) {
  357. window.open(globalConfig.context + url + '?id=' + id)
  358. },
  359. copyrightDownloadFile: function (id, sign, url) {
  360. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign)
  361. },
  362. newDownloadFile: function (id, sign, url,type) {
  363. if (!type ) {
  364. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign);
  365. };
  366. if ( type ) {
  367. window.open(globalConfig.context + url + '?id=' + id + '&sign=' + sign + '&type=' + type);
  368. };
  369. },
  370. companySearch(input, option) {
  371. return option.props.children.indexOf(input) >= 0
  372. },
  373. getInUrgentTime(date, inUrgent) {
  374. let now = new Date(date);
  375. for (var i = 1; i <= inUrgent;) {
  376. now.setDate(now.getDate() + 1);
  377. if (!vocations[getKey(now)]) {
  378. i++;
  379. };
  380. };
  381. return now;
  382. function getKey(date) {
  383. var year = date.getFullYear(),
  384. month = date.getMonth() + 1,
  385. day = date.getDate();
  386. year = "" + year;
  387. month = (month > 9 ? "" : "0") + month;
  388. day = (day > 9 ? "" : "0") + day;
  389. return year + month + day;
  390. }
  391. },
  392. getStepList(pid,url) {
  393. let stepList = [];
  394. $.ajax({
  395. method: "get",
  396. dataType: "json",
  397. crossDomain: false,
  398. cache: false,
  399. url: globalConfig.context + url + "?pid=" + pid,
  400. success: function (data) {
  401. if (!data.data) {
  402. if (data.error && data.error.length ) {
  403. return;
  404. };
  405. };
  406. for (var item in data.data) {
  407. stepList.push(
  408. <Timeline.Item key={item}>
  409. <span>{module.exports.getPatentState(data.data[item].state)}</span>
  410. {module.exports.getTime(data.data[item].recordTime)}
  411. </Timeline.Item>
  412. )
  413. };
  414. }.bind(this),
  415. });
  416. return stepList;
  417. },
  418. //各种通过接口获取下拉列表
  419. setPatentStateOption(permission) {
  420. let theArr = [];
  421. patentStateList.map(function (item) {
  422. for (let i = 0; i < permission.length; i++) {
  423. if (item.value == permission[i]) {
  424. theArr.push(item);
  425. };
  426. };
  427. });
  428. return theArr;
  429. },
  430. setUserContactsList(){
  431. let theOption = [];
  432. $.ajax({
  433. method: "get",
  434. dataType: "json",
  435. crossDomain: false,
  436. url: globalConfig.context + '/api/user/getContacts',
  437. success: function (data) {
  438. if (!data.data) {
  439. if ( data.error && data.error.length ) {
  440. message.warning(data.error[0].message);
  441. };
  442. return;
  443. };
  444. for (let item in data.data) {
  445. let theData = data.data[item];
  446. theOption.push(
  447. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  448. );
  449. };
  450. }
  451. });
  452. return theOption;
  453. },
  454. setAdminContactsList(uid){
  455. let theOption = [];
  456. $.ajax({
  457. method: "get",
  458. dataType: "json",
  459. crossDomain: false,
  460. url: globalConfig.context + '/api/admin/getContacts',
  461. data:{ "uid": uid },
  462. success: function (data) {
  463. if (!data.data) {
  464. if ( data.error && data.error.length ) {
  465. message.warning(data.error[0].message);
  466. };
  467. return;
  468. };
  469. for (let item in data.data) {
  470. let theData = data.data[item];
  471. theOption.push(
  472. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  473. );
  474. };
  475. }
  476. });
  477. return theOption;
  478. },
  479. //高企培育资料完成情况(比重)
  480. getProportion(uid,callback){
  481. $.ajax({
  482. method: "get",
  483. dataType: "json",
  484. crossDomain: false,
  485. url: globalConfig.context + '/api/admin/proportion',
  486. data:{ "uid": uid },
  487. success: function (data) {
  488. if (!data.data) {
  489. if ( data.error && data.error.length ) {
  490. message.warning(data.error[0].message);
  491. };
  492. data.data = {}
  493. callback(data.data);
  494. };
  495. callback(data.data);
  496. }
  497. });
  498. },
  499. saveProportion(id,sign,status){
  500. $.ajax({
  501. method: "post",
  502. dataType: "json",
  503. crossDomain: false,
  504. url: globalConfig.context + '/api/admin/confirmProportion',
  505. data:{
  506. "id": id,
  507. "sign":sign,
  508. "status":status
  509. },
  510. success: function (data) {
  511. if (!data.data) {
  512. if ( data.error && data.error.length ) {
  513. message.warning(data.error[0].message);
  514. };
  515. return;
  516. };
  517. }
  518. });
  519. }
  520. }