OrderScreen.js 4 KB
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    navBarHeight: String,
    show: {
      type: Boolean,
      observer: function (n, o) {
        if (n) {
          this.setViewData()
        } else {
          this.setData({
            x: this.data.windowWidth
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    maxDate: new Date().format('yyyy-MM-dd'),
    orderTimeList: [{
      name: '全部',
      active: true
    }, {
      name: '今日',
      createdStartDate: new Date().format('yyyy-MM-dd'),
      createdEndDate: new Date().format('yyyy-MM-dd')
    }, {
      name: '本月',
      createdStartDate: new Date(new Date().setDate(1)).format('yyyy-MM-dd'),
      createdEndDate: new Date().format('yyyy-MM-dd')
    }, {
      createdStartDate: '',
      createdEndDate: '',
      type: 'custom'
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setViewData() {
      let {
        navBarHeight
      } = this.data
      wx.$util.getViewInfo(
        '.btn-box',
        res => {
          console.log(res)
          this.setData({
            height: navBarHeight,
            btnHeight: res.height
          })
        },
        this
      )
    },
    init() {
      let {
        orderTimeList
      } = this.data
      this.setData({
        ['form.orderTimeList']: wx.$util.deepClone(orderTimeList)
      })
    },
    showMore(e) {
      let {
        type
      } = e.currentTarget.dataset
      let {
        employShowMore,
        salesmanShowMore
      } = this.data
      let prop = type == 1 ? 'employShowMore' : 'salesmanShowMore'
      this.setData({
        [prop]: type == 1 ? !employShowMore : !salesmanShowMore
      })
    },
    rangeSelect(e) {
      let {
        index,
        name
      } = e.currentTarget.dataset
      let data = this.data.form[name]
      let {
        date: {
          start,
          end
        }
      } = e.detail
      data?.map(i => (i.active = false))
      let obj = name == 'orderTimeList' ? {
        active: true,
        createdStartDate: start,
        createdEndDate: end,
        type: 'custom'
      } : {
          active: true,
          payStartDate: start,
          payEndDate: end,
          type: 'custom'
        }
      data[index] = obj
      this.setData({
        [`form.${name}`]: data,
        isReset: false
      })
    },
    // 日期组件
    showCalendar(e) {
      let {
        target
      } = e.currentTarget.dataset
      let calendarModule = target == 'showOrder' ? this.selectComponent('#orderCalendar') : this.selectComponent('#payCalendar')
      calendarModule.showCalendar && calendarModule.showCalendar(e)
    },
    choose(e) {
      let {
        index,
        listName
      } = e.currentTarget.dataset
      let target = this.data.form[listName]
      if (target[index].disabled) return
      target.forEach(i => {
        i.active = false
      })
      target[index].active = true
      this.setData({
        [`form.${listName}`]: target,
        isReset: false
      })
    },
    reset() {
      this.init()
    },
    confirm() {
      let {
        form,
        userInfo,
        isReset
      } = this.data
      let obj = {}
      Object.keys(form).forEach(e => {
        form[e]?.map(i => {
          if (i.active) {
            let {
              createdStartDate,
              createdEndDate,
            } = i
            if (createdStartDate && createdEndDate) {
              obj.createdStartDate = `${createdStartDate} 00:00:00`
              obj.createdEndDate = `${createdEndDate} 23:59:59`
            }
          }
        })
      })
      if (isReset) obj = {}
      this.triggerEvent('confirm', obj)
    }
  },
  attached() {
    wx.$util.getSystemInfo(info => {
      let {
        windowWidth
      } = info
      this.setData({
        x: windowWidth,
        windowWidth,
        isFullSucreen: wx.$util.isFullSucreen(true)
      })
    })
    this.init()
  }
})