httpRequest.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**
  2. * 有关 访问服务器的uri
  3. */
  4. var $http = function() {
  5. this.version = "V1.2";
  6. this.ajaxLock = false;
  7. // this.ip = "http://192.168.31.132:9002";
  8. // this.ip = "http://39.96.81.16:9002";
  9. this.ip = "https://weixin.jinyutires.com/api-web";
  10. // this.ip = "http://172.70.16.57:9002";
  11. /****** 用户相关 ******/
  12. // 根据省获取经销商
  13. this.getUpuserByProvideUrl = "/base/agent/listByArea";
  14. // 注册用户
  15. this.regizeUrl = "/jinyu/bizLogin/registRetailer";
  16. // 登录用户
  17. this.loginUrl = "/jinyu/bizLogin/login";
  18. // 根据loginid获取用户信息
  19. this.getUserInfoUrl = "/base/retailer/loginToInfo";
  20. /******* 订单相关 ********/
  21. // 查看剩余库存
  22. this.getStockUrl_old = "/jinyu/bizAgentStock/page";
  23. this.getStockUrl = "/base/material/pageMaterialStock";
  24. // 添加商品到购物车
  25. this.addCarUrl = "/jinyu/bizCart/save";
  26. // 获取购物车列表
  27. this.shopCarListUrl = "/jinyu/bizCart/list";
  28. // 获取商品详情
  29. this.getInfoUrl = "/base/material/info";
  30. // 下单传 {"retailerId":"212","amounr":100,"bizCartDtoList":[{"id":121...},{"id":12..}] 这里把购物车的列表给我}
  31. this.downOrderUrl = "/base/bizOrder/save";
  32. // 删除购物车 --删除一个
  33. this.deleteCar = "/jinyu/bizCart/deleteOne";
  34. // 删除购物车记录 -- 珊瑚多个
  35. this.deleteCars = "/jinyu/bizCart/delete";
  36. // 获取订单列表
  37. this.getOrderListUrl = "/base/bizOrder/page";
  38. // 获取订单详情
  39. this.getOrderInfo = "/base/bizOrder/info";
  40. // ---------- 525 ---------
  41. // 获取库存详情
  42. this.getKucunInfoUrl = "/jinyu/bizRetailerStock/page";
  43. // 获取商品类别
  44. this.getStoreTypeUrl = "/jinyu/bizGoodsType/list";
  45. // 添加商品类别
  46. this.addStoreTypeUrl = "/jinyu/bizGoodsType/save";
  47. // 添加商品
  48. this.addStoreUrl = "/jinyu/bizGoods/saveGoods";
  49. // 查看自己的供应商
  50. this.getSupplierUrl = "/jinyu/bizSupplier/list";
  51. // 根据条形码查询商品
  52. this.getStoreByScanUrl = "/jinyu/bizGoods/selectBySerialNumber";
  53. // 添加供应商
  54. this.addSupplierUrl = "/jinyu/bizSupplier/save";
  55. // 进货
  56. this.buyStoreUrl = "/jinyu/bizBills/save";
  57. // 单据
  58. this.buyListUrl = "/jinyu/bizBills/page";
  59. // 商品详情
  60. this.getStoreInfoUrl = "/jinyu/bizGoods/info";
  61. // 选择品牌
  62. this.chooseBrandUrl = "/base/brand/list";
  63. // 根据扫出来的码获取商品信息(进销存) -- 需要后面拼接
  64. this.jinstoreByScanUrl = "/base/material/infoByKey";
  65. // 获取门店经销商列表
  66. this.getSupplierListUrl = "/base/retailerAgent/list";
  67. // 经销商查询自己库存
  68. // this.checkStoreUrl = "/jinyu/bizAgentStock/page";
  69. this.checkStoreUrl_old = "/jinyu/bizAgentStock/page";
  70. this.checkStoreUrl = "/jinyu/bizAgentStock/pageOwn";
  71. // 扫码商品 0705
  72. this.addStoreByScanUrl = "/jinyu/bizGoods/selectBySerialNumberAndRetailerId";
  73. // 入库扫码
  74. this.addOrgoScanUrl = '/jinyu/bizGoods/selectInBySerialNumberAndRetailerId';
  75. // 出库扫码
  76. this.outScanUrl = '/jinyu/bizGoods/selectOutBySerialNumberAndRetailerId';
  77. /********* 0706 ***********/
  78. // 收取短信验证码
  79. this.getPhoneCode = '/jinyu/bizLogin/sendCode';
  80. // 获取客户信息
  81. this.customListUrl = '/jinyu/bizCustomRetailer/page';
  82. // 获取门店详情
  83. this.getMDInfo = "/base/retailer/retailerInfo";
  84. // 获取所有的轮胎服务类目
  85. this.getServices = "/base/service/list";
  86. // 添加服务
  87. this.addServices = "/jinyu/bizRetailerService/save";
  88. // 根据品牌统计库存
  89. this.getStockByPP = "/jinyu/bizRetailerStock/selectStockByBrand";
  90. // 获取积分
  91. this.getJFStore = "/jinyu/bizMall/page";
  92. // 获取新闻条
  93. this.getNews = "/jinyu/bizArticle/page";
  94. // 根据品牌获取上级代理商
  95. this.getUpByBrand = "/jinyu/bizAgentBrand/listByAgentIds";
  96. // 根据品牌和省市获取上级代理商
  97. this.getUpByBrandAndArea = "/jinyu/bizAgentBrand/listByBrandIds";
  98. // 获取门店积分列表
  99. this.getJFlistUrl = "/jinyu/bizRetailerIntegral/page";
  100. // 兑换商品
  101. this.exchangeUrl = "/jinyu/bizMallOrder/save";
  102. // 查看兑换记录
  103. this.exchangeListUrl = "/jinyu/bizMallOrder/page";
  104. // 检查版本
  105. this.getVersionUrl = "/biz/getAppVersion";
  106. // 活动banner
  107. this.getBannerUrl = "/biz/bizBanner/list";
  108. // 获取参加活动的商品
  109. this.getStoreBannerUrl = "/biz/bizActivity/activityInfo";
  110. }
  111. // api的ajax
  112. $http.prototype.$post = function(url, data, callback, other) {
  113. var content = "", urlT = "", _this = this;
  114. if (data.url == "json") {
  115. delete data.url;
  116. // 确认contenttype选项
  117. content = "application/json;charset=UTF-8";
  118. } else {
  119. content = "application/x-www-form-urlencoded"
  120. }
  121. var datas = this.serize(data);
  122. if ( typeof other != 'undefined' && other != "" && other != 'undefined') {
  123. urlT = this.ip + eval('this.' + url) + '/' + other;
  124. } else {
  125. urlT = this.ip + eval('this.' + url);
  126. }
  127. api.showProgress({
  128. });
  129. if (this.ajax == true) {
  130. return;
  131. }
  132. this.ajax = true;
  133. api.ajax({
  134. url : urlT,
  135. method : 'post',
  136. data : datas,
  137. headers : {
  138. "Content-type" : content
  139. },
  140. }, function(ret, err) {
  141. _this.ajax = false;
  142. api.hideProgress();
  143. api.refreshHeaderLoadDone();
  144. if (ret) {
  145. callback(ret);
  146. } else {
  147. api.toast({
  148. msg : JSON.stringify(err)
  149. });
  150. }
  151. });
  152. }
  153. // 单独的get请求
  154. $http.prototype.$getadd = function(url, data, callback, other) {
  155. var _this = this;
  156. api.showProgress({
  157. });
  158. this.ajax = true;
  159. api.ajax({
  160. url : this.ip + eval('this.' + url) + data,
  161. method : 'get',
  162. data : {
  163. values : {
  164. }
  165. },
  166. headers : {
  167. "Content-type" : "application/json;charset=UTF-8"
  168. },
  169. }, function(ret, err) {
  170. _this.ajax = false;
  171. api.hideProgress();
  172. api.refreshHeaderLoadDone();
  173. if (ret) {
  174. callback(ret);
  175. } else {
  176. api.toast({
  177. msg : JSON.stringify(err)
  178. });
  179. }
  180. });
  181. }
  182. // get获取
  183. $http.prototype.$get = function(url, data, callback, other) {
  184. var content = "", urlT = "", _this = this;
  185. if (data.url == "json") {
  186. delete data.url;
  187. // 确认contenttype选项
  188. content = "application/json;charset=UTF-8";
  189. } else {
  190. content = "application/x-www-form-urlencoded"
  191. }
  192. var datas = this.serize(data);
  193. if ( typeof other != 'undefined' && other != "" && other != 'undefined') {
  194. urlT = this.ip + eval('this.' + url) + '/' + other;
  195. } else {
  196. urlT = this.ip + eval('this.' + url);
  197. }
  198. api.showProgress({
  199. });
  200. if (this.ajax == true) {
  201. return;
  202. }
  203. this.ajax = true;
  204. api.ajax({
  205. url : urlT,
  206. method : 'get',
  207. data : {
  208. values : {
  209. }
  210. },
  211. headers : {
  212. "Content-type" : "application/json;charset=UTF-8"
  213. },
  214. }, function(ret, err) {
  215. _this.ajax = false;
  216. api.hideProgress();
  217. api.refreshHeaderLoadDone();
  218. if (ret) {
  219. callback(ret);
  220. } else {
  221. api.toast({
  222. msg : JSON.stringify(err)
  223. });
  224. }
  225. });
  226. }
  227. // 对数据进行处理,第一个为values,第二个为file body
  228. $http.prototype.serize = function(data) {
  229. var serizeData;
  230. if ( data instanceof Array) {
  231. if (data.length > 1) {
  232. serizeData = {
  233. values : data[0]
  234. }
  235. } else {
  236. serizeData = {
  237. values : data[0],
  238. files : data[1]
  239. }
  240. }
  241. } else {
  242. if (data.type == 'body') {
  243. delete data.type;
  244. if (data.yy == 'keng') {
  245. delete data.yy
  246. serizeData = {
  247. body : data.id
  248. }
  249. } else {
  250. serizeData = {
  251. body : data
  252. }
  253. }
  254. } else {
  255. serizeData = {
  256. values : data
  257. }
  258. }
  259. }
  260. return serizeData;
  261. }
  262. function alertJson(str) {
  263. alert(JSON.stringify(str));
  264. }