StatisticsMobile.vue 8.9 KB

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