index.vue 11 KB

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