displayCard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="display-card" v-if="cardShow">
  3. <span @click="cardClose" v-if="cardShow" class="cardClose"><img src="/images/all/close.png"></span>
  4. <div class="content" v-if="cardShow">
  5. <div>
  6. <ul class="list-unstyled">
  7. <li ref="pingdanListWrapper" v-for="item in title" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  8. <span>{{item}}</span>
  9. </li>
  10. </ul>
  11. <ul class="list-unstyled">
  12. <li ref="pingdanListWrapper" v-for="c in counts" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  13. <span v-for="(item, index) in formatScrollNumber(c.count, c.logo)" class="count-distance" :class="'count' + index">{{item}}</span>
  14. </li>
  15. </ul>
  16. </div>
  17. <div v-for="item in itemCounts">
  18. <p>
  19. <span v-html="item.count"></span>
  20. <span style="color: #333" v-if="item.type === 3">家</span>
  21. <span style="color: #333" v-if="item.type === 2">条</span>
  22. </p>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'display-card',
  30. data () {
  31. return {
  32. cardShow: true,
  33. timerIndex: 0,
  34. isTop: false, // 判断是否滚动至顶,
  35. timer: {}, // 定时器实体
  36. title: ['品 牌', '现 货', '规格书', '店 铺']
  37. }
  38. },
  39. mounted () {
  40. this.$nextTick(() => {
  41. this.changeInterval(true)
  42. })
  43. },
  44. methods: {
  45. changeInterval: function (flag) {
  46. if (flag) {
  47. this.timer = setInterval(() => {
  48. this.isTop = false
  49. let isChange = true
  50. this.timerIndex++
  51. if (this.$refs.pingdanListWrapper[0]) {
  52. let _transitionEvent = this.baseUtils.whichTransitionEvent()
  53. _transitionEvent && this.$refs.pingdanListWrapper[0].addEventListener(
  54. _transitionEvent, () => {
  55. if (isChange) {
  56. let title = this.title.shift()
  57. let count = this.counts.shift()
  58. this.title.push(title)
  59. this.counts.push(count)
  60. this.timerIndex = 0
  61. isChange = false
  62. this.isTop = true
  63. }
  64. })
  65. }
  66. }, 3000)
  67. } else {
  68. clearInterval(this.timer)
  69. }
  70. },
  71. cardClose () {
  72. this.cardShow = false
  73. },
  74. formatScrollNumber (num, logo) {
  75. if (num) {
  76. if (num > 99999999) {
  77. let str2 = num.toString()
  78. num = Math.floor(num / 100000000)
  79. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  80. num = num + 1
  81. }
  82. let length = String(num).length
  83. this.len = length > 3 ? length + 1 : length
  84. num = (Array(7 - length).join(0) + num)
  85. num = num.toString() + '亿'
  86. } else if (num > 9999) {
  87. let str = num.toString()
  88. num = Math.floor(num / 10000)
  89. if (parseInt(str.charAt(str.length - 4)) > 4) {
  90. num = num + 1
  91. }
  92. let length = String(num).length
  93. this.len = length > 3 ? length + 1 : length
  94. num = (Array(7 - length).join(0) + num)
  95. num = num.toString() + '万'
  96. } else {
  97. let length = String(num).length
  98. this.len = length > 3 ? length + 1 : length
  99. num = (Array(7 - length).join(0) + num)
  100. if (logo === 0) {
  101. num = num.toString() + '家'
  102. } else {
  103. num = num.toString() + '个'
  104. }
  105. }
  106. }
  107. let _arr = []
  108. for (let i = 0; i < num.length; i++) {
  109. _arr.push(num[i])
  110. }
  111. return _arr
  112. },
  113. formatNumber (num, type) {
  114. if (num) {
  115. if (num.toString().indexOf('E') !== -1) {
  116. let arr = num.toString().split('E')
  117. num = arr[0] * Math.pow(10, arr[1])
  118. }
  119. if (num > 99999999) {
  120. let str2 = num.toString()
  121. num = Math.floor(num / 100000000)
  122. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  123. num = num + 1
  124. }
  125. num += '<span style="color: #333">亿</span>'
  126. } else if (num > 9999) {
  127. let str = num.toString()
  128. num = Math.floor(num / 10000)
  129. if (parseInt(str.charAt(str.length - 4)) > 4) {
  130. num = num + 1
  131. }
  132. num += '<span style="color: #333">万</span>'
  133. } else {
  134. if (type === 1) {
  135. num += '<span style="color: #333">元</span>'
  136. } else {
  137. num += ''
  138. }
  139. }
  140. }
  141. return num
  142. },
  143. formatDouble (num) {
  144. if (num) {
  145. if (num.toString().indexOf('E') !== -1) {
  146. let arr = num.toString().split('E')
  147. num = arr[0] * Math.pow(10, arr[1])
  148. }
  149. if (num > 99999999) {
  150. num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">亿</span>'
  151. } else if (num > 9999) {
  152. num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">万</span>'
  153. } else {
  154. num += ''
  155. }
  156. }
  157. return num
  158. },
  159. },
  160. computed: {
  161. counter () {
  162. return this.$store.state.option.counter.data
  163. },
  164. inquirySheet () {
  165. let sheetNum = this.$store.state.count.inquirySheet.data
  166. return sheetNum ? this.formatDouble(sheetNum.count) : 0
  167. },
  168. inquirySheetLast () {
  169. let lastSheetNum = this.$store.state.count.inquirySheetLast.data
  170. return lastSheetNum ? this.formatDouble(lastSheetNum.count) : 0
  171. },
  172. itemCounts () {
  173. let arr = []
  174. let count = this.baseUtils.deepCopy(this.counter)
  175. if(count.length){
  176. count.forEach((value) => {
  177. if (value.item === '供应商') {
  178. arr[0] = {id: value.item, count: this.formatNumber(value.count), type: 3}
  179. } else if (value.item === '本年交易金额') {
  180. arr[1] = {id: value.item, count: this.formatNumber(value.count), type: 1}
  181. } else if (value.item === '上年交易金额') {
  182. arr[2] = {id: value.item, count: this.formatNumber(value.count), type: 1}
  183. }
  184. })
  185. arr[3] = {id: '本月求购数', count: this.inquirySheet ? this.inquirySheet : 0, type: 2}
  186. arr[4] = {id: '上月求购数', count: this.inquirySheetLast ? this.inquirySheetLast : 0, type: 2}
  187. }
  188. return arr
  189. },
  190. counts () {
  191. let arr = []
  192. let count = this.baseUtils.deepCopy(this.counter)
  193. if(count.length) {
  194. count.forEach((value) => {
  195. if (value.item === '品牌') {
  196. arr[0] = {id: value.item, count: value.count, logo: 1}
  197. } else if (value.item === '现货') {
  198. arr[1] = {id: value.item, count: value.count, logo: 1}
  199. } else if (value.item === '规格书') {
  200. arr[2] = {id: value.item, count: value.count, logo: 1}
  201. } else if (value.item === '店铺') {
  202. arr[3] = {id: value.item, count: value.count, logo: 0}
  203. }
  204. })
  205. }
  206. return arr
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .display-card{
  213. position: fixed;
  214. right: 56px;
  215. top: 182px;
  216. z-index: 100;
  217. .cardClose{
  218. position: absolute;
  219. right: -5px;
  220. top: 12px;
  221. opacity: 0.8;
  222. &:hover{
  223. cursor: pointer;
  224. }
  225. }
  226. .content{
  227. margin-top: 10px;
  228. /*width: 178px;*/
  229. /*height: 536px;*/
  230. background: url('/images/all/countBg.png') no-repeat;
  231. div{
  232. height: 56px;
  233. width: 158px;
  234. padding-top: 19px;
  235. margin-left: 16px;
  236. &:first-child{
  237. height: 109px;
  238. padding-top: 1px;
  239. ul{
  240. &:first-child{
  241. max-height: 30px;
  242. width: 100%;
  243. text-align: center;
  244. overflow: hidden;
  245. position: relative;
  246. top: 16px;
  247. li{
  248. height: 30px;
  249. line-height: 30px;
  250. font-weight: bold;
  251. font-size: 21px;
  252. letter-spacing: 0px;
  253. color: #ff3600;
  254. position: relative;
  255. top: 0;
  256. transition: top 1s;
  257. -moz-transition: top 1s; /* Firefox 4 */
  258. -webkit-transition: top 1s; /* Safari and Chrome */
  259. -o-transition: top 1s; /* Opera */
  260. &.top {
  261. transition: top 0s;
  262. -moz-transition: top 0s; /* Firefox 4 */
  263. -webkit-transition: top 0s; /* Safari and Chrome */
  264. -o-transition: top 0s; /* Opera */
  265. }
  266. }
  267. }
  268. &:last-child{
  269. max-height: 30px;
  270. width: 100%;
  271. overflow: hidden;
  272. position: relative;
  273. top: 21px;
  274. text-align: right;
  275. li{
  276. position: relative;
  277. top: 0;
  278. left: 0;
  279. margin: 0 auto;
  280. width: 141px;
  281. height: 30px;
  282. line-height: 28px;
  283. font-weight: bold;
  284. font-size: 21px;
  285. text-align: left;
  286. color: #bc1b1c;
  287. transition: top 1s;
  288. -moz-transition: top 1s;
  289. -webkit-transition: top 1s;
  290. -o-transition: top 1s;
  291. &.top {
  292. transition: top 0s;
  293. -moz-transition: top 0s; /* Firefox 4 */
  294. -webkit-transition: top 0s; /* Safari and Chrome */
  295. -o-transition: top 0s; /* Opera */
  296. }
  297. span.count-distance{
  298. display: inline-block;
  299. padding-left: 3.3px;
  300. margin-left: 2px;
  301. font-size: 18px;
  302. color: #bc1b1c;
  303. width: 17px;
  304. }
  305. span.count-distance.count6{
  306. position:relative;
  307. top: -2px;
  308. padding-left: 0;
  309. font-weight: bold;
  310. color: #fff;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. p{
  317. width: 100%;
  318. text-align: center;
  319. font-size: 20px;
  320. color: #f14e4e;
  321. }
  322. }
  323. .enter{
  324. width: 100%;
  325. display: inline-block;
  326. position: absolute;
  327. bottom: 35px;
  328. left: -5px;
  329. text-align: center;
  330. }
  331. }
  332. }
  333. </style>