pdd-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div id="app" class="product-page">
  3. <div style="padding-bottom: 100px;">
  4. <!-- 商品图片 -->
  5. <el-carousel class="product-img">
  6. <el-carousel-item v-for="item in spuInfo.goodsGalleryUrls" :key="item">
  7. <img :src="item" style="width: 100%;height: 100%;">
  8. </el-carousel-item>
  9. </el-carousel>
  10. <!-- <img :src="spuInfo.goodsImageUrl" class="product-img" alt="iPhone 15 Pro Max"> -->
  11. <!-- 标签与商品名 -->
  12. <div class="tag-bar">
  13. <span class="product-name">{{ spuInfo.goodsName }}</span>
  14. </div>
  15. <!-- 优惠信息 -->
  16. <div class="promo-bar">
  17. <span class="coupon-tag" v-if="spuInfo.hasCoupon">{{ spuInfo.couponDiscount }}元券</span>
  18. <span class="promo-text">
  19. <span v-for="(item, index) in spuInfo.unifiedTags" :key="index">
  20. {{ item }} <!-- 展示数组中的每个标签文本 -->
  21. <!-- 给除最后一个外的标签添加 | 分隔符 -->
  22. <span v-if="index < spuInfo.unifiedTags.length - 1"> | </span>
  23. </span></span>
  24. </div>
  25. <!-- 价格与销量 -->
  26. <div class="price-info">
  27. <div class="price">¥{{ spuInfo.minGroupPrice }} <span style="font-size:12px;color:#999;">券后价</span>
  28. <div class="yyh" v-if="parseInt(spuInfo.couponDiscount) > 0">
  29. 已优惠{{ spuInfo.couponDiscount }}元
  30. </div>
  31. </div>
  32. <div class="sales">销量 {{ spuInfo.salesTip }}</div>
  33. </div>
  34. <!-- 店铺信息 -->
  35. <div class="shop-section" v-if="spuInfo.mallName">
  36. <div class="shop-logo"><img :src="spuInfo.mallImgUrl" style="width: 30px;height: 30px;"></div>
  37. <div class="shop-info">
  38. <div class="shop-name">
  39. <el-tag type="danger" size="mini">{{ spuInfo.merchantType == 3 ? '旗舰店' : spuInfo.merchantType == 4 ? '专卖店' :
  40. spuInfo.merchantType == 5 ? '专营店' : '' }}</el-tag>
  41. {{ spuInfo.mallName }}
  42. </div>
  43. <div class="shop-tags">
  44. <span>描述相符 {{ spuInfo.descTxt }}</span>
  45. <span>服务态度 {{ spuInfo.servTxt }}</span>
  46. <span>发货速度 {{ spuInfo.lgstTxt }}</span>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 商品描述 -->
  51. <div class="desc-section">
  52. <div class="desc-title">商品描述</div>
  53. <div class="desc-content">
  54. {{ spuInfo.goodsDesc }}
  55. </div>
  56. </div>
  57. </div>
  58. <!-- 底部操作栏 -->
  59. <div class="bottom-bar">
  60. <!-- <div class="bar-left">
  61. <span>推广可赚 <span style="color: red; font-size: 18px;">¥{{ spuInfo.predictPromotionRate }}</span> </span>
  62. </div> -->
  63. <div class="bar-btn btn-buy" @click="openAPP">APP打开</div>
  64. <!-- <div class="bar-btn btn-promote">立即推广</div> -->
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. import { goodsDetail, getAppLatestVersion } from '@/api/index.js'
  70. export default {
  71. name: 'pdd-detail',
  72. data() {
  73. return {
  74. androidLinkurl: "https://oss.qianzhi-y.com/appapk/qianzhiyun_V1.0.0_release.apk",
  75. spuInfo: {},
  76. query: {
  77. platform: "",
  78. shareUserId: "",
  79. token: "",
  80. goodsSign: ""
  81. }
  82. }
  83. },
  84. mounted() {
  85. this.getAppdownloadUrl()
  86. this.query.platform = this.GetQueryString("platform")
  87. this.query.shareUserId = this.GetQueryString("shareUserId")
  88. this.query.token = this.GetQueryString("token")
  89. this.query.goodsSign = this.GetQueryString("goodsSign")
  90. this.getgoodDetail()
  91. },
  92. methods: {
  93. getAppdownloadUrl() {
  94. getAppLatestVersion().then(res => {
  95. this.androidLinkurl = res.data.downloadUrl
  96. })
  97. },
  98. getgoodDetail() {
  99. goodsDetail({
  100. goodsSign: this.query.goodsSign,
  101. needSkuInfo: true
  102. }).then(res => {
  103. this.spuInfo = res.data
  104. })
  105. },
  106. openAPP() {
  107. const that = this;
  108. // 1. 解析用户代理,判断设备类型
  109. const ua = navigator.userAgent;
  110. const isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1; // 安卓终端
  111. // 新增:标记是否已唤起APP(核心修复)
  112. let isAppInvoked = false;
  113. // 2. 安卓端唤醒逻辑(核心优化)
  114. if (isAndroid) {
  115. // 记录唤醒开始时间
  116. const loadStartTime = new Date().getTime();
  117. // APP Scheme 唤起链接(带参数)
  118. const schemeUrl = "com.benefit.workbox://promotion-goods" + location.search;
  119. // ========== 关键优化1:监听页面隐藏事件(唤起APP会触发) ==========
  120. // 当页面被隐藏(切换到APP),标记为已唤起
  121. const onPageHide = () => {
  122. isAppInvoked = true;
  123. // 移除监听,避免重复触发
  124. document.removeEventListener('visibilitychange', onPageHide);
  125. window.removeEventListener('pagehide', onPageHide);
  126. };
  127. // 监听页面隐藏(兼容不同浏览器)
  128. document.addEventListener('visibilitychange', onPageHide);
  129. window.addEventListener('pagehide', onPageHide);
  130. // ========== 关键优化2:简化唤起方式(避免重复触发) ==========
  131. // 仅用iframe唤起(去掉location.href兜底,减少误触发)
  132. const iframe = document.createElement('iframe');
  133. iframe.style.display = 'none';
  134. iframe.src = schemeUrl;
  135. document.body.appendChild(iframe);
  136. // 用完销毁iframe
  137. setTimeout(() => {
  138. document.body.removeChild(iframe);
  139. }, 2000);
  140. // ========== 关键优化3:精准检测唤起状态 ==========
  141. setTimeout(() => {
  142. const currentTime = new Date().getTime();
  143. const timeDiff = currentTime - loadStartTime;
  144. // 只有「未标记唤起」且「时间差小于阈值」,才跳转下载
  145. if (!isAppInvoked && timeDiff < 5000) { // 阈值从10000缩短到5000,更精准
  146. // 校验下载链接是否有效,避免报错
  147. if (that.androidLinkurl && that.androidLinkurl.trim()) {
  148. const a = document.createElement('a');
  149. a.target = '_blank';
  150. a.href = that.androidLinkurl;
  151. a.click();
  152. } else {
  153. console.error('安卓下载链接未配置');
  154. }
  155. } else {
  156. // 唤起成功,清空标记
  157. isAppInvoked = false;
  158. // 移除监听
  159. document.removeEventListener('visibilitychange', onPageHide);
  160. window.removeEventListener('pagehide', onPageHide);
  161. }
  162. }, 2000); // 检测延迟从1000延长到2000,给APP唤起足够时间
  163. } else {
  164. this.$message({
  165. message: '暂不支持苹果端,请在安卓端打开',
  166. type: 'warning'
  167. })
  168. }
  169. },
  170. GetQueryString(name) {
  171. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  172. var r = window.location.search.substr(1).match(reg);
  173. if (r != null) return unescape(r[2]);
  174. return null;
  175. },
  176. }
  177. }
  178. </script>
  179. <!-- Add "scoped" attribute to limit CSS to this component only -->
  180. <style scoped>
  181. .product-page {
  182. /* max-width: 375px; */
  183. margin: 0 0px;
  184. padding: 0px;
  185. background: #fff;
  186. min-height: 100vh;
  187. }
  188. /* 顶部导航栏 */
  189. .top-nav {
  190. display: flex;
  191. align-items: center;
  192. justify-content: space-between;
  193. padding: 12px 16px;
  194. background: #fff;
  195. border-bottom: 1px solid #eee;
  196. }
  197. .nav-back {
  198. font-size: 20px;
  199. color: #333;
  200. }
  201. .nav-title {
  202. font-size: 18px;
  203. font-weight: 600;
  204. color: #ff2f2f;
  205. }
  206. .nav-actions {
  207. display: flex;
  208. gap: 12px;
  209. }
  210. /* 商品图片 */
  211. .product-img {
  212. width: 100%;
  213. height: 300px;
  214. object-fit: cover;
  215. background: #f8f8f8;
  216. }
  217. /* 标签栏 */
  218. .tag-bar {
  219. display: flex;
  220. align-items: center;
  221. gap: 8px;
  222. padding: 8px 16px;
  223. background: #fff;
  224. }
  225. .tag {
  226. padding: 2px 4px;
  227. border-radius: 4px;
  228. font-size: 12px;
  229. color: #fff;
  230. min-width: 60px;
  231. text-align: center;
  232. }
  233. .tag-subsidy {
  234. background: #ff4444;
  235. }
  236. .tag-flash {
  237. background: #ff6600;
  238. }
  239. .product-name {
  240. font-size: 16px;
  241. font-weight: 500;
  242. color: #333;
  243. overflow: hidden;
  244. white-space: nowrap;
  245. text-overflow: ellipsis;
  246. -o-text-overflow: ellipsis;
  247. /* padding: 0 16px; */
  248. }
  249. /* 优惠信息 */
  250. .promo-bar {
  251. display: flex;
  252. align-items: center;
  253. gap: 8px;
  254. padding: 8px 16px;
  255. background: #fff9f9;
  256. }
  257. .coupon-tag {
  258. background: #ff4444;
  259. color: #fff;
  260. padding: 2px 6px;
  261. border-radius: 4px;
  262. font-size: 12px;
  263. min-width: 60px;
  264. }
  265. .promo-text {
  266. font-size: 12px;
  267. color: #666;
  268. }
  269. /* 佣金与价格 */
  270. .price-section {
  271. padding: 12px 16px;
  272. display: flex;
  273. justify-content: space-between;
  274. align-items: center;
  275. }
  276. .commission {
  277. font-size: 14px;
  278. color: #666;
  279. }
  280. .commission-value {
  281. color: #ff4444;
  282. font-size: 18px;
  283. font-weight: 600;
  284. }
  285. .upgrade-btn {
  286. background: #ff4444;
  287. color: #fff;
  288. border: none;
  289. padding: 6px 12px;
  290. border-radius: 20px;
  291. font-size: 12px;
  292. }
  293. .price-info {
  294. padding: 0 16px 12px;
  295. display: flex;
  296. justify-content: space-between;
  297. align-items: center;
  298. }
  299. .yyh {
  300. font-size: 12px;
  301. background: red;
  302. color: white;
  303. border-radius: 7px;
  304. display: flex;
  305. flex-direction: row;
  306. align-items: center;
  307. justify-content: center;
  308. padding: 0px 5px;
  309. height: 23px;
  310. margin-left: 10px;
  311. }
  312. .price {
  313. font-size: 18px;
  314. color: #ff4444;
  315. font-weight: 600;
  316. display: flex;
  317. flex-direction: row;
  318. align-items: center;
  319. }
  320. .sales {
  321. font-size: 14px;
  322. color: #666;
  323. }
  324. /* 规格选择 */
  325. .spec-section {
  326. padding: 12px 16px;
  327. border-top: 8px solid #f5f5f5;
  328. }
  329. .spec-title {
  330. font-size: 14px;
  331. color: #333;
  332. margin-bottom: 12px;
  333. }
  334. .spec-options {
  335. display: flex;
  336. flex-wrap: wrap;
  337. gap: 12px;
  338. margin-bottom: 16px;
  339. }
  340. .spec-option {
  341. padding: 8px 12px;
  342. border: 1px solid #ddd;
  343. border-radius: 4px;
  344. font-size: 14px;
  345. color: #333;
  346. }
  347. .spec-option.active {
  348. border-color: #ff4444;
  349. color: #ff4444;
  350. background: #fff5f5;
  351. }
  352. /* 店铺信息 */
  353. .shop-section {
  354. padding: 12px 16px;
  355. border-top: 8px solid #f5f5f5;
  356. display: flex;
  357. align-items: center;
  358. gap: 12px;
  359. }
  360. .shop-logo {
  361. width: 40px;
  362. height: 40px;
  363. border-radius: 50%;
  364. background: #f5f5f5;
  365. display: flex;
  366. align-items: center;
  367. justify-content: center;
  368. }
  369. .shop-info {
  370. flex: 1;
  371. }
  372. .shop-name {
  373. font-size: 14px;
  374. font-weight: 500;
  375. color: #333;
  376. margin-bottom: 4px;
  377. }
  378. .shop-tags {
  379. display: flex;
  380. gap: 16px;
  381. font-size: 12px;
  382. color: #666;
  383. }
  384. /* 商品描述 */
  385. .desc-section {
  386. padding: 12px 16px;
  387. border-top: 8px solid #f5f5f5;
  388. }
  389. .desc-title {
  390. font-size: 14px;
  391. font-weight: 500;
  392. color: #333;
  393. margin-bottom: 8px;
  394. }
  395. .desc-content {
  396. font-size: 13px;
  397. color: #666;
  398. line-height: 1.6;
  399. }
  400. /* 底部操作栏 */
  401. .bottom-bar {
  402. position: fixed;
  403. bottom: 0;
  404. left: 0;
  405. right: 0;
  406. /* max-width: 375px; */
  407. margin: 0 auto;
  408. display: flex;
  409. background: #fff;
  410. border-top: 1px solid #eee;
  411. padding: 8px;
  412. }
  413. .bar-left {
  414. flex: 1;
  415. display: flex;
  416. align-items: center;
  417. justify-content: center;
  418. flex-direction: column;
  419. font-size: 12px;
  420. color: #666;
  421. }
  422. .bar-btn {
  423. flex: 2;
  424. padding: 10px;
  425. border-radius: 24px;
  426. text-align: center;
  427. font-size: 16px;
  428. font-weight: 500;
  429. /* 点击效果核心属性 */
  430. touch-action: manipulation;
  431. /* 阻止移动端双击缩放,提升点击响应 */
  432. user-select: none;
  433. /* 禁止文字选中 */
  434. cursor: pointer;
  435. transition: all 0.2s ease;
  436. /* 过渡动画,让效果更丝滑 */
  437. transform: scale(1);
  438. /* 初始缩放 */
  439. box-shadow: 0 2px 8px rgba(244, 51, 60, 0.3);
  440. /* 初始阴影 */
  441. }
  442. .btn-buy {
  443. background: #ff9900;
  444. color: #fff;
  445. margin-right: 8px;
  446. }
  447. .btn-promote {
  448. background: #ff2f2f;
  449. color: #fff;
  450. }
  451. /deep/ .el-carousel__indicators {
  452. display: flex;
  453. }
  454. </style>