index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <view class="goodsDetail">
  3. <image class="good-img" :src="info.goodsPath" mode="aspectFit"></image>
  4. <view class="goods-info">
  5. <view class="price-box">
  6. <view class="left">
  7. <view class="unit"> ¥ </view>
  8. <view class="price">
  9. {{ info.realPrice }}
  10. </view>
  11. <view class="old-price"> 市场价 ¥{{ info.marketPrice }} </view>
  12. </view>
  13. <view class="right"> 销量{{ info.saleNum }} </view>
  14. </view>
  15. <view class="goods-name">
  16. {{ info.goodsName }}
  17. </view>
  18. <view class="desc">
  19. {{ info.goodsDescribe }}
  20. </view>
  21. </view>
  22. <template v-if="info.specs[0].specValues.length">
  23. <view class="type-box" v-for="item in info.specs" :key="item.specId">
  24. <view class="type-title">
  25. {{ item.specName }}
  26. </view>
  27. <view class="type-list">
  28. <view
  29. class="type-item"
  30. :class="[active == d ? 'active' : '']"
  31. v-for="(i, d) in item.specValues"
  32. :key="i.specId"
  33. >
  34. {{ i.specValue }}
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <!--
  40. <view class="shop-limit" @click="jump('/detail/shopList/index')">
  41. <view class="info">
  42. <view class="shop-name">
  43. {{shopInfo.shopVo.shopName}}
  44. </view>
  45. <view class="address">
  46. {{shopInfo.district}} {{(shopInfo.shopVo.distance/1000).toFixed(2)}} KM
  47. </view>
  48. </view>
  49. <view class="num">
  50. {{shopList.length}}家店适用
  51. <image class="icon" src="../../static/shop-desc.png" mode=""></image>
  52. </view>
  53. </view> -->
  54. <view class="tab-group">
  55. <view
  56. class="tab"
  57. :class="[tab == 1 ? 'active' : '']"
  58. @click="handleTab(1)"
  59. >
  60. 商品详情
  61. </view>
  62. <view
  63. class="tab"
  64. :class="[tab == 2 ? 'active' : '']"
  65. @click="handleTab(2)"
  66. >
  67. 购买须知
  68. </view>
  69. </view>
  70. <view class="desc-box" v-show="tab == 1">
  71. <rich-text class="goods-desc" :nodes="info.goodsDetail"></rich-text>
  72. </view>
  73. <view class="list" v-show="tab == 2">
  74. <view class="item" v-for="(item, index) in info.attrs" :key="index">
  75. <view class="label">
  76. {{ item.attrName == "validDay" ? "有效期" : item.attrName }}
  77. </view>
  78. <view class="value" v-html="filterMsg(item.attrValue)"> </view>
  79. </view>
  80. <!-- <view class="item">
  81. <view class="label">
  82. 使用时间
  83. </view>
  84. <view class="value">
  85. 营业时间内可用
  86. </view>
  87. </view> -->
  88. </view>
  89. <view class="buy-box">
  90. <!-- <image class="head" :src="shopInfo.logoPath" @click="goShopDetail(shopInfo)" mode=""></image> -->
  91. <view class="btn-box">
  92. <!-- <view class="group-btn" @click="handleBuy">
  93. <view class="label">
  94. 团购
  95. </view>
  96. <view class="price">
  97. ¥{{info.realPrice}}
  98. </view>
  99. </view> -->
  100. <view
  101. class="buy-btn"
  102. :class="[info.realStockNum ? '' : 'none']"
  103. @click="handleBuy"
  104. >
  105. <view class="label">
  106. {{ info.realStockNum ? "购买" : "售罄" }}
  107. </view>
  108. <view class="price"> ¥{{ info.realPrice }} </view>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </template>
  114. <script>
  115. import { detail } from "@/api/goods.js";
  116. import { search } from "@/api/shop.js";
  117. export default {
  118. data() {
  119. return {
  120. active: 0,
  121. tab: 1,
  122. shopList: [],
  123. info: {
  124. specs: [{ specValues: [] }],
  125. },
  126. shopInfo: {},
  127. };
  128. },
  129. methods: {
  130. filterMsg(val) {
  131. return val.replace(/\n/g, "<br>");
  132. },
  133. jump(url) {
  134. uni.navigateTo({
  135. url,
  136. });
  137. },
  138. handleTab(val) {
  139. this.tab = val;
  140. },
  141. handleBuy() {
  142. if (!this.info.realStockNum) return;
  143. let that = this;
  144. if (uni.getStorageSync("token")) {
  145. uni.navigateTo({
  146. url: `/pay/pay`,
  147. success: function (res) {
  148. // 通过eventChannel向被打开页面传送数据
  149. res.eventChannel.emit("pay", that.info);
  150. },
  151. });
  152. } else {
  153. uni.showModal({
  154. title: "请登录",
  155. confirmText: "去登录",
  156. success(res) {
  157. console.log(res);
  158. if (res.confirm) {
  159. uni.navigateTo({
  160. url: `/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`,
  161. });
  162. }
  163. },
  164. });
  165. }
  166. },
  167. detail(goodsId) {
  168. detail({ goodsId, resource: 2 }).then((res) => {
  169. if (res.state == "Success") {
  170. this.info = res.content;
  171. this.info.goodsDetail = res.content.goodsDetail.replace(
  172. /<img/gi,
  173. '<img class="img_class" '
  174. );
  175. }
  176. });
  177. },
  178. goShopDetail(shopInfo) {
  179. uni.setStorageSync("shopInfo", JSON.stringify(shopInfo));
  180. uni.navigateTo({
  181. url: `../../detail/shopDetail/shopDetail`,
  182. });
  183. },
  184. getShopList(goodsId) {
  185. let location = JSON.parse(uni.getStorageSync("location"));
  186. let obj = {
  187. goodsId,
  188. pageCurrent: 1,
  189. pageSize: 99,
  190. };
  191. obj["location.lat"] = location.latitude;
  192. obj["location.lon"] = location.longitude;
  193. search(obj).then((res) => {
  194. if (res.state == "Success") {
  195. this.shopList = res.content.records;
  196. uni.setStorageSync("shopList", JSON.stringify(this.shopList));
  197. }
  198. });
  199. },
  200. },
  201. onLoad(option) {
  202. this.shopInfo = JSON.parse(uni.getStorageSync("shopInfo"));
  203. this.detail(option.id);
  204. this.getShopList(option.id);
  205. let that = this;
  206. // this.info = JSON.parse(uni.getStorageSync('goodsInfo'))
  207. // const eventChannel = this.getOpenerEventChannel();
  208. // if(JSON.stringify(eventChannel) !=='{}'){
  209. // eventChannel.on('goodsInfo', function(data) {
  210. // that.info = data
  211. // })
  212. // }
  213. },
  214. };
  215. </script>
  216. <style lang="scss">
  217. .goodsDetail {
  218. background: #f9f9f9;
  219. padding-bottom: 200rpx;
  220. min-height: 100vh;
  221. .good-img {
  222. width: 100%;
  223. height: 660rpx;
  224. vertical-align: bottom;
  225. }
  226. .goods-info {
  227. padding: 24rpx;
  228. margin-bottom: 20rpx;
  229. background: #fff;
  230. .price-box {
  231. display: flex;
  232. justify-content: space-between;
  233. align-items: center;
  234. .left {
  235. display: flex;
  236. align-items: flex-end;
  237. .unit {
  238. font-size: 20rpx;
  239. color: #ff4d3a;
  240. font-weight: bold;
  241. }
  242. .price {
  243. font-size: 32rpx;
  244. color: #ff4d3a;
  245. font-weight: bold;
  246. }
  247. .old-price {
  248. font-size: 20rpx;
  249. color: #aaaaaa;
  250. text-decoration: line-through;
  251. margin-left: 12rpx;
  252. }
  253. }
  254. .right {
  255. font-size: 24rpx;
  256. color: #aaaaaa;
  257. }
  258. }
  259. .goods-name {
  260. font-size: 32rpx;
  261. color: #222222;
  262. font-weight: bold;
  263. margin-top: 20rpx;
  264. }
  265. .desc {
  266. font-size: 24rpx;
  267. color: #aaaaaa;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. white-space: nowrap;
  271. margin-top: 12rpx;
  272. }
  273. }
  274. .type-box {
  275. padding: 24rpx;
  276. background: #fff;
  277. margin-bottom: 20rpx;
  278. .type-title {
  279. font-size: 28rpx;
  280. color: #222222;
  281. }
  282. .type-list {
  283. display: flex;
  284. flex-wrap: wrap;
  285. justify-content: space-between;
  286. .type-item {
  287. width: 316rpx;
  288. height: 52rpx;
  289. text-align: center;
  290. line-height: 52rpx;
  291. background: #f0f0f0;
  292. border-radius: 26rpx 26rpx 26rpx 26rpx;
  293. font-weight: 300;
  294. font-size: 24rpx;
  295. color: #aaaaaa;
  296. margin-top: 28rpx;
  297. }
  298. .type-item.active {
  299. background: #ee4320;
  300. color: #ffffff;
  301. }
  302. }
  303. }
  304. .shop-limit {
  305. padding: 24rpx;
  306. background: #fff;
  307. display: flex;
  308. align-items: center;
  309. justify-content: space-between;
  310. margin-bottom: 20rpx;
  311. .info {
  312. .shop-name {
  313. font-size: 28rpx;
  314. color: #222222;
  315. }
  316. .address {
  317. font-size: 24rpx;
  318. color: #aaaaaa;
  319. margin-top: 16rpx;
  320. }
  321. }
  322. .num {
  323. display: flex;
  324. align-items: center;
  325. font-size: 24rpx;
  326. color: #aaaaaa;
  327. .icon {
  328. width: 48rpx;
  329. height: 48rpx;
  330. transform: rotate(-90deg);
  331. }
  332. }
  333. }
  334. .tab-group {
  335. display: flex;
  336. background: #fff;
  337. .tab {
  338. flex: 1;
  339. padding: 24rpx 0;
  340. text-align: center;
  341. font-size: 28rpx;
  342. color: #222222;
  343. }
  344. .tab.active {
  345. font-weight: 600;
  346. }
  347. }
  348. .desc-box {
  349. .goods-desc {
  350. color: #222222;
  351. font-size: 24rpx;
  352. .img_class {
  353. max-width: 100% !important;
  354. }
  355. }
  356. }
  357. .list {
  358. background: #fff;
  359. .item {
  360. padding: 24rpx;
  361. border-top: 1rpx solid #f0f0f0;
  362. .label {
  363. font-weight: 600;
  364. font-size: 28rpx;
  365. color: #222222;
  366. }
  367. .value {
  368. font-size: 24rpx;
  369. color: #aaaaaa;
  370. margin-top: 16rpx;
  371. line-height: 40rpx;
  372. }
  373. }
  374. }
  375. .buy-box {
  376. position: fixed;
  377. bottom: 0%;
  378. left: 0%;
  379. width: 100%;
  380. background: #fff;
  381. padding: 10rpx 24rpx 76rpx;
  382. display: flex;
  383. justify-content: space-between;
  384. box-sizing: border-box;
  385. .head {
  386. width: 80rpx;
  387. height: 80rpx;
  388. background: #aaa;
  389. border-radius: 50%;
  390. }
  391. .btn-box {
  392. display: flex;
  393. text-align: center;
  394. .group-btn {
  395. width: 280rpx;
  396. height: 80rpx;
  397. background: #6499ff;
  398. border-radius: 40rpx 0rpx 0rpx 40rpx;
  399. display: flex;
  400. flex-direction: column;
  401. justify-content: space-around;
  402. .label {
  403. font-weight: 600;
  404. font-size: 28rpx;
  405. color: #ffffff;
  406. }
  407. .price {
  408. font-size: 24rpx;
  409. color: #ffffff;
  410. }
  411. }
  412. .buy-btn.none {
  413. filter: grayscale(1);
  414. }
  415. .buy-btn {
  416. // width: 280rpx;
  417. margin: 0 auto;
  418. width: 690rpx;
  419. height: 80rpx;
  420. line-height: 80rpx;
  421. border-radius: 40rpx;
  422. background: $uni-color-primary;
  423. color: #fff;
  424. .label {
  425. font-weight: 600;
  426. font-size: 28rpx;
  427. color: #ffffff;
  428. }
  429. .price {
  430. font-size: 24rpx;
  431. color: #ffffff;
  432. }
  433. }
  434. }
  435. }
  436. }
  437. </style>