detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. if (e == '0') {
  312. let specs_id;
  313. let specs = that.specs.find(i => i.name == that.Selected)
  314. if (specs) specs_id = specs._id
  315. let data = {
  316. customer: user._id,
  317. shop: that.shop._id,
  318. goods: that.info._id,
  319. goodsSpec: specs_id,
  320. num: that.num
  321. }
  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. uni.navigateTo({
  337. url: `/pagesHome/order/order?id=${e._id}`
  338. })
  339. }
  340. } else {
  341. uni.showModal({
  342. title: '提示',
  343. content: '请选择规格',
  344. confirmColor: '#ff0000',
  345. showCancel: false,
  346. success: function(res) {}
  347. });
  348. }
  349. },
  350. fail: function(err) {
  351. uni.navigateTo({
  352. url: `/pages/login/index`
  353. })
  354. }
  355. });
  356. },
  357. // 关闭弹框
  358. toClose() {
  359. const that = this;
  360. that.$refs.popup.close()
  361. },
  362. // 详情数据
  363. async search() {
  364. const that = this;
  365. let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  366. id: that.id
  367. });
  368. if (res.errcode == '0') {
  369. that.$set(that, `info`, res.data.goods)
  370. that.$set(that, `specs`, res.data.specs)
  371. that.$set(that, `shop`, res.data.shop)
  372. if (res.data.specs.length > 0) that.$set(that, `money`, res.data.specs[0].sell_money)
  373. that.$set(that, `bannerList`, res.data.goods.file)
  374. }
  375. },
  376. }
  377. }
  378. </script>
  379. <style lang="scss">
  380. .scrollView {
  381. height: 100vh;
  382. }
  383. .main {
  384. display: flex;
  385. flex-direction: column;
  386. width: 100vw;
  387. height: 100vh;
  388. .onemain {
  389. position: relative;
  390. flex-grow: 1;
  391. background-color: var(--f9Color);
  392. .one {
  393. swiper {
  394. height: 70vw;
  395. }
  396. .list {
  397. border-radius: 5px;
  398. .image {
  399. width: 100%;
  400. height: 100%;
  401. border-radius: 5px;
  402. }
  403. }
  404. }
  405. .two {
  406. padding: 0 0 2vw 0;
  407. background-color: var(--mainColor);
  408. .two_1 {
  409. display: flex;
  410. align-items: center;
  411. border-bottom: 0.5vw solid var(--f9Color);
  412. padding: 2vw;
  413. .money_1 {
  414. color: var(--ff0Color);
  415. text {
  416. margin: 0 1vw 0 0;
  417. }
  418. text:last-child {
  419. font-size: var(--font20Szie);
  420. font-weight: bold;
  421. }
  422. }
  423. .money_2 {
  424. text-decoration: line-through;
  425. color: var(--f99Color);
  426. text {
  427. margin: 0 1vw 0 0;
  428. }
  429. text:last-child {
  430. font-size: var(--font16Size);
  431. }
  432. }
  433. }
  434. .two_2 {
  435. font-size: var(--font18Szie);
  436. font-weight: bold;
  437. padding: 1vw 2vw;
  438. }
  439. .two_3 {
  440. font-size: var(--font16Szie);
  441. color: var(--f85Color);
  442. padding: 1vw 2vw;
  443. }
  444. .two_4 {
  445. font-size: var(--font12Size);
  446. color: var(--fcColor);
  447. padding: 1vw 2vw;
  448. text {
  449. margin: 0 2vw 0 0;
  450. }
  451. }
  452. }
  453. .thr {
  454. .thr_1 {
  455. display: flex;
  456. flex-direction: row;
  457. justify-content: space-between;
  458. margin: 2vw 0 2vw 0;
  459. padding: 2vw;
  460. background-color: var(--mainColor);
  461. }
  462. }
  463. .four {
  464. padding: 2vw;
  465. background-color: var(--mainColor);
  466. .four_1 {
  467. display: flex;
  468. justify-content: space-between;
  469. .image {
  470. width: 15vw;
  471. height: 15vw;
  472. border: 0.1vw solid var(--fcColor);
  473. }
  474. .other {
  475. flex-grow: 1;
  476. margin: 0 0 0 2vw;
  477. .name {
  478. font-size: var(--font16Szie);
  479. }
  480. .other_1 {
  481. font-size: var(--font12Size);
  482. text {
  483. color: var(--fcColor);
  484. margin: 0 2vw 0 0;
  485. }
  486. }
  487. }
  488. }
  489. .four_2 {
  490. display: flex;
  491. flex-direction: row;
  492. justify-content: space-evenly;
  493. padding: 2vw 0;
  494. color: var(--f99Color);
  495. .grade {
  496. font-size: var(--font14Size);
  497. color: var(--f85Color);
  498. text {
  499. color: var(--ff0Color);
  500. }
  501. }
  502. .btn {
  503. border: 0.1vw solid var(--fcColor);
  504. padding: 1vw 6vw;
  505. border-radius: 1vw;
  506. color: var(--f00Color);
  507. }
  508. .btn:last-child {
  509. padding: 1vw 10vw;
  510. }
  511. }
  512. }
  513. .five {
  514. margin: 2vw 0 0 0;
  515. .five_1 {
  516. padding: 2vw;
  517. background-color: var(--mainColor);
  518. font-size: var(--font18Szie);
  519. color: var(--f99Color);
  520. }
  521. .five_2 {
  522. padding: 0 2vw;
  523. background-color: var(--mainColor);
  524. text-align: center;
  525. }
  526. }
  527. }
  528. }
  529. .scroll-view {
  530. position: absolute;
  531. top: 0;
  532. left: 0;
  533. right: 0;
  534. bottom: 0;
  535. .list-scroll-view {
  536. display: flex;
  537. flex-direction: column;
  538. }
  539. }
  540. .scrollView {
  541. height: 100vh;
  542. }
  543. .collect {
  544. position: fixed;
  545. top: 4vw;
  546. right: 5vw;
  547. text {
  548. font-size: 30px;
  549. background-color: #0000005f;
  550. border-radius: 90px;
  551. }
  552. }
  553. .menu {
  554. position: fixed;
  555. bottom: 30vw;
  556. right: 5vw;
  557. text {
  558. font-size: 30px;
  559. background-color: #0000005f;
  560. border-radius: 90px;
  561. }
  562. }
  563. .menu_1 {
  564. position: fixed;
  565. bottom: 40vw;
  566. right: 5vw;
  567. background-color: var(--mainColor);
  568. padding: 2vw;
  569. .title {
  570. display: flex;
  571. padding: 2vw;
  572. border-bottom: 0.1vw solid var(--fcColor);
  573. .image {
  574. width: 7vw;
  575. height: 6vw;
  576. }
  577. .name {
  578. margin: 0 0 0 1vw;
  579. font-size: var(--font14Size);
  580. }
  581. }
  582. }
  583. .backTop {
  584. position: fixed;
  585. bottom: 20vw;
  586. right: 5vw;
  587. text {
  588. font-size: 30px;
  589. background-color: #0000005f;
  590. border-radius: 90px;
  591. }
  592. }
  593. uni-popup {
  594. z-index: 999999 !important;
  595. }
  596. .content {
  597. height: 100vw;
  598. .one {
  599. display: flex;
  600. flex-direction: row;
  601. justify-content: space-between;
  602. margin: 2vw;
  603. padding: 2vw 0;
  604. border-bottom: 1px solid var(--f9Color);
  605. .image {
  606. width: 25vw;
  607. height: 25vw;
  608. margin: 0 2vw 0 0;
  609. }
  610. .other {
  611. display: flex;
  612. flex-direction: column;
  613. flex-grow: 1;
  614. margin: 0 0 0 2vw;
  615. .money {
  616. color: var(--fFB1Color);
  617. font-size: var(--font20Szie);
  618. padding: 2vw 0;
  619. }
  620. .other_1 {
  621. font-size: var(--font14Size);
  622. text {
  623. padding: 0 2vw;
  624. color: var(--f85Color);
  625. }
  626. }
  627. }
  628. }
  629. .two {
  630. margin: 0 2vw;
  631. padding: 2vw 0;
  632. font-size: var(--font12Size);
  633. border-bottom: 1px solid var(--f9Color);
  634. .two_2 {
  635. padding: 1vw;
  636. text {
  637. margin: 0 2vw 0 0;
  638. padding: 1vw;
  639. border-radius: 1vw;
  640. background-color: var(--f9Color);
  641. }
  642. .style {
  643. color: var(--mainColor);
  644. background-color: var(--ff0Color);
  645. }
  646. }
  647. }
  648. .thr {
  649. display: flex;
  650. justify-content: flex-start;
  651. margin: 0 2vw;
  652. padding: 2vw 0;
  653. text {
  654. margin: 0 2vw 0 0;
  655. }
  656. text:last-child {
  657. margin: 0 0 0 2vw;
  658. font-size: var(--font12Size);
  659. color: var(--f85Color);
  660. }
  661. }
  662. .button {
  663. position: fixed;
  664. width: 100vw;
  665. padding: 4vw 0;
  666. background-color: var(--fFB1Color);
  667. bottom: 0;
  668. text-align: center;
  669. font-size: var(--font18Szie);
  670. color: var(--mainColor);
  671. }
  672. }
  673. </style>