summary.js 26.8 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 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
// packageOutput/pages/summary/summary.js
import outputApi from '~/api/outputApi/index'
import { getMockData } from '~/api/api'
import { IMG_URL } from '~/utils/constantData'
import { getNowMonth } from '~/utils/format'
import utils from '~/utils/util.js'
const defaultSceneCode = 'SC004'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    sceneCodeList: ['SC002', 'SC003', 'SC004', 'SC001'],
    merchantInfo: {},
    sceneInfo: {
      sceneList: [{
        sceneCode: "SC002", flag: false
      }, {
        sceneCode: "SC003", flag: false
      }, {
        sceneCode: "SC004", flag: false
      }, {
        sceneCode: "SC001", flag: false
      }]
    },
    sceneData: {},
    sceneCodeActive: defaultSceneCode,
    scenePriceList: [
      {
        total: 0.0
      },
      {
        total: 0.0
      },
      {
        total: 0.0
      },
      {
        total: 0.0
      }
    ],
    isShowService: false,
    // 活动内容
    scrollLeft: 0,
    activityActive: 0,
    activityList: [],
    sceneActivityObj: {
      scene0: [],
      scene1: [],
      scene2: [],
      scene3: []
    },
    fixScenceCode: '-1',
    // 产值
    searchForm: {
      sceneSC002: 0,
      sceneSC003: 0,
      sceneSC004: 0
    },
    baseData: {
      timeList: ['全部', '本月', '本日'],
      actStatusList: ['全部', '申请中', '活动中', '已结束']
    },
    mockObj: {},
    isMock: {
      'SC001': false,
      'SC002': false,
      'SC003': false,
      'SC004': false
    }
  },

  // 场景切换
  handleSceneChange(e) {
    var sceneCode = e.detail.sceneCode
    this.setData({
      sceneCodeActive: sceneCode,
      activityActive: 0
    })
    if (!this.data.sceneActivityObj['scene' + this.findSceneIdx()].length) {
      this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()])
      return true
    }
    if (['SC002', 'SC003'].includes(this.data.sceneCodeActive)) {
      this.getCustomerDetail(false, false)
    } else {
      this.setCurActivity()
    }
  },

  // 活动切换
  handleActChange(e) {
    var idx = e.currentTarget.dataset.idx
    this.setData({
      activityActive: idx,
      // productStatus:0未申请;1申请中;2已开通;3:已结束
      isShowData: [2, 3].includes(+this.data.activityList[idx].productStatus)
    })
    if (['SC002', 'SC003'].includes(this.data.sceneCodeActive)) {
      this.getCustomerDetail(false, false)
    }
  },

  setCurActivity() {
    this.setData({
      activityList: JSON.parse(JSON.stringify(this.data.sceneActivityObj['scene' + this.findSceneIdx()])),
      // productStatus:0未申请;1申请中;2已开通;3:已结束
      isShowData: [2, 3].includes(+this.data.sceneActivityObj['scene' + this.findSceneIdx()][this.data.activityActive].productStatus)
    })
    // activityActive为0时,触发置顶(左)
    if (this.data.activityActive == 0) {
      this.setData({
        scrollLeft: 0
      })
    }
  },

  // 搜索条件切换
  handleSearch() {
    wx.showActionSheet({
      itemList: this.data.sceneCodeActive != 'SC002' ? this.data.baseData.actStatusList : this.data.baseData.timeList,
      success: res => {
        this.setData({
          ['searchForm.scene' + this.data.sceneCodeActive]: res.tapIndex
        })
        this.data.sceneCodeActive != 'SC004' ? this.getCustomerDetail(false, false) : this.getActivityRevenue()
      }
    })
  },

  handleJump(e) {
    var params = {
      merchantInfo: this.data.merchantInfo,
      sceneCodeActive: this.data.sceneCodeActive,
      sceneCodeList: this.data.sceneCodeList
    }
    wx.$router.go('packagesList.openBusiness', params)
  },

  // 将已开通的活动提前
  // productStatus:0未申请;1申请中;2已开通;3:已结束
  dealOpenActivity(list) {
    list.forEach(item => {
      let tempList = []
      let idx = 0
      item.productList.forEach(k => {
        k.productStatus == 2 ? tempList.splice(idx++, 0, k) : tempList.push(k)
      })
      item.productList = tempList
    })
    return list
  },

  // 定位已开通的场景,默认定位至场景4
  findOpenScene() {
    let sceneCodeActive = defaultSceneCode
    if (this.data.fixScenceCode != '-1') {
      this.setData({
        sceneCodeActive: this.data.fixScenceCode || 'SC004'
      })
      return
    }
    const list = []
    this.data.sceneCodeList.forEach(item => {
      let sceneIsOpen = this.data.sceneData.find(k => k.sceneCode == item)?.sceneIsOpen
      list.push(sceneIsOpen)
    })
    // 全场景都没开通或场景4开通,则默认定位至场景4
    if (list[this.findSceneIdx(defaultSceneCode)] || !list.some(item => item == true)) {
      return true
    }
    // 开通sc002和sc003场景:默认定位至sc002场景,否则定位至已开通的场景
    sceneCodeActive = list[this.findSceneIdx('SC002')] ? 'SC002' : 'SC003'
    if (!list[this.findSceneIdx('SC002')] && !list[this.findSceneIdx('SC002')]) {
      sceneCodeActive = 'SC001'
    }
    this.setData({
      sceneCodeActive: sceneCodeActive
    })
  },

  getSceneProStatus(sceneCode, isFirst = false) {
    var params = {
      serviceMerchantId: this.data.merchantInfo.pMerchantId,
      merchant4sId: this.data.merchantInfo.merchantId,
      sceneCode: sceneCode
    }
    outputApi.getSceneProStatus(params).then(res => {
      console.log(res, 'res---')
      var data = this.dealOpenActivity(res)
      var sceneActivityObj = {}
      // sceneStatus:0未开通 1已开通
      res.forEach((item, index) => {
        let idx = this.findSceneIdx(item.sceneCode)
        if (idx != -1) {
          this.data.sceneInfo.sceneList[idx].flag = item.sceneStatus == 1
          item.sceneIsOpen = item.sceneStatus == 1
          sceneActivityObj['scene' + idx] = item.sceneCode == 'SC003' ? [data[index].productList.find(k => k.productCode == 'PC012')] : data[index].productList
        }
      })
      console.log(sceneActivityObj, 'sceneActivityObj--')
      this.setData({
        sceneData: res,
        sceneInfo: this.data.sceneInfo,
        sceneActivityObj: sceneActivityObj
      })
      // 首次进入,默认定位至SC004场景;需要调获取SC002和SC003场景的接口,以计算这两个场景的总额
      if (isFirst) {
        this.findOpenScene()
        if (!['SC002', 'SC003'].includes(this.data.sceneCodeActive)) {
          this.getCustomerDetail(isFirst)
        }
        if (!['SC001'].includes(this.data.sceneCodeActive) && this.data.sceneInfo.sceneList[this.findSceneIdx('SC001')].flag) {
          this.getEquityRevenue(isFirst)
        }
        if (!['SC004'].includes(this.data.sceneCodeActive) && this.data.sceneInfo.sceneList[this.findSceneIdx('SC004')].flag) {
          this.getActivityRevenue(isFirst)
        }
      }
      if (['SC002', 'SC003'].includes(this.data.sceneCodeActive)) {
        this.getCustomerDetail()
      } else if (this.data.sceneCodeActive == 'SC001') {
        this.getEquityRevenue()
      } else if (this.data.sceneCodeActive == defaultSceneCode) {
        this.getActivityRevenue()
      } else {
        this.setCurActivity()
      }
    })
  },

  initTime() {
    let date = new Date()
    let today = date.getDate()
    let month = getNowMonth()
    const todayTime = {
      startTime: `${month}-${today} 00:00:00`,
      endTime: `${month}-${today} 23:59:59`
    }
    const monthTime = {
      startTime: `${month}-01 00:00:00`,
      endTime: `${month}-${today} 23:59:59`
    }
    const defaultTime = {
      startTime: '',
      endTime: `${month}-${today} 23:59:59`
    }
    this.setData({
      dataObj: {
        todayTime,
        monthTime,
        defaultTime
      }
    })
  },

  dealSearchTime() {
    var params = {}
    // switch (this.data.searchForm['scene' + this.data.sceneCodeActive]) {
    switch (this.data.searchForm['sceneSC002']) {
      // 本月
      case 1:
        params = this.data.dataObj.monthTime
        break
      // 本日
      case 2:
        params = this.data.dataObj.todayTime
        break
    }
    return params
  },

  /**
   * 查询SC001场景值
   */
  getEquityRevenue(isFirst = false) {
    // outputApi.getEquityRevenue({ merchantId: this.data.merchantInfo.merchantId }).then(res => {
    outputApi.getEquityRevenue({ merchantIds: [this.data.merchantInfo.merchantId] }).then(res => {
      // outputApi.getEquityRevenue({ merchantIds: ['44211227'] }).then(res => {
      if (res.length) {
        var actList = this.data.sceneActivityObj['scene' + this.findSceneIdx('SC001')]
        var actCodeList = actList.map(item => item.productCode)
        var total = 0
        res.forEach((item, idx) => {
          // var idx = actCodeList.findIndex(i => i == item.productCode)
          // var orderTotal = item.orderTotal
          // if (item.orderTotal) {
          //   total = (total + Number(item.orderTotal?.totalAmount)).toFixed(2)
          //   item.orderTotal.totalAmount = utils.moneyThreeForTwoThousands(Number(orderTotal.totalAmount).toFixed(2))
          //   item.orderTotal.monthAmount = Number(orderTotal.monthAmount).toFixed(2)
          //   item.orderTotal.price = Number(orderTotal.price).toFixed(2)
          // }
          item.conversionRate = (item.conversionRate * 100).toFixed(0)
          item.turnover = (item.turnover / 100).toFixed(2)
          item.fuseCustomerPrice = (item.fuseCustomerPrice / 100).toFixed(2)
          item.equityCustomerPrice = (item.equityCustomerPrice / 100).toFixed(2)
          total = item.turnover
          actList[idx] = {
            ...actList[idx],
            orderTotal: res[idx]
          }
        })
        if (!isFirst) {
          this.setData({
            ['sceneActivityObj.scene' + this.findSceneIdx()]: actList
          })
          this.setCurActivity()
        }
        this.setData({
          ['scenePriceList[' + this.findSceneIdx('SC001') + '].total']: total
        })
      }
    })
  },

  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(isFirst) {
    let params = {
      ...this.dealSC003SearchStatus(),
      serviceMerchantId: this.data.merchantInfo.pMerchantId,
      merchantId: this.data.merchantInfo.merchantId,
    }
    outputApi.getActivityStatistics(params).then(res => {
      this.setData({
        ['scenePriceList[' + this.findSceneIdx('SC003') + '].total']: (res.totalOutputValue / 100).toFixed(2)
      })
      this.getBusiStatistics(isFirst, res)
    })
  },

  // SC003
  getBusiStatistics(isFirst, totalObj) {
    let { userInfo } = wx.$storage.get()
    let params = {
      ...this.dealSC003SearchStatus(),
      pageNum: 1,
      pageSize: 99999,
      serviceMerchantId: userInfo.subLoginUser.merchantId,
      merchantId: this.data.merchantInfo.merchantId
    }
    outputApi.getActivityList(params).then(res => {
      let list = this.dealToTime(res?.list || [], 'SC003')
      let _obj = {
        activityList: list,
        totalAmount: (totalObj.totalOutputValue / 100).toFixed(2),
        totalNum: totalObj.totalActivityCount,
        totalOrderCount: totalObj.totalOrderCount
      }
      this.setData({
        ['sceneActivityObj.scene' + this.findSceneIdx('SC003') + '[0].outputData']: _obj
      })
      if (!isFirst) {
        this.setCurActivity()
      }
    }).finally(function () {
    })
  },

  /** sc002和sc003场景产品数据处理
   * 调同一个接口,返回两个场景下面的全部产品的数据
   */
  getCustomerDetail(isFirst = false, isChangeOtherTotal = true) {
    var params = this.dealSearchTime()
    outputApi.getCustomerDetail({ merchantId: this.data.merchantInfo.merchantId, ...params }).then(res => {
      // var actList = this.data.sceneActivityObj['scene' + (isFirst ? this.findSceneIdx('SC002') : this.findSceneIdx())]
      var actList = this.data.sceneActivityObj['scene' + this.findSceneIdx('SC002')]
      var actCodeList = actList.map(item => item.productCode)
      var curTotal = 0
      // var otherTotal = 0
      // var otherSceneIdx = isFirst ? this.findSceneIdx('SC002') : this.data.sceneCodeActive == 'SC002' ? this.findSceneIdx('SC003') : this.findSceneIdx('SC002')
      let obj = this.judgeUpgrade()
      res.forEach(item => {
        var idx = actCodeList.findIndex(i => i == item.productCode)
        if (idx != -1) {
          var orderTotal = item.orderTotal
          if ((isFirst || this.data.sceneCodeActive == 'SC002') && obj.flag) {
            let upgradeObj = this.data.mockObj.upgradeObj[obj.idx]
            item.orderTotal = upgradeObj.orderTotal
          } else if (item.orderTotal) {
            item.orderTotal.calCustomerUnitPrice = orderTotal.upgradeCount ? Math.round((orderTotal.totalSubOrderOrderMoney / orderTotal.upgradeCount).toFixed(2) * 100) / 100 : '0.00'
            item.orderTotal.calExperience = orderTotal.toShopCount ? Math.round((orderTotal.experienceCount * 100) / orderTotal.toShopCount).toFixed(0) : '0'
            item.orderTotal.calTransform = orderTotal.experienceCount ? Math.round((orderTotal.upgradeCount * 100) / orderTotal.experienceCount).toFixed(0) : '0'
          }
          actList[idx] = {
            ...actList[idx],
            orderTotal: item.orderTotal
          }
          curTotal = curTotal + (+item.orderTotal?.totalSubOrderOrderMoney || 0)
        }
        // else {
        //   otherTotal = otherTotal + (+item.orderTotal?.totalSubOrderOrderMoney || 0)
        // }
      })
      if (!isFirst) {
        this.setData({
          ['sceneActivityObj.scene' + this.findSceneIdx('SC002')]: actList
        })
      }
      // 总金额
      this.setData({
        // ['scenePriceList[' + (isFirst ? this.findSceneIdx('SC002') : this.findSceneIdx()) + '].total']: curTotal.toFixed(2)
        ['scenePriceList[' + this.findSceneIdx('SC002') + '].total']: curTotal.toFixed(2)
      })
      // if (isChangeOtherTotal) {
      //   this.setData({
      //     ['scenePriceList[' + (isFirst ? this.findSceneIdx('SC003') : otherSceneIdx) + '].total']: otherTotal.toFixed(2)
      //   })
      // }
      //sceneActivityObj
      this.getActivityTotal(isFirst)
      !isFirst && this.setCurActivity()
    })
  },

  dealSC003SearchStatus() {
    var params = {}
    switch (this.data.searchForm['scene' + this.data.sceneCodeActive]) {
      // 申请中
      case 1:
        params.activityStatus = '1'
        break
      // 活动中
      case 2:
        params.activityStatus = '2'
        break
      // 已结束
      case 3:
        params.activityStatus = '3'
        break
    }
    return params
  },

  dealSearchStatus() {
    var params = {}
    switch (this.data.searchForm['scene' + this.data.sceneCodeActive]) {
      case 0:
        params.activityStatuList = [1, 2, 3]
        break
      // 申请中
      case 1:
        params.activityStatuList = [1]
        break
      // 活动中
      case 2:
        params.activityStatuList = [2]
        break
      // 已结束
      case 3:
        params.activityStatuList = [3]
        break
    }
    return params
  },

  /**处理SC004的数据 */
  mockDealCrowd(data) {
    var obj = this.judgeCrowd(this.data.merchantInfo.pMerchantId, data.merchantId)
    if (!obj.flag) {
      return data
    }
    var mockActivityList = this.data.mockObj?.crowdObj[obj.pIdx].merchantList[obj.idx].activityList
    var actIds = mockActivityList.map(item => item.activityId)
    data.activityList.forEach(item => {
      let idx = actIds.findIndex(k => k == item.activityId)
      if (idx != -1) {
        item.activityName = mockActivityList[idx].activityName
        item.mockPoster = mockActivityList[idx].postUrl
      }
    })
    return data
  },

  /** 查询场景4的产值 */
  getActivityRevenue(isFirst = false) {
    wx.showLoading()
    var params = this.dealSearchStatus()
    outputApi
      .getActivityRevenue({ merchantId: this.data.merchantInfo.merchantId, ...params })
      .then(res => {
        var actList = this.data.sceneActivityObj['scene' + (isFirst ? this.findSceneIdx('SC004') : this.findSceneIdx())]
        var total = 0
        res.forEach(item => {
          total = total + item.totalAmount
        })
        var activitingIdx = -1
        actList.forEach((item, idx) => {
          var curItem = res.find(k => k.goodsCategoryCode == item.productCode)
          if (curItem) {
            curItem = this.mockDealCrowd(curItem)
            curItem.totalNum = curItem.activityList.length
            curItem.shareBtnIdx = -1
            let shareFlag = false
            curItem.activityList.forEach((k, kIdx) => {
              // 分享按钮判断shareStatus:活动分享状态 0:未分享  1:已分享
              if (k.activityStatus == 2 && k.shareStatus == 0) {
                curItem.shareBtnIdx = shareFlag ? -1 : kIdx + ''
                shareFlag = true
              }
              // 时间
              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
              }
              k.suggestTxtList = []
              k.suggestList = []
              if (k.activityStatus == 2) {
                k.suggestTxtList.push('距离活动结束剩余' + k.toEndDays + '天')
                if (k.visitCount < 200) {
                  k.suggestTxtList.push('低于200个独立访客')
                  k.suggestList.push('低于200个独立访客,触达车主的数量太少,建议与4S店关键人沟通注册员工的转发执行情况')
                }
                if (k.shareRate < 0.4) {
                  k.suggestTxtList.push('分享员工占比低于40%')
                  k.suggestList.push('分享员工占比低于40%,建议与4S店关键人沟通下注册员工的转发执行情况')
                }
                if (k.conversionRate < 0.05) {
                  k.suggestTxtList.push('点击转化率低于5%')
                  k.suggestList.push('点击转化率低于5%,建议调整该产品的品类话术和营销内容')
                }
                k.suggestTxt = k.suggestTxtList.join(',') + '。'
              }
            })
            // 定位进行中的活动
            if (activitingIdx == -1 && curItem.shareBtnIdx != -1) {
              activitingIdx = idx
            }
            actList[idx].outputData = curItem
          } else {
            actList[idx].outputData = []
          }
        })
        if (!isFirst) {
          this.setData({
            ['sceneActivityObj.scene' + this.findSceneIdx()]: actList
          })
          this.setCurActivity()
        }
        if (this.data.sceneCodeActive == 'SC004' && activitingIdx != -1) {
          var params = {
            currentTarget: {
              dataset: {
                idx: activitingIdx
              }
            }
          }
          this.handleActChange(params)
        }
        this.setData({
          ['scenePriceList[' + this.findSceneIdx('SC004') + '].total']: total.toFixed(2)
        })
      })
      .finally(() => {
        wx.hideLoading()
      })
  },

  // 分享母链
  async handleBtnShare(e) {
    const idx = this.data.activityList[this.data.activityActive].outputData.shareBtnIdx
    const item = this.data.activityList[this.data.activityActive].outputData.activityList[idx]
    // const posterObj = this.selectComponent('#crowdPoster')
    const { options } = wx.$router.getPageInstance()
    // try {
    //   let flag = await posterObj.check(item)
    //   posterObj.setData({
    //     poster: flag,
    //     show: true
    //   })
    // } catch (error) {
    if (item.mockPoster) {
      item.posterUrl = item.mockPoster

      this.setData({
        crowdPosterItem: item,
        isShowTip: false
      })
      return
    }
    wx.$api.showLoading('加载中...')
    outputApi
      .getPosterUrl({
        id: item.activityId
      })
      .then(res => {
        item.posterUrl = res
        this.setData({
          crowdPosterItem: item,
          isShowTip: false
        })
      })
      .catch(() => {
        wx.$api.showToast('下载海报失败')
      })
    // }
  },
  /**长按海报 */
  async longtouch(e) {
    let { activityId } = e.detail
    const res = await outputApi.reportPosterTrack({
      activityId
    })
    wx.$eventbus.emit('clientRefresh')
    this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()])
  },

  // 母链分享
  posterTrack() {
    wx.$eventbus.emit('clientRefresh')
    this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()])
  },

  // 战报
  handleZhanReport(e) {
    const { idx, posterItem } = e.detail
    this.setData({
      ['sceneActivityObj.scene' + this.findSceneIdx() + '[' + this.data.activityActive + '].outputData.activityList[' + idx + '].reportDate']: posterItem.date
    })
    this.setCurActivity()
  },

  // 精品升级-SC002
  judgeUpgrade(pId, id) {
    let res = {
      flag: false,
      idx: -1
    }
    let pMerchantId = pId || this.data.merchantInfo.pMerchantId
    let merchantId = id || this.data.merchantInfo.merchantId
    if (this.data.mockObj?.upgradeObj) {
      let pList = this.data.mockObj.upgradeObj.map(item => item.pMerchantId)
      for (let i = 0; i < this.data.mockObj.upgradeObj.length; i++) {
        let item = this.data.mockObj.upgradeObj[i]
        if (item.pMerchantId == pMerchantId && item.merchantId == merchantId) {
          res = {
            flag: true,
            idx: i
          }
          break
        }
      }
    }
    return res
  },

  // 售后众筹-SC004
  judgeCrowd(pId, id) {
    let res = {
      flag: false,
      pIdx: -1,
      idx: -1
    }
    if (this.data.mockObj?.crowdObj) {
      let pList = this.data.mockObj.crowdObj.map(item => item.pMerchantId)
      for (let i = 0; i < this.data.mockObj.crowdObj.length; i++) {
        let item = this.data.mockObj.crowdObj[i]
        let cList = item.merchantList.map(k => k.merhantId)
        if (cList.includes((id || this.data.merchantInfo.merchantId) + '') && pList.includes((pId || this.data.merchantInfo.pMerchantId) + '')) {
          res = {
            flag: true,
            pIdx: i,
            idx: cList.findIndex(k => k == (id || this.data.merchantInfo.merchantId))
          }
          break
        }
      }
    }
    return res
  },

  // 判断是否Mock数据写死
  judgeAccount() {
    // 精品升级-SC002
    // 售后众筹-SC004
    this.setData({
      ['isMock.SC002']: this.judgeUpgrade().flag,
      ['isMock.SC004']: this.judgeCrowd().flag
    })
  },

  async getMockInfo(userInfo) {
    let res = await getMockData() || { serviceMerchatList: [] }
    this.setData({
      mockObj: res,
      isShowService: res.serviceMerchatList.includes(userInfo.merchantId + '')
    })
  },

  // 二维码自动登录
  onRoute(options) {
    if (!options.hasOwnProperty('fixScenceCode')) {
      return
    }
    this.setData({
      merchantInfo: options,
      fixScenceCode: options.fixScenceCode
    })

    let { userInfo } = wx.$storage.get()
    // var res = await getMockData()
    this.getMockInfo(userInfo)
    this.judgeAccount()
    this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()], true)
  },

  /**
   * 生命周期函数--监听页面加载
   * 从client跳转
   */
  onLoad(options) {
    this.initTime()
    wx.$router.getData(obj => {
      this.setData({
        merchantInfo: obj,
      })
      if (obj.fixSceneCode) {
        this.setData({
          sceneCodeActive: obj.fixSceneCode,
          fixScenceCode: obj.fixSceneCode
        })
      }

      let { userInfo } = wx.$storage.get()
      this.getMockInfo(userInfo)
      this.judgeAccount()
      this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()], true)
    })
  },

  // 查找当前高亮场景的idx
  findSceneIdx(sceneCode = this.data.sceneCodeActive) {
    return this.data.sceneCodeList.findIndex(item => item == sceneCode)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    wx.setNavigationBarTitle({
      title: this.data.merchantInfo?.merchantName
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.initTime()
    this.setData({
      activityActive: 0,
      sceneCodeActive: defaultSceneCode,
    })
    wx.$api.showToast({
      title: '刷新成功',
      icon: 'success'
    })
    this.getSceneProStatus(this.data.sceneCodeList[this.findSceneIdx()], true)
  }
})