123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- function _BASE(code, companyId, traceType) {
- var tips = function (msg) {
- alert(msg);
- };
- if (!code) {
- tips('身份码不能为空');
- return;
- }
- if (!companyId) {
- tips('企业信息不能为空');
- return;
- }
- if (!traceType) {
- tips('查询类型不能为空');
- return;
- }
- var base = {
- _apiUrl: (window.location.origin.indexOf("localhost") > 0 ? "http://localhost:25585" : window.location.origin) + "/api",
- tips: tips,
- audioPlayed: false,
- requestSuccess: function (res, callback) {
- if (res.code === 200) {
- callback && callback(res.data);
- }
- else if (res.code === 400) {
- base.tips(res.info);
- }
- else if (res.code === 500) {
- base.tips('服务端异常,请联系管理员');
- console.error(res.info);
- }
- },
- getArmBlockChainInfo: function (callback, armId) {
- COMMON.ajax({
- url: this._apiUrl + "/Arm/GetBlockChainInfo?armid=" + armId,
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getCodeInfo: function (callback) {
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetCodeInfo",
- data: { Code: code, CompanyId: companyId, TraceType: traceType },
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getCodeQueryData: function (callback, queryInfoId, queryDataId, needFilingInfo) {
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetCodeQueryData",
- data: { Code: code, CompanyId: companyId, TraceType: traceType, queryInfoId: queryInfoId, queryDataId: queryDataId, needFilingInfo: needFilingInfo },
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getData: function (callback, encryptStr, params) {
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetData",
- data: { companyId: companyId, encryptStr: encryptStr, paramStr: params ? JSON.stringify(params): '' },
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getCodeQueryRecord: function (callback) {
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetCodeQueryRecord",
- data: { Code: code, TraceType: traceType },
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- checkSecurityCode: function (secCode, callback) {
- if (!secCode) {
- base.tips('防伪码不能为空');
- return;
- }
- COMMON.ajax({
- url: this._apiUrl + "/Trace/CheckSecurityCode",
- data: { Code: code, SecurityCode: secCode, CompanyId: companyId },
- type: "post",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- initAudio: function (text) {
- var ele = document.createElement("audio");
- ele.preload = true;
- ele.id = "queryAudio";
- ele.src = base.getAudioUrl(text);
- document.body.append(ele);
- base.audioPlay();
- },
- audioPlay: function (e) {
- try {
- if (!base.audioPlayed) {
- document.getElementById('queryAudio').play().then(function () {
- base.audioPlayed = true;
- document.removeEventListener("WeixinJSBridgeReady", base.audioPlay, false);
- document.removeEventListener('YixinJSBridgeReady', base.audioPlay, false);
- document.removeEventListener("touchstart", base.audioPlay, false);
- }, function () {
- document.addEventListener("WeixinJSBridgeReady", base.audioPlay, false);
- document.addEventListener('YixinJSBridgeReady', base.audioPlay, false);
- document.addEventListener("touchstart", base.audioPlay, false);
- });
- }
- }
- catch (err) {
- }
- },
- getFileUrl: function (fileId) {
- if (!fileId) return '';
- //thumbnail缩图 128 默认 256 512 1024
- return this._apiUrl + '/File/Download?thumbnail=512&fileId=' + fileId;
- },
- getQueryType: function (value) {
- if (!value) return '';
- switch (value) {
- case 1: return "Web查询";
- case 2: return "扫码查询";
- default: return "";
- }
- },
- datetimeFormat: function (value, format) {
- if (!value) return '';
- var date = new Date(value.replace('T', ' ').replace(/-/g, '/'));
- return date.Format(format || 'yyyy-MM-dd hh:mm');
- },
- getDataItem: function (value, field) {
- if (!value) return '';
- if (!field.DataSource) return value;
- var text = '';
- value.split(',').forEach(val => {
- var item = field.DataSource.find((i) => { return i.Value === val; });
- item && (text += ',' + item.Text);
- });
- text && (text = text.substring(1));
- return text;
- },
- getFileInfos: function (fileIds, callback) {
- if (!fileIds) return;
- COMMON.ajax({
- url: this._apiUrl + "/File/GetMultipleFileInfo",
- data: { FileIdList: fileIds },
- type: "POST",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getAreaName: function (areaIds, callback) {
- if (!areaIds) return '';
- COMMON.ajax({
- url: this._apiUrl + "/Trace/getAreaName",
- data: { areaIds: areaIds },
- type: "GET",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getDataItemName: function (itemCode, itemValue, callback) {
- if (!itemCode) return '';
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetDataItemName",
- data: { itemCode: itemCode, itemValue: itemValue },
- type: "GET",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- GetEncryptStr: function (callback) {
- COMMON.ajax({
- url: this._apiUrl + "/Trace/GetEncryptStr?str={'':''}",
- type: "GET",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getQualityPic: function (code, callback) {
- COMMON.ajax({
- url: this._apiUrl + "/ProductCertInfo/GetQualityPath",
- data: { code: code },
- type: "GET",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- GetCertType: function (certificlass, callback) {
- COMMON.ajax({
- url: this._apiUrl + "/CertifiCate/GetCertType?itemCode=" + certificlass,
- type: "get",
- dataType: "json",
- success: function (res) {
- base.requestSuccess(res, callback);
- }
- });
- },
- getAudioUrl: function (text) {
- if (text == null || text.length === 0) return '';
- var url = "http://yy.org315.cn/speech/Synthesis?appname=xztsc&text=";
- return url += encodeURI(text);
- }
- };
- return base;
- }
|