supplementaryOrderList.js 10.9 KB
// subvehicleConversion/components/supplementaryOrderDetail/supplementaryOrderDetail.js
import api from '~/subvehicleConversion/api'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    navBarHeight: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    userInfo: {},
    storeInfo: {},
    tabIndex: 0,
    pageSize: 4,
    pageNum: 1,
    tabList: ['全部', '待支付', '已支付', '已退款'],
    btnTxt: {
        0: '去支付',
        1: '去退款',
        4: '去退款'
    },
    orderStatusObj: {
        0: '待支付',
        1: '已支付',
        2: '已退款',
        3: '预支付',
        4: '退定金', // 正常流程 自定义值
        5: '退定金' // 预支付状态下退定金 自定义值
    },
    orderStatusList: [
        {
            confName: '全部',
            confId: ''
        }, {
            confName: '待支付',
            confId: '0'
        }, {
            confName: '已支付',
            confId: '1'
        },
        {
            confName: '已退款',
            confId: '2'
        }
    ],
    subOrderCodeCopy: '',
    searchObj: {},
    orderObj: [
      {
        label: '商品名称',
        key: 'goodsName'
      },
      {
        label: '订金金额',
        key: 'activityPrice',
        type: 'price'
      },
      {
        label: '订金支付',
        key: 'payedDateStr'
      },
      {
          label: '订单编号',
          key: 'subOrderCode'
      },
      // {
      //     label: '尾款金额',
      //     key: 'tailPayment',
      //     type: 'price'
      // },
      {
          label: '转化人员',
          key: 'transfer'
      },
      
    ],
    list: [],
    isToBottom: false,
    selectData: ['客户姓名','订单编号','手机号'], // 下拉列表的数据
    selectIndex: 0, // 选择的下拉列表下标
    showSelect: false, // 下拉框
    confirmFlag: false,
    total: 0,
    inputValue: '',
    showRemark: false,
    showCopyPopup: false, // 复制二次选择
    copyObj: {}, // 复制 姓名/手机号
    remarkType: '' // 备注类型 1备注 2 退款原因
  },

  lifetimes: {
    attached() {
      this.setData({
        storeInfo: wx.$util.getUserInfo()?.default4SStoreInfo_newCarConversion || {},
        userInfo: wx.$util.getUserInfo() || {}
      })
      // this.onLoad(true)
    }
},

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad(noGetList) {
      this.setData({
        nothing: false,
        pageNum: 1,
        storeInfo: wx.$util.getUserInfo()?.default4SStoreInfo_newCarConversion || {}
      })
      if (!noGetList) this.getList(true)
    },
    search() {
      this.setData({
        pageNum: 1,
        nothing: false,
        total: 0
      })
      this.getList(true)
    },
    onBottomRefresh() {
      let { isToBottom } = this.data
      if (isToBottom) return
      this.setData({isToBottom: true})
      this.getList()
    },
    getList(isReset = false) {
      this.setData({
        isToBottom: false
      })
      let {pageSize, pageNum, tabList, tabIndex, inputValue, nothing, orderStatusList, selectIndex} = this.data
      let userInfo = wx.$util.getUserInfo()
      if (nothing) {
        return
      }
      let params = {
        pageSize,
        pageNum,
        customerName: selectIndex == 0 ? inputValue: '',
        subOrderCode: selectIndex == 1 ? inputValue: '',
        customerPhone: selectIndex == 2 ? inputValue: '',
        merchantId: userInfo?.default4SStoreInfo_newCarConversion?.merchantId,
        sceneType: 2, // 场景值(2 次新车转化)
        tailOrderStatus: orderStatusList.find(item => item.confName == tabList[tabIndex])?.confId || ''
      }
      wx.showLoading()
      api.getSupplementaryOrderList(params).then(res => {
        wx.hideLoading()
        if (res.code == '0') {
          let {list, total} = res.data
          list.forEach(val => {
            val.payedDateStr = val.payedDate ? wx.$util.tsFormatTime(val.payedDate, 'Y年M月D日 h:m:s') : ''
            val.tailPayedDateStr = val.tailPayedDate ? wx.$util.tsFormatTime(val.tailPayedDate, 'Y年M月D日 h:m:s') : ''
            // depositStatus定金状态 1:退定金 0:未退定金 tailOrderStatus尾款状态 0:待支付 1:已支付 2:已退款 3:预支付
            if (val?.depositStatus == 1 && val.tailOrderStatus == 1) { // 已支付状态的 退定金 
              val.tailOrderStatus = 4 // 可操作退款
            } else if ((val?.depositStatus == 1 && val.tailOrderStatus == 0) || (val?.depositStatus == 1 && val?.tailOrderStatus == 3)) { // 待支付或预支付 退定金
              val.tailOrderStatus = 5 // 不可操作
            } else {
              val.tailOrderStatus = val.tailOrderStatus
            }
          })
          let tempList = isReset ? list : this.data.list.concat(list)
          this.setData({
            list: tempList,
            pageNum: pageNum + 1,
            total,
            nothing: total == tempList.length,
            triggered: false
          })
          if (isReset) {
            this.setData({
              scrollTop: 0
            })
          }
          // console.log(this.data.list)
        } else {
          this.setData({
            list: [],
            nothing: false,
            total: 0
          })
          wx.$util.showToast(res.message || '接口异常')
        }
      })
    },
    // tab切换
    tabClick(e) {
      let {searchObj} = this.data
      delete searchObj.statusList
      this.setData({
        tabIndex: e?.detail,
        searchObj
      })
      this.search()
    },
    handleReset() {
      this.setData({
        inputValue: ''
      })
      this.search()
    },

    showMask(e) {
      const { item } = e.currentTarget.dataset || {}
      this.setData({
        showRemark: true,
        remarkType: 1,
        selectItem: item
      })
    },
    // 备注确认
    remarkConfirm(e) {
      let value = e.detail
      // 备注类型 remarkType 1备注 2退款原因
      const {subOrderCodeCopy, remarkType, list, selectItem} = this.data
      if (remarkType == 1) {
        if (value) {
          wx.showLoading()
          api.updateOrderRemark({
            orderCode: selectItem?.subOrderCode,
            remark: value
          }).then(res => {
            wx.hideLoading()
            let { code } = res
            if (code == 0) {
              // 将订单项备注值回填 不请求接口刷新页面
              list.forEach(val => {
                if (val.subOrderCode == selectItem.subOrderCode) {
                  val.remark = value
                }
              })
              this.setData({list})
            }
          })
        }
      } else {
        let params = {
          orderCode: subOrderCodeCopy,
          refundRemark: value
        }
        wx.showModal({
          title: '温馨提示',
          content: '请确定将此订单状态标记为已退款',
          complete: (res) => {
            if (res.confirm) {
              wx.showLoading()
              api.markAsRefunded(params).then(res => {
                wx.hideLoading()
                if (res.code == 0) {
                  wx.$util.showToast('退款成功!')
                  this.getList()
                } else {
                  wx.$util.showToast(res.message || '接口异常')
                }
              })
            }
          }
        })
      }
    },

    input(e) {
      let {value} = e.detail
      this.setData({
        inputValue: value
      })
    },
    // 查询条件类型切换
    selectTap() {
      this.setData({
        showSelect: !this.data.showSelect
      });
    },
    optionTap(e) {
      let { index } = e.currentTarget.dataset
      this.setData({
        selectIndex: index,
        showSelect: !this.data.showSelect
      })
    },
    closeSelect() {
      this.setData({
        showSelect: false
      })
    },
    // 复制文案(订单编号)
    copyData(e) {
      const {target, flag} = e.currentTarget.dataset
      if (flag == 1) { // 姓名和手机号
        if (target.customerName && target.customerPhone) { // 姓名手机号都有
          return this.setData({
            showCopyPopup: true,
            copyObj: {
              customerName: target.customerName,
              customerPhone: target.customerPhone
            }
          })
        }
        let copyItem = target.customerName || target.customerPhone // 只手机号或姓名
        wx.setClipboardData({
          data: copyItem
        })
      }
      let copyItem = target.subOrderCode
      wx.setClipboardData({
        data: copyItem
      })
    },
    // 复制文案(手机号/姓名)
    handleCopy(e) {
      const {target} = e.currentTarget.dataset
      wx.setClipboardData({
        data: target
      })
      this.setData({
        showCopyPopup: false
      })
    },
    onCopyPopupClose() {
      this.setData({
        showCopyPopup: false
      })
    },
    handleClickBtn(e) {
      const {target} = e.currentTarget.dataset
      let { confirmFlag } = this.data
      this.setData({
        subOrderCodeCopy: target.subOrderCode
      })
      if (target.tailOrderStatus == 0) { // 待支付
          let {accountName} = wx.$util.getUserInfo()
          const {subOrderCode, goodsId: shopmallGoodsId,} = target
          let params = {
              subOrderCode,
              shopmallGoodsId,
              orderPaySource: 1, // 订单支付源(1.正常付尾款,2关联尾款单)
              selectPayType: 1, // 支付方式(1:线上微信支付,2:线下收款,3:POS机收款, 4:支付宝支付)  默认使用微信支付
              updatedBy: accountName,
              remark: target?.remark
          }
          if (confirmFlag) return
          wx.showLoading()
          this.setData({confirmFlag: true})
          api.createPayOrderAPI(params).then(res => {
              let {code, data, message} = res
              wx.hideLoading()
              if (code == '0') {
                  // wx.$router.reLaunch
                  wx.$router.go('supplementaryOrderPay', {orderCode: target.subOrderCode})
                  setTimeout(() => {
                    this.setData({
                      confirmFlag: false
                    })
                  }, 3000)
              } else {
                  wx.$util.showToast(message || '接口异常')
                  this.setData({
                    confirmFlag: false
                  })
              }
          })
      }
      if (target.tailOrderStatus == 1 || target.tailOrderStatus == 4) { // 已支付或退定金状态
        this.setData({
          showRemark: true,
          remarkType: 2
        })
      }
    },
    remarkCancel() {
      this.setData({
        showRemark: false
      })
    },
    // 关联尾款单
    handlefinalPayment(e) {
      const {target} = e.currentTarget.dataset
      wx.$router.go('relatedFinalPayment', {list: target})
    }
  }
})