index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. shopInfo: {},
  125. };
  126. },
  127. methods: {
  128. filterMsg(val) {
  129. return val.replace(/\n/g, "<br>");
  130. },
  131. jump(url) {
  132. uni.navigateTo({
  133. url,
  134. });
  135. },
  136. handleTab(val) {
  137. this.tab = val;
  138. },
  139. handleBuy() {
  140. if (!this.info.realStockNum) return;
  141. let that = this;
  142. if (uni.getStorageSync("token")) {
  143. uni.navigateTo({
  144. url: `/pay/pay`,
  145. success: function (res) {
  146. // 通过eventChannel向被打开页面传送数据
  147. res.eventChannel.emit("pay", that.info);
  148. },
  149. });
  150. } else {
  151. uni.showModal({
  152. title: "请登录",
  153. confirmText: "去登录",
  154. success(res) {
  155. console.log(res);
  156. if (res.confirm) {
  157. uni.navigateTo({
  158. url: `/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`,
  159. });
  160. }
  161. },
  162. });
  163. }
  164. },
  165. detail(goodsId) {
  166. detail({ goodsId, resource: 2 }).then((res) => {
  167. if (res.state == "Success") {
  168. this.info = res.content;
  169. this.info.goodsDetail = res.content.goodsDetail.replace(
  170. /<img/gi,
  171. '<img class="img_class" '
  172. );
  173. }
  174. });
  175. },
  176. goShopDetail(shopInfo) {
  177. uni.setStorageSync("shopInfo", JSON.stringify(shopInfo));
  178. uni.navigateTo({
  179. url: `../../detail/shopDetail/shopDetail`,
  180. });
  181. },
  182. getShopList(goodsId) {
  183. let location = JSON.parse(uni.getStorageSync("location"));
  184. let obj = {
  185. goodsId,
  186. pageCurrent: 1,
  187. pageSize: 99,
  188. };
  189. obj["location.lat"] = location.latitude;
  190. obj["location.lon"] = location.longitude;
  191. search(obj).then((res) => {
  192. if (res.state == "Success") {
  193. this.shopList = res.content.records;
  194. uni.setStorageSync("shopList", JSON.stringify(this.shopList));
  195. }
  196. });
  197. },
  198. },
  199. onLoad(option) {
  200. this.shopInfo = JSON.parse(uni.getStorageSync("shopInfo"));
  201. this.detail(option.id);
  202. this.getShopList(option.id);
  203. let that = this;
  204. // this.info = JSON.parse(uni.getStorageSync('goodsInfo'))
  205. // const eventChannel = this.getOpenerEventChannel();
  206. // if(JSON.stringify(eventChannel) !=='{}'){
  207. // eventChannel.on('goodsInfo', function(data) {
  208. // that.info = data
  209. // })
  210. // }
  211. },
  212. };
  213. </script>
  214. <style lang="scss">
  215. .goodsDetail {
  216. background: #f9f9f9;
  217. padding-bottom: 200rpx;
  218. min-height: 100vh;
  219. .good-img {
  220. width: 100%;
  221. height: 660rpx;
  222. vertical-align: bottom;
  223. }
  224. .goods-info {
  225. padding: 24rpx;
  226. margin-bottom: 20rpx;
  227. background: #fff;
  228. .price-box {
  229. display: flex;
  230. justify-content: space-between;
  231. align-items: center;
  232. .left {
  233. display: flex;
  234. align-items: flex-end;
  235. .unit {
  236. font-size: 20rpx;
  237. color: #ff4d3a;
  238. font-weight: bold;
  239. }
  240. .price {
  241. font-size: 32rpx;
  242. color: #ff4d3a;
  243. font-weight: bold;
  244. }
  245. .old-price {
  246. font-size: 20rpx;
  247. color: #aaaaaa;
  248. text-decoration: line-through;
  249. margin-left: 12rpx;
  250. }
  251. }
  252. .right {
  253. font-size: 24rpx;
  254. color: #aaaaaa;
  255. }
  256. }
  257. .goods-name {
  258. font-size: 32rpx;
  259. color: #222222;
  260. font-weight: bold;
  261. margin-top: 20rpx;
  262. }
  263. .desc {
  264. font-size: 24rpx;
  265. color: #aaaaaa;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. white-space: nowrap;
  269. margin-top: 12rpx;
  270. }
  271. }
  272. .type-box {
  273. padding: 24rpx;
  274. background: #fff;
  275. margin-bottom: 20rpx;
  276. .type-title {
  277. font-size: 28rpx;
  278. color: #222222;
  279. }
  280. .type-list {
  281. display: flex;
  282. flex-wrap: wrap;
  283. justify-content: space-between;
  284. .type-item {
  285. width: 316rpx;
  286. height: 52rpx;
  287. text-align: center;
  288. line-height: 52rpx;
  289. background: #f0f0f0;
  290. border-radius: 26rpx 26rpx 26rpx 26rpx;
  291. font-weight: 300;
  292. font-size: 24rpx;
  293. color: #aaaaaa;
  294. margin-top: 28rpx;
  295. }
  296. .type-item.active {
  297. background: #ee4320;
  298. color: #ffffff;
  299. }
  300. }
  301. }
  302. .shop-limit {
  303. padding: 24rpx;
  304. background: #fff;
  305. display: flex;
  306. align-items: center;
  307. justify-content: space-between;
  308. margin-bottom: 20rpx;
  309. .info {
  310. .shop-name {
  311. font-size: 28rpx;
  312. color: #222222;
  313. }
  314. .address {
  315. font-size: 24rpx;
  316. color: #aaaaaa;
  317. margin-top: 16rpx;
  318. }
  319. }
  320. .num {
  321. display: flex;
  322. align-items: center;
  323. font-size: 24rpx;
  324. color: #aaaaaa;
  325. .icon {
  326. width: 48rpx;
  327. height: 48rpx;
  328. transform: rotate(-90deg);
  329. }
  330. }
  331. }
  332. .tab-group {
  333. display: flex;
  334. background: #fff;
  335. .tab {
  336. flex: 1;
  337. padding: 24rpx 0;
  338. text-align: center;
  339. font-size: 28rpx;
  340. color: #222222;
  341. }
  342. .tab.active {
  343. font-weight: 600;
  344. }
  345. }
  346. .desc-box {
  347. .goods-desc {
  348. color: #222222;
  349. font-size: 24rpx;
  350. .img_class {
  351. max-width: 100% !important;
  352. }
  353. }
  354. }
  355. .list {
  356. background: #fff;
  357. .item {
  358. padding: 24rpx;
  359. border-top: 1rpx solid #f0f0f0;
  360. .label {
  361. font-weight: 600;
  362. font-size: 28rpx;
  363. color: #222222;
  364. }
  365. .value {
  366. font-size: 24rpx;
  367. color: #aaaaaa;
  368. margin-top: 16rpx;
  369. line-height: 40rpx;
  370. }
  371. }
  372. }
  373. .buy-box {
  374. position: fixed;
  375. bottom: 0%;
  376. left: 0%;
  377. width: 100%;
  378. background: #fff;
  379. padding: 10rpx 24rpx 76rpx;
  380. display: flex;
  381. justify-content: space-between;
  382. box-sizing: border-box;
  383. .head {
  384. width: 80rpx;
  385. height: 80rpx;
  386. background: #aaa;
  387. border-radius: 50%;
  388. }
  389. .btn-box {
  390. display: flex;
  391. text-align: center;
  392. .group-btn {
  393. width: 280rpx;
  394. height: 80rpx;
  395. background: #6499ff;
  396. border-radius: 40rpx 0rpx 0rpx 40rpx;
  397. display: flex;
  398. flex-direction: column;
  399. justify-content: space-around;
  400. .label {
  401. font-weight: 600;
  402. font-size: 28rpx;
  403. color: #ffffff;
  404. }
  405. .price {
  406. font-size: 24rpx;
  407. color: #ffffff;
  408. }
  409. }
  410. .buy-btn.none {
  411. filter: grayscale(1);
  412. }
  413. .buy-btn {
  414. // width: 280rpx;
  415. margin: 0 auto;
  416. width: 690rpx;
  417. height: 80rpx;
  418. line-height: 80rpx;
  419. border-radius: 40rpx;
  420. background: $uni-color-primary;
  421. color: #fff;
  422. .label {
  423. font-weight: 600;
  424. font-size: 28rpx;
  425. color: #ffffff;
  426. }
  427. .price {
  428. font-size: 24rpx;
  429. color: #ffffff;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. </style>