StatisticsMobile.vue 9.0 KB

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