StatisticsMobile.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div class="statistics">
  3. <ul class="list-inline pull-left" ref="pingdanListWrapperL" :style="'top: -' + 0.7 * timerIndexL + 'rem'" :class="{'topL': isTopL}">
  4. <li v-for="(item, index) in itemLeft">
  5. <span class="number">
  6. <span class="name" v-html="nameLeft[index]"></span>
  7. <span class="num" v-html="formatNumber(item.count, item.type)"></span>
  8. <span class="unit" v-if="item.type === 3">家</span>
  9. </span>
  10. </li>
  11. </ul>
  12. <ul class="list-inline pull-right" ref="pingdanListWrapperR" :style="'top: -' + 0.7 * timerIndexR + 'rem'" :class="{'topR': isTopR}">
  13. <li v-for="(item, index) in itemRight">
  14. <span class="number" v-if="item.type === 2">
  15. <span class="name" v-html="nameRight[index]"></span>
  16. <span class="month" v-if="item.id === '上月询价单'">(上月)</span>
  17. <span class="month" v-if="item.id === '本月询价单'">(本月)</span>
  18. <span class="num" v-html="formatDouble(item.count)"></span>
  19. <span class="unit">条</span>
  20. </span>
  21. <span class="number" v-else>
  22. <span class="name" v-html="nameRight[index]"></span>
  23. <span class="num" v-html="formatNumber(item.count, item.type)"></span>
  24. </span>
  25. </li>
  26. </ul>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'StatisticsView',
  32. data () {
  33. return {
  34. step: 1,
  35. nameLeft: ['现货', '品牌', '规格书', '平台用户', '店铺'],
  36. nameRight: ['询价求购', '询价求购', '上年交易', '本年交易'],
  37. topLeft: 0,
  38. topRight: 0,
  39. // timer: {},
  40. // timerIndex: 0,
  41. timerIndexL: 0,
  42. timerIndexR: 0,
  43. isTopL: false,
  44. isTopR: false,
  45. timerL: {},
  46. timerR: {}, // 定时器实体
  47. imgbox: {
  48. 'src': ''
  49. }
  50. }
  51. },
  52. mounted () {
  53. this.$nextTick(() => {
  54. this.changeIntervalL(true)
  55. this.changeIntervalR(true)
  56. })
  57. },
  58. methods: {
  59. changeIntervalL: function (flag) {
  60. if (flag) {
  61. this.timerL = setInterval(() => {
  62. this.isTopL = false
  63. let isChange = true
  64. this.timerIndexL++
  65. if (this.$refs.pingdanListWrapperL) {
  66. let _transitionEvent = this.baseUtils.whichTransitionEvent()
  67. _transitionEvent && this.$refs.pingdanListWrapperL.addEventListener(
  68. _transitionEvent, () => {
  69. if (isChange) {
  70. let title = this.itemLeft.shift()
  71. let name = this.nameLeft.shift()
  72. this.itemLeft.push(title)
  73. this.nameLeft.push(name)
  74. this.timerIndexL = 0
  75. isChange = false
  76. this.isTopL = true
  77. }
  78. })
  79. }
  80. }, 2400)
  81. } else {
  82. clearInterval(this.timerL)
  83. }
  84. },
  85. changeIntervalR: function (flag) {
  86. if (flag) {
  87. this.timerR = setInterval(() => {
  88. this.isTopR = false
  89. let isChange = true
  90. this.timerIndexR++
  91. if (this.$refs.pingdanListWrapperR) {
  92. let _transitionEvent = this.baseUtils.whichTransitionEvent()
  93. _transitionEvent && this.$refs.pingdanListWrapperR.addEventListener(
  94. _transitionEvent, () => {
  95. if (isChange) {
  96. let title = this.itemRight.shift()
  97. let name = this.nameRight.shift()
  98. this.itemRight.push(title)
  99. this.nameRight.push(name)
  100. this.timerIndexR = 0
  101. isChange = false
  102. this.isTopR = true
  103. }
  104. })
  105. }
  106. }, 3000)
  107. } else {
  108. clearInterval(this.timerR)
  109. }
  110. },
  111. formatNumber (num, type) {
  112. if (num === '' || !num) return 0
  113. if (num.toString().indexOf('E') !== -1) {
  114. let arr = num.toString().split('E')
  115. num = arr[0] * Math.pow(10, arr[1])
  116. }
  117. if (num > 99999999) {
  118. let str2 = num.toString()
  119. num = Math.floor(num / 100000000)
  120. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  121. num = num + 1
  122. }
  123. num = num + '亿'
  124. } else if (num > 9999) {
  125. let str = num.toString()
  126. num = Math.floor(num / 10000)
  127. if (parseInt(str.charAt(str.length - 4)) > 4) {
  128. num = num + 1
  129. }
  130. num += '万'
  131. } else {
  132. if (type === 4) {
  133. num += '元'
  134. } else if (type === 1) {
  135. num += '个'
  136. } else {
  137. num += ''
  138. }
  139. }
  140. return num || 0
  141. },
  142. formatDouble (num) {
  143. if (num === '' || !num) return 0
  144. if (num.toString().indexOf('E') !== -1) {
  145. let arr = num.toString().split('E')
  146. num = arr[0] * Math.pow(10, arr[1])
  147. }
  148. if (num > 99999999) {
  149. num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '亿'
  150. } else if (num > 9999) {
  151. num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '万'
  152. } else {
  153. num += ''
  154. }
  155. return num || 0
  156. }
  157. },
  158. computed: {
  159. counter () {
  160. return this.$store.state.option.counter.data
  161. },
  162. inquirySheet () {
  163. let sheetNum = this.$store.state.count.inquirySheet.data
  164. return sheetNum ? this.formatDouble(sheetNum.count) : 0
  165. },
  166. inquirySheetLast () {
  167. let lastSheetNum = this.$store.state.count.inquirySheetLast.data
  168. return lastSheetNum ? this.formatDouble(lastSheetNum.count) : 0
  169. },
  170. itemData () {
  171. let str = []
  172. if (this.counter.length) {
  173. this.counter.forEach((value, key, $data) => {
  174. if($data[key].item === '店铺') {
  175. str[4] = {id: $data[key].item, count: $data[key].count, type: 3}
  176. } else if($data[key].item === '供应商') {
  177. str[3] = {id: $data[key].item, count: $data[key].count, type: 3}
  178. } else if($data[key].item === '本年交易金额') {
  179. str[8] = {id: $data[key].item, count: $data[key].count, type: 4}
  180. } else if($data[key].item ==='上年交易金额') {
  181. str[7] = {id: $data[key].item, count: $data[key].count, type: 4}
  182. } else if($data[key].item === '品牌') {
  183. str[1] = {id: $data[key].item, count: $data[key].count, type: 1}
  184. } else if($data[key].item === '现货') {
  185. str[0] = {id: $data[key].item, count: $data[key].count, type: 1}
  186. } else if($data[key].item === '规格书') {
  187. str[2] = {id: $data[key].item, count: $data[key].count, type: 1}
  188. }
  189. })
  190. }
  191. str[6] = {id: '本月询价单', count: this.$store.state.count.inquirySheet.data ? this.$store.state.count.inquirySheet.data.count : 0, type: 2}
  192. str[5] ={id: '上月询价单', count: this.$store.state.count.inquirySheetLast.data ? this.$store.state.count.inquirySheetLast.data.count : 0, type: 2}
  193. return str
  194. },
  195. itemLeft () {
  196. return this.itemData.slice(0, 5)
  197. },
  198. itemRight () {
  199. return this.itemData.slice(5, 9)
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .statistics{
  206. position:relative;
  207. height: 0.7rem;
  208. border-radius:.48rem;
  209. background: #fff;
  210. margin:0 .05rem .2rem;
  211. overflow: hidden;
  212. background: url('/images/mobile/@2x/home/countnewbg1.png') no-repeat center;
  213. background-size: auto 0.69rem;
  214. ul{
  215. width:50%;
  216. position:relative;
  217. transition: .5s all linear;
  218. &.topL {
  219. transition: top 0s;
  220. -moz-transition: top 0s; /* Firefox 4 */
  221. -webkit-transition: top 0s; /* Safari and Chrome */
  222. -o-transition: top 0s; /* Opera */
  223. }
  224. &.topR {
  225. transition: top 0s;
  226. -moz-transition: top 0s; /* Firefox 4 */
  227. -webkit-transition: top 0s; /* Safari and Chrome */
  228. -o-transition: top 0s; /* Opera */
  229. }
  230. &:first-child{
  231. margin-left: .0rem;
  232. }
  233. &:no_tran{
  234. transition:none;
  235. }
  236. li{
  237. width:100%;
  238. text-align: center;
  239. height:0.7rem;
  240. line-height: 0.7rem;
  241. font-size: .28rem;
  242. font-weight: bold;
  243. white-space: nowrap;
  244. overflow: hidden;
  245. vertical-align:top;
  246. span{
  247. &.number{
  248. display: inline-block;
  249. color:red;
  250. font-size: 0.32rem;
  251. height: .7rem;
  252. line-height:.7rem;
  253. font-weight: bold;
  254. .name, .month{
  255. color: #fff;
  256. }
  257. .month{
  258. font-size: 0.22rem;
  259. }
  260. .unit, .num{
  261. color: #feff00;
  262. }
  263. .num{
  264. padding-left: .1rem;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>