detail.vue 17 KB

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