step1.js 2.12 KB
// packageUsedCar/pages/deliveryNote/components/step1/step1.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import newApi from '~/packageUsedCar/api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 当前步骤
    step: {
      type: [String, Number],
      value: 1
    },
    // 详情数据
    detail: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    isLoading: false, // 加载状态
    deliveryTips: [
      '核实车款: 引导客户现场完成尾款支付,并确认款项到账。',
      '核验人车: 核对客户身份信息,并与客户共同确认车辆信息及实际车况。',
      '交接资料: 清点并交付车辆登记证、行驶证、车钥匙等重要物品。',
      '签署确认: 引导客户签署《车辆交付确认书》,完成交付流程。'
    ]
  },

  /**
   * 组件生命周期
   */
  lifetimes: {
    attached: function() {
      // 组件实例进入页面节点树时执行
      console.log('delivery-step组件已加载')
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 确认到店按钮点击事件
     */
    confirmArrive: async function() {
      let { detail, step } = this.data
      // 如果正在加载或禁用,直接返回
      if (this.data.isLoading) {
        return
      }
      // 埋点
      wx.$track.setTrackData(0, 'delivery_arrive_shop', {}, '', 7)
      wx.$util.showLoading('加载中')
      // 设置加载状态
      this.setData({
        isLoading: true
      })
      try {
        const result = await newApi.confirmArrive({deliveryOrderId: detail.deliveryOrderId})
        console.log(result)
        if (result.data.code == 0) {
          // 成功回调
          this.triggerEvent('confirm', step)
          this.triggerEvent('refreshlog')
        } else {
          throw result.data.msg
        }
      } catch (error) {
        this.triggerEvent('openError', error)
      } finally {
        wx.hideLoading()
        this.setData({
          isLoading: false
        })
      }
    }
  }
})