detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. route: 'pages/market/index',
  169. }, {
  170. icon: 'chat',
  171. text: '客服',
  172. }
  173. ],
  174. buttonGroup: [{
  175. text: '加入购物车',
  176. backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
  177. color: '#fff',
  178. type: '0'
  179. },
  180. {
  181. text: '立即购买',
  182. backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
  183. color: '#fff',
  184. type: '1'
  185. }
  186. ],
  187. // 商品id
  188. id: '',
  189. // 轮播图
  190. bannerList: [],
  191. // 商品详情
  192. info: {},
  193. // 商店详情
  194. shop: {},
  195. // 规格情况
  196. specs: [],
  197. // 已选
  198. Selected: '',
  199. // 是否显示返回顶部
  200. isShow: false,
  201. topItem: '',
  202. // 收藏
  203. collection: false,
  204. // 菜单显示
  205. menu: false,
  206. disabled: true,
  207. // 显示文字判断
  208. type: '0',
  209. // 选择规格
  210. isActive: -1,
  211. money: 0,
  212. // 计数器
  213. num: 1,
  214. max: 0
  215. };
  216. },
  217. onLoad: async function(e) {
  218. const that = this;
  219. that.$set(that, `id`, e.id || '');
  220. that.search();
  221. },
  222. onShow: function() {},
  223. methods: {
  224. //店铺,购物车,客服跳转
  225. onClick(e) {
  226. if (e && e.content.route) {
  227. uni.reLaunch({
  228. url: `/${e.content.route}`
  229. })
  230. }
  231. },
  232. // 公共跳转
  233. toCommon(e) {
  234. uni.navigateTo({
  235. url: `/${e}`
  236. })
  237. },
  238. // 收藏
  239. toCollect() {
  240. const that = this;
  241. that.collection = !that.collection;
  242. if (that.collection == true) {
  243. uni.showToast({
  244. title: `收藏成功`,
  245. icon: 'none'
  246. })
  247. } else {
  248. uni.showToast({
  249. title: `取消成功`,
  250. icon: 'none'
  251. })
  252. }
  253. },
  254. //主菜单跳转
  255. toPath(e) {
  256. if (e && e.route) uni.reLaunch({
  257. url: `/${e.route}`
  258. })
  259. },
  260. // 菜单展开
  261. toMenu() {
  262. const that = this;
  263. that.menu = !that.menu
  264. },
  265. // 计算高度
  266. handleScroll(e) {
  267. const that = this;
  268. let scrollTop = e.detail.scrollTop;
  269. that.isShow = scrollTop > 500;
  270. that.topItem = '';
  271. },
  272. // 返回顶部
  273. backTop() {
  274. const that = this;
  275. that.topItem = 'top'
  276. },
  277. //加入购物车,立即购买弹窗
  278. buttonClick(e) {
  279. const that = this;
  280. if (e && e.content) that.type = e.content.type;
  281. that.$refs.popup.open();
  282. },
  283. // 选择规格
  284. toChoose() {
  285. const that = this;
  286. that.type = '1';
  287. that.$refs.popup.open();
  288. },
  289. // 修改样式
  290. toStyle(e, index) {
  291. const that = this;
  292. that.$set(that, `isActive`, index)
  293. that.$set(that, `Selected`, e.name)
  294. that.$set(that, `max`, e.num)
  295. that.$set(that, `money`, e.sell_money)
  296. that.disabled = false;
  297. },
  298. // 计数器
  299. toCount(e) {
  300. const that = this;
  301. that.num = e;
  302. },
  303. // 立即购买
  304. toBuy(e) {
  305. const that = this;
  306. uni.getStorage({
  307. key: 'token',
  308. success: async function(res) {
  309. let user = that.$jwt(res.data);
  310. if (that.Selected) {
  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. if (e == '0') {
  322. let arr = await that.$api(`/cart`, 'POST', data)
  323. if (arr.errcode == '0') {
  324. uni.showToast({
  325. title: `加入购物车成功`,
  326. icon: 'success'
  327. })
  328. that.$refs.popup.close()
  329. } else {
  330. uni.showToast({
  331. title: arr.errmsg,
  332. icon: 'none'
  333. })
  334. }
  335. } else {
  336. let arr = await that.$api(`/util/checkCanBuy`, 'POST', data)
  337. if (arr.errcode == '0') {
  338. if (arr.data.result == true) {
  339. uni.navigateTo({
  340. url: `/pagesHome/order/order?id=${e._id}`
  341. })
  342. } else {
  343. uni.showToast({
  344. title: arr.data.msg,
  345. icon: 'none'
  346. })
  347. }
  348. } else {
  349. uni.showToast({
  350. title: arr.errmsg,
  351. icon: 'none'
  352. })
  353. }
  354. }
  355. } else {
  356. uni.showModal({
  357. title: '提示',
  358. content: '请选择规格',
  359. confirmColor: '#ff0000',
  360. showCancel: false,
  361. success: function(res) {}
  362. });
  363. }
  364. },
  365. fail: function(err) {
  366. uni.navigateTo({
  367. url: `/pages/login/index`
  368. })
  369. }
  370. });
  371. },
  372. // 关闭弹框
  373. toClose() {
  374. const that = this;
  375. that.$refs.popup.close()
  376. },
  377. // 详情数据
  378. async search() {
  379. const that = this;
  380. let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  381. id: that.id
  382. });
  383. if (res.errcode == '0') {
  384. that.$set(that, `info`, res.data.goods)
  385. that.$set(that, `specs`, res.data.specs)
  386. that.$set(that, `shop`, res.data.shop)
  387. if (res.data.specs.length > 0) that.$set(that, `money`, res.data.specs[0].sell_money)
  388. that.$set(that, `bannerList`, res.data.goods.file)
  389. }
  390. },
  391. }
  392. }
  393. </script>
  394. <style lang="scss">
  395. .scrollView {
  396. height: 100vh;
  397. }
  398. .main {
  399. display: flex;
  400. flex-direction: column;
  401. width: 100vw;
  402. height: 100vh;
  403. .onemain {
  404. position: relative;
  405. flex-grow: 1;
  406. background-color: var(--f1Color);
  407. .one {
  408. swiper {
  409. height: 70vw;
  410. }
  411. .list {
  412. border-radius: 5px;
  413. .image {
  414. width: 100%;
  415. height: 100%;
  416. border-radius: 5px;
  417. }
  418. }
  419. }
  420. .two {
  421. padding: 0 0 2vw 0;
  422. background-color: var(--mainColor);
  423. .two_1 {
  424. display: flex;
  425. align-items: center;
  426. border-bottom: 0.5vw solid var(--f9Color);
  427. padding: 2vw;
  428. .money_1 {
  429. color: var(--ff0Color);
  430. text {
  431. margin: 0 1vw 0 0;
  432. }
  433. text:last-child {
  434. font-size: var(--font20Szie);
  435. font-weight: bold;
  436. }
  437. }
  438. .money_2 {
  439. text-decoration: line-through;
  440. color: var(--f99Color);
  441. text {
  442. margin: 0 1vw 0 0;
  443. }
  444. text:last-child {
  445. font-size: var(--font16Size);
  446. }
  447. }
  448. }
  449. .two_2 {
  450. font-size: var(--font18Szie);
  451. font-weight: bold;
  452. padding: 1vw 2vw;
  453. }
  454. .two_3 {
  455. font-size: var(--font16Szie);
  456. color: var(--f85Color);
  457. padding: 1vw 2vw;
  458. }
  459. .two_4 {
  460. font-size: var(--font12Size);
  461. color: var(--fcColor);
  462. padding: 1vw 2vw;
  463. text {
  464. margin: 0 2vw 0 0;
  465. }
  466. }
  467. }
  468. .thr {
  469. .thr_1 {
  470. display: flex;
  471. flex-direction: row;
  472. justify-content: space-between;
  473. margin: 2vw 0 2vw 0;
  474. padding: 2vw;
  475. background-color: var(--mainColor);
  476. }
  477. }
  478. .four {
  479. padding: 2vw;
  480. background-color: var(--mainColor);
  481. .four_1 {
  482. display: flex;
  483. justify-content: space-between;
  484. .image {
  485. width: 15vw;
  486. height: 15vw;
  487. border: 0.1vw solid var(--fcColor);
  488. }
  489. .other {
  490. flex-grow: 1;
  491. margin: 0 0 0 2vw;
  492. .name {
  493. font-size: var(--font16Szie);
  494. }
  495. .other_1 {
  496. font-size: var(--font12Size);
  497. text {
  498. color: var(--fcColor);
  499. margin: 0 2vw 0 0;
  500. }
  501. }
  502. }
  503. }
  504. .four_2 {
  505. display: flex;
  506. flex-direction: row;
  507. justify-content: space-evenly;
  508. padding: 2vw 0;
  509. color: var(--f99Color);
  510. .grade {
  511. font-size: var(--font14Size);
  512. color: var(--f85Color);
  513. text {
  514. color: var(--ff0Color);
  515. }
  516. }
  517. .btn {
  518. border: 0.1vw solid var(--fcColor);
  519. padding: 1vw 6vw;
  520. border-radius: 1vw;
  521. color: var(--f00Color);
  522. }
  523. .btn:last-child {
  524. padding: 1vw 10vw;
  525. }
  526. }
  527. }
  528. .five {
  529. margin: 2vw 0 0 0;
  530. .five_1 {
  531. padding: 2vw;
  532. background-color: var(--mainColor);
  533. font-size: var(--font18Szie);
  534. color: var(--f99Color);
  535. }
  536. .five_2 {
  537. padding: 0 2vw;
  538. background-color: var(--mainColor);
  539. text-align: center;
  540. }
  541. }
  542. }
  543. }
  544. .scroll-view {
  545. position: absolute;
  546. top: 0;
  547. left: 0;
  548. right: 0;
  549. bottom: 0;
  550. .list-scroll-view {
  551. display: flex;
  552. flex-direction: column;
  553. }
  554. }
  555. .scrollView {
  556. height: 100vh;
  557. }
  558. .collect {
  559. position: fixed;
  560. top: 4vw;
  561. right: 5vw;
  562. text {
  563. font-size: 30px;
  564. background-color: #0000005f;
  565. border-radius: 90px;
  566. }
  567. }
  568. .menu {
  569. position: fixed;
  570. bottom: 30vw;
  571. right: 5vw;
  572. text {
  573. font-size: 30px;
  574. background-color: #0000005f;
  575. border-radius: 90px;
  576. }
  577. }
  578. .menu_1 {
  579. position: fixed;
  580. bottom: 40vw;
  581. right: 5vw;
  582. background-color: var(--mainColor);
  583. padding: 2vw;
  584. .title {
  585. display: flex;
  586. padding: 2vw;
  587. border-bottom: 0.1vw solid var(--fcColor);
  588. .image {
  589. width: 7vw;
  590. height: 6vw;
  591. }
  592. .name {
  593. margin: 0 0 0 1vw;
  594. font-size: var(--font14Size);
  595. }
  596. }
  597. }
  598. .backTop {
  599. position: fixed;
  600. bottom: 20vw;
  601. right: 5vw;
  602. text {
  603. font-size: 30px;
  604. background-color: #0000005f;
  605. border-radius: 90px;
  606. }
  607. }
  608. uni-popup {
  609. z-index: 999999 !important;
  610. }
  611. .content {
  612. height: 100vw;
  613. .one {
  614. display: flex;
  615. flex-direction: row;
  616. justify-content: space-between;
  617. margin: 2vw;
  618. padding: 2vw 0;
  619. border-bottom: 1px solid var(--f9Color);
  620. .image {
  621. width: 25vw;
  622. height: 25vw;
  623. margin: 0 2vw 0 0;
  624. }
  625. .other {
  626. display: flex;
  627. flex-direction: column;
  628. flex-grow: 1;
  629. margin: 0 0 0 2vw;
  630. .money {
  631. color: var(--fFB1Color);
  632. font-size: var(--font20Szie);
  633. padding: 2vw 0;
  634. }
  635. .other_1 {
  636. font-size: var(--font14Size);
  637. text {
  638. padding: 0 2vw;
  639. color: var(--f85Color);
  640. }
  641. }
  642. }
  643. }
  644. .two {
  645. margin: 0 2vw;
  646. padding: 2vw 0;
  647. font-size: var(--font12Size);
  648. border-bottom: 1px solid var(--f9Color);
  649. .two_2 {
  650. padding: 1vw;
  651. text {
  652. margin: 0 2vw 0 0;
  653. padding: 1vw;
  654. border-radius: 1vw;
  655. background-color: var(--f9Color);
  656. }
  657. .style {
  658. color: var(--mainColor);
  659. background-color: var(--ff0Color);
  660. }
  661. }
  662. }
  663. .thr {
  664. display: flex;
  665. justify-content: flex-start;
  666. margin: 0 2vw;
  667. padding: 2vw 0;
  668. text {
  669. margin: 0 2vw 0 0;
  670. }
  671. text:last-child {
  672. margin: 0 0 0 2vw;
  673. font-size: var(--font12Size);
  674. color: var(--f85Color);
  675. }
  676. }
  677. .button {
  678. position: fixed;
  679. width: 100vw;
  680. padding: 4vw 0;
  681. background-color: var(--fFB1Color);
  682. bottom: 0;
  683. text-align: center;
  684. font-size: var(--font18Szie);
  685. color: var(--mainColor);
  686. }
  687. }
  688. </style>