detail.vue 18 KB

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