index.vue 14 KB

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