classification.vue 16 KB

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