logisticsDetails.js 8.51 KB

let plugin = requirePlugin("yoho-utils");
import { jumpByUrl } from '../../libs/urlRoute';
import { getChannelCode, getGenderCode } from '../../utils/home';
import { parseBrandListData } from '../../utils/productList';


let app = getApp();

const GET_NEW_EXPRESS = 'app.express.getNewExpress';

Page({
  
  data: {
    isLoading: true,
    isShowHomeNav: false,
    data:{},
    moreDetails: false,
    dot1: "./images/Oval@3x.png",
    dot2: "./images/Oval2@3x.png",
    orderID: '',
    order_code: '',
    firstItem: null,
    list: null,
    current_page_name: 'logisticsDetails',
    resources:[],
    activityResources:[],
    recommdData:[],
  },

  onLoad: function (options) {
    //获取应用实例
    if (options && options.order_code) {
      let order_code = options.order_code;
      this.setData({
        order_code,
        isShowHomeNav: app.globalData.currentScene === 1014 || app.globalData.currentScene === "1014",
      });

      wx.showLoading({
        title: '加载中...',
      })
      this.setData({
        isLoading: true,
      });
      this.getLogisticInfo();
    } else if (options && options.apply_id) {
      let apply_id = options.apply_id;
      let epress_type = options.type
      this.setData({
        apply_id,
        epress_type,
        isShowHomeNav: app.globalData.currentScene === 1014 || app.globalData.currentScene === "1014",
      });
      this.getExpress(apply_id, epress_type);
    }
    this.getActivityResources();
    this.getResources();
    this.getRecommed();
  },

  getExpress(apply_id, epress_type) {
    let that = this;
    wx.showLoading({
      title: '加载中',
    })
    plugin.get({
      data: {
        method: GET_NEW_EXPRESS,
        id: apply_id,
        type: epress_type
      }
    }).then(data => {
      wx.hideLoading();
      that.setData({
        isLoading: false,
      });
      if (data && data.code == 200) {
        let first = null;
        let list = null;
        if (data.data && data.data.express_detail && data.data.express_detail.length > 0) {
          first = data.data.express_detail[0];
          if (data.data.express_detail.length > 1) {
            list = new Array(data.data.express_detail.length - 1);
            for (var i = 1; i < data.data.express_detail.length; i++) {
              list[i - 1] = data.data.express_detail[i];
            }
          }
        }

        that.setData({
          data: data.data,
          firstItem: first,
          list: list,
        });
      } else {
        wx.showModal({
          content: data.message,
          showCancel: false,
          confirmText: "确定",
        });
      }
      }).catch(function (error) {
        wx.hideLoading();
        that.setData({
          isLoading: false,
        });
      });
  },

  copyTapped: function(){
    wx.setClipboardData({
      data: this.data.orderID,
      success: function (res) {
        wx.showModal({
          content: '已复制到剪贴板!',
          showCancel: false,
          confirmText: "ok",
          success: function (res) {
          }
        })
      },
    })  
  },



  getLogisticInfo: function () {
    let that = this;
    let param = {
      method: 'app.express.li',
      uid: app.getUid(),
      fromPage: 'iFP_Logistics',
      order_code: this.data.order_code,
      physical_channel: 1,
    };

    plugin.get({data: param})
      .then(function (data) {
        // console.log(data);
        wx.hideLoading();
        that.setData({
          isLoading: false,
        });
        if (data && data.code == 200) {
          let first = null;
          let list = null;
          if (data.data && data.data.express_detail && data.data.express_detail.length > 0){
          first = data.data.express_detail[0];
          if (data.data.express_detail.length > 1){
            list = new Array(data.data.express_detail.length - 1);
            for (var i = 1; i < data.data.express_detail.length; i++){
              list[i - 1] = data.data.express_detail[i];
            }
          }
          }

          that.setData({
            data:data.data,
            firstItem:first,
            list:list,
          });
        } else {
          wx.showModal({
            content: data.message,
            showCancel: false,
            confirmText: "确定",
          });
        }
      })
      .catch(function (error) {
        wx.hideLoading();
        that.setData({
          isLoading: false,
        });
      });
  },

/**
 * 活动资源位
 */
getActivityResources: function () {
  var app = getApp();
  let that = this;
  let content_code = "05a074fdedbdb9257ec56b33971a9109";

  let param = {
    content_code,
  };
  plugin.get({
    url: '/operations/api/v5/resource/get',
    data: param
  }).then(json => {
    if (json && json.code && json.code == 200) {
      for (var i = 0; i < json.data.length; i++) {
        //图片url转换
        if (json.data[i].data && json.data[i].data.list) {
          for (var j = 0; j < json.data[i].data.list.length; j++) {
            json.data[i].data.list[j].src = json.data[i].data.list[j].src.replace('{width}', json.data[i].data.imageWidth).replace('{height}', json.data[i].data.imageHeight).replace('{mode}', 2);
          }
        }
        //图片宽高转换
        if (json.data[i].data.imageHeight && json.data[i].data.imageWidth) {
          json.data[i].data.imageHeight = parseInt(json.data[i].data.imageHeight) / parseInt(json.data[i].data.imageWidth) * 750;//750rpx是小程序自适应屏幕宽度
          json.data[i].data.imageWidth = 750;//rpx
        }
      }
      that.setData({
        activityResources: json.data,
      });
    }
  }).catch(error => { });
},

//获取资源位
  getResources: function () {
    var app = getApp();
    let that = this;
    let content_code = "b53e62fd06b9ce43a24b1d961da9e674";

    let param = {
      content_code,
    };
    plugin.get({
      url: '/operations/api/v5/resource/get',
      data: param
    }).then(json => {
      if (json && json.code && json.code == 200) {
        for (var i = 0; i < json.data.length; i++) {
          //图片url转换
          if (json.data[i].data && json.data[i].data.list) {
            for (var j = 0; j < json.data[i].data.list.length; j++) {
              json.data[i].data.list[j].src = json.data[i].data.list[j].src.replace('{width}', json.data[i].data.imageWidth).replace('{height}', json.data[i].data.imageHeight).replace('{mode}', 2);
            }
          }
          //图片宽高转换
          if (json.data[i].data.imageHeight && json.data[i].data.imageWidth) {
            json.data[i].data.imageHeight = parseInt(json.data[i].data.imageHeight) / parseInt(json.data[i].data.imageWidth) * 750;//750rpx是小程序自适应屏幕宽度
            json.data[i].data.imageWidth = 750;//rpx
          }
        }
        that.setData({
          resources: json.data,
        });
      }
    }).catch(error => { });
  },

  /**
   * 为你优选
   */
  getRecommed: function () {
    let gender = getGenderCode(getApp().globalData.selectedChannel);
    let yh_channel = getChannelCode(getApp().globalData.selectedChannel);
    let param = {
      method: "app.home.newPreference",
      gender,
      yh_channel,
      rec_pos: 100004,
      limit: 30,
      fromPage: "aFP_My",
    }
    plugin.get({data: param})
      .then(json => {
        if (json && json.code && json.code == 200) {

          let data = json.data.product_list;
          data = parseBrandListData(data);
          this.setData({
            recommdData: data,
          })
        }
      });
  },

moreDetails: function(){
  let that = this;
  let more = that.data.moreDetails;
  that.setData({
    moreDetails: !more,
  });
},

copy: function (e) {
  var that = this;
  var content = e.currentTarget.dataset.copy_content;
  wx.setClipboardData({
    data: '' + content,
  })
},

lookup: function (e) {
  var that = this;
  var copy_url = e.currentTarget.dataset.copy_url;
  var copy_content = e.currentTarget.dataset.copy_content;
  var copy_type = e.currentTarget.dataset.copy_type;
  wx.setClipboardData({
    data: '' + copy_url,
    success: function (res) {
      wx.hideToast();
    },
  })
  wx.showModal({
    title: '',
    content: copy_content,
    showCancel: false,
  })
},

  jumpByRule: function(e){
    let url = e.currentTarget.dataset.jumpurl;
    jumpByUrl(url);
  },
})