index.vue 11 KB

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