StoreMessage.js 6.32 KB
// packageCustomer/components/StoreMessage/StoreMessage.js
import { IMG_URL } from '~/utils/constantData'
Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    // 盈亏与展业等摘要信息
    summary: {
      type: Object,
      value: {
        profit: { ok: true, text: '盈利情况' },
        business: { ok: true, text: '展业情况', warningCount: 0 },
        bottomMetric: {
          title: '渗透率临近业务兜底指标',
          periodIndex: 0.1094, // 10.94%
          bottomRequire: 0.5 // 50%
        }
      }
    },
    // 兜底指标预警列表
    warnings: {
      type: Array,
      value: [
        { title: '轮胎转化率临近业务兜底指标预警', periodIndex: 0.1094, bottomRequire: 0.5 },
        { title: '安心包转化率临近业务兜底指标预警', periodIndex: 0.1094, bottomRequire: 0.5 },
        { title: '转化率临近业务兜底指标预警', periodIndex: 0.1094, bottomRequire: 0.5 }
      ]
    },
    // 驻店人员列表
    residents: {
      type: Array,
      value: [
        // { role: '店总', name: '李四', phone: '13510769158' },
        // { role: '王五', name: '王五', phone: '13510769158' }
      ]
    },
    // 默认展开的折叠项(自定义折叠仍可参考该配置)
    defaultActive: {
      type: Array,
      value: ['bottom', 'residents']
    }
  },

  data: {
    IMG_URL,
    activeNames: [],
    // 自定义折叠展开状态
    showBusiness: false,
    showBottom: false,
    // 动画对象
    businessAnimation: {},
    bottomAnimation: {},
    infoData: {
      displaySituationWarningCount: 5,
      safetyIndexWarningCount: 2,
      profitAndLoss: 2,
      // 展业情况测试数据
      displaySituationWarningList: [],
      // 兜底指标预警测试数据
      safetyIndexWarningList: [{
        rule: '轮胎转化率临近业务兜底指标预警',
        cycleIndicator: 50,
        fallbackIndicator: 20
      }, {
        rule: '安心包转化率临近业务兜底指标预警',
        cycleIndicator: 35,
        fallbackIndicator: 25
      }, {
        rule: '保险产品转化率临近业务兜底指标预警',
        cycleIndicator: 28,
        fallbackIndicator: 30
      }, {
        rule: '增值服务转化率临近业务兜底指标预警',
        cycleIndicator: 45,
        fallbackIndicator: 40
      }, {
        rule: '客户满意度临近业务兜底指标预警',
        cycleIndicator: 38,
        fallbackIndicator: 35
      }],
      storePersonnel: [{
        personnelName: '王五王五王五王五王五王五王五王五王五王五王五',
        personnelMobile: 13510769158
      }, {
        personnelName: '王五',
        personnelMobile: 13510769158
      }]
    }
  },

  lifetimes: {
    attached() {
      // 初始化展开状态:仅在有数据时允许展开
      const hasBusiness = (this.data.infoData?.displaySituationWarningList || []).length > 0
      const hasBottom = (this.data.infoData?.safetyIndexWarningList || []).length > 0
      this.setData({
        showBusiness: hasBusiness ? false : false,
        showBottom: hasBottom ? false : false
      })
    }
  },

  methods: {
    // 兼容之前 collapse 的回调(不再使用)
    onCollapseChange(e) {
      this.setData({ activeNames: e.detail })
    },
    // 切换展业情况展开
    toggleBusiness(e) {
      const has = Number(e?.currentTarget?.dataset?.has || 0)
      if (!has) return
      
      const isExpanding = !this.data.showBusiness
      this.setData({ showBusiness: isExpanding })
      
      if (isExpanding) {
        this.expandPanel('business')
      } else {
        this.collapsePanel('business')
      }
    },
    // 切换兜底预警展开
    toggleBottom(e) {
      const has = Number(e?.currentTarget?.dataset?.has || 0)
      if (!has) return
      
      const isExpanding = !this.data.showBottom
      this.setData({ showBottom: isExpanding })
      
      if (isExpanding) {
        this.expandPanel('bottom')
      } else {
        this.collapsePanel('bottom')
      }
    },
    getDetailData() {
      let { infoData } = this.data
      infoData.safetyIndexWarningList?.forEach(val => {
        val.cycleIndicator = this.formatPercent(val.cycleIndicator)
        val.fallbackIndicator = this.formatPercent(val.fallbackIndicator)
      })
      this.setData({
        infoData
      })
    },
    formatPercent(n) {
      const rate = Number(n || 0)
      return `${rate.toFixed(2)}%`
    },
    
    // 展开面板动画
    expandPanel(type) {
      const contentSelector = type === 'business' ? '.business-content' : '.bottom-content'
      const animationKey = type === 'business' ? 'businessAnimation' : 'bottomAnimation'
      
      // 先临时设置为auto高度以获取实际高度
      const tempAnimation = wx.createAnimation({
        duration: 0,
        timingFunction: 'ease'
      })
      tempAnimation.height('auto').opacity(1).step()
      this.setData({
        [animationKey]: tempAnimation.export()
      })
      
      // 下一帧获取内容实际高度并应用动画
      setTimeout(() => {
        wx.createSelectorQuery().in(this).select(contentSelector).boundingClientRect((rect) => {
          if (rect && rect.height > 0) {
            // 先设置为0,然后动画到实际高度
            const startAnimation = wx.createAnimation({
              duration: 0,
              timingFunction: 'ease'
            })
            startAnimation.height('0px').opacity(0).step()
            
            const endAnimation = wx.createAnimation({
              duration: 300,
              timingFunction: 'ease'
            })
            endAnimation.height(rect.height + 'px').opacity(1).step()
            
            this.setData({
              [animationKey]: startAnimation.export()
            })
            
            setTimeout(() => {
              this.setData({
                [animationKey]: endAnimation.export()
              })
            }, 50)
          }
        }).exec()
      }, 50)
    },
    
    // 收起面板动画
    collapsePanel(type) {
      const animationKey = type === 'business' ? 'businessAnimation' : 'bottomAnimation'
      
      const animation = wx.createAnimation({
        duration: 300,
        timingFunction: 'ease'
      })
      
      animation.height('0px').opacity(0).step()
      this.setData({
        [animationKey]: animation.export()
      })
    }
  }
})