base.vue 15 KB

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