123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /**
- * 有关 访问服务器的uri
- */
- var $http = function() {
- //this.ip = "https://b2bcnapi.sailuntire.com/api/test/b2bapi/action/api/tms";//测试
- this.ip = "https://b2bcnapi.sailuntire.com/api/b2bapi/action/api/tms";//正式
- // 获取签收单据的主表信息
- this.signOrderOfHead = "/signOrderOfHead.xhtml";
- /****** 获取签收单据的明细信息 ******/
- this.signOrderOfItem = "/signOrderOfItem.xhtml";
- //获取签收信息
- this.getSignMsg = "/getSignMsg.xhtml";
- // 签收实际操作
- this.signOperate = "/signOperate.xhtml";
- }
- // api的ajax
- $http.prototype.$post = function(url, data, callback, other) {
- var content = "", urlT = "";
- if (data.url == "json") {
- delete data.url;
- // 确认contenttype选项
- content = "application/json;charset=UTF-8";
- } else if(data.url="formdata"){
- content = "Content-type:multipart/form-data"
- } else{
- content = "application/x-www-form-urlencoded"
- }
- var datas = this.serize(data);
- if ( typeof other != 'undefined' && other != "" && other != 'undefined') {
- urlT = this.ip + eval('this.' + url) + '/' + other;
- } else {
- urlT = this.ip + eval('this.' + url);
- }
- api.showProgress({
- });
- // console.log(urlT)
- // console.log(JSON.stringify(datas))
- api.ajax({
- url : urlT,
- method : 'post',
- data : datas,
- headers : {
- "Content-type" : content
- },
- }, function(ret, err) {
- // console.log(JSON.stringify(ret));
- api.hideProgress();
- api.refreshHeaderLoadDone();
- if (ret) {
- callback(ret);
- } else {
- api.toast({
- msg: '当前网络不稳定,请稍后再试'
- });
- }
- });
- }
- // get方法
- $http.prototype.$get = function(url, data, callback, other) {
- var urlT = other == 'formdata' ? (this.ip + eval('this.' + url)) : (this.ip + eval('this.' + url) + '?' + data);
- api.showProgress({
- });
- api.ajax({
- url : urlT,
- method : 'get',
- data : {},
- headers : {
- "Content-type" : "application/json;charset=UTF-8"
- },
- }, function(ret, err) {
- api.hideProgress();
- api.refreshHeaderLoadDone();
- if (ret) {
- callback(ret);
- } else {
- api.toast({
- msg: '当前网络不稳定,请稍后再试'
- });
- }
- });
- }
- // 对数据进行处理,第一个为values,第二个为file body
- $http.prototype.serize = function(data) {
- var serizeData;
- if ( data instanceof Array) {
- if (data.length > 1) {
- serizeData = {
- values : data[0]
- }
- } else {
- serizeData = {
- values : data[0],
- files : data[1]
- }
- }
- } else {
- if (data.type == 'body') {
- delete data.type;
- if (data.yy == 'keng') {
- delete data.yy
- serizeData = {
- body : data.id
- }
- } else {
- serizeData = {
- body : data
- }
- }
- } else {
- serizeData = {
- values : data
- }
- }
- }
- return serizeData;
- }
- function alertJson(str) {
- alert(JSON.stringify(str));
- }
|