GoodList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <div>
  3. <div class="tab-filter" >
  4. <div class="inline-block item" @click="sortBy('normal1')" :class="{'active': activeTag === 'normal1'}">默认排序</div>
  5. <div class="inline-block item" @click="sortBy('normal2')" :class="activeTag==='normal2'?'active':''">现货优选<i class="fa fa-long-arrow-down" v-show="reserve_asc"></i><i class="fa fa-long-arrow-up" v-show="!reserve_asc"></i></div>
  6. <div class="inline-block item" @click="sortBy('price')" :class="activeTag==='price'?'active':''">价格<i class="fa fa-long-arrow-down" v-show="price_asc"></i><i class="fa fa-long-arrow-up" v-show="!price_asc"></i></div>
  7. <div class="inline-block price-filter">
  8. <input type="number" min="0" step="0.01" v-model="min_price" class="form-control" placeholder="¥" onfocus="this.placeholder=''" onblur="this.placeholder='¥'" />
  9. <span>&nbsp;-&nbsp;</span>
  10. <input type="number" :min="min_price === ''?0:min_price" step="0.01" v-model="max_price" class="form-control" placeholder="¥" onfocus="this.placeholder=''" onblur="this.placeholder='¥'" />
  11. <a class="fp-btn inline-block" @click="filter_price">确定</a>
  12. </div>
  13. <div class="fr">
  14. <span>共{{good_list.total}}条商品信息</span>
  15. <span class="page-info"><span class="active">{{nowPage}}</span>/{{total_page}}</span>
  16. <a href="javascript:void(0)" class="icon-xiangzuo iconfont" @click="changePage('pre')"></a>
  17. <a href="javascript:void(0)" class="icon-xiangyou iconfont" @click="changePage('next')"></a>
  18. </div>
  19. </div>
  20. <ul class="good-list" v-if="good_list.pcbgoods && good_list.pcbgoods.length">
  21. <li v-for="item in good_list.pcbgoods" class="inline-block">
  22. <nuxt-link :to="`/pcb/product/${item.productid}/${item.batchCode}`">
  23. <div class="img">
  24. <img :src="getLogo(item)">
  25. </div>
  26. <p class="price">{{item.prices ? item.currencyName === 'RMB' ? '¥' + '&nbsp;&nbsp;' + item.prices[0].rMBPrice : '$' + '&nbsp;&nbsp;' + item.prices[0].uSDPrice : '-'}}</p>
  27. <p>{{item.code}}</p>
  28. <p>销量<span class="sell-count">{{item.saleQty || 0}}</span>件</p>
  29. </nuxt-link>
  30. </li>
  31. </ul>
  32. <div class="com-empty" v-if="!good_list.pcbgoods || !good_list.pcbgoods.length">
  33. <img class="com-empty-img" src="/images/brandList/empty-cart.png">
  34. <span class="com-empty-text">暂无搜索结果</span>
  35. </div>
  36. <page :total="total_count" :page-size="pageSize"
  37. :current="nowPage" @childEvent="listenPage"></page>
  38. </div>
  39. </template>
  40. <script>
  41. import Page from '~components/common/page/pageComponent.vue'
  42. import Buy from '~components/common/buyOrCar/buyComponent.vue'
  43. export default {
  44. data () {
  45. return {
  46. nowPage: 1,
  47. pageSize: 20,
  48. sorting: {},
  49. price_asc: true,
  50. reserve_asc: true,
  51. min_price: '',
  52. max_price: '',
  53. filter: {},
  54. activeTag: 'normal1'
  55. }
  56. },
  57. components: {
  58. Page,
  59. Buy
  60. },
  61. filters: {
  62. currency: function (input) {
  63. if (typeof input === 'number') {
  64. if (input <= 0.000001) {
  65. input = 0.000001
  66. } else {
  67. if (input.toString().indexOf('.') === -1) {
  68. input = input + '.00'
  69. } else {
  70. let inputStr = input.toString()
  71. let arr = inputStr.split('.')
  72. let floatNum = arr[1]
  73. if (floatNum.length > 6) {
  74. input = inputStr.substring(0, arr[0].length + 7)
  75. if (Number(floatNum.charAt(6)) > 4) {
  76. input = (Number(input) * 1000000 + 1) / 1000000
  77. }
  78. } else if (floatNum.length === 1) {
  79. input = input + '0'
  80. }
  81. }
  82. }
  83. }
  84. return input
  85. }
  86. },
  87. watch: {
  88. $route: function (val, oldVal) {
  89. this.filter = {}
  90. this.activeTag = 'normal1'
  91. }
  92. },
  93. computed: {
  94. good_lists () {
  95. return this.$store.state.pcb.search.list
  96. },
  97. good_list () {
  98. return this.good_lists.data
  99. },
  100. total_count () {
  101. return Math.min(this.good_list.total, 100 * this.pageSize)
  102. },
  103. total_page () {
  104. let currentCount = Math.floor(this.good_list.total / this.pageSize) + (this.good_list.total % this.pageSize > 0 ? 1 : 0)
  105. return currentCount > 100 ? 100 : currentCount
  106. },
  107. buy_info () {
  108. return this.$store.state.user.buy.buyInfo.data
  109. },
  110. car_info () {
  111. return this.$store.state.user.car.addCarInfo.data
  112. },
  113. tab () {
  114. return this.$store.state.chat.tab.tab.data
  115. },
  116. user () {
  117. return this.$store.state.option.user
  118. }
  119. },
  120. methods: {
  121. goWebChat: function () {
  122. if (!this.user.logged) {
  123. this.$http.get('/login/page').then(response => {
  124. if (response.data) {
  125. this.$router.push('/auth/login')
  126. }
  127. })
  128. } else {
  129. // 获得窗口的垂直位置
  130. let iTop = (window.screen.availHeight - 30 - 780) / 2
  131. // 获得窗口的水平位置
  132. let iLeft = (window.screen.availWidth - 10 - 1030) / 2
  133. if (this.tab.close) {
  134. this.tab.close()
  135. }
  136. let newTab = window.open('', '即时对话框', 'height=750, width=1000, top=' + iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')
  137. newTab.close()
  138. newTab = window.open('', '即时对话框', 'height=750, width=1000, top=' + iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')
  139. this.$store.dispatch('chat/setChatTab', {tab: newTab})
  140. this.$http.get('/basic/enterprise/' + this.storeInfo.enUU + '/info')
  141. .then(response => {
  142. let obj = {}
  143. obj.userPhone = this.user.data.userTel
  144. obj.userType = 'ENTERPRISE'
  145. this.user.data.enterprises.forEach(function (item, index) {
  146. if (item.current) {
  147. obj.enUU = item.uu
  148. obj.enterprise = {enUU: item.uu, name: item.enName}
  149. }
  150. })
  151. obj.otherEnUU = response.data.uu
  152. obj.otherUserType = 'STORE'
  153. obj.otherEnterprise = {enUU: response.data.uu, name: response.data.enName}
  154. obj.type = 'CHAT'
  155. if (!(/^1\d{10}$/).test(response.data.enTel)) {
  156. this.$http.get('/basic/enterprise/' + response.data.uu + '/admin').then(response => {
  157. obj.toPhone = response.data.userTel
  158. console.log(obj)
  159. this.openWebChat(newTab, obj)
  160. }, err => {
  161. console.log(err)
  162. this.$message.error('暂无卖家管理员手机号!')
  163. })
  164. } else {
  165. obj.toPhone = response.data.enTel
  166. this.openWebChat(newTab, obj)
  167. }
  168. }, err => {
  169. console.log(err)
  170. })
  171. }
  172. },
  173. openWebChat: function (newTab, obj) {
  174. this.$http.post('https://im.ubtob.com/api/chat/infos?condition=chat_info', obj)
  175. .then(response => {
  176. if (response.data.success) {
  177. newTab.location.href = 'https://im.ubtob.com/chat/visit?gid=' + response.data.content
  178. }
  179. })
  180. },
  181. listenPage: function (changedPage) {
  182. this.nowPage = changedPage
  183. this.$emit('pageEvent', this.nowPage)
  184. },
  185. changePage: function (type) {
  186. if (type === 'next' && this.nowPage < this.total_page) {
  187. this.listenPage(++this.nowPage)
  188. } else if (type === 'pre' && this.nowPage > 1) {
  189. this.listenPage(--this.nowPage)
  190. }
  191. },
  192. sortBy: function (param) {
  193. if (param === 'normal1') {
  194. this.sorting = {}
  195. this.activeTag = 'normal1'
  196. } else if (param === 'normal2') {
  197. if (this.reserve_asc) {
  198. this.sorting = {'RESERVE': 'ASC'}
  199. } else {
  200. this.sorting = {'RESERVE': 'DESC'}
  201. }
  202. this.activeTag = 'normal2'
  203. this.reserve_asc = !this.reserve_asc
  204. } else if (param === 'type') {
  205. this.sorting = {'RESERVE': 'DESC'}
  206. this.activeTag = 'type'
  207. } else if (param === 'price') {
  208. if (this.price_asc) {
  209. this.sorting = {'PRICE': 'ASC'}
  210. } else {
  211. this.sorting = {'PRICE': 'DESC'}
  212. }
  213. this.activeTag = 'price'
  214. this.price_asc = !this.price_asc
  215. }
  216. this.$emit('sortEvent', this.sorting)
  217. this.nowPage = 1
  218. },
  219. filter_price: function () {
  220. if (this.min_price === '' && this.max_price !== '') {
  221. this.filter.goods_maxpricermb = this.max_price
  222. } else if (this.min_price !== '' && this.max_price === '') {
  223. this.filter.goods_minpricermb = this.min_price
  224. } else if (this.min_price !== '' && this.max_price !== '') {
  225. if (this.min_price <= this.max_price) {
  226. this.filter.goods_minpricermb = this.min_price
  227. this.filter.goods_maxpricermb = this.max_price
  228. }
  229. } else {
  230. delete this.filter.goods_minpricermb
  231. delete this.filter.goods_maxpricermb
  232. }
  233. this.$emit('filterPriceEvent', this.filter)
  234. },
  235. clear_price: function () {
  236. this.min_price = ''
  237. this.max_price = ''
  238. this.$emit('filterPriceEvent', this.filter)
  239. },
  240. goUnstandardDetail: function (comp) {
  241. if (!comp.uuid) {
  242. this.$router.push('/store/productDetail/' + comp.batchCode)
  243. }
  244. },
  245. getLogo: function (item) {
  246. if (item.batchCode) {
  247. if (item.img) {
  248. return item.img
  249. } else {
  250. return '/images/component/default.png'
  251. }
  252. } else {
  253. if (item.brand && item.brand.logoUrl) {
  254. return item.brand.logoUrl
  255. } else {
  256. return '/images/component/default.png'
  257. }
  258. }
  259. }
  260. }
  261. }
  262. </script>
  263. <style scoped lang="scss">
  264. .tab-filter {
  265. height: 34px;
  266. background: #f4f4f4;
  267. padding: 5px 31px 0 14px;
  268. margin-bottom: 20px;
  269. line-height: normal;
  270. .item {
  271. width: 74px;
  272. height: 24px;
  273. text-align: center;
  274. color: #999;
  275. line-height: 22px;
  276. background: #fff;
  277. border: 1px solid #d9d9d9;
  278. border-right: none;
  279. cursor: pointer;
  280. font-size: 12px;
  281. &:last-child {
  282. border-right: 1px solid #d9d9d9;
  283. }
  284. &.active {
  285. border: 1px solid #5078cb;
  286. background: #5078cb;
  287. color: #fff;
  288. }
  289. }
  290. .price-filter {
  291. margin-left: 30px;
  292. .form-control {
  293. width: 74px;
  294. height: 24px;
  295. border: 1px solid #d9d9d9;
  296. border-radius: 0;
  297. padding: 0 6px;
  298. font-size: 12px;
  299. }
  300. .fp-btn {
  301. width: 43px;
  302. height: 24px;
  303. line-height: 24px;
  304. background: #5078cb;
  305. color: #fff;
  306. text-align: center;
  307. border-radius: 2px;
  308. margin-left: 6px;
  309. }
  310. }
  311. .fr {
  312. height: 24px;
  313. line-height: 24px;
  314. color: #999;
  315. .page-info {
  316. margin-left: 20px;
  317. margin-right: 4px;
  318. .active {
  319. color: #3f85f6;
  320. }
  321. }
  322. .iconfont {
  323. display: inline-block;
  324. width: 38px;
  325. height: 24px;
  326. line-height: 24px;
  327. text-align: center;
  328. border: 1px solid #d9d9d9;
  329. color: #666;
  330. background: #fff;
  331. }
  332. }
  333. }
  334. .good-list {
  335. .inline-block {
  336. width: 220px;
  337. height: 300px;
  338. margin-right: 15px;
  339. border: 1px solid #d9d9d9;
  340. padding: 0 20px;
  341. margin-bottom: 15px;
  342. &:nth-child(5n) {
  343. margin-right: 0;
  344. }
  345. p {
  346. color: #666;
  347. }
  348. $img-size: 179px;
  349. .img {
  350. width: $img-size;
  351. height: $img-size;
  352. line-height: $img-size;
  353. text-align: center;
  354. margin: 0 auto;
  355. img {
  356. max-width: $img-size;
  357. max-height: $img-size;
  358. }
  359. }
  360. .price {
  361. font-size: 18px;
  362. color: #e4393c;
  363. }
  364. .sell-count {
  365. color: #767cf9;
  366. }
  367. }
  368. }
  369. .com-empty{
  370. text-align: center;
  371. height:130px;
  372. border: 1px solid #eee;
  373. line-height: 130px;
  374. margin-bottom: 20px;
  375. .com-empty-text {
  376. color: #aaa;
  377. margin-left: 10px;
  378. }
  379. }
  380. </style>