base.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. function _BASE(code, companyId, traceType) {
  2. var tips = function (msg) {
  3. alert(msg);
  4. };
  5. if (!code) {
  6. tips('身份码不能为空');
  7. return;
  8. }
  9. if (!companyId) {
  10. tips('企业信息不能为空');
  11. return;
  12. }
  13. if (!traceType) {
  14. tips('查询类型不能为空');
  15. return;
  16. }
  17. var base = {
  18. _apiUrl: (window.location.origin.indexOf("localhost") > 0 ? "http://localhost:25585" : window.location.origin) + "/api",
  19. tips: tips,
  20. audioPlayed: false,
  21. requestSuccess: function (res, callback) {
  22. if (res.code === 200) {
  23. callback && callback(res.data);
  24. }
  25. else if (res.code === 400) {
  26. base.tips(res.info);
  27. }
  28. else if (res.code === 500) {
  29. base.tips('服务端异常,请联系管理员');
  30. console.error(res.info);
  31. }
  32. },
  33. getArmBlockChainInfo: function (callback, armId) {
  34. COMMON.ajax({
  35. url: this._apiUrl + "/Arm/GetBlockChainInfo?armid=" + armId,
  36. type: "get",
  37. dataType: "json",
  38. success: function (res) {
  39. base.requestSuccess(res, callback);
  40. }
  41. });
  42. },
  43. getCodeInfo: function (callback) {
  44. COMMON.ajax({
  45. url: this._apiUrl + "/Trace/GetCodeInfo",
  46. data: { Code: code, CompanyId: companyId, TraceType: traceType },
  47. type: "get",
  48. dataType: "json",
  49. success: function (res) {
  50. base.requestSuccess(res, callback);
  51. }
  52. });
  53. },
  54. getCodeQueryData: function (callback, queryInfoId, queryDataId, needFilingInfo) {
  55. COMMON.ajax({
  56. url: this._apiUrl + "/Trace/GetCodeQueryData",
  57. data: { Code: code, CompanyId: companyId, TraceType: traceType, queryInfoId: queryInfoId, queryDataId: queryDataId, needFilingInfo: needFilingInfo },
  58. type: "get",
  59. dataType: "json",
  60. success: function (res) {
  61. base.requestSuccess(res, callback);
  62. }
  63. });
  64. },
  65. getData: function (callback, encryptStr, params) {
  66. COMMON.ajax({
  67. url: this._apiUrl + "/Trace/GetData",
  68. data: { companyId: companyId, encryptStr: encryptStr, paramStr: params ? JSON.stringify(params): '' },
  69. type: "get",
  70. dataType: "json",
  71. success: function (res) {
  72. base.requestSuccess(res, callback);
  73. }
  74. });
  75. },
  76. getCodeQueryRecord: function (callback) {
  77. COMMON.ajax({
  78. url: this._apiUrl + "/Trace/GetCodeQueryRecord",
  79. data: { Code: code, TraceType: traceType },
  80. type: "get",
  81. dataType: "json",
  82. success: function (res) {
  83. base.requestSuccess(res, callback);
  84. }
  85. });
  86. },
  87. checkSecurityCode: function (secCode, callback) {
  88. if (!secCode) {
  89. base.tips('防伪码不能为空');
  90. return;
  91. }
  92. COMMON.ajax({
  93. url: this._apiUrl + "/Trace/CheckSecurityCode",
  94. data: { Code: code, SecurityCode: secCode, CompanyId: companyId },
  95. type: "post",
  96. dataType: "json",
  97. success: function (res) {
  98. base.requestSuccess(res, callback);
  99. }
  100. });
  101. },
  102. initAudio: function (text) {
  103. var ele = document.createElement("audio");
  104. ele.preload = true;
  105. ele.id = "queryAudio";
  106. ele.src = base.getAudioUrl(text);
  107. document.body.append(ele);
  108. base.audioPlay();
  109. },
  110. audioPlay: function (e) {
  111. try {
  112. if (!base.audioPlayed) {
  113. document.getElementById('queryAudio').play().then(function () {
  114. base.audioPlayed = true;
  115. document.removeEventListener("WeixinJSBridgeReady", base.audioPlay, false);
  116. document.removeEventListener('YixinJSBridgeReady', base.audioPlay, false);
  117. document.removeEventListener("touchstart", base.audioPlay, false);
  118. }, function () {
  119. document.addEventListener("WeixinJSBridgeReady", base.audioPlay, false);
  120. document.addEventListener('YixinJSBridgeReady', base.audioPlay, false);
  121. document.addEventListener("touchstart", base.audioPlay, false);
  122. });
  123. }
  124. }
  125. catch (err) {
  126. }
  127. },
  128. getFileUrl: function (fileId) {
  129. if (!fileId) return '';
  130. //thumbnail缩图 128 默认 256 512 1024
  131. return this._apiUrl + '/File/Download?thumbnail=512&fileId=' + fileId;
  132. },
  133. getQueryType: function (value) {
  134. if (!value) return '';
  135. switch (value) {
  136. case 1: return "Web查询";
  137. case 2: return "扫码查询";
  138. default: return "";
  139. }
  140. },
  141. datetimeFormat: function (value, format) {
  142. if (!value) return '';
  143. var date = new Date(value.replace('T', ' ').replace(/-/g, '/'));
  144. return date.Format(format || 'yyyy-MM-dd hh:mm');
  145. },
  146. getDataItem: function (value, field) {
  147. if (!value) return '';
  148. if (!field.DataSource) return value;
  149. var text = '';
  150. value.split(',').forEach(val => {
  151. var item = field.DataSource.find((i) => { return i.Value === val; });
  152. item && (text += ',' + item.Text);
  153. });
  154. text && (text = text.substring(1));
  155. return text;
  156. },
  157. getFileInfos: function (fileIds, callback) {
  158. if (!fileIds) return;
  159. COMMON.ajax({
  160. url: this._apiUrl + "/File/GetMultipleFileInfo",
  161. data: { FileIdList: fileIds },
  162. type: "POST",
  163. dataType: "json",
  164. success: function (res) {
  165. base.requestSuccess(res, callback);
  166. }
  167. });
  168. },
  169. getAreaName: function (areaIds, callback) {
  170. if (!areaIds) return '';
  171. COMMON.ajax({
  172. url: this._apiUrl + "/Trace/getAreaName",
  173. data: { areaIds: areaIds },
  174. type: "GET",
  175. dataType: "json",
  176. success: function (res) {
  177. base.requestSuccess(res, callback);
  178. }
  179. });
  180. },
  181. getDataItemName: function (itemCode, itemValue, callback) {
  182. if (!itemCode) return '';
  183. COMMON.ajax({
  184. url: this._apiUrl + "/Trace/GetDataItemName",
  185. data: { itemCode: itemCode, itemValue: itemValue },
  186. type: "GET",
  187. dataType: "json",
  188. success: function (res) {
  189. base.requestSuccess(res, callback);
  190. }
  191. });
  192. },
  193. GetEncryptStr: function (callback) {
  194. COMMON.ajax({
  195. url: this._apiUrl + "/Trace/GetEncryptStr?str={'':''}",
  196. type: "GET",
  197. dataType: "json",
  198. success: function (res) {
  199. base.requestSuccess(res, callback);
  200. }
  201. });
  202. },
  203. getQualityPic: function (code, callback) {
  204. COMMON.ajax({
  205. url: this._apiUrl + "/ProductCertInfo/GetQualityPath",
  206. data: { code: code },
  207. type: "GET",
  208. dataType: "json",
  209. success: function (res) {
  210. base.requestSuccess(res, callback);
  211. }
  212. });
  213. },
  214. GetCertType: function (certificlass, callback) {
  215. COMMON.ajax({
  216. url: this._apiUrl + "/CertifiCate/GetCertType?itemCode=" + certificlass,
  217. type: "get",
  218. dataType: "json",
  219. success: function (res) {
  220. base.requestSuccess(res, callback);
  221. }
  222. });
  223. },
  224. getAudioUrl: function (text) {
  225. if (text == null || text.length === 0) return '';
  226. var url = "http://yy.org315.cn/speech/Synthesis?appname=xztsc&text=";
  227. return url += encodeURI(text);
  228. }
  229. };
  230. return base;
  231. }