orderList.js 7.13 KB
// tabWorkOrder/pages/index/index.js
import api from '../../carEquityApi'
import order_mixins from '../../order_mixins.js'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
let timeoutId;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMG_URL,
    ...order_mixins.data,
    showIcon1: true, // 初始显示图标
    // showIcon2: true, // 初始隐藏第二个图标
    activeIndex: 0,
    orderObj: [{
        label: '销售顾问',
        arr: ['merchantName', 'employeeName']
      },
      {
        label: '转化人员',
        arr: ['sellerMerchantName', 'sellerName']
      },
      {
        label: '工单编号',
        key: 'orderCode'
      },
      {
        label: '工单时间',
        key: 'orderTime'
      }
    ],
    searchObj: {},
    pageNum: 1,
    keyword: '',
    list: [],
    tabIndex: 0,
    tabList: ['全部', '待跟进', '已升级', '战败'],
    tabListTemplate: ['全部', '待跟进', '已升级', '战败']
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
  },
  jumpReception(e) {
    const {
      item
    } = e.currentTarget.dataset;
    wx.$router.go("reception", Object.assign(item, {
      customerPhone: item.customer.customerPhone
    }));
  },
  tabClick(e) {
    let {
      searchObj
    } = this.data
    delete searchObj.statusList
    this.setData({
      tabIndex: e.detail,
      searchObj
    })
    this.search()
  },
  input(e) {
    let {
      value
    } = e.detail
    this.setData({
      keyword: value
    })
  },
  clear() {
    this.setData({
      keyword: ''
    })
    this.search()
  },




  // 查看全部商品
  showAllGoodsList(e) {
    let {
      item
    } = e.currentTarget.dataset
    let {
      list
    } = this.data
    list.forEach(val => {
      val?.forEach(subVal => {
        if (subVal.id == item.id) subVal.showAllGoodsListFlag = !subVal?.showAllGoodsListFlag
      })
    })
    this.setData({
      list
    })
  },





  search() {
    wx.$orderListRefresh = false
    let {
      searchObj,
      userInfo
    } = this.data
    let merchantId
    // 判断是不是超管,不是只能筛选当前4s店的
    if (!searchObj.merchantId && !userInfo.isSuper) {
      merchantId = userInfo?.shopMerchantId
      this.setData({
        ['searchObj.merchantId']: merchantId
      })
    }
    this.setData({
      list: [],
      pageNum: 1,
      flag: false,
      nothing: false,

    })
    this.getWorkList()
  },
  getWorkList() {
    this.showLoading && this.showLoading('加载中...')
    let {
      searchObj,
      pageNum,
      keyword,
      userInfo,
      status,
      staffUuid,
      searchdate,
      phoneNumberLists,
      merchantId
    } = this.data
    let obj = {
      keyword,
      pageNum,
      installUpgradeBeginTimeStr: searchdate + ' 00:00:00',
      installUpgradeEndTimeStr: searchdate + ' 23:59:59',
      sellerUserIdList: [staffUuid],
      customerPhoneList: phoneNumberLists,
      // merchantIdList: [merchantId]
    }


    api.getWorkList(obj).then(res => {
      wx.$util.hideLoading()

      let {
        code,
        data,
        errId,
        message
      } = res
      let total = 0
      let list = []
      if (code == 0) {
        // 这个是用来判断哪些用户可以撤销的
        let userType = !userInfo.isSuper && userInfo.merchantType
        // let userType = true

        data.list.map(e => {
          if (e.orderTime) e.orderTime = new Date(e.orderTime).format('yyyy-MM-dd hh:mm:ss')
          e.subOrderList.map(i => {
            i.totalPrice = Number(wx.$util.decimal(i.totalPrice, 2)).toFixed(2)
          })
          e.total_price = e.totalPrice
          e.totalPrice = Number(wx.$util.decimal(e.totalPrice, 2)).toFixed(2)
          // && e.status != 1 待跟进现在也能撤销
          let orderType = (userInfo.userType == 1 || userInfo.userType == 2) && e.status != 9 && ![1, 3, 4].includes(e.selectPayType)
          // let orderType = userInfo.userType !== 1 && e.status != 9 && e.status != 1 && e.selectPayType != 3 && e.selectPayType != 1
          // console.log(userType);
          // console.log(orderType);
          e.repeal = userType && orderType
          // 处理subOrderList 商品为空的情况
          e.subOrderList = e.subOrderList.filter(item => item.merchantGoodsId)
          // e.subOrderList = e.subOrderList.filter(item => item.id)

          // 处理显示订单右上角文字
          // console.log(status[e.status])
          // console.log(' status[e.status]', status[e.status])
          let text = status[e.status].text
          let color = status[e.status].color
          let background = status[e.status].background
          // 不是订单失效状态优先显示已施工
          if (![9, 11, 12].includes(e.status) && e.constructionFlag == 'Y') {
            text = '已施工'
            color = '#347BFF'
            background = '#F3F7FC'
          }
          e.statusText = text
          e.statuscolor = color
          e.statusbackground = background
          // 商品是否包含太阳膜
          e.isFilmOrder = e.subOrderList?.findIndex(subE => subE.upgradeGoodsType == 1) > -1
        })
        list = data.list
        total = data.total
      } else {
        if (errId != '-5003') wx.$util.showToast(message)
      }
      if (total != 0) {
        this.setData({
          [`list[${pageNum - 1}]`]: list
        })
      }
      this.setData({
        total,
        flag: true,
        triggered: false
      })
    })
  },


  onRoute(options) {
    if (Object.keys(options)?.length) {
      this.setData({
        staffUuid: options?.staffUuid, // 员工id
        searchdate: options?.searchdate, // 质检页面筛选的时间条件
        merchantId: options?.merchantId, // 员工归属门店
        phoneNumberLists: options.phoneNumberLists ? options.phoneNumberLists : [] // 接待客户手机号
      })
    }



    let userInfo = wx.$util.getUserInfo()
    this.setData({
      userInfo: {
        ...userInfo,
        merchantType: userInfo?.merchantAccountList.includes('6') || userInfo?.merchantAccountList.includes('8')
      }
    })
    this.getWorkList()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },

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

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

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  scrollonReachBottom() {
    let {
      total,
      pageNum
    } = this.data
    wx.$util.onReachBottom({
        total,
        pageNum
      },
      res => {
        this.getWorkList()
      }
    )
  },
  /**
   * 监听 TabBar 切换点击
   */
  // onTabItemTap(item) {
  //   console.log(item, 'item')
  // },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})