EquityList.js 8.95 KB
// packageEquity/pages/carEquity/components/EquityList/EquityList.js
import { checkDailyReport } from "~/store/ModalToQueueControl";
import carLifeApi from '../../../../carEquityApi'
import constantData from '../constant/data'
const TABLIST = ['全部', '待补单', '提单失败', '已完成']
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    navBarHeight: {
      type: Number,
      value: 0
    },
    outTabIndex: {
      type: Number,
      observer(val) {
        console.log(val)
        if (val == 1) {
          let {
            list
          } = this.data
          setTimeout(() => {
            // 解决商品内容提早请求,导致不计算问题
            this.setData({
              list: {
                ...list
              }
            })
          }, 10)
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    storeInfo: {},
    orderObj: [{
      label: '车架号',
      key: 'vin'
    },
    {
      label: '业务来源',
      key: 'ywly'
    },
    {
      label: '商品名称',
      key: 'goodName'
    },
    {
      label: '服务期限',
      key: 'serviceExpire',
      suffix: '年'
    },
    {
      label: '商品内容',
      key: 'goodServiceName'
    }
    ],
    statisticsObj: {},
    btnTxt: {
      0: '去录单',
      2: '查看合同',
      3: '重新录单'
    },
    searchObj: {},
    customerName: '',
    list: [],
    tabIndex: 0,
    // 0待补单;2提单成功;3提单失败
    tabList: ['全部', '待补单', '提单失败', '已完成'],
    pageSize: 4,
    pageNum: 1,
    total: 0,
    nothing: false,
    flag: true,
    tipsProps: {
      tipsText: '为保障客户权益,请尽快处理!',
      showTips: true,
      type: 1,
      noIcon: true,
      iconUrl: '../images/order-close.png'
    },
    triggered: false,
    scrollTop: 0,
    isShowTips: true,
    userInfo: {}
  },

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

  /**
   * 组件的方法列表
   */
  methods: {
    onLoad(noGetList) {
      let userInfo = wx.$util.getUserInfo() || {};
      this.setData({
        nothing: false,
        pageNum: 1,
        storeInfo: wx.$util.getUserInfo()?.default4SStoreInfo || {},
        isOrder: !(userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5)
      })
      this.getTotal()
      if (!noGetList) this.getList(true)
    },
    onBottomRefresh() {
      this.getList()
    },
    closeTips() {
      this.setData({
        isShowTips: false
      })
    },
    getTotal() {
      let {
        storeInfo
      } = this.data
      carLifeApi
        .equityStatistics({
          merchantId: storeInfo?.merchantId
        })
        .then(res => {
          // console.log(res, '统计---')
          if (res.code == '0') {
            let {
              data
            } = res
            this.setData({
              statisticsObj: data || {}
            })
            this.setData({
              ['tabList[0]']: { text: TABLIST[0], count: data.totalOder || 0 },
              ['tabList[1]']: { text: TABLIST[1], count: data.ladingOder || 0 },
              ['tabList[2]']: { text: TABLIST[2], count: data.failed || 0 },
              ['tabList[3]']: { text: TABLIST[3], count: data.success || 0 }
            })
          } else {
            wx.$util.showToast(res.message || '接口异常')
          }
        })
    },
    getList(isReset = false) {
      let {
        pageSize,
        pageNum,
        tabList,
        tabIndex,
        customerName,
        storeInfo
      } = this.data
      if (this.data.nothing) {
        return
      }
      let params = {
        pageSize,
        pageNum,
        customerName,
        // item.confName ==
        orderStatus: constantData.equityStatusList.find(item => tabList[tabIndex].text == item.confName)?.confId || '',
        merchantId: storeInfo?.merchantId
      }
      carLifeApi.equityPage(params).then(res => {
        if (res.code == '0') {
          let {
            data,
            count
          } = res.data
          let tempList = isReset ? data || [] : this.data.list.concat(data || [])
          this.setData({
            list: tempList,
            pageNum: pageNum + 1,
            total: count,
            nothing: count == 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 || '接口异常')
        }
      })
    },
    search() {
      this.setData({
        pageNum: 1,
        nothing: false,
        total: 0
      })
      this.getList(true)
    },
    handleReset() {
      this.setData({
        customerName: ''
      })
      this.search()
    },
    input(e) {
      let {
        value
      } = e.detail
      this.setData({
        customerName: value
      })
    },
    // 首次进入会触发该方法,因此不需要在attached调getList
    tabClick(e) {
      let {
        searchObj
      } = this.data
      delete searchObj.statusList
      this.setData({
        tabIndex: e.detail,
        searchObj
      })
      this.search()
    },
    // 录单/重新录单
    async handleRecordOrder(e) {
      // 校验是否填写昨日日报
      let staffCheck = await checkDailyReport(true);
      if (staffCheck) return false;;
      let {
        target
      } = e.currentTarget.dataset
      console.log(target)
      wx.$router.go('serviceInfo', {
        contractNo: target.contractNo,
        apiName: 'detail'
      })
    },
    // 查看/下载合同
    async handlePreviewContract(e) {
      let {
        target,
        type
      } = e.currentTarget.dataset
      wx.$util.showLoading('加载中...')
      let params = {
        contractNo: target.contractNo
        // contractNo: 'car679883190869172224' //开发测试用
      }
      let result = await carLifeApi.equityOrderList({
        orderId: target.orderId
      })
      let {
        code,
        data
      } = result
      if (code == 0) {
        if (data.length == 1) {
          carLifeApi.printContract(params).then(res => {
            wx.$util.hideLoading()
            if (res.code == '0') {
              this.setData({
                url: res.data
              })
              if (type == 'download') {
                // 复制合同链接
                this.copyContractUrl(res.data)
              } else this.handleDownload()
              console.log(this.data.url)
            } else {
              wx.$util.showToast(res.message || '接口异常')
            }
          })
        } else {
          wx.$util.hideLoading()
          wx.$router.go('previewList', {
            list: data
          })
        }
      }
      console.log(result, 'result')
      return
    },

    // 签名
    async handleSignature(e) {
      // 校验是否填写昨日日报
      let staffCheck = await checkDailyReport(true);
      if (staffCheck) return false;
      let { target } = e.currentTarget.dataset
      wx.$router.go("signature", {
        orderId: target.orderId,
        tabIndex: 2
      });
    },

    // 复制链接
    copyContractUrl(e) {
      if (!e) {
        wx.$util.showToast('没有合同')
        return
      }
      wx.showModal({
        title: '温馨提示',
        content: '如需下载PDF报告单,请复制下载地址后到手机浏览器中打开。下载地址5分钟内有效',
        confirmText: '复制地址',
        confirmColor: '#347BFF',
        success(res) {
          if (res.confirm) {
            wx.setClipboardData({
              data: e
            })
          }
        }
      })
    },

    handleDownload() {
      let {
        url
      } = this.data
      let _this = this
      if (!url) {
        wx.$util.showToast('没有合同')
        return
      }
      console.log('handleDownload')
      wx.downloadFile({
        // 示例 url,并非真实存在
        url: url,
        success: function (res) {
          const manage = wx.getFileSystemManager()
          let file = url.split('/')
          let fileName = file[file.length - 1]
          manage.saveFile({
            tempFilePath: res.tempFilePath,
            filePath: wx.env.USER_DATA_PATH + '/' + fileName,
            success: function (res) {
              console.log('保存成功')
              wx.openDocument({
                filePath: wx.env.USER_DATA_PATH + '/' + fileName,
                fileType: 'pdf',
                showMenu: true,
                success: function (res) {
                  console.log('打开文档成功')
                }
              })
            }
          })
          // console.log(wx.env.USER_DATA_PATH + "/" + fileName,'wx.env.USER_DATA_PATH + "/" + fileName');
        }
      })
    }
  }
})