StatisticsMobile.vue 8.7 KB

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