shareOrderInfo.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var app = getApp();
  2. var status = require('../../utils/index.js');
  3. Page({
  4. data: {
  5. order: [],
  6. groupInfo: {
  7. group_name: '社区',
  8. owner_name: '团长'
  9. }
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. let that = this;
  16. status.setGroupInfo().then((groupInfo) => {
  17. that.setData({ groupInfo })
  18. });
  19. let order_id = options.order_id || 0;
  20. if (order_id == undefined || !order_id){
  21. wx.redirectTo({
  22. url: '/lionfish_comshop/pages/index/index',
  23. })
  24. }
  25. wx.showLoading();
  26. this.getData(order_id);
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. /**
  34. * 获取数据
  35. */
  36. getData: function (order_id) {
  37. let that = this;
  38. app.util.request({
  39. 'url': 'entry/wxapp/index',
  40. 'data': {
  41. controller: 'order.order_share_info',
  42. id: order_id,
  43. is_share: 1
  44. },
  45. dataType: 'json',
  46. method: 'POST',
  47. success: function (res) {
  48. wx.hideLoading();
  49. if(res.data.code == 0){
  50. let order = res.data.data;
  51. let order_info = order.order_info || '';
  52. if (order_info){
  53. let { shipping_name, shipping_address } = order_info;
  54. shipping_name = that.formatData(shipping_name, 2);
  55. shipping_address = that.formatData(shipping_address, 6);
  56. order.order_info.shipping_name = shipping_name;
  57. order.order_info.shipping_address = shipping_address;
  58. }
  59. that.setData({ order })
  60. } else {
  61. app.util.message(res.data.msg || '请求出错', '', 'error');
  62. }
  63. }
  64. })
  65. },
  66. /**
  67. * 去商品详情
  68. */
  69. goGoodsDetails: function(e){
  70. let id = e.currentTarget.dataset.id || 0;
  71. let head_id = this.data.order.order_info.head_id || '';
  72. wx.navigateTo({
  73. url: '/lionfish_comshop/pages/goods/goodsDetail?id=' + id + '&community_id=' + head_id,
  74. })
  75. },
  76. formatData: function(str, len) {
  77. str = str+"";
  78. len = str.length > 3 ? len : 1;
  79. if (str.length > len) {
  80. return str.substr(0, str.length - len) + new Array(len+1).join('*');
  81. } else {
  82. return str;
  83. }
  84. }
  85. })