client.js 14.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
// pages/tab/output/components/client/client.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
import { deleteSecond } from '~/utils/format'
import { h5Url } from '~/utils/request/http'
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true
  },
  properties: {},

  options: {
    styleIsolation: 'shared'
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    pMerchantId: '',
    totalProfit: 0,
    pageObj: {
      currentPage: 1,
      pageSize: 10
    },
    totalPages: -1,
    list: [],
    sceneCodeList: ['SC002', 'SC003', 'SC004', 'SC001'],
    tabActive: 'store',
    // 业务经营汇总
    stickyScrollTop: 0,
    stickyOffsetTop: 0,
    formData: {
      // 0:全部-1;1:精品升级SC002;2:售后众筹SC004;3:会员权益/升级SC001
      busiIdx: 0,
      sceneCode: '-1',
      // 时间筛选Idx(全部,精品升级,会员权益)
      timeIdx: 0,
      // 产品/状态筛选Idx(售后众筹)
      proIdx: 0,
      statusIdx: 0
    },
    busiObj: {},
    busiTotalList: [],
    crowdOrderObj: {},
    isAsk: {
      client: false,
      business: false
    }
  },
  lifetimes: {
    attached() {
      wx.$eventbus.on('clientRefresh', res => {
        this.clientRefresh()
        this.getBusinessData()
      })
      this.getPMerchantInfo()
      this.getBusinessData()
      this.getClientApi()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // tab切换
    handleTabChange(e) {
      let { tabActive } = e.detail
      this.setData({
        tabActive
      })
    },

    getBusinessData() {
      this.getBusiStatistics()
    },

    // tab-业务经营切换
    handleBusiSearch(e) {
      this.getBusiStatistics(true, true)
    },

    // 升降序
    handleSort(e) {
      let { detail } = e
      let { formData } = this.data
      if (!['SC003', 'SC004'].includes(formData.sceneCode)) {
        let sortTabModule = this.selectComponent("#sortTab")
        let sortTabFixModule = this.selectComponent("#sortTabFix")
        sortTabModule.syncVal(detail)
        sortTabFixModule.syncVal(detail)
      }
      this.getBusiStatistics(true)
    },

    // 吸顶
    handleBusiScroll: wx.$util.debounce(function (e) {
      this.setData({
        stickyScrollTop: e?.detail?.scrollTop
      })
    }, 50),

    resetBusiData() {
      this.setData({
        busiObj: {},
        busiTotalList: [],
        crowdOrderObj: {}
      })
    },

    // 阻止冒泡事件
    sceneCatch() { },

    // 点击场景
    handleSceneChange(e) {
      let { detail } = e
      this.handleJump({
        currentTarget: {
          dataset: {
            idx: detail.listIdx,
            sceneCode: detail.sceneCode
          }
        }
      })
    },

    dealToTime(list, sceneCode = 'SC004') {
      list.forEach(k => {
        // 特殊处理
        if (sceneCode == 'SC003') {
          k.totalOutputValue = (k.totalOutputValue / 100).toFixed(2)
        }
        // 时间
        k.time = k.startTime.slice(0, 16).replace(/-/g, '.') + ' - ' + k.endTime.slice(0, 16).replace(/-/g, '.')
        let startTimeFormat = k.startTime.slice(0, 10).replace(/-/g, '/') + ' 00:00:00'
        let nowDateFormat = new Date().toLocaleDateString().replace(/-/g, '/') + ' 23:59:59'
        // activityStatus 1:未开始  2:进行中  3:已结束
        switch (k.activityStatus) {
          case 1:
            k.interDays = parseInt((new Date(startTimeFormat).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)) + 1
            k.realTime = '-'
            break
          case 2:
            let endTimeFormat = k.endTime.slice(0, 10).replace(/-/g, '/') + ' 23:59:59'
            k.interDays = parseInt((new Date().getTime() - new Date(startTimeFormat).getTime()) / (1000 * 60 * 60 * 24)) + 1
            k.toEndDays = parseInt((new Date(endTimeFormat).getTime() - new Date(nowDateFormat).getTime()) / (1000 * 60 * 60 * 24)) + 1
            k.realTime = k.realStartTime?.slice(0, 16).replace(/-/g, '.') + ' - ' + '已开始' + k.interDays + '天'
            break
          case 3:
            k.interDays = parseInt((new Date(nowDateFormat).getTime() - new Date(k.endTime.replace(/-/g, '/')).getTime()) / (1000 * 60 * 60 * 24)) + 1
            k.realTime = (k.realStartTime?.slice(0, 16).replace(/-/g, '.') || '') + ' - ' + (k.realEndTime?.slice(0, 16).replace(/-/g, '.') || '')
            break
        }
      })
      return list
    },

    // 次新车转化-总收益
    getActivityTotal() {
      let { userInfo } = wx.$storage.get()
      let totalTabModule = this.selectComponent('#totalTab')
      let busiSearchData = totalTabModule ? totalTabModule.dealParams() : {}
      let params = {
        ...busiSearchData,
        serviceMerchantId: userInfo.subLoginUser.merchantId
      }
      outputApi.getActivityTotal(params).then(res => {
        this.setData({
          ['crowdOrderObj.totalAmount']: (res / 100).toFixed(2)
        })
      })
    },

    // 众筹数据处理
    dealCrowdObj(data) {
      let _obj = {
        totalNum: data.activityTotal,
        totalOrderCount: data.orderTotal,
        totalAmount: data.totalAmount,
        activityList: data.activityList || []
      }
      _obj.activityList = this.dealToTime(_obj.activityList)
      this.setData({
        crowdOrderObj: _obj
      })
    },

    getBusiStatistics(isReset = false, isBusiTab = false) {
      let { isAsk: { business } } = this.data
      let _this = this
      if (business) {
        return true
      }
      let totalTabModule = this.selectComponent('#totalTab')
      let busiSearchData = totalTabModule ? totalTabModule.dealParams() : {}
      let sortTabModule = this.selectComponent('#sortTab')
      if (sortTabModule && isBusiTab) {
        sortTabModule.resetAllAsc()
      }
      let sortSearchData = sortTabModule ? sortTabModule.dealParams() : {}
      this.setData({
        formData: JSON.parse(JSON.stringify(totalTabModule.data.formData))
      })
      let { userInfo } = wx.$storage.get()
      let { formData } = this.data
      let params = {
        ...busiSearchData,
        ...sortSearchData,
        serviceMerchantId: userInfo.subLoginUser.merchantId,
        pageNum: 1,
        pageSize: 99999,
      }
      this.setData({
        ['isAsk.business']: true
      })
      let apiName = formData.sceneCode == 'SC003' ? 'getActivityList' : 'getBusiStatistics'
      outputApi[apiName](params).then(res => {
        this.resetBusiData()
        if (isReset) {
          this.setData({
            busiScrollTop: 0
          })
        }
        this.setData({
          triggered: false
        })
        if (formData.sceneCode == 'SC004') {
          this.dealCrowdObj(res)
        } else if (formData.sceneCode == 'SC003') {
          let list = this.dealToTime(res?.list || [], 'SC003')
          this.getActivityTotal()
          this.setData({
            ['crowdOrderObj.activityList']: list
          })
        } else {
          let _list = []
          switch (formData.sceneCode) {
            case '-1':
              _list = res.merchantList || []
              // 0:全部-1;1:精品升级SC002;2:售后众筹SC004;3:会员权益/升级SC001
              let _openList = [{
                code: 'SC002',
                name: 'boutiqueUpgrade'
              }, {
                code: 'SC004',
                name: 'afterSalesCrowdfunding'
              }, {
                code: 'SC001',
                name: 'vdUpgrade'
              }, {
                code: 'SC003',
                name: 'carTransform'
              }]
              _list.forEach(item => {
                _openList.forEach(k => {
                  if (!item.sceneCodes) {
                    item[k.name] = '未开通'
                  } else if (item.sceneCodes && !item.sceneCodes.includes(k.code)) {
                    item[k.name] = '未开通'
                  }
                })
              })
              break
            case 'SC002':
              res.merchantList.forEach(item => {
                let _dto = item.orderSummaryTotalDTO
                _dto.calTransform = _dto.experienceCount ? Math.round((_dto.upgradeCount * 100) / _dto.experienceCount).toFixed(0) : '0'
                _dto.calUpPrice = _dto.upgradeCount ? Math.round(_dto.totalSubOrderOrderMoney / _dto.upgradeCount).toFixed(2) : '0.00'
                _list.push(_dto)
              })
              break
            case 'SC001':
              res.merchantList.forEach(item => {
                let _dto = item.quotationMerchantStatisticsDTO
                _dto.turnover = (_dto.turnover / 100).toFixed(2)
                _dto.fuseCustomerPrice = (_dto.fuseCustomerPrice / 100).toFixed(2)
                _dto.equityCustomerPrice = (_dto.equityCustomerPrice / 100).toFixed(2)
                _dto.conversionRate = (_dto.conversionRate * 100).toFixed(0)
                _list.push(_dto)
              })
              break
          }
          this.setData({
            busiObj: res,
            busiTotalList: _list
          })
        }
      }).finally(function () {
        _this.setData({
          ['isAsk.business']: false
        })
      })
    },

    // 业务经营汇总-全部-点击跳转h5
    handleBusiCardTap(e) {
      const { detail } = e
      if (detail.label != '精品升级') {
        return true
      }
      const { idx } = e.currentTarget.dataset
      let obj = this.data.busiTotalList[idx]
      let url = h5Url + '?merchantId=' + obj?.merchantId4s + '&merchantName=' + obj?.merchantName4s
      wx.$router.jumpH5(url)
    },

    // 门店经营汇总-start
    getPMerchantInfo() {
      let { userInfo } = wx.$storage.get()
      this.setData({
        pMerchantInfo: userInfo,
        pMerchantId: userInfo.subLoginUser.merchantId
      })
    },
    onBindRefresh() {
      this.clientRefresh(true)
    },
    clientRefresh(isPull = false) {
      this.getPMerchantInfo()
      this.setData({
        ['pageObj.currentPage']: 1,
        list: []
      })
      this.getClientApi(isPull)
    },
    getClientApi(isPull = false) {
      this.getProfit()
      this.getList()
      isPull &&
        wx.$api.showToast({
          title: '刷新成功',
          icon: 'success'
        })
      if (this.data.pageObj.currentPage == 1) {
        this.setData({
          scrollTop: 0,
          triggered: false
        })
      }
    },
    getProfit() {
      outputApi.getMerchantTotal({ merchantId: this.data.pMerchantId }).then(res => {
        this.setData({
          totalProfit: res
        })
      })
    },
    getList() {
      let { sceneCodeList, isAsk: { client } } = this.data
      let _this = this
      if (client) {
        return true
      }
      this.setData({
        ['isAsk.client']: true
      })
      outputApi.getCustomerPageList({ merchantId: this.data.pMerchantId, ...this.data.pageObj }).then(res => {
        var list = this.data.list
        list = list.concat(res.list)
        list.forEach((item, index) => {
          item.scenePriceList = []
          item.sceneList.forEach((k, idx) => {
            item['scene' + (idx + 1)] = item.sceneList[idx].flag
            let i = sceneCodeList.findIndex(m => m == k.sceneCode)
            item.scenePriceList[i] = {
              total: item.sceneList[idx].totalMoney || 0
            }
          })
          item.isOpenScene = item.sceneList.map(item => item.flag).some(item => item == true)
        })
        this.setData({
          list: list,
          totalPages: res.pages,
          ['pageObj.currentPage']: this.data.pageObj.currentPage + 1
        })
      }).finally(function () {
        _this.setData({
          ['isAsk.client']: false
        })
      })
    },
    onReachBottom() {
      if (this.data.totalPages != -1 && this.data.pageObj.currentPage == (this.data.totalPages + 1)) {
        return true
      }
      this.getClientApi()
    },
    handleJumpIdx() {
      wx.$router.go('pages.index')
    },

    async handleShare(e) {
      let { idx } = e.currentTarget.dataset
      var item = {
        activityId: this.data.list[idx].activityLastUnSharedInfo.id,
        activityName: this.data.list[idx].activityLastUnSharedInfo.activityName
      }
      wx.$api.showLoading('加载中...')
      outputApi
        .getPosterUrl({
          id: item.activityId
        })
        .then(res => {
          item.posterUrl = res
          this.setData({
            posterItem: item,
            isShowTip: false
          })
        })
        .catch(() => {
          wx.$api.showToast('下载海报失败')
        })
    },
    /**长按海报 */
    async longtouch(e) {
      this.clientRefresh()
      let { activityId } = e.detail
      const res = await outputApi.reportPosterTrack({
        activityId
      })
    },

    /**战报 */
    handleReport(e) {
      const { item, idx } = e.detail.currentTarget.dataset
      wx.$api.showLoading('战报生成中')
      outputApi
        .getNewReportUrl({ activityId: item.activityId })
        .then(res => {
          if (!res.url) {
            wx.$api.showToast('战报生成失败')
            return true
          }
          var posterItem = {
            ...item,
            posterUrl: res.url,
            updatedTime: deleteSecond(res.updatedDate),
            type: 'warReport'
          }
          this.setData({
            posterItem: posterItem,
            isShowTip: false
          })
          wx.$api.hideLoading()
          this.triggerEvent('handleZhanReport', { item: item, idx: idx, posterItem: posterItem })
        })
        .catch(() => {
          wx.$api.showToast('下载战报失败')
        })
        .finally(() => {
          wx.$api.hideLoading()
        })
    },
    /**喜报 */
    handleXiReport(e) {
      const { item } = e.detail.currentTarget.dataset
      wx.$api.showLoading('喜报生成中')
      outputApi
        .getNewGoodUrl({ activityId: item.activityId })
        .then(res => {
          if (!res.goodUrl) {
            wx.$api.showToast('暂无喜报')
            return true
          }
          var posterItem = {
            ...item,
            posterUrl: res.goodUrl,
            updatedTime: res.goodReportDate ? deleteSecond(res.goodReportDate) : '',
            type: 'warReport'
          }
          this.setData({
            posterItem: posterItem
          })
          wx.$api.hideLoading()
        })
        .catch(() => {
          wx.$api.showToast('下载喜报失败')
        })
        .finally(() => {
        })
    },
    handleJump(e) {
      let { idx, sceneCode } = e.currentTarget.dataset
      var currentItem = this.data.list[idx]
      var params = {
        merchantId: currentItem.merchantId,
        merchantName: currentItem.merchantName,
        pMerchantId: this.data.pMerchantId,
        pMerchantName: this.data.pMerchantInfo.subLoginUser.merchantName,
        isSuper: this.data.pMerchantInfo.isSuper
      }
      if (sceneCode == 'SC003') {
        params.fixSceneCode = sceneCode
      }
      wx.$router.go('/packagesList/packageOutput/pages/summary', params)
    }
    // 门店经营汇总-end
  }
})