api.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import WechatShare from '../wechat/WechatShare.js';
  2. import UserAgent from './userAgent';
  3. let envHost = process.env.API_ROOT;
  4. let enter_url = "";
  5. let gWxShare = null;
  6. class Api {
  7. static host() {
  8. return envHost;
  9. }
  10. static special(special_id) {
  11. return this.host() + "/mobile/index.php?act=special&op=index&page=10&curpage=1&client_type=ajax&special_id=" + special_id;
  12. }
  13. static brands() {
  14. return this.host() + "/mobile/index.php?act=brand&op=home&client_type=ajax";
  15. }
  16. static functionList() {
  17. return this.host() + "/mobile/index.php?client_type=ajax&act=category&op=index"
  18. }
  19. static goodsDetail(goods_id) {
  20. return this.host() + `/mobile/index.php?goods_id=${goods_id}&act=goods_common&op=index&client_type=ajax`
  21. }
  22. static searchSuggest() {
  23. return this.host() + '/mobile/index.php?act=search&op=history&curpage=1&client_type=ajax'
  24. }
  25. static search() {
  26. return this.host() + '/mobile/index.php?act=search&op=suggest_words&client_type=ajax'
  27. }
  28. static goodsContent(goods_id) {
  29. return this.host() + `/mobile/index.php?act=goods_common&op=detail_ajax&goods_id=${goods_id}&client_type=ajax`
  30. }
  31. static memberInfo() {
  32. return this.host() + '/mobile/index.php?act=member_info&op=get&client_type=ajax'
  33. }
  34. static shoppingCart() {
  35. return this.host() + '/mobile/index.php?act=cart&op=list&client_type=ajax'
  36. }
  37. static cartMoney() {
  38. return this.host() + '/mobile/index.php?act=member_buy&op=calc_cash&client_type=ajax'
  39. }
  40. static changeOrderState(action, order_id) {
  41. return this.host() + '/mobile/index.php?act=member_order&op=change_state&client_type=ajax&act_type=' + action + "&order_id=" + order_id
  42. }
  43. static orderList() {
  44. return this.host() + '/mobile/index.php?act=member_order&page=30&op=list&page=15&client_type=ajax'
  45. }
  46. static refundOrder(order_sn) {
  47. return this.host() + '/mobile/index.php?act=member_refund&op=order_refund&client_type=ajax&order_sn=' + order_sn
  48. }
  49. static deliverInfo(order_id) {
  50. return this.host() + '/mobile/index.php?act=member_order&op=search_deliver&order_id=' + order_id
  51. }
  52. static shoppingCartEdit(quantity, cart_id) {
  53. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&op=edit&cart_id=${cart_id}&client_type=ajax`
  54. }
  55. static shoppingCartAdd(quantity, goods_id) {
  56. return this.host() + `/mobile/index.php?quantity=${quantity}&act=cart&goods_id=${goods_id}&op=addex&client_type=ajax`
  57. }
  58. static userBonus() {
  59. return this.host() + '/mobile/index.php?act=cart&op=rate_money&client_type=ajax'
  60. }
  61. static addressList() {
  62. return this.host() + '/mobile/index.php?act=member_address&op=address_list&client_type=ajax';
  63. }
  64. static homeTabs() {
  65. return this.host() + "/mobile/index.php?act=index&op=tabs&client_type=ajax"
  66. }
  67. static login(mobile, code) {
  68. return this.host() + `/mobile/index.php?act=login&op=bind_mobile&client_type=ajax&mobile=${mobile}&code=${code}`;
  69. }
  70. static getCode(mobile) {
  71. return this.host() + `/mobile/index.php?act=login&op=getcodex&client_type=ajax&mobile=${mobile}&type=register`;
  72. }
  73. static getFCode() {
  74. return this.host() + '/mobile/index.php?act=member_fcode&op=list&curpage=1&client_type=ajax';
  75. }
  76. static stepFirst(ifcart, cart_id, goods_id, num) {
  77. let goods_datas = '';
  78. if (ifcart == 0) {
  79. goods_datas = goods_id + '|' + num;
  80. }
  81. else {
  82. goods_datas = cart_id;
  83. }
  84. return this.host() + `/mobile/index.php?act=member_buy&op=step_first&curpage=1&ifcart=${ifcart}&cart_id=${goods_datas}&client_type=ajax`;
  85. }
  86. static stepSecond(cart_ids, goods_id, goods_num, addr_id, inv_id, vat_hash, offpay_hash, offpay_hash_batch) {
  87. let ifcart = cart_ids !== '' ? true : false;
  88. let iscart = ifcart ? 1 : 0;
  89. let cartids = ifcart ? cart_ids : (goods_id + '|' + goods_num);
  90. return this.host() + `/mobile/index.php?client_type=ajax&act=member_buy&op=step_second&payment=jspay&usebonus=1&ifcart=${iscart}&cart_id=${cartids}&address_id=${addr_id}&invoice_id=${inv_id}&vat_hash=${vat_hash}&offpay_hash=${offpay_hash}&offpay_hash_batch=${offpay_hash_batch}`;
  91. }
  92. static getAddress() {
  93. return this.host() + '/mobile/index.php?act=app_update&op=area&curpage=1&client_type=ajax';
  94. }
  95. static addAddress(true_name, area_id, address, mobile) {
  96. return this.host() + `/mobile/index.php?act=member_address&op=address_add&curpage=1&client_type=ajax&true_name=${true_name}&area_id=${area_id}&address=${address}&mob_phone=${mobile}`;
  97. }
  98. static setDefaultAddress(id, is_default) {
  99. return this.host() + `/mobile/index.php?act=member_address&op=set_default&curpage=1&client_type=ajax&address_id=${id}&is_default=${is_default}`;
  100. }
  101. static paySn(pay_sn) {
  102. return this.host() + `/mobile/index.php?act=member_order&op=pay_info&curpage=1&pay_sn=${pay_sn}&client_type=ajax`;
  103. }
  104. static comments(common_id,curpage) {
  105. return this.host() + `/mobile/index.php?act=goods_common&op=comments&curpage=${curpage}&page=10&goods_commonid=${common_id}&client_type=ajax`;
  106. }
  107. static init_url() {
  108. if (enter_url == "") {
  109. enter_url = window.location.href;
  110. }
  111. }
  112. static create_share(data) {
  113. if (UserAgent.iOS()) {
  114. gWxShare = new WechatShare(data, this.sign_url());
  115. return gWxShare;
  116. }
  117. else {
  118. return new WechatShare(data, this.sign_url());
  119. }
  120. }
  121. static sign_url() {
  122. let temp;
  123. if (UserAgent.iOS()) {
  124. Api.init_url();
  125. temp = enter_url;
  126. } else {
  127. temp = window.location.href;
  128. }
  129. return temp;
  130. }
  131. }
  132. export default Api