index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view class="goods-detail">
  3. <navbarTransparent :title="page.title" />
  4. <!-- swiper -->
  5. <view class="home-swiper">
  6. <!-- <uni-swiper-dot :info="info" :current="current1" :mode="mode" :dots-styles="dotsStyles">
  7. <swiper class="swiper-box" @change="change1" circular>
  8. <swiper-item v-for="(item ,index) in info" :key="index">
  9. <view class="swiper-item" >
  10. <image style="width: 100%;height:576rpx;" :src="item.img" mode="aspectFill"></image>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. </uni-swiper-dot> -->
  15. <uni-swiper-dot :mode="mode" :info="info" :current="current1" :dots-styles="dotsStyles">
  16. <swiper class="swiper-box" @change="change1" circular>
  17. <swiper-item v-for="(item ,index) in info" :key="index" v-if="resource_type == 1 ">
  18. <view class="swiper-item">
  19. <image style="width: 100vw;height:100vw;" :src="item.img" mode="aspectFill"></image>
  20. </view>
  21. </swiper-item>
  22. <swiper-item v-if="resource_type == 2 ">
  23. <view class="swiper-item">
  24. <video class="baner-video" id="myVideo" ref="myVideo" style="width: 100%; height: 564rpx;"
  25. :src="video_url" controls :enable-progress-gesture="false">
  26. </video>
  27. </view>
  28. </swiper-item>
  29. </swiper>
  30. </uni-swiper-dot>
  31. </view>
  32. <view style="background-color: #f9f9f9;">
  33. <!-- 价格 -->
  34. <view class="price">
  35. <view class="price-top" v-if="produceType == 1">
  36. <text>¥</text>
  37. <text>{{productDetail.price}}</text>
  38. </view>
  39. <view class="price-top" v-if="produceType == 2">
  40. <text>{{productDetail.price}}</text>
  41. <text>积分</text>
  42. </view>
  43. <text class="price-text">{{productDetail.name}}</text>
  44. <view @click="goOther" class="price-banner" :style="{backgroundImage:'url('+backImageUrl+')'}">
  45. <text>加入IHG优悦会会员享受更多福利</text>
  46. <image style="width: 12rpx;height: 20rpx;" src="/static/icon/right02.png" mode=""></image>
  47. </view>
  48. <!--规格-->
  49. <view class="price-specs" @click="Recipientopen()">
  50. <view class="price-specs-left">
  51. <text>选择</text>
  52. </view>
  53. <view class="price-specs-main" @click="Recipientopen()">
  54. <text>{{showAttr||'请选择规格'}}</text>
  55. </view>
  56. <view @click="Recipientopen()">
  57. <image style="width: 12rpx;height: 20rpx;" src="/static/icon/right03.png" mode=""></image>
  58. </view>
  59. </view>
  60. </view>
  61. <!--酒店信息 -->
  62. <view class="about">
  63. <text class="about-title">可购买酒店信息</text>
  64. <text class="about-name">{{hotelDetail.name}}</text>
  65. <view class="about-address">
  66. <text style="margin-right:20rpx ;">地址:</text>
  67. <text>{{hotelDetail.address?hotelDetail.address:""}}</text>
  68. </view>
  69. <view class="about-phone">
  70. <text style="margin-right:20rpx ;">电话:</text>
  71. <text>{{hotelDetail.phone?hotelDetail.phone:""}}</text>
  72. </view>
  73. <view class="about-all">
  74. <text @click="goGoodsHotel(product_id)" style="margin-right: 16rpx;">全部酒店</text>
  75. <image @click="goGoodsHotel(product_id)" style="width: 12rpx;height: 20rpx;"
  76. src="/static/icon/right04.png" mode=""></image>
  77. </view>
  78. </view>
  79. <!-- 产品介绍 -->
  80. <view class="produce">
  81. <view class="produce-title">
  82. <text>产品简介</text>
  83. </view>
  84. <view class="produce-text">
  85. <u-parse :content="productDetail.details"></u-parse>
  86. </view>
  87. </view>
  88. </view>
  89. <view class="buy-btn">
  90. <view class="buy-btn-left" @click="goHome">
  91. <image style="width: 40rpx;height: 42rpx;" src="/static/icon/home01.png" mode=""></image>
  92. <text>首页</text>
  93. </view>
  94. <view class="buy-btn-right" @click="goIntegralOrder" v-if="produceType==1">
  95. <text>立即购买</text>
  96. </view>
  97. <view v-if="produceType==2" class="buy-btn-right" @click="goProductChange(product_id,flavorIsActive)">
  98. <text>立即兑换</text>
  99. </view>
  100. </view>
  101. <view style="height: 90px;background-color: #f9f9f9;"></view>
  102. <!-- 选择规格 -->
  103. <uni-popup ref="Recipient" type="bottom" mask-background-color=" rgba(0,0,0,0.3);">
  104. <view class="pop">
  105. <view class="pop-price">
  106. <view class="pop-price-left">
  107. <image style="width: 180rpx;height: 136rpx; border-radius:12rpx ;"
  108. :src="productDetail.cover_img" mode=""></image>
  109. <view class="pop-price-left-money" v-if="produceType == 1">
  110. <text>¥</text>
  111. <text>{{productDetail.price}}</text>
  112. </view>
  113. <view class="pop-price-left-money" v-if="produceType == 2">
  114. <text>{{productDetail.price}}</text>
  115. <text>积分</text>
  116. </view>
  117. </view>
  118. <image style="width: 52rpx;height: 52rpx;" src="/static/icon/close01.png" mode=""
  119. @click="Recipientclose"></image>
  120. </view>
  121. <view class="pop-flavor" v-for="i in attr_groups" :key="i.attr_group_id" style="margin-top: 44rpx;">
  122. <text>{{i.attr_group_name}}</text>
  123. <view class="tab_flavor">
  124. <view class="flavorTitle-item"
  125. :class="{'flavorTitle-item-active':flavorIsActive[i.attr_group_name] === item.attr_name}"
  126. v-for="(item,index) in i.attr_list" :key="item.attr_id"
  127. @click="flavorchecked(item.attr_name,i.attr_group_name)">
  128. <view :class="{'active-flavor':flavorIsActive[i.attr_group_name] === item.attr_name}">
  129. {{item.attr_name}}
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. <view class="purchase" v-if="produceType == 1" @click="goIntegralOrder">
  136. <view class="purchase-btn">立即购买</view>
  137. </view>
  138. <view class="purchase" v-if="produceType == 2" @click="selectSpecs(product_id,flavorIsActive)">
  139. <view class="purchase-btn">立即兑换</view>
  140. <!-- <view class="purchase-btn">确认</view> -->
  141. </view>
  142. </uni-popup>
  143. <!-- 二维码购买 -->
  144. <uni-popup ref="codePurchase" type="center">
  145. <view class="code-purchase">
  146. <view class="title"><text>识别下方二维码即可购买</text></view>
  147. <view style="margin-left:30rpx;width: 580rpx;height: 2rpx;background: #F0F0F0;"></view>
  148. <view class="img">
  149. <image src="http://t9.9026.com/imgs/Kudosbg.png"></image>
  150. </view>
  151. <view class="btn">
  152. <view class="cancel" @click="dialogClose"><text>取消</text></view>
  153. <view class="download" @click="dialogConfirm"><text>保存图片</text></view>
  154. </view>
  155. </view>
  156. </uni-popup>
  157. </view>
  158. </template>
  159. <script>
  160. import navbarTransparent from "@/components/extra/navbarTransparent.vue"
  161. export default {
  162. components: {
  163. navbarTransparent
  164. },
  165. data() {
  166. return {
  167. jump_type: '',
  168. jump_config: '',
  169. resource_type: '',
  170. //1:第三方产品2:积分兑换产品
  171. produceType: '',
  172. // 规格
  173. specsText: '',
  174. specs: {
  175. pack: '',
  176. weight: '',
  177. flavor: '',
  178. },
  179. // 产品详情
  180. productDetail: '',
  181. // 酒店详情
  182. hotelDetail: '',
  183. // 产品id
  184. product_id: '',
  185. //激活指定table菜单
  186. isActive: 0,
  187. flavorIsActive: {},
  188. weightIsActive: 0,
  189. packIsActive: 0,
  190. backImageUrl: require('../../../static/icon/add01.png'),
  191. //轮播图
  192. info: [{
  193. img: 'http://t9.9026.com/imgs/swiper01.png',
  194. name: '酒店预订'
  195. }, ],
  196. dotsStyles: {
  197. backgroundColor: 'rgba(255, 255, 255, .3)',
  198. border: '1px rgba(255, 255, 255, .3) solid',
  199. color: '#fff',
  200. selectedBackgroundColor: 'rgba(255, 255, 255, 1)',
  201. selectedBorder: '1px rgba(255, 255, 255, 1) solid'
  202. },
  203. //指示点显示位置
  204. current1: 0,
  205. //指示点模式
  206. mode: 'dot',
  207. attr_groups: [],
  208. page: {
  209. title: '产品详情'
  210. },
  211. sku: {
  212. keys: [],
  213. }
  214. }
  215. },
  216. onReady: function() {
  217. this.videoContext = uni.createVideoContext('myVideo')
  218. },
  219. onLoad(op) {
  220. const {
  221. id,
  222. type
  223. } = op;
  224. this.admin = this.$store.getters.userInfo
  225. this.product_id = id
  226. this.produceType = type
  227. this.getProductDetail(this.product_id, true)
  228. },
  229. computed: {
  230. showAttr: function() {
  231. if (this.flavorIsActive.length <= 0) return false;
  232. let text = '';
  233. for (const k in this.flavorIsActive) {
  234. text += `${k}-${this.flavorIsActive[k]},`
  235. }
  236. return text.substr(0, text.length - 1);
  237. },
  238. selectedHotelId: function() {
  239. return this.$store.state.tab.selectedHotelId;
  240. }
  241. },
  242. methods: {
  243. //显示所选规格
  244. //获取当前页面路径
  245. getPageUrl() {
  246. const pages = getCurrentPages();
  247. if (pages.length == 1) {
  248. const currentPage = pages[0];
  249. console.log(currentPage.options, '--------->currentPage.options')
  250. let pageUrl = `/${currentPage.route}?type=${currentPage.options.type}`;
  251. return pageUrl
  252. console.log('当前页面url:', pageUrl);
  253. } else {
  254. const currentPage = pages[pages.length - 1];
  255. console.log(currentPage.options, '--------->currentPage.options')
  256. let pageUrl = `/${currentPage.route}?type=${currentPage.options.type}`;
  257. return pageUrl
  258. console.log('当前页面url:', pageUrl);
  259. }
  260. },
  261. // 跳转其他小程序
  262. goOther() {
  263. let _this = this
  264. wx.navigateToMiniProgram({
  265. appId: 'wx255b58f0992b3c53', //appid
  266. path: 'newUIMain/enrollment/enrollment', //path
  267. extraData: { //参数
  268. foo: 'bar'
  269. },
  270. // envVersion: 'develop', //开发版develop 开发版 trial 体验版 release 正式版
  271. success(res) {
  272. let page = _this.getPageUrl()
  273. let user_id = ''
  274. if (_this.admin != null) {
  275. user_id = _this.admin.id
  276. } else {
  277. user_id = 0
  278. }
  279. console.log('成功', page)
  280. _this.$api.my.userMemberAdd({
  281. user_id,
  282. page,
  283. }).then(res => {
  284. console.log(res.data);
  285. })
  286. // 打开成功
  287. },
  288. fail(e) {
  289. console.log(e, '失败')
  290. }
  291. })
  292. },
  293. //视频自动播放
  294. openVideoPlay() {
  295. this.videoContext.play()
  296. },
  297. // 获取商品详情
  298. getProductDetail(product_id, init = false) {
  299. this.$store.commit("tab/SET_SELECTEDHOTELId", 0)
  300. this.$api.product.getProductDetail({
  301. product_id: product_id
  302. }).then(res => {
  303. if (res.code == 0 && res.data) {
  304. this.productDetail = res.data
  305. this.info = JSON.parse(res.data.img_urls).map(item => {
  306. return {
  307. img: item
  308. }
  309. })
  310. //跳转h5和小程序
  311. this.jump_type = res.data.jump_type,
  312. this.jump_config = res.data.jump_config
  313. //banner展示视频或者图片
  314. this.resource_type = res.data.resource_type
  315. this.video_url = res.data.video_url
  316. //视频自动播放
  317. this.openVideoPlay()
  318. //规格对接
  319. this.attr_groups = JSON.parse(res.data.attr_group)
  320. //获取默认酒店
  321. const hotel_ids = JSON.parse(res.data.hotel_ids);
  322. if ((hotel_ids.constructor == Array) && (hotel_ids.length > 0)) {
  323. this.$store.commit("tab/SET_SELECTEDHOTELId", hotel_ids[0])
  324. }
  325. //
  326. const sku = JSON.parse(res.data.sku);
  327. this.sku.keys = Object.keys(sku.attrs);
  328. this.sku.sku = sku.sku;
  329. //首次默认选中第一个规格
  330. if (init) {
  331. this.attr_groups.forEach(item => {
  332. this.flavorchecked(item.attr_list[0]?.attr_name, item.attr_group_name)
  333. })
  334. }
  335. }
  336. })
  337. },
  338. // 获取酒店详情
  339. getHotelDetail(id) {
  340. this.$api.hotel.getHotelDetail({
  341. hotel_id: id
  342. }).then(res => {
  343. this.hotelDetail = res.data
  344. })
  345. },
  346. //跳转酒店列表
  347. goGoodsHotel(id) {
  348. uni.navigateTo({
  349. url: '/pages/goods/goods-hotel/index?product_id=' + id
  350. })
  351. },
  352. //首页
  353. goHome() {
  354. uni.switchTab({
  355. url: '/pages/index/index'
  356. })
  357. },
  358. //二维码购买确认按钮
  359. dialogConfirm() {
  360. console.log('确认');
  361. this.codePurchaseClose()
  362. },
  363. //二维码购买取消按钮
  364. dialogClose() {
  365. console.log('取消');
  366. this.codePurchaseClose()
  367. },
  368. //菜单index切换
  369. checked(index) {
  370. this.isActive = index
  371. },
  372. // 口味切换
  373. flavorchecked(index, name) {
  374. this.$set(this.flavorIsActive, name, index)
  375. this.specs.flavor = name
  376. if (Object.keys(this.flavorIsActive).length < this.sku.keys.length) return;
  377. for (let index = 0; index < this.sku.sku.length; index++) {
  378. const item = this.sku.sku[index];
  379. let res = true;
  380. for (const k in this.flavorIsActive) {
  381. if (item[k] != this.flavorIsActive[k]) {
  382. res = false
  383. }
  384. }
  385. if (res) {
  386. this.productDetail.price = item.price;
  387. this.productDetail.integral = item.price
  388. break;
  389. }
  390. }
  391. },
  392. // // 重量切换
  393. // weightchecked(index,name) {
  394. // this.weightIsActive = index
  395. // this.specs.weight=name
  396. // console.log(this.specs.weight);
  397. // },
  398. // // 包装切换
  399. // packchecked(index,name) {
  400. // this.packIsActive = index
  401. // this.specs.pack=name
  402. // console.log(this.specs.pack);
  403. // },
  404. // 立即兑换
  405. selectSpecs(id, flavorIsActive) {
  406. const resArr = [];
  407. outer: for (const k in this.flavorIsActive) {
  408. inner: for (const i in this.attr_groups) {
  409. if (this.attr_groups[i].attr_group_name == k) {
  410. laster: for (const l in this.attr_groups[i].attr_list) {
  411. if (this.attr_groups[i].attr_list[l].attr_name == this.flavorIsActive[k]) {
  412. resArr.push(this.attr_groups[i].attr_list[l].attr_id);
  413. break inner;
  414. }
  415. }
  416. }
  417. }
  418. }
  419. const selectedIds = resArr.join(':');
  420. console.log(this.productDetail.integral);
  421. uni.navigateTo({
  422. url: `/pages/my/integral/integralOrder?product_id=${this.productDetail.id}&attr=${selectedIds}&integral=${this.productDetail.integral}`
  423. })
  424. this.Recipientclose()
  425. },
  426. Recipientopen() {
  427. this.$refs.Recipient.open('bottom')
  428. },
  429. Recipientclose() {
  430. this.$refs.Recipient.close()
  431. },
  432. codePurchaseClose() {
  433. this.$refs.codePurchase.close()
  434. },
  435. // 切换轮播图指示点
  436. change1(e) {
  437. this.current1 = e.detail.current;
  438. },
  439. //积分兑换
  440. goProductChange(id, flavorIsActive) {
  441. const resArr = [];
  442. outer: for (const k in this.flavorIsActive) {
  443. inner: for (const i in this.attr_groups) {
  444. if (this.attr_groups[i].attr_group_name == k) {
  445. laster: for (const l in this.attr_groups[i].attr_list) {
  446. if (this.attr_groups[i].attr_list[l].attr_name == this.flavorIsActive[k]) {
  447. resArr.push(this.attr_groups[i].attr_list[l].attr_id);
  448. break inner;
  449. }
  450. }
  451. }
  452. }
  453. }
  454. const selectedIds = resArr.join(':');
  455. uni.navigateTo({
  456. url: `/pages/my/integral/integralOrder?product_id=${this.productDetail.id}&attr=${selectedIds}&integral=${this.productDetail.integral}`
  457. })
  458. },
  459. // 跳转积分兑换
  460. goIntegralOrder() {
  461. this.$utils.jump({
  462. jump_type: this.hotelDetail.buy_jump_type,
  463. jump_config: this.hotelDetail.buy_jump_config,
  464. attr: JSON.stringify(this.flavorIsActive)
  465. })
  466. },
  467. },
  468. watch: {
  469. selectedHotelId(newValue) {
  470. newValue && this.getHotelDetail(newValue);
  471. }
  472. }
  473. }
  474. </script>
  475. <style lang="scss" scoped src="./index.scss"></style>
  476. <style lang="scss">
  477. .produce-text img {
  478. width: 100%;
  479. object-fit: fill;
  480. }
  481. </style>