index.vue 11 KB

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