selectPostCompany.js 2.27 KB
// page/subPackage/pages/selectPostCompany/selectPostCompany.js
import { GET } from '../../../../libs/request';
import { API_HOST } from '../../../../libs/config';
import { getImageUrlWithWH } from '../../../../utils/util.js';

const EXPRESS_COMPANY = 'app.express.getExpressCompany';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    return_value: [],
    search_value: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getPostCompany();
  },

  getPostCompany() {
    GET(API_HOST, {
      method: EXPRESS_COMPANY,
    }).then(data => {
      if (data && data.code === 200 && data.data) {
        this.setData({
          company_list: data.data
        })
      }
    })
  },

  backSelectCompany(e) {
    let company = e.currentTarget.dataset.company;
    let pages = getCurrentPages();
    let page = pages[pages.length - 2];
    page.setData({
      defalut_post_company: company.company_name,
      company
    });
    tt.navigateBack({
      delta: 1
    });
  },

  searchCompany(e) {
    let value = e.detail.value;
    this.setData({
      search_value: value
    });
    let { company_list } = this.data;
    let return_value = [];
    Object.keys(company_list).forEach(key => {
      company_list[key].forEach(company => {
        if (company && (company.company_name.indexOf(value) !== -1)) {
          return_value.push(company);
        }
      });
    });
    if (return_value.length === 0) {
      tt.showToast({
        title: '没有搜索到该物流公司哦~',
        icon: 'none'
      });
    }
    this.setData({
      return_value
    })
  },

  doNothing(e) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})