detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="onemain">
  5. <scroll-view scroll-y="true" class="scroll-view" scroll-with-animation :scroll-into-view="topItem"
  6. @scroll="handleScroll">
  7. <view class="list-scroll-view" id="top">
  8. <view class="one">
  9. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff"
  10. indicator-active-color="#FB1438" :autoplay="true" :interval="3000" :duration="1000">
  11. <swiper-item class="list" v-for="(item,index) in bannerList" :key="index">
  12. <image class="image" :src="item.url" mode="">
  13. </image>
  14. </swiper-item>
  15. </swiper>
  16. </view>
  17. <view class="two">
  18. <view class="two_1">
  19. <view class="money_1">
  20. <text>¥</text>
  21. <text>{{specs&&specs.length>0?specs[0].sell_money:''}}</text>
  22. </view>
  23. <view class="money_2">
  24. <text>¥</text>
  25. <text>{{specs&&specs.length>0?specs[0].flow_money:''}}</text>
  26. </view>
  27. </view>
  28. <view class="two_2">{{info.name}}</view>
  29. <view class="two_3">{{info.shot_brief}}</view>
  30. <view class="two_4">
  31. <text>运费{{specs&&specs.length>0?specs[0].freight:''}}元</text>
  32. <text>{{info.send_time}}内发货</text>
  33. </view>
  34. </view>
  35. <view class="thr">
  36. <view class="thr_1" @click="toChoose">
  37. <view class="title">选择规格</view>
  38. <text class="iconfont icon-jiantouyou"></text>
  39. </view>
  40. <view class="thr_1">
  41. <view class="title">商品评价({{info.comment||0}})</view>
  42. <text class="iconfont icon-jiantouyou"></text>
  43. </view>
  44. </view>
  45. <view class="four">
  46. <view class="four_1">
  47. <image class="image" :src="shop.logo&&shop.logo.length>0?shop.logo[0].url:''"></image>
  48. <view class="other">
  49. <view class="name">{{shop.name}}</view>
  50. <view class="other_1"><text>宝贝数</text>{{shop.num||0}}</view>
  51. </view>
  52. </view>
  53. <view class="four_2">
  54. <view class="grade">商品:<text>{{shop.grade||'5.00'}}</text></view>|
  55. <view class="grade">发货:<text>{{shop.grade||'5.00'}}</text></view>|
  56. <view class="grade">服务:<text>{{shop.grade||'5.00'}}</text></view>
  57. </view>
  58. <view class="four_2">
  59. <view class="btn" @tap="toCommon('pagesHome/shop/index')">进入店铺</view>
  60. <view class="btn">关注</view>
  61. </view>
  62. </view>
  63. <view class="five">
  64. <view class="five_1">{{info.brief}}</view>
  65. <view class="five_2" v-for="(item,index) in bannerList" :key="index">
  66. <image class="image" :src="item.url"></image>
  67. </view>
  68. </view>
  69. </view>
  70. </scroll-view>
  71. </view>
  72. <view class="foot">
  73. <uni-goods-nav :options="options" :button-group="buttonGroup" @click="onClick"
  74. @buttonClick="buttonClick" />
  75. </view>
  76. </view>
  77. <view class="collect">
  78. <text v-if="!collection" @click="toCollect" class="iconfont icon-yduishoucangkongxin"></text>
  79. <text v-else @click="toCollect" class="iconfont icon-yduishoucangshixin"></text>
  80. </view>
  81. <view class="menu">
  82. <text @click="toMenu" class="iconfont icon-gengduo"></text>
  83. </view>
  84. <view class="menu_1" v-if="menu">
  85. <view class="title" v-for="(item,index) in barList" :key="index" @click="toPath(item)">
  86. <image class="image" :src="item.normal"></image>
  87. <view class="name">{{item.name}}</view>
  88. </view>
  89. </view>
  90. <view class="backTop" v-if="isShow==true">
  91. <text @click="backTop" class="iconfont icon-fanhuidingbu"></text>
  92. </view>
  93. <uni-popup ref="popup" background-color="#fff" type="bottom">
  94. <view class="content">
  95. <view class="one">
  96. <image class="image" :src="info.file&&info.file.length>0?info.file[0].url:''"></image>
  97. <view class="other">
  98. <view class="money">
  99. <text>¥</text>
  100. <text>{{money}}</text>
  101. </view>
  102. <view class="other_1">
  103. 已选: <text>{{Selected}}</text>
  104. </view>
  105. </view>
  106. <view class="btn">
  107. <text @click="toClose" class="iconfont icon-shanchu"></text>
  108. </view>
  109. </view>
  110. <view class="two">
  111. <view class="two_1">规格</view>
  112. <view class="two_2">
  113. <text v-for="(item,index) in specs" :key="index" @click="toStyle(item,index)"
  114. :class="{ 'style': isActive==index}">{{item.name}}</text>
  115. </view>
  116. </view>
  117. <view class="thr">
  118. <text>数量</text>
  119. <view class="count">
  120. <uni-number-box :min="1" :max="max" :disabled="disabled" v-model="num" @change="toCount">
  121. </uni-number-box>
  122. </view>
  123. <text>库存{{max}}</text>
  124. </view>
  125. <view @click="toBuy(type)" class="button">{{type=='0'?'加入购物车':'立即购买'}}</view>
  126. </view>
  127. </uni-popup>
  128. </mobile-frame>
  129. </template>
  130. <script>
  131. export default {
  132. data() {
  133. return {
  134. barList: [{
  135. name: '首页',
  136. route: 'pages/home/index',
  137. normal: require('@/static/shouye.png'),
  138. },
  139. {
  140. name: '微店',
  141. route: 'pages/store/index',
  142. normal: require('@/static/store.png'),
  143. },
  144. {
  145. name: '周边',
  146. route: 'pages/week/index',
  147. normal: require('@/static/week.png'),
  148. },
  149. {
  150. name: '购物车',
  151. route: 'pages/market/index',
  152. normal: require('@/static/market.png'),
  153. },
  154. {
  155. name: '我的',
  156. route: 'pages/my/index',
  157. normal: require('@/static/my.png'),
  158. },
  159. ],
  160. options: [{
  161. icon: 'shop',
  162. text: '店铺',
  163. route: 'pagesHome/shop/index',
  164. },
  165. {
  166. icon: 'cart',
  167. text: '购物车',
  168. }, {
  169. icon: 'chat',
  170. text: '客服',
  171. }
  172. ],
  173. buttonGroup: [{
  174. text: '加入购物车',
  175. backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
  176. color: '#fff',
  177. type: '0'
  178. },
  179. {
  180. text: '立即购买',
  181. backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
  182. color: '#fff',
  183. type: '1'
  184. }
  185. ],
  186. // 商品id
  187. id: '',
  188. // 轮播图
  189. bannerList: [],
  190. // 商品详情
  191. info: {},
  192. // 商店详情
  193. shop: {},
  194. // 规格情况
  195. specs: [],
  196. // 已选
  197. Selected: '',
  198. // 是否显示返回顶部
  199. isShow: false,
  200. topItem: '',
  201. // 收藏
  202. collection: false,
  203. // 菜单显示
  204. menu: false,
  205. disabled: true,
  206. // 显示文字判断
  207. type: '0',
  208. // 选择规格
  209. isActive: -1,
  210. money: 0,
  211. // 计数器
  212. num: 1,
  213. max: 0
  214. };
  215. },
  216. onLoad: async function(e) {
  217. const that = this;
  218. that.$set(that, `id`, e.id || '');
  219. that.search();
  220. },
  221. onShow: function() {},
  222. methods: {
  223. //店铺,购物车,客服跳转
  224. onClick(e) {
  225. if (e && e.content.route) {
  226. uni.navigateTo({
  227. url: `/${e.content.route}`
  228. })
  229. }
  230. },
  231. // 公共跳转
  232. toCommon(e) {
  233. uni.navigateTo({
  234. url: `/${e}`
  235. })
  236. },
  237. // 收藏
  238. toCollect() {
  239. const that = this;
  240. that.collection = !that.collection;
  241. if (that.collection == true) {
  242. uni.showToast({
  243. title: `收藏成功`,
  244. icon: 'none'
  245. })
  246. } else {
  247. uni.showToast({
  248. title: `取消成功`,
  249. icon: 'none'
  250. })
  251. }
  252. },
  253. //主菜单跳转
  254. toPath(e) {
  255. if (e && e.route) uni.reLaunch({
  256. url: `/${e.route}`
  257. })
  258. },
  259. // 菜单展开
  260. toMenu() {
  261. const that = this;
  262. that.menu = !that.menu
  263. },
  264. // 计算高度
  265. handleScroll(e) {
  266. const that = this;
  267. let scrollTop = e.detail.scrollTop;
  268. that.isShow = scrollTop > 500;
  269. that.topItem = '';
  270. },
  271. // 返回顶部
  272. backTop() {
  273. const that = this;
  274. that.topItem = 'top'
  275. },
  276. //加入购物车,立即购买弹窗
  277. buttonClick(e) {
  278. const that = this;
  279. if (e && e.content) that.type = e.content.type;
  280. that.$refs.popup.open();
  281. },
  282. // 选择规格
  283. toChoose() {
  284. const that = this;
  285. that.type = '1';
  286. that.$refs.popup.open();
  287. },
  288. // 修改样式
  289. toStyle(e, index) {
  290. const that = this;
  291. that.$set(that, `isActive`, index)
  292. that.$set(that, `Selected`, e.name)
  293. that.$set(that, `max`, e.num)
  294. that.$set(that, `money`, e.sell_money)
  295. that.disabled = false;
  296. },
  297. // 计数器
  298. toCount(e) {
  299. const that = this;
  300. that.num = e;
  301. },
  302. // 立即购买
  303. toBuy(e) {
  304. const that = this;
  305. uni.getStorage({
  306. key: 'token',
  307. success: async function(res) {
  308. let user = that.$jwt(res.data);
  309. if (that.Selected) {
  310. if (e == '0') {
  311. let specs_id;
  312. let specs = that.specs.find(i => i.name == that.Selected)
  313. if (specs) specs_id = specs._id
  314. let data = {
  315. customer: user._id,
  316. shop: that.shop._id,
  317. goods: that.info._id,
  318. goodsSpec: specs_id,
  319. num: that.num
  320. }
  321. let arr = await that.$api(`/cart`, 'POST', data)
  322. if (arr.errcode == '0') {
  323. uni.showToast({
  324. title: `加入购物车成功`,
  325. icon: 'success'
  326. })
  327. that.$refs.popup.close()
  328. } else {
  329. uni.showToast({
  330. title: arr.errmsg,
  331. icon: 'none'
  332. })
  333. }
  334. } else {
  335. uni.navigateTo({
  336. url: `/pagesHome/order/order`
  337. })
  338. }
  339. } else {
  340. uni.showModal({
  341. title: '提示',
  342. content: '请选择规格',
  343. confirmColor: '#ff0000',
  344. showCancel: false,
  345. success: function(res) {}
  346. });
  347. }
  348. },
  349. fail: function(err) {
  350. uni.navigateTo({
  351. url: `/pages/login/index`
  352. })
  353. }
  354. });
  355. },
  356. // 关闭弹框
  357. toClose() {
  358. const that = this;
  359. that.$refs.popup.close()
  360. },
  361. // 详情数据
  362. async search() {
  363. const that = this;
  364. let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  365. id: that.id
  366. });
  367. if (res.errcode == '0') {
  368. that.$set(that, `info`, res.data.goods)
  369. that.$set(that, `specs`, res.data.specs)
  370. that.$set(that, `shop`, res.data.shop)
  371. if (res.data.specs.length > 0) that.$set(that, `money`, res.data.specs[0].sell_money)
  372. that.$set(that, `bannerList`, res.data.goods.file)
  373. }
  374. },
  375. }
  376. }
  377. </script>
  378. <style lang="scss">
  379. .scrollView {
  380. height: 100vh;
  381. }
  382. .main {
  383. display: flex;
  384. flex-direction: column;
  385. width: 100vw;
  386. height: 100vh;
  387. .onemain {
  388. position: relative;
  389. flex-grow: 1;
  390. background-color: var(--f9Color);
  391. .one {
  392. swiper {
  393. height: 70vw;
  394. }
  395. .list {
  396. border-radius: 5px;
  397. .image {
  398. width: 100%;
  399. height: 100%;
  400. border-radius: 5px;
  401. }
  402. }
  403. }
  404. .two {
  405. padding: 0 0 2vw 0;
  406. background-color: var(--mainColor);
  407. .two_1 {
  408. display: flex;
  409. align-items: center;
  410. border-bottom: 0.5vw solid var(--f9Color);
  411. padding: 2vw;
  412. .money_1 {
  413. color: var(--ff0Color);
  414. text {
  415. margin: 0 1vw 0 0;
  416. }
  417. text:last-child {
  418. font-size: var(--font20Szie);
  419. font-weight: bold;
  420. }
  421. }
  422. .money_2 {
  423. text-decoration: line-through;
  424. color: var(--f99Color);
  425. text {
  426. margin: 0 1vw 0 0;
  427. }
  428. text:last-child {
  429. font-size: var(--font16Size);
  430. }
  431. }
  432. }
  433. .two_2 {
  434. font-size: var(--font18Szie);
  435. font-weight: bold;
  436. padding: 1vw 2vw;
  437. }
  438. .two_3 {
  439. font-size: var(--font16Szie);
  440. color: var(--f85Color);
  441. padding: 1vw 2vw;
  442. }
  443. .two_4 {
  444. font-size: var(--font12Size);
  445. color: var(--fcColor);
  446. padding: 1vw 2vw;
  447. text {
  448. margin: 0 2vw 0 0;
  449. }
  450. }
  451. }
  452. .thr {
  453. .thr_1 {
  454. display: flex;
  455. flex-direction: row;
  456. justify-content: space-between;
  457. margin: 2vw 0 2vw 0;
  458. padding: 2vw;
  459. background-color: var(--mainColor);
  460. }
  461. }
  462. .four {
  463. padding: 2vw;
  464. background-color: var(--mainColor);
  465. .four_1 {
  466. display: flex;
  467. justify-content: space-between;
  468. .image {
  469. width: 15vw;
  470. height: 15vw;
  471. border: 0.1vw solid var(--fcColor);
  472. }
  473. .other {
  474. flex-grow: 1;
  475. margin: 0 0 0 2vw;
  476. .name {
  477. font-size: var(--font16Szie);
  478. }
  479. .other_1 {
  480. font-size: var(--font12Size);
  481. text {
  482. color: var(--fcColor);
  483. margin: 0 2vw 0 0;
  484. }
  485. }
  486. }
  487. }
  488. .four_2 {
  489. display: flex;
  490. flex-direction: row;
  491. justify-content: space-evenly;
  492. padding: 2vw 0;
  493. color: var(--f99Color);
  494. .grade {
  495. font-size: var(--font14Size);
  496. color: var(--f85Color);
  497. text {
  498. color: var(--ff0Color);
  499. }
  500. }
  501. .btn {
  502. border: 0.1vw solid var(--fcColor);
  503. padding: 1vw 6vw;
  504. border-radius: 1vw;
  505. color: var(--f00Color);
  506. }
  507. .btn:last-child {
  508. padding: 1vw 10vw;
  509. }
  510. }
  511. }
  512. .five {
  513. margin: 2vw 0 0 0;
  514. .five_1 {
  515. padding: 2vw;
  516. background-color: var(--mainColor);
  517. font-size: var(--font18Szie);
  518. color: var(--f99Color);
  519. }
  520. .five_2 {
  521. padding: 0 2vw;
  522. background-color: var(--mainColor);
  523. text-align: center;
  524. }
  525. }
  526. }
  527. }
  528. .scroll-view {
  529. position: absolute;
  530. top: 0;
  531. left: 0;
  532. right: 0;
  533. bottom: 0;
  534. .list-scroll-view {
  535. display: flex;
  536. flex-direction: column;
  537. }
  538. }
  539. .scrollView {
  540. height: 100vh;
  541. }
  542. .collect {
  543. position: fixed;
  544. top: 4vw;
  545. right: 5vw;
  546. text {
  547. font-size: 30px;
  548. background-color: #0000005f;
  549. border-radius: 90px;
  550. }
  551. }
  552. .menu {
  553. position: fixed;
  554. bottom: 30vw;
  555. right: 5vw;
  556. text {
  557. font-size: 30px;
  558. background-color: #0000005f;
  559. border-radius: 90px;
  560. }
  561. }
  562. .menu_1 {
  563. position: fixed;
  564. bottom: 40vw;
  565. right: 5vw;
  566. background-color: var(--mainColor);
  567. padding: 2vw;
  568. .title {
  569. display: flex;
  570. padding: 2vw;
  571. border-bottom: 0.1vw solid var(--fcColor);
  572. .image {
  573. width: 7vw;
  574. height: 6vw;
  575. }
  576. .name {
  577. margin: 0 0 0 1vw;
  578. font-size: var(--font14Size);
  579. }
  580. }
  581. }
  582. .backTop {
  583. position: fixed;
  584. bottom: 20vw;
  585. right: 5vw;
  586. text {
  587. font-size: 30px;
  588. background-color: #0000005f;
  589. border-radius: 90px;
  590. }
  591. }
  592. uni-popup {
  593. z-index: 999999 !important;
  594. }
  595. .content {
  596. height: 100vw;
  597. .one {
  598. display: flex;
  599. flex-direction: row;
  600. justify-content: space-between;
  601. margin: 2vw;
  602. padding: 2vw 0;
  603. border-bottom: 1px solid var(--f9Color);
  604. .image {
  605. width: 25vw;
  606. height: 25vw;
  607. margin: 0 2vw 0 0;
  608. }
  609. .other {
  610. display: flex;
  611. flex-direction: column;
  612. flex-grow: 1;
  613. margin: 0 0 0 2vw;
  614. .money {
  615. color: var(--fFB1Color);
  616. font-size: var(--font20Szie);
  617. padding: 2vw 0;
  618. }
  619. .other_1 {
  620. font-size: var(--font14Size);
  621. text {
  622. padding: 0 2vw;
  623. color: var(--f85Color);
  624. }
  625. }
  626. }
  627. }
  628. .two {
  629. margin: 0 2vw;
  630. padding: 2vw 0;
  631. font-size: var(--font12Size);
  632. border-bottom: 1px solid var(--f9Color);
  633. .two_2 {
  634. padding: 1vw;
  635. text {
  636. margin: 0 2vw 0 0;
  637. padding: 1vw;
  638. border-radius: 1vw;
  639. background-color: var(--f9Color);
  640. }
  641. .style {
  642. color: var(--mainColor);
  643. background-color: var(--ff0Color);
  644. }
  645. }
  646. }
  647. .thr {
  648. display: flex;
  649. justify-content: flex-start;
  650. margin: 0 2vw;
  651. padding: 2vw 0;
  652. text {
  653. margin: 0 2vw 0 0;
  654. }
  655. text:last-child {
  656. margin: 0 0 0 2vw;
  657. font-size: var(--font12Size);
  658. color: var(--f85Color);
  659. }
  660. }
  661. .button {
  662. position: fixed;
  663. width: 100vw;
  664. padding: 4vw 0;
  665. background-color: var(--fFB1Color);
  666. bottom: 0;
  667. text-align: center;
  668. font-size: var(--font18Szie);
  669. color: var(--mainColor);
  670. }
  671. }
  672. </style>