tools.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import {
  2. message
  3. } from 'antd';
  4. import {
  5. provinceList,
  6. patentTypeList,
  7. patentStateList,
  8. techFieldList,
  9. technicalSourceList,
  10. catagoryList,
  11. intellectualGetList,
  12. conversionFormList,
  13. annualReportStateList
  14. } from './dataDic.js';
  15. module.exports = {
  16. addressInit: function (_cmbProvince, _cmbCity, _cmbArea, defaultProvince, defaultCity, defaultArea) {
  17. var cmbProvince = document.getElementById(_cmbProvince);
  18. var cmbCity = document.getElementById(_cmbCity);
  19. var cmbArea = document.getElementById(_cmbArea);
  20. function cmbSelect(cmb, str) {
  21. for (var i = 0; i < cmb.options.length; i++) {
  22. if (cmb.options[i].value == str) {
  23. cmb.selectedIndex = i;
  24. return;
  25. }
  26. }
  27. }
  28. function cmbAddOption(cmb, str, obj) {
  29. var option = document.createElement("OPTION");
  30. cmb.options.add(option);
  31. option.innerText = str;
  32. option.value = str;
  33. option.obj = obj;
  34. }
  35. function changeCity() {
  36. cmbArea.options.length = 0;
  37. if (cmbCity.selectedIndex == -1) return;
  38. var item = cmbCity.options[cmbCity.selectedIndex].obj;
  39. for (var i = 0; i < item.areaList.length; i++) {
  40. cmbAddOption(cmbArea, item.areaList[i], null);
  41. }
  42. cmbSelect(cmbArea, defaultArea);
  43. }
  44. function changeProvince() {
  45. cmbCity.options.length = 0;
  46. cmbCity.onchange = null;
  47. if (cmbProvince.selectedIndex == -1) return;
  48. var item = cmbProvince.options[cmbProvince.selectedIndex].obj;
  49. for (var i = 0; i < item.cityList.length; i++) {
  50. cmbAddOption(cmbCity, item.cityList[i].name, item.cityList[i]);
  51. }
  52. cmbSelect(cmbCity, defaultCity);
  53. changeCity();
  54. cmbCity.onchange = changeCity;
  55. }
  56. for (var i = 0; i < provinceList.length; i++) {
  57. cmbAddOption(cmbProvince, provinceList[i].name, provinceList[i]);
  58. }
  59. cmbSelect(cmbProvince, defaultProvince);
  60. changeProvince();
  61. cmbProvince.onchange = changeProvince;
  62. },
  63. splitUrl: function (string, i, url) {
  64. let theList = [];
  65. let theArr = [];
  66. if (string) {
  67. theArr = string.split(i);
  68. theArr.map(function (item, i) {
  69. theList.push({
  70. uid: -i,
  71. url: url + item,
  72. response: {
  73. data: item
  74. }
  75. });
  76. });
  77. }
  78. return theList;
  79. },
  80. getBase64: function (img, callback) {
  81. const reader = new FileReader();
  82. reader.addEventListener('load', () => callback(reader.result));
  83. reader.readAsDataURL(img);
  84. },
  85. beforeUpload: function (file) {
  86. // debugger
  87. // const isJPG = file.type === 'image/jpeg/document';
  88. // if (!isJPG) {
  89. // message.error('You can only upload JPG file!');
  90. // }
  91. // const isLt2M = file.size / 1024 / 1024 < 2;
  92. // if (!isLt2M) {
  93. // message.error('Image must smaller than 2MB!');
  94. // }
  95. // return isJPG && isLt2M;
  96. },
  97. beforeUploadFile: function (file) {
  98. // debugger
  99. // const isJPG = file.type === 'image/jpeg/document';
  100. // if (!isJPG) {
  101. // message.error('You can only upload JPG file!');
  102. // }
  103. // const isLt2M = file.size / 1024 / 1024 < 2;
  104. // if (!isLt2M) {
  105. // message.error('Image must smaller than 2MB!');
  106. // }
  107. // return isJPG && isLt2M;
  108. },
  109. getTime: function (e, t) {
  110. if (e && !t) {
  111. var d = new Date(e);
  112. d = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " ";
  113. // + (d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" +
  114. // (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" +
  115. // (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
  116. return d;
  117. } else if (e && t) {
  118. var d1 = new Date(e);
  119. var d2 = new Date(e);
  120. d2 = d2.setMonth(d1.getMonth() + t);
  121. d2 = new Date(d2)
  122. d2 = d2.getFullYear() + "-" + (d2.getMonth() + 1) + "-" + d2.getDate() + " ";
  123. return d2;
  124. } else {
  125. return '';
  126. }
  127. },
  128. getPatentType: function (e) {
  129. if (e) {
  130. let theType = '';
  131. patentTypeList.map(function (item) {
  132. if (item.value == e) {
  133. theType = item.key;
  134. };
  135. });
  136. return theType;
  137. }
  138. },
  139. getPatentState: function (e) {
  140. if (e) {
  141. let theState = '';
  142. patentStateList.map(function (item) {
  143. if (item.value == e) {
  144. theState = item.key;
  145. };
  146. });
  147. return theState;
  148. }
  149. },
  150. getTechnicalSource: function (e) {
  151. if (e) {
  152. let theSource = '';
  153. technicalSourceList.map(function (item) {
  154. if (item.value == e) {
  155. theSource = item.key;
  156. };
  157. });
  158. return theSource;
  159. }
  160. },
  161. getTechField: function (field1, field2, field3) {
  162. let fieldList = [];
  163. for (let i = 0; i < techFieldList.length; i++) {
  164. fieldList.push({
  165. value: techFieldList[i].value,
  166. label: techFieldList[i].label
  167. });
  168. if (techFieldList[i].children) {
  169. for (let j = 0; j < techFieldList[i].children.length; j++) {
  170. fieldList.push({
  171. value: techFieldList[i].children[j].value,
  172. label: techFieldList[i].children[j].label
  173. });
  174. if (techFieldList[i].children[j].children) {
  175. for (let n = 0; n < techFieldList[i].children[j].children.length; n++) {
  176. fieldList.push({
  177. value: techFieldList[i].children[j].children[n].value,
  178. label: techFieldList[i].children[j].children[n].label
  179. });
  180. }
  181. };
  182. };
  183. }
  184. };
  185. fieldList.sort(function (a, b) {
  186. return a.value - b.value
  187. });
  188. let fieldKey = "";
  189. fieldList.map(function (item) {
  190. if (field1 == item.value) {
  191. fieldKey = item.label;
  192. };
  193. if (field2 == item.value) {
  194. fieldKey = fieldKey + "/" + item.label;
  195. };
  196. if (field3 == item.value) {
  197. fieldKey = fieldKey + "/" + item.label;
  198. };
  199. });
  200. return fieldKey;
  201. },
  202. getCatagory: function (e) {
  203. if (e) {
  204. let theType = '';
  205. catagoryList.map(function (item) {
  206. if (item.value == e) {
  207. theType = item.key;
  208. };
  209. });
  210. return theType;
  211. }
  212. },
  213. getIntellectualObtainWay: function (e) {
  214. if (e) {
  215. let theType = '';
  216. intellectualGetList.map(function (item) {
  217. if (item.value == e) {
  218. theType = item.key;
  219. };
  220. });
  221. return theType;
  222. }
  223. },
  224. getConversionForm: function (e) {
  225. if (e) {
  226. let theType = '';
  227. conversionFormList.map(function (item) {
  228. if (item.value == e) {
  229. theType = item.key;
  230. };
  231. });
  232. return theType;
  233. }
  234. },
  235. getAnnualReportState: function (e) {
  236. if (e) {
  237. let theType = '';
  238. annualReportStateList.map(function (item) {
  239. if (item.value == e) {
  240. theType = item.key;
  241. };
  242. });
  243. return theType;
  244. }
  245. }
  246. }