base.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="tabs hflex acenter">
  5. <block v-for="(item,index) in tabs" :key="index">
  6. <view class="hflex acenter" style="padding-right: 68rpx;">
  7. <view class="tab_item" :class="tab_active == index ? 'tab_active': ''" @click="changeTab(index)">{{item.name}}</view>
  8. <view class="vflex acenter jcenter" v-if="index == 2">
  9. <u-icon name="arrow-up-fill" :color="color" size="10"></u-icon>
  10. <u-icon name="arrow-down-fill" :color="color2" size="10"></u-icon>
  11. </view>
  12. </view>
  13. </block>
  14. </view>
  15. <view class="menuList hflex jbetween">
  16. <scroll-view scroll-y="true" class="menu_left">
  17. <view class="vflex">
  18. <block v-for="(item,index) in titleList" :key="index">
  19. <view class="left_item text_hide hflex acenter" :class="index == left_active? 'left_active':''" @click="clickTab1(index)">
  20. <text class="text_hide" style="width:100%; text-align: center;">{{item.name}}</text>
  21. </view>
  22. </block>
  23. </view>
  24. </scroll-view>
  25. <scroll-view scroll-y="true" class="menu_right">
  26. <view class="vflex">
  27. <block v-for="(item,index) in pageList" :key="index">
  28. <view class="right_item hflex acenter" @click="toDetail2(item.id)">
  29. <image :src="item.cover[0]" class="item_cover" mode="aspectFill"></image>
  30. <view class="goodsDesc">
  31. <text class="item_title">{{item.name}}</text>
  32. <view class="hflex acenter jbetween">
  33. <view class="item_price">¥{{item.price_selling}}</view>
  34. <image src="/static/images/shop/add-cart.png" style="width: 44rpx;height: 44rpx;" @tap.stop="addCart(index)"></image>
  35. </view>
  36. </view>
  37. </view>
  38. </block>
  39. </view>
  40. </scroll-view>
  41. </view>
  42. </view>
  43. <u-popup :show="norm_show" @close="close" mode="bottom" :round="20" :closeable="true">
  44. <view class="popu">
  45. <view class="hflex acenter">
  46. <image :src="pageList[good_index].items[norm_active].show_image?pageList[good_index].items[norm_active].show_image:pageList[good_index].cover" class="popu_img" mode="aspectFill"></image>
  47. <view class="vflex jbetween popu_right">
  48. <view class="popu_price">¥{{pageList[index].items[norm_active].price_selling?pageList[index].items[norm_active].price_selling:pageList[index].price_selling}}</view>
  49. <view class="popu_norm text_hide">{{normStr?normStr:'选择规格'}}</view>
  50. </view>
  51. </view>
  52. <view class="" v-for="(item,index) in pageList[index].specs" :key="index">
  53. <view class="popu_title">{{item.name}}</view>
  54. <view class="hflex acenter fwrap">
  55. <block v-for="(item2,index2) in item.list" :key="index2">
  56. <view class="popu_box" @click="selectNorm(index,index2)" :class="item2.select?'sele_active':''" v-if="item2.show && item2.check">{{item2.name}}</view>
  57. <view class="popu_box popu_box2" v-else @click="selectNorm2">{{item2.name}}</view>
  58. </block>
  59. </view>
  60. </view>
  61. <view class="hflex acenter jbetween">
  62. <view class="popu_title">数量</view>
  63. <u-number-box v-model="pageList[index].num" @change="changeNum"></u-number-box>
  64. </view>
  65. <view class="sure_btn" @click="sure">确定</view>
  66. </view>
  67. </u-popup>
  68. </view>
  69. </template>
  70. <script>
  71. import $api from '@/static/js/api.js'
  72. var that = ''
  73. export default {
  74. data() {
  75. return {
  76. titleList: [],
  77. pageList: [],
  78. tabs: [
  79. {
  80. index: 0,
  81. name: '全部',
  82. },
  83. {
  84. index: 1,
  85. name: '销量',
  86. },
  87. {
  88. index: 2,
  89. name: '价格',
  90. }
  91. ],
  92. tab_active: 0,
  93. color: '#7D7D7D',
  94. color2: '#7D7D7D',
  95. cateids: '',
  96. bartitle: '',
  97. norm_show: false,
  98. normStr: '',
  99. norm: '',
  100. color: '',
  101. delivery: '',
  102. num: 1,
  103. norm_active: -1,
  104. color_active:-1,
  105. index: 0,
  106. page:1,
  107. limit: 10,
  108. total: 10,
  109. type1: false,
  110. type2: false,
  111. id: '',
  112. left_active: -1,
  113. }
  114. },
  115. onLoad(options) {
  116. that = this
  117. console.log('options===',options);
  118. if(options.data) {
  119. var option = JSON.parse(options.data)
  120. that.titleList = option
  121. // that.id = option[0].id
  122. // that.getDate()
  123. }
  124. that.id = options.id
  125. that.pageList = []
  126. that.getDate()
  127. that.bartitle = options.name
  128. },
  129. onReady() {
  130. uni.setNavigationBarTitle({
  131. title: that.bartitle
  132. });
  133. },
  134. onReachBottom() {
  135. if (Number(that.page) * Number(that.limit) >= Number(that.total)) {
  136. $api.info("没有更多了")
  137. } else {
  138. that.page++
  139. that.getDate()
  140. }
  141. },
  142. methods: {
  143. // 获取产品数据
  144. getDate() {
  145. $api.req({
  146. url: '/data/api.Goods/getGoods',
  147. data: {
  148. page: that.page,
  149. cateids: that.left_active != -1? that.titleList[that.left_active].id : that.id,
  150. admin_id: '',
  151. name: '',
  152. sales_order: that.tab_active == 1 ? !that.type1 ? 'asc' : 'desc' : '',
  153. price_order: that.tab_active != 2 ? '' : !that.type2 ? 'asc' : 'desc',
  154. }
  155. }, function(res) {
  156. if(res.code == 1) {
  157. // that.$set(that.pageList[index],'goods',res.data.list)
  158. // that.pageList[index].goods = res.data
  159. that.total = res.data.page.total
  160. that.pageList = that.pageList.concat(res.data.list)
  161. for(var i=0;i<that.pageList.length;i++) {
  162. that.pageList[i].cover = that.pageList[i].cover.split('|')
  163. }
  164. }
  165. })
  166. },
  167. /* // 点击产品列表
  168. myEvent(e) {
  169. console.log(e);
  170. },
  171. // 点击菜单列表
  172. myMenu(e) {
  173. console.log('menu',e);
  174. that.id = e.id
  175. that.getDate()
  176. }, */
  177. addCart(e) {
  178. that.norm_show = true
  179. that.index = e
  180. },
  181. // 切换tabs
  182. changeTab(e) {
  183. console.log(e);
  184. that.tab_active = e
  185. if(that.tab_active == 0) {
  186. that.left_active = -1
  187. }
  188. if(that.tab_active == 1) {
  189. that.type1 = !that.type1
  190. }
  191. if(that.tab_active == 2) {
  192. that.type2 = !that.type2
  193. if(that.type2) {
  194. that.color = '#506dff'
  195. that.color2 = '#7D7D7D'
  196. } else {
  197. that.color = '#7D7D7D'
  198. that.color2 = '#506dff'
  199. }
  200. }
  201. that.page = 1
  202. that.pageList = []
  203. that.getDate()
  204. },
  205. clickTab1(e) {
  206. that.left_active = e
  207. that.page = 1
  208. that.pageList = []
  209. that.getDate()
  210. },
  211. close() {
  212. that.norm_show = false
  213. that.num = 1
  214. },
  215. toDetail2(id) {
  216. $api.jump('/page_shop/pages/good/detail?id=' + id)
  217. },
  218. // 选择规格
  219. selectNorm(index,index2) {
  220. for(var i=0;i<that.pageList[that.index].specs[index].list.length;i++) {
  221. if(i == index2) {
  222. that.$set(that.pageList[that.index].specs[index].list[i],'select',true)
  223. } else {
  224. that.$set(that.pageList[that.index].specs[index].list[i],'select',false)
  225. }
  226. }
  227. that.normStr = ''
  228. that.item_id = ''
  229. for(var i=0;i<that.pageList[that.index].specs.length;i++) {
  230. for(var j=0;j<that.pageList[that.index].specs[i].list.length;j++) {
  231. if(that.pageList[that.index].specs[i].list[j].select) {
  232. that.normStr += that.pageList[that.index].specs[i].name+'::'+that.pageList[that.index].specs[i].list[j].name+';;'
  233. // that.item_id +=
  234. }
  235. }
  236. }
  237. that.normStr = that.normStr.substring(0, that.normStr.length-2)
  238. for(var i=0;i<that.pageList[that.index].items.length;i++) {
  239. if(that.pageList[that.index].items[i].goods_spec == that.normStr) {
  240. that.norm_active = i
  241. }
  242. }
  243. that.normStr = $api.resetspec(that.normStr)
  244. // that.norm_active = index2
  245. // that.normStr = that.pageData.items[index].goods_spec
  246. // that.normStr = that.norm + ' ' + that.color + ' ' + 'X' + that.pageData.norm.num
  247. },
  248. selectNorm2() {
  249. $api.info('该规格已下架,请重新选择')
  250. },
  251. // 选择数量
  252. changeNum(e) {
  253. that.num = e.value
  254. // that.normStr = that.norm + ' ' + that.color + ' ' + 'X' + that.num
  255. },
  256. sure() {
  257. $api.req({
  258. url: '/data/api.Goods/cart_add',
  259. method: 'POST',
  260. data: {
  261. admin_id: that.pageList[that.index].admin_id,
  262. goods_id: that.pageList[that.index].id,
  263. item_id: that.pageList[that.index].items[that.norm_active].id,
  264. num: that.num
  265. }
  266. }, function(res) {
  267. if(res.code == 1) {
  268. console.log(res);
  269. $api.info(res.info)
  270. that.num = 1
  271. that.close()
  272. }
  273. })
  274. }
  275. },
  276. }
  277. </script>
  278. <style lang="scss" scoped>
  279. .content {
  280. background-color: #F4F4F4;
  281. padding-top: 24rpx;
  282. .box {
  283. background: #FFFFFF;
  284. border-radius: 20rpx 20rpx 0 0;
  285. .tabs {
  286. width: 100%;
  287. box-sizing: border-box;
  288. padding: 34rpx 30rpx 40rpx;
  289. .tab_item {
  290. font-size: 32rpx;
  291. font-weight: 500;
  292. color: #7D7D7D;
  293. line-height: 44rpx;
  294. padding-right: 10rpx;
  295. }
  296. .tab_active {
  297. font-size: 36rpx;
  298. font-weight: 500;
  299. color: #222222;
  300. line-height: 50rpx;
  301. position: relative;
  302. }
  303. .tab_active::after {
  304. content: "";
  305. position: absolute;
  306. left: 18rpx;
  307. bottom: -5rpx;
  308. width: 40rpx;
  309. height: 8rpx;
  310. background: #506DFF;
  311. border-radius: 4rpx;
  312. }
  313. }
  314. .menuList {
  315. width: 100%;
  316. height: calc(100vh - 150rpx);
  317. margin-bottom: 20rpx;
  318. .menu_left {
  319. width: 200rpx;
  320. height: calc(100vh - 150rpx);
  321. background: #F5F5F5;
  322. border-radius: 0px 28rpx 0px 0px;
  323. .left_item {
  324. width: 180rpx;
  325. font-size: 28rpx;
  326. font-weight: 400;
  327. color: #222222;
  328. line-height: 40rpx;
  329. padding: 30rpx 20rpx;
  330. }
  331. .left_active {
  332. color: #506DFF;
  333. background: #fff;
  334. }
  335. }
  336. .menu_right {
  337. width: 550rpx;
  338. height: calc(100vh - 150rpx);
  339. background: #FFFFFF;
  340. position: relative;
  341. .right_tab {
  342. background: #F3F3F7;
  343. border-radius: 24rpx;
  344. font-size: 22rpx;
  345. font-weight: 400;
  346. color: #393939;
  347. line-height: 48rpx;
  348. padding: 0 24rpx;
  349. height: 48rpx;
  350. margin-right: 20rpx;
  351. }
  352. .right_tab:nth-last-child(1) {
  353. margin-right: 80rpx;
  354. }
  355. .right_tab_active {
  356. background: #E7EBFF;
  357. border: 1rpx solid #5471FF;
  358. color: #5B77FF;
  359. }
  360. .cate_bg {
  361. position: absolute;
  362. top: 0;
  363. left: 0;
  364. width: 100%;
  365. height: 100%;
  366. background: rgba(0,0,0,0.4);
  367. z-index: 9;
  368. .cate_top {
  369. width: 100%;
  370. box-sizing: border-box;
  371. padding: 24rpx 20rpx;
  372. background: #FFFFFF;
  373. .top_left {
  374. font-size: 26rpx;
  375. font-weight: 500;
  376. color: #393939;
  377. line-height: 32rpx;
  378. }
  379. .top_text {
  380. font-size: 16rpx;
  381. font-weight: 400;
  382. color: #393939;
  383. line-height: 22rpx;
  384. }
  385. .cate {
  386. height: 48rpx;
  387. background: #F3F3F7;
  388. border-radius: 24rpx;
  389. padding: 0 24rpx;
  390. font-size: 22rpx;
  391. font-weight: 400;
  392. color: #393939;
  393. line-height: 32rpx;
  394. margin: 24rpx 20rpx 0 0;
  395. }
  396. .cate_active {
  397. background: #E7EBFF;
  398. border: 1px solid #5471FF;
  399. color: #5B77FF;
  400. }
  401. }
  402. }
  403. .tabs_text {
  404. position: absolute;
  405. z-index: 99;
  406. right: 0;
  407. top: 0;
  408. width: 80rpx;
  409. height: 56rpx;
  410. background: #FFFFFF;
  411. font-size: 20rpx;
  412. font-weight: 400;
  413. color: #393939;
  414. line-height: 48rpx;
  415. }
  416. .right_item {
  417. width: 100%;
  418. box-sizing: border-box;
  419. padding: 10rpx 20rpx;
  420. .item_cover {
  421. width: 144rpx;
  422. height: 144rpx;
  423. border-radius: 16rpx;
  424. }
  425. .goodsDesc {
  426. width: calc(100% - 164rpx);
  427. margin-left: 20rpx;
  428. }
  429. .item_left {
  430. position: relative;
  431. .item_cover {
  432. width: 144rpx;
  433. height: 144rpx;
  434. border-radius: 16rpx;
  435. margin-right: 20rpx;
  436. }
  437. .bq1 {
  438. position: absolute;
  439. top: 0;
  440. right: 20rpx;
  441. width: 60rpx;
  442. height: 60rpx;
  443. }
  444. }
  445. .item_title {
  446. font-size: 28rpx;
  447. font-weight: 500;
  448. color: #222222;
  449. line-height: 40rpx;
  450. text-overflow: ellipsis;
  451. overflow: hidden;
  452. display: -webkit-box;
  453. -webkit-box-orient: vertical;
  454. box-orient: vertical;
  455. line-clamp: 2;
  456. -webkit-line-clamp: 2;
  457. }
  458. .item_price {
  459. margin-top: 22rpx;
  460. font-size: 28rpx;
  461. font-weight: bold;
  462. color: #FF2626;
  463. line-height: 32rpx;
  464. }
  465. .item_bottom {
  466. width: 100%;
  467. padding: 20rpx;
  468. .btn1 {
  469. width: 120rpx;
  470. height: 48rpx;
  471. border-radius: 4rpx;
  472. border: 1rpx solid #708AFF;
  473. margin-left: 32rpx;
  474. font-size: 28rpx;
  475. font-weight: 400;
  476. color: #5B77FF;
  477. line-height: 40rpx;
  478. }
  479. .btn2 {
  480. border: 1px solid #979797;
  481. color: #222222;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. .popu {
  489. background: #FFFFFF;
  490. box-sizing: border-box;
  491. padding: 48rpx 30rpx;
  492. .popu_img {
  493. width: 160rpx;
  494. height: 160rpx;
  495. border-radius: 12rpx;
  496. margin-right: 20rpx;
  497. }
  498. .popu_right {
  499. height: 124rpx;
  500. margin: 20rpx 0 16rpx;
  501. .popu_price {
  502. font-size: 28rpx;
  503. font-weight: 400;
  504. color: #FF4747;
  505. line-height: 34rpx;
  506. }
  507. .popu_norm {
  508. max-width: 450rpx;
  509. font-size: 24rpx;
  510. font-weight: 400;
  511. color: #A7A7A7;
  512. line-height: 34rpx;
  513. }
  514. }
  515. .popu_title {
  516. font-size: 28rpx;
  517. font-weight: 600;
  518. color: #222222;
  519. line-height: 40rpx;
  520. margin: 15rpx 0;
  521. text-overflow: ellipsis;
  522. overflow: hidden;
  523. display: -webkit-box;
  524. -webkit-box-orient: vertical;
  525. box-orient: vertical;
  526. line-clamp: 2;
  527. -webkit-line-clamp: 2;
  528. }
  529. .address {
  530. .address_img {
  531. width: 200rpx;
  532. height: 200rpx;
  533. border-radius: 50%;
  534. margin-bottom: 20rpx;
  535. }
  536. .address_text {
  537. text-align: center;
  538. font-size: 28rpx;
  539. color: #222222;
  540. line-height: 40rpx;
  541. }
  542. }
  543. .box_bg {
  544. background: #F5F5F5;
  545. border-radius: 16rpx;
  546. box-sizing: border-box;
  547. padding: 24rpx 20rpx;
  548. margin: 10rpx 0;
  549. .check_img {
  550. width: 24rpx;
  551. height: 24rpx;
  552. }
  553. .popu_right2 {
  554. padding-left: 30rpx;
  555. .popu_name {
  556. font-size: 28rpx;
  557. font-weight: 500;
  558. color: #222222;
  559. line-height: 40rpx;
  560. }
  561. .popu_phone {
  562. padding-left: 16rpx;
  563. font-size: 22rpx;
  564. font-weight: 400;
  565. color: #999999;
  566. line-height: 16px;
  567. }
  568. .popu_addr {
  569. padding: 16rpx 0 0;
  570. font-size: 24rpx;
  571. font-weight: 400;
  572. color: #444444;
  573. line-height: 34rpx;
  574. }
  575. }
  576. }
  577. .popu_box {
  578. background: #F4F4F4;
  579. border-radius: 8rpx;
  580. font-size: 26rpx;
  581. font-weight: 400;
  582. color: #222222;
  583. line-height: 36rpx;
  584. padding: 7rpx 36rpx;
  585. margin: 0 22rpx 28rpx 0;
  586. text-overflow: ellipsis;
  587. overflow: hidden;
  588. display: -webkit-box;
  589. -webkit-box-orient: vertical;
  590. box-orient: vertical;
  591. line-clamp: 2;
  592. -webkit-line-clamp: 2;
  593. }
  594. .popu_box2 {
  595. background-color: #5b5b5b;
  596. }
  597. // .popu_box:nth-child(4n+4) {
  598. // margin: 0 0 28rpx 0;
  599. // }
  600. .sele_active {
  601. background: #F1F4FF;
  602. border: 1px solid #5471FF;
  603. color: #506DFF;
  604. }
  605. .sure_btn {
  606. width: 100%;
  607. height: 84rpx;
  608. background: #506DFF;
  609. border-radius: 42rpx;
  610. font-size: 36rpx;
  611. font-weight: 500;
  612. color: #FFFFFF;
  613. line-height: 84rpx;
  614. text-align: center;
  615. margin-top: 94rpx;
  616. }
  617. }
  618. }
  619. </style>