tools.js 7.7 KB

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