zjf
2023-03-08 51468f93275c2bcfcc7ad25bf05f3d6a079ff764
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
import {
  mapGetters
} from 'vuex'
 
import { moneyFormat } from '@/utils'
 
export default {
  data () {
    return {}
  },
  props: {
    /** 是公海 默认是客户 */
    isSeas: {
      type: Boolean,
      default: false
    }
  },
 
  computed: {
    ...mapGetters(['crm']),
    // 能否查看详情
    canShowDetail () {
      // if (this.detailData.length === 0) {
      //   return false
      // }
      // return this.crm && this.crm[this.crmType] && this.crm[this.crmType].read
      return true
    }
  },
 
  watch: {
    id: function () {
      if (this.canShowDetail) {
        this.getDetial()
      }
    }
  },
 
  mounted () {
    if (this.canShowDetail) {
      this.getDetial()
    }
  },
 
  methods: {
    /** 顶部头 操作 */
    detailHeadHandle (data) {
      console.log(data)
      if (data.type === 'edit') {
        this.isCreate = true
      } else if (data.type === 'delete') {
        this.hideView()
      } else if (data.type === 'discard') {
        this.getDetial()
      }
      this.$emit('handle', data)
    },
    moneyFormat (money) {
      return moneyFormat(money)
    },
    //* * tab标签点击 */
    handleClick (tab, event) {},
    // 滚动条滚动
    onScroll (e) {
      console.log('onscrll事件')
      let scrollItems = document.querySelectorAll('.scroll-item')
      console.log(scrollItems)
      for (let i = scrollItems.length - 1; i >= 0; i--) {
        // 判断滚动条滚动距离是否大于当前滚动项可滚动距离
        let judge = e.target.scrollTop >= scrollItems[i].offsetTop - scrollItems[0].offsetTop
        // console.log(e.target.scrollTop, scrollItems[i].offsetTop, scrollItems[0].offsetTop)
        if (judge) {
          this.tabCurrentName = this.tabnames[i].name
 
          break
        }
      }
    },
    jump (index, info) {
      console.log(index, info, this.tabCurrentName)
      let target = document.querySelector('.t-loading-content')
      let scrollItems = document.querySelectorAll('.scroll-item')
      // 判断滚动条是否滚动到底部
      if (target.scrollHeight <= target.scrollTop + target.clientHeight) {
        this.tabCurrentName = this.tabnames[index.index].name
      }
      let totalY = scrollItems[index.index].offsetTop - scrollItems[0].offsetTop // 锚点元素距离其offsetParent(这里是body)顶部的距离(待滚动的距离)
      let distance = document.querySelector('.t-loading-content').scrollTop // 滚动条距离滚动区域顶部的距离
      // let distance = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset // 滚动条距离滚动区域顶部的距离(滚动区域为窗口)
      // 滚动动画实现, 使用setTimeout的递归实现平滑滚动,将距离细分为50小段,10ms滚动一次
      // 计算每一小段的距离
      let step = totalY / 50
      if (totalY > distance) {
        smoothDown(document.querySelector('.t-loading-content'))
      } else {
        let newTotal = distance - totalY
        step = newTotal / 50
        smoothUp(document.querySelector('.t-loading-content'))
      }
 
      // 参数element为滚动区域
      function smoothDown (element) {
        if (distance < totalY) {
          distance += step
          element.scrollTop = distance
          setTimeout(smoothDown.bind(this, element), 10)
        } else {
          element.scrollTop = totalY
        }
      }
 
      // 参数element为滚动区域
      function smoothUp (element) {
        if (distance > totalY) {
          distance -= step
          element.scrollTop = distance
          setTimeout(smoothUp.bind(this, element), 10)
        } else {
          element.scrollTop = totalY
        }
      }
    }
  },
 
  deactivated: function () { }
 
}