GoodList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. this.openWebChat(newTab, obj)
  159. }, err => {
  160. console.log(err)
  161. this.$message.error('暂无卖家管理员手机号!')
  162. })
  163. } else {
  164. obj.toPhone = response.data.enTel
  165. this.openWebChat(newTab, obj)
  166. }
  167. }, err => {
  168. console.log(err)
  169. })
  170. }
  171. },
  172. openWebChat: function (newTab, obj) {
  173. this.$http.post('https://im.ubtob.com/api/chat/infos?condition=chat_info', obj)
  174. .then(response => {
  175. if (response.data.success) {
  176. newTab.location.href = 'https://im.ubtob.com/chat/visit?gid=' + response.data.content
  177. }
  178. })
  179. },
  180. listenPage: function (changedPage) {
  181. this.nowPage = changedPage
  182. this.$emit('pageEvent', this.nowPage)
  183. },
  184. changePage: function (type) {
  185. if (type === 'next' && this.nowPage < this.total_page) {
  186. this.listenPage(++this.nowPage)
  187. } else if (type === 'pre' && this.nowPage > 1) {
  188. this.listenPage(--this.nowPage)
  189. }
  190. },
  191. sortBy: function (param) {
  192. if (param === 'normal1') {
  193. this.sorting = {}
  194. this.activeTag = 'normal1'
  195. } else if (param === 'normal2') {
  196. if (this.reserve_asc) {
  197. this.sorting = {'RESERVE': 'ASC'}
  198. } else {
  199. this.sorting = {'RESERVE': 'DESC'}
  200. }
  201. this.activeTag = 'normal2'
  202. this.reserve_asc = !this.reserve_asc
  203. } else if (param === 'type') {
  204. this.sorting = {'RESERVE': 'DESC'}
  205. this.activeTag = 'type'
  206. } else if (param === 'price') {
  207. if (this.price_asc) {
  208. this.sorting = {'PRICE': 'ASC'}
  209. } else {
  210. this.sorting = {'PRICE': 'DESC'}
  211. }
  212. this.activeTag = 'price'
  213. this.price_asc = !this.price_asc
  214. }
  215. this.$emit('sortEvent', this.sorting)
  216. this.nowPage = 1
  217. },
  218. filter_price: function () {
  219. if (this.min_price === '' && this.max_price !== '') {
  220. this.filter.goods_maxpricermb = this.max_price
  221. } else if (this.min_price !== '' && this.max_price === '') {
  222. this.filter.goods_minpricermb = this.min_price
  223. } else if (this.min_price !== '' && this.max_price !== '') {
  224. if (this.min_price <= this.max_price) {
  225. this.filter.goods_minpricermb = this.min_price
  226. this.filter.goods_maxpricermb = this.max_price
  227. }
  228. } else {
  229. delete this.filter.goods_minpricermb
  230. delete this.filter.goods_maxpricermb
  231. }
  232. this.$emit('filterPriceEvent', this.filter)
  233. },
  234. clear_price: function () {
  235. this.min_price = ''
  236. this.max_price = ''
  237. this.$emit('filterPriceEvent', this.filter)
  238. },
  239. goUnstandardDetail: function (comp) {
  240. if (!comp.uuid) {
  241. this.$router.push('/store/productDetail/' + comp.batchCode)
  242. }
  243. },
  244. getLogo: function (item) {
  245. if (item.batchCode) {
  246. if (item.img) {
  247. return item.img
  248. } else {
  249. return '/images/component/default.png'
  250. }
  251. } else {
  252. if (item.brand && item.brand.logoUrl) {
  253. return item.brand.logoUrl
  254. } else {
  255. return '/images/component/default.png'
  256. }
  257. }
  258. }
  259. }
  260. }
  261. </script>
  262. <style scoped lang="scss">
  263. .tab-filter {
  264. height: 34px;
  265. background: #f4f4f4;
  266. padding: 5px 31px 0 14px;
  267. margin-bottom: 20px;
  268. line-height: normal;
  269. .item {
  270. width: 74px;
  271. height: 24px;
  272. text-align: center;
  273. color: #999;
  274. line-height: 22px;
  275. background: #fff;
  276. border: 1px solid #d9d9d9;
  277. border-right: none;
  278. cursor: pointer;
  279. font-size: 12px;
  280. &:last-child {
  281. border-right: 1px solid #d9d9d9;
  282. }
  283. &.active {
  284. border: 1px solid #5078cb;
  285. background: #5078cb;
  286. color: #fff;
  287. }
  288. }
  289. .price-filter {
  290. margin-left: 30px;
  291. .form-control {
  292. width: 74px;
  293. height: 24px;
  294. border: 1px solid #d9d9d9;
  295. border-radius: 0;
  296. padding: 0 6px;
  297. font-size: 12px;
  298. }
  299. .fp-btn {
  300. width: 43px;
  301. height: 24px;
  302. line-height: 24px;
  303. background: #5078cb;
  304. color: #fff;
  305. text-align: center;
  306. border-radius: 2px;
  307. margin-left: 6px;
  308. }
  309. }
  310. .fr {
  311. height: 24px;
  312. line-height: 24px;
  313. color: #999;
  314. .page-info {
  315. margin-left: 20px;
  316. margin-right: 4px;
  317. .active {
  318. color: #3f85f6;
  319. }
  320. }
  321. .iconfont {
  322. display: inline-block;
  323. width: 38px;
  324. height: 24px;
  325. line-height: 24px;
  326. text-align: center;
  327. border: 1px solid #d9d9d9;
  328. color: #666;
  329. background: #fff;
  330. }
  331. }
  332. }
  333. .good-list {
  334. .inline-block {
  335. width: 220px;
  336. height: 300px;
  337. margin-right: 15px;
  338. border: 1px solid #d9d9d9;
  339. padding: 0 20px;
  340. margin-bottom: 15px;
  341. &:nth-child(5n) {
  342. margin-right: 0;
  343. }
  344. p {
  345. color: #666;
  346. }
  347. $img-size: 179px;
  348. .img {
  349. width: $img-size;
  350. height: $img-size;
  351. line-height: $img-size;
  352. text-align: center;
  353. margin: 0 auto;
  354. img {
  355. max-width: $img-size;
  356. max-height: $img-size;
  357. }
  358. }
  359. .price {
  360. font-size: 18px;
  361. color: #e4393c;
  362. }
  363. .sell-count {
  364. color: #767cf9;
  365. }
  366. }
  367. }
  368. .com-empty{
  369. text-align: center;
  370. height:130px;
  371. border: 1px solid #eee;
  372. line-height: 130px;
  373. margin-bottom: 20px;
  374. .com-empty-text {
  375. color: #aaa;
  376. margin-left: 10px;
  377. }
  378. }
  379. </style>