orderSwitchPopup.js 4.08 KB
import api from '../../api/api.js'
import Util from '../../utils/util'
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /*组件的属性列表*/
  properties: {
    title: {
      type: String,
      value: '标题'
    },
    // 弹窗内容
    content: {
      type: String,
      value: '内容'
    },
    // 弹窗取消按钮文字
    btn_no: {
      type: String,
      value: '取消'
    },
    // 弹窗确认按钮文字
    btn_ok: {
      type: String,
      value: '补录这笔订单'
    },
    //是否显示取消按钮
    isShowCancel: {
      type: Boolean,
      value: true
    },
    //是否显示右上角关闭按钮
    isShowClose: {
      type: Boolean,
      value: true
      //       <view class="order-popup-close" bindtap="close">
      //       <image src="../images/order-close.png" />
      //   </view>
    },
    //应用于某些场景的button的open-type属性
    sureButtonType: {
      type: String,
      value: ''
    },
    //控制弹窗的显示
    flag: {
      type: Boolean,
      value: true
    }
    // merchantId: {
    //   //是否根据4s店查询
    //   type: String,
    //   value: ''
    // }
  },
  /* 组件的初始数据 */
  data: {
    bgOpacity: 0,
    wrapAnimate: 'wrapAnimate',
    popupAnimate: 'popupAnimate',
    currentPage: 1,
    pageSize: 10,
    tableList: [],
    activeIndex: ''
  },
  lifetimes: {
    attached: function () {
      this.getWaitinputorder()
      // 在组件实例进入页面节点树时执行
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    }
  },
  /* 组件的方法列表 */
  methods: {
    choose(e) {
      let { item, index } = e.currentTarget.dataset
      console.log(index)
      let { tableList } = this.data
      tableList.forEach(element => {
        element.active = false
      })
      tableList[index].active = true
      this.setData({
        tableList,
        activeIndex: index
      })
    },
    restPageNum() {
      console.log('restPageNum')
      this.setData({
        currentPage: 1
      })
      this.getWaitinputorder()
    },
    scrollonReachBottom() {
      console.log('scrollonReachBottom')
      let { pages, currentPage } = this.data
      // 判断当前页是否是末页
      if (pages == currentPage) return wx.$util.showToast('列表已到底')

      this.setData({
        currentPage: currentPage + 1
      })
      this.getWaitinputorder()
    },
    getWaitinputorder() {
      let { currentPage, pageSize, tableList } = this.data
      api
        .waitinputorder({ currentPage, pageSize })
        .then(result => {
          let { code, data } = result
          if (code == 0) {
            // console.log(data.list)
            data.list.forEach(element => {
              // element.totalFee = element.totalFee / 100
              element.formatAccountDate = Util.tsFormatTime(element.accountDate, 'M/D h:m')

              element.accountDate = new Date(element.accountDate).format('yyyy-MM-dd')
            })
            // console.log(data.list)
            this.setData({
              tableList: currentPage == 1 ? data.list : [...tableList, ...data.list],
              pages: data.pages,
              triggered: false
            })
            // console.log(tableList)
          }
          // console.log(result)
        })
        .catch(err => {})
    },
    /* 内部私有方法建议以下划线开头 triggerEvent 用于触发事件 */
    _close() {
      //触发取消回调
      this.triggerEvent('close')
    },
    _success() {
      let { tableList, activeIndex } = this.data
      //   console.log('number' === typeof activeIndex)
      //   debugger
      if ('number' !== typeof activeIndex) return wx.$util.showToast('请选择订单')
      let { accountDate, outTradeNo, totalFee } = tableList[activeIndex]
      tableList[activeIndex] && this.triggerEvent('success', { accountDate, outTradeNo, totalFee })
      //   if (activeIndex != '') {
      //     //触发成功回调
      //     console.log(tableList[activeIndex].tradeNo)
      //   }
    }
  }
})