classification.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <view>
  3. <view style="background-color: #E75F37;padding: 20rpx;">
  4. <u-search placeholder="请输入商品名称" bgColor="#fff" searchIconColor='#E75F37' :actionStyle="{color:'#FFF'}"
  5. :searchIconSize='24' v-model="name" @search="custom()" @custom="custom()"></u-search>
  6. </view>
  7. <scroll-view @scrolltolower="lowerBottom" scroll-y="true" style="max-height: 82vh;" @scroll="scroll"
  8. :scroll-top="scrollTop">
  9. <view class="recentSearches" v-if="recentSearches.length != 0">
  10. <view class="recentSearches-head">
  11. <view class="recentSearches-headLeft">
  12. <u-icon name="clock" color="#C4C4C4"></u-icon>
  13. <view style="font-size: 26rpx;margin-left: 6rpx;">最近搜索</view>
  14. </view>
  15. <view class="recentSearches-headRight">
  16. <u-icon name="trash" size="20px" @click="searchDeleteShow = true" color="#C4C4C4"></u-icon>
  17. </view>
  18. </view>
  19. <view class="recentSearches-text">
  20. <u-tag v-for="(item,index) in recentSearches" :key="index" :text="item" bgColor="#EFEFEF"
  21. color="#414141" borderColor="#EFEFEF" size="medium" closable :show="item" @close="tagClose(index)"
  22. shape="circle" @click.stop="tagSearches(item)"></u-tag>
  23. </view>
  24. <u-modal :show="searchDeleteShow" content="确认删除搜索记录吗?" showCancelButton @confirm="searchDeletefun"
  25. @cancel="searchDeleteShow = false" ref="uModal" :asyncClose="true">
  26. </u-modal>
  27. </view>
  28. <view class="tag-calss">
  29. <view style="margin:0 12rpx;">
  30. <u-tag text="品牌" bgColor="#fff" borderColor='#E75F37' color="#E75F37" @click="openBrand"
  31. size="mini">
  32. </u-tag>
  33. </view>
  34. <view style="margin:0 12rpx;width: 2rpx;height: 43rpx;background: #E75F37;border-radius: 1rpx;"></view>
  35. <view style="margin:0 12rpx;">
  36. <u-tag text="重置" bgColor="#F8AA09" borderColor='#F8AA09' color="#fff" @click="emptyfun" size="mini">
  37. </u-tag>
  38. </view>
  39. </view>
  40. <view v-for="(item, index) in dataList" :key="index">
  41. <view class="card" @click="selectProduct(item)">
  42. <image :src="item.url" class="cardImg" mode="scaleToFill">
  43. </image>
  44. <view class="">
  45. <view style="display: flex;align-items: center;">
  46. <view class="cardName">
  47. {{item.cname}}
  48. </view>
  49. <image src="/static/images/tabBar/carIcon@2x.png" @click.stop="shoppingCartfun(item)"
  50. style="width: 54rpx;height: 54rpx;margin-left: 32rpx;" mode="scaleToFill">
  51. </image>
  52. </view>
  53. <view style="display: flex;align-items: center;">
  54. <view class="cardTab">
  55. <image src="/static/images/tabBar/280@2x.png" style="width: 142rpx;height: 36rpx;"
  56. mode="scaleToFill">
  57. </image>
  58. <image src="/static/images/tabBar/6@2x.png"
  59. style="width: 78rpx;height: 20rpx;position: absolute;left:10rpx;top:8rpx"
  60. mode="scaleToFill">
  61. </image>
  62. <view class="cardKc">
  63. {{Number(item.inventoryLocal) > 10?'充足':Number(item.inventoryLocal)}}
  64. </view>
  65. </view>
  66. <view>
  67. <view class="cardTab" style="margin-left: 10rpx;">
  68. <image src="/static/images/tabBar/2801@2x.png" style="width: 142rpx;height: 36rpx;"
  69. mode="scaleToFill">
  70. </image>
  71. <image src="/static/images/tabBar/7@2x.png"
  72. style="width: 78rpx;height: 20rpx;position: absolute;left:10rpx;top:8rpx"
  73. mode="scaleToFill">
  74. </image>
  75. <view class="cardKc">
  76. {{Number(item.inventoryShare) > 10?'充足':Number(item.inventoryShare)}}
  77. </view>
  78. </view>
  79. </view>
  80. <view class="cardPrice">
  81. ¥{{item.mallPrice}}
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <u-loadmore v-if="page.total !== 0" :status="status" />
  88. </scroll-view>
  89. <u-back-top :scroll-top="old.scrollTop" @tap="goTop" bottom="300rpx"></u-back-top>
  90. <uni-popup ref="popup" background-color="#fff" type="bottom">
  91. <view>
  92. <uni-row>
  93. <uni-col :span="6" v-for="(item,index) in tabbarTwo" :key="index">
  94. <view class="brandImg" @click="swichMenu(item,index)">
  95. <image :src="item.brandFilesList[0].url" mode="aspectFit"
  96. style="width:110rpx;height: 110rpx;border-radius:6rpx;border: 2rpx solid #EBEBEB;" />
  97. <text class='text'>{{item.cname}}</text>
  98. </view>
  99. </uni-col>
  100. </uni-row>
  101. </view>
  102. </uni-popup>
  103. </view>
  104. </template>
  105. <script>
  106. import {
  107. listAll2,
  108. goodsList
  109. } from '@/api/tabBar/classification.js'
  110. import {
  111. details,
  112. nameDetail
  113. } from '@/api/views/personalInformation/index.js'
  114. import {
  115. appDetail,
  116. addToCart
  117. } from '@/api/tabBar/home.js'
  118. export default {
  119. data() {
  120. return {
  121. scrollTop: 0,
  122. old: {
  123. scrollTop: 0
  124. },
  125. radios: [{
  126. label: '静音棉',
  127. checked: false,
  128. },
  129. {
  130. label: '自修补',
  131. checked: false,
  132. },
  133. {
  134. label: '防爆',
  135. checked: false,
  136. },
  137. ],
  138. current: 0, // 预设当前项的值
  139. tabbar: [],
  140. dataList: [],
  141. show: false,
  142. status: 'loadmore',
  143. filesList: [],
  144. tabbarTwo: [],
  145. name: '',
  146. page: {
  147. total: 0,
  148. size: 10,
  149. current: 1
  150. },
  151. search: {
  152. whether: '0'
  153. },
  154. checkStatus: null,
  155. recentSearches: [], // 搜索数据
  156. searchDeleteShow: false, // 搜索全部删除弹窗
  157. form: {}, // 详情数据
  158. checkboxValue: [], // 多选
  159. salesmanName: '', // 业务员姓名
  160. phoneNumber: '', // 业务员联系电话
  161. salesmanShow: false, // 联系业务员弹窗
  162. }
  163. },
  164. options: {
  165. styleIsolation: 'shared', // 解除样式隔离
  166. },
  167. props: {
  168. keyword: {
  169. type: String
  170. }
  171. },
  172. created() {
  173. // 获取最近搜索数据
  174. if (uni.getStorageSync('recentSearches')) {
  175. this.recentSearches = uni.getStorageSync('recentSearches').slice(0, 8);
  176. }
  177. // 获取审核状态
  178. details().then(res => {
  179. this.checkStatus = res.data.checkStatus
  180. uni.setStorageSync('checkStatus', res.data.checkStatus);
  181. if (this.checkStatus != '通过') {
  182. // uni.showToast({
  183. // title: "当前用户未授权,请联系客服",
  184. // icon: "none",
  185. // mask:true
  186. // });
  187. uni.switchTab({
  188. url: '/pages/tabBar/home'
  189. })
  190. return
  191. }
  192. this.salesmanName = res.data.salesmanName
  193. // 查询业务员详情拿取手机号
  194. if (!this.phoneNumber) {
  195. nameDetail({
  196. id: res.data.salesmanId
  197. }).then(res => {
  198. this.phoneNumber = res.data.phone
  199. })
  200. }
  201. })
  202. listAll2({
  203. type: 'PP',
  204. enableOrNot: '1',
  205. whetherIntegral: '1'
  206. }).then(res => {
  207. console.log(res.data.sort(this.compare('sort')), 111111)
  208. let arr = []
  209. arr = res.data.sort(this.compare('sort'))
  210. this.tabbarTwo = arr
  211. this.page = {
  212. total: 0,
  213. size: 10,
  214. current: 1
  215. }
  216. this.dataList = []
  217. let searchCache = JSON.parse(JSON.stringify(uni.getStorageSync('homeSearch')))
  218. uni.removeStorageSync('homeSearch')
  219. if (searchCache.cname) {
  220. this.name = searchCache.cname
  221. this.custom()
  222. } else {
  223. this.name = null
  224. if (this.current == -1) {
  225. this.current = 0
  226. }
  227. this.search = {
  228. // brandId: this.tabbarTwo[this.current].id,
  229. whether: '0',
  230. }
  231. this.onSearch()
  232. }
  233. })
  234. },
  235. methods: {
  236. searchData(data) {
  237. console.log(data)
  238. this.name = data
  239. this.custom()
  240. },
  241. openBrand() {
  242. this.$refs.popup.open('bottom')
  243. },
  244. goTop(e) {
  245. // 解决view层不同步的问题
  246. this.scrollTop = this.old.scrollTop
  247. this.$nextTick(() => {
  248. this.scrollTop = 0
  249. this.old.scrollTop = 0
  250. });
  251. },
  252. scroll(e) {
  253. this.old.scrollTop = e.detail.scrollTop
  254. },
  255. // 数组排序 property:根据什么属性排序
  256. compare(property) {
  257. return function(a, b) {
  258. var value1 = a[property]
  259. var value2 = b[property]
  260. return value1 - value2
  261. }
  262. },
  263. // 点击联系业务员
  264. clickCall() {
  265. uni.makePhoneCall({
  266. phoneNumber: this.phoneNumber,
  267. success: function() {
  268. console.log('拨打电话成功');
  269. },
  270. fail() {
  271. console.log('打电话失败了');
  272. }
  273. })
  274. },
  275. // 清空搜索条件
  276. emptyfun() {
  277. this.name = ''
  278. this.current = -1
  279. this.checkboxValue = []
  280. this.search = {
  281. whether: '0'
  282. }
  283. this.page = {
  284. total: 0,
  285. size: 10,
  286. current: 1
  287. }
  288. this.dataList = []
  289. this.onSearch()
  290. },
  291. checkboxChange(value) {
  292. this.checkboxValue = value
  293. this.search.originalFactory = null
  294. this.search.selfRecovery = null
  295. this.search.explosionProof = null
  296. if (this.checkboxValue.indexOf('静音棉') != -1) {
  297. this.search.originalFactory = 1
  298. }
  299. if (this.checkboxValue.indexOf('自修补') != -1) {
  300. this.search.selfRecovery = 1
  301. }
  302. if (this.checkboxValue.indexOf('防爆') != -1) {
  303. this.search.explosionProof = 1
  304. }
  305. this.page = {
  306. total: 0,
  307. size: 10,
  308. current: 1
  309. }
  310. this.dataList = []
  311. this.onSearch()
  312. },
  313. // 加入购物车
  314. shoppingCartfun(row) {
  315. console.log(row, 166);
  316. if (row.inventory == 0) {
  317. uni.showToast({
  318. title: "当前商品库存为零",
  319. icon: "none",
  320. mask: true,
  321. duration: 2500
  322. });
  323. return
  324. }
  325. // 获取详情数据
  326. appDetail({
  327. id: row.id
  328. }).then(res => {
  329. if (res.data.type == 0) {
  330. this.form = res.data.thisLocality
  331. } else {
  332. this.form = res.data.offsite
  333. }
  334. addToCart({
  335. ...this.form,
  336. whetherIntegral: '1',
  337. detailsText: ''
  338. }).then(res => {
  339. uni.showToast({
  340. title: "加入购物车成功",
  341. icon: "none",
  342. mask: true,
  343. duration: 2500
  344. });
  345. this.$emit('goTab', 2)
  346. })
  347. })
  348. },
  349. // 搜索全部删除
  350. searchDeletefun() {
  351. this.recentSearches = []
  352. uni.setStorageSync('recentSearches', this.recentSearches);
  353. this.searchDeleteShow = false
  354. },
  355. // 点击搜索
  356. tagSearches(name) {
  357. this.name = name
  358. this.search.cname = name
  359. this.custom()
  360. },
  361. // 最近搜索点击关闭按钮
  362. tagClose(index) {
  363. this.recentSearches.splice(index, 1)
  364. uni.setStorageSync('recentSearches', this.recentSearches.slice(0, 8));
  365. },
  366. selectProduct(item) {
  367. uni.$u.route('/pages/integralMall/buyGoods/commodityDetails', {
  368. id: item.id
  369. });
  370. },
  371. // 点击搜索
  372. inSearch() {
  373. uni.navigateTo({
  374. url: `/pages/integralMall/searchPage?searchData=${this.name?this.name:''}`
  375. })
  376. },
  377. lowerBottom() {
  378. this.status = 'loading'
  379. if (this.dataList.length < this.page.total) {
  380. this.page.current++
  381. this.onSearch()
  382. } else {
  383. this.status = 'nomore'
  384. }
  385. },
  386. // 搜索
  387. custom() {
  388. this.current = -1
  389. this.page = {
  390. total: 0,
  391. size: 10,
  392. current: 1
  393. }
  394. if (this.name) {
  395. this.recentSearches.unshift(this.name)
  396. // 去重
  397. this.recentSearches = this.recentSearches.filter((item, index) => this.recentSearches.indexOf(item) ===
  398. index).slice(0, 8);
  399. uni.setStorageSync('recentSearches', this.recentSearches.slice(0, 8));
  400. }
  401. delete this.search.brandId
  402. this.search.cname = this.name
  403. this.dataList = []
  404. this.onSearch()
  405. },
  406. // 左侧选择
  407. swichMenu(row, index) {
  408. // this.current = index;
  409. this.page = {
  410. total: 0,
  411. size: 10,
  412. current: 1
  413. }
  414. this.search.brandId = row.id
  415. this.search.cname = this.name ? this.name : null
  416. this.dataList = []
  417. this.onSearch()
  418. this.$refs.popup.close()
  419. },
  420. // 列表数据获取
  421. onSearch() {
  422. uni.showLoading({
  423. title: '加载中',
  424. mask: true
  425. });
  426. goodsList({
  427. size: this.page.size,
  428. current: this.page.current,
  429. ...this.search,
  430. whetherIntegral: "1"
  431. }).then(res => {
  432. this.dataList = this.dataList.concat(res.data.records)
  433. this.page.total = res.data.total
  434. if (this.dataList.length == res.data.total) {
  435. this.status = 'nomore'
  436. }
  437. uni.hideLoading();
  438. }).catch(err => {
  439. uni.hideLoading();
  440. })
  441. },
  442. }
  443. }
  444. </script>
  445. <style lang="scss" scoped>
  446. .brandImg {
  447. display: flex;
  448. flex-direction: column;
  449. align-items: center;
  450. justify-content: center;
  451. margin: 10rpx 0;
  452. .text {
  453. white-space: nowrap;
  454. overflow: hidden;
  455. text-overflow: ellipsis;
  456. width: 130rpx;
  457. text-align: center;
  458. font-size: 24rpx;
  459. color: #797979;
  460. }
  461. }
  462. .tag-calss {
  463. display: flex;
  464. padding: 8rpx 63rpx 18rpx 63rpx;
  465. background-color: #fff;
  466. justify-content: flex-end;
  467. ::v-deep .u-tag--mini {
  468. font-size: 28rpx;
  469. line-height: 22px;
  470. padding: 0rpx 24rpx !important;
  471. }
  472. }
  473. .card {
  474. display: flex;
  475. align-items: center;
  476. background-color: #fff;
  477. width: 100%;
  478. margin-top: 28rpx;
  479. .cardImg {
  480. margin: 31rpx;
  481. width: 180rpx;
  482. height: 180rpx;
  483. border: 2rpx solid #E7E7E7;
  484. }
  485. .cardName {
  486. font-weight: 400;
  487. font-size: 24rpx;
  488. height: 64rpx;
  489. width: 400rpx;
  490. color: #797979;
  491. display: -webkit-box;
  492. -webkit-box-orient: vertical;
  493. -webkit-line-clamp: 2;
  494. overflow: hidden;
  495. text-overflow: ellipsis;
  496. margin-bottom: 28rpx;
  497. }
  498. .cardTab {
  499. position: relative;
  500. top: 4rpx;
  501. .cardKc {
  502. text-align: center;
  503. position: absolute;
  504. right: 4rpx;
  505. top: 3rpx;
  506. font-size: 22rpx;
  507. color: #FFFFFF;
  508. font-weight: 500;
  509. width: 43rpx;
  510. height: 28rpx;
  511. }
  512. }
  513. .cardPrice {
  514. margin-left: 10rpx;
  515. color: #E75F37;
  516. font-size: 32rpx;
  517. font-weight: 500;
  518. }
  519. }
  520. .recentSearches {
  521. padding: 8rpx 12rpx;
  522. background-color: #fff;
  523. .recentSearches-head {
  524. display: flex;
  525. align-items: center;
  526. justify-content: space-between;
  527. color: #C4C4C4;
  528. .recentSearches-headLeft {
  529. display: flex;
  530. align-items: center;
  531. }
  532. .recentSearches-headRight {}
  533. }
  534. .recentSearches-text {
  535. display: flex;
  536. flex-wrap: wrap;
  537. align-items: baseline;
  538. ::v-deep .u-tag__close{
  539. z-index: 99 !important;
  540. }
  541. }
  542. }
  543. </style>