tools.js 17 KB

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