金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1350 lines
36 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view style="overflow-x: hidden;">
  3. <lf-nav title="商品详情" titleColor="#fff" :spreadOut="false" :showIcon="true" bgColor="transparent"></lf-nav>
  4. <skeleton :loading="skeletonLoading" :row="12" :showAvatar="false" :showTitle="true">
  5. <block>
  6. <!-- 商品图片轮播 -->
  7. <swiper :current="current" :indicator-dots="pictures.length > 1" :circular="true" class="swiper-box" indicator-active-color="#1998FE">
  8. <swiper-item v-for="(item, index) in pictures" :key="index">
  9. <image mode="aspectFill" :src="item" style="width: 100%; height: 100%;" @click="lookImg(index)"></image>
  10. <view class="seckill-box" v-if="type == 'seckill' && $isRight(seckill.seckill.end_left_time)" style="z-index: 999;">
  11. <view>距离结束还剩余</view>
  12. <view v-if="$isRight(seckill.seckill.end_left_time)">
  13. <countdown-time
  14. :day="seckill.seckill.end_left_time[0]"
  15. :hour="seckill.seckill.end_left_time[1]"
  16. :minute="seckill.seckill.end_left_time[2]"
  17. :second="seckill.seckill.end_left_time[3]"
  18. color="white"
  19. splitorColor="white"
  20. >
  21. </countdown-time>
  22. </view>
  23. </view>
  24. <view class="seckill-box" v-if="type == 'seckill' && $isRight(seckill.seckill.start_left_time)" style="z-index: 999;">
  25. <view>距离开始还剩余</view>
  26. <view v-if="$isRight(seckill.seckill.start_left_time)">
  27. <countdown-time
  28. :day="seckill.seckill.start_left_time[0]"
  29. :hour="seckill.seckill.start_left_time[1]"
  30. :minute="seckill.seckill.start_left_time[2]"
  31. :second="seckill.seckill.start_left_time[3]"
  32. color="white"
  33. splitorColor="white"
  34. >
  35. </countdown-time>
  36. </view>
  37. </view>
  38. </swiper-item>
  39. </swiper>
  40. <!-- 商品主要信息 -->
  41. <view class="head-info">
  42. <view class="lf-row-between">
  43. <view v-if="type == 'point'">
  44. <text class="lf-font-48 lf-color-primary lf-font-bold">{{ goods_detail.redeem_point }}</text>
  45. <text class="lf-font-28 lf-color-777 lf-m-l-10">个积分兑换</text>
  46. </view>
  47. <lf-price :iftext="false" :price="seckill.seckill_price || 0" v-else-if="type == 'seckill'"></lf-price>
  48. <lf-price :iftext="false" :price="goods_detail.sell_price || 0" v-else></lf-price>
  49. <text class="lf-iconfont icon-fenxiang lf-font-40" @click="shareGraphic()"></text>
  50. </view>
  51. <view class="lf-row-between lf-font-24 lf-m-t-20 lf-p-b-20">
  52. <view class="lf-font-bold lf-font-32 lf-color-222">{{ goods_detail.name }}</view>
  53. </view>
  54. <view class="lf-row-between lf-font-24 lf-p-b-30">
  55. <view class="lf-font-28 lf-color-777 lf-row-between">可自提/可邮寄</view>
  56. </view>
  57. </view>
  58. <!-- 商品优惠 -->
  59. <block v-if="coupons && coupons.length">
  60. <self-line></self-line>
  61. <view class="bg-white" >
  62. <view class="cu-bar padding-lr">
  63. <view class="lf-flex">
  64. <text class="lf-color-777 lf-font-28">优惠</text>
  65. <view style="width: 580rpx; padding-left: 20rpx;">
  66. <text class="lf-color-222 lf-font-26"
  67. v-for="(item, index) in coupons" :key="index">{{ item.title }};
  68. </text>
  69. </view>
  70. </view>
  71. <!-- <view>
  72. <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text>
  73. </view> -->
  74. </view>
  75. </view>
  76. </block>
  77. <self-line></self-line>
  78. <!-- 服务tags -->
  79. <block v-if="goods_detail.tags.length">
  80. <view class="bg-white">
  81. <view class="cu-bar padding-lr">
  82. <view class="lf-flex">
  83. <text class="lf-color-777 lf-font-28">服务</text>
  84. <view style="width: 600rpx;flex-wrap: wrap;display: flex;margin-top: 32rpx;">
  85. <view class="lf-m-l-30" v-for="(tagItem, tagIndex) in goods_detail.tags" :key="tagIndex">
  86. <text class="lf-iconfont icon-xuanzhong lf-font-30" style="color: #15716E;"></text>
  87. <text class="lf-m-l-10 lf-font-26 lf-color-black">{{ tagItem }}</text>
  88. </view>
  89. </view>
  90. </view>
  91. <view>
  92. <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text>
  93. </view>
  94. </view>
  95. </view>
  96. </block>
  97. <!-- 商品选择规格 -->
  98. <block v-if="$isRight(goods_stock.specs)">
  99. <view class="bg-white">
  100. <view class="cu-bar padding-lr" @click="shoot(3)" v-if="type == 'point'">
  101. <view class="lf-flex">
  102. <text class="lf-color-777 lf-font-28">选择</text>
  103. <text class="lf-color-222 lf-font-26 lf-m-l-30">{{ showSpec }}</text>
  104. </view>
  105. <view>
  106. <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text>
  107. </view>
  108. </view>
  109. <view class="cu-bar padding-lr" @click="shoot(2)" v-else>
  110. <view class="lf-flex">
  111. <text class="lf-color-777 lf-font-28">选择</text>
  112. <text class="lf-color-222 lf-font-26 lf-m-l-30">{{ showSpec }}</text>
  113. </view>
  114. <view>
  115. <text class="lf-font-24 lf-color-777 lf-iconfont icon-xiangyou"></text>
  116. </view>
  117. </view>
  118. </view>
  119. <self-line></self-line>
  120. </block>
  121. <!-- 店铺信息 -->
  122. <view v-if="type != 'point'">
  123. <view class="user-top">
  124. <view class="lf-row-between lf-w-100">
  125. <view class="lf-flex" @click="$url('/pages/shop/shopdetail?id='+ brand_detail.id)">
  126. <view class="tag-father">
  127. <image :src="brand_detail.logo" mode="widthFix" class="head-img"></image>
  128. </view>
  129. <view class="lf-flex-column lf-m-l-20">
  130. <text class="lf-font-28 lf-color-black lf-font-bold">{{ brand_detail.name }}</text>
  131. <view class="lf-font-24 lf-color-777">
  132. <text class="lf-iconfont icon-dizhi lf-font-24 lf-color-primary"></text>
  133. <text class="lf-m-l-10">{{ brand_detail.floor }}</text>
  134. </view>
  135. </view>
  136. </view>
  137. <view>
  138. <button class="head-btn" @click="makePhoneCall(brand_detail.tel)">
  139. <text class="lf-iconfont icon-kefuhdpi lf-font-24"></text>
  140. <text class="lf-m-l-10">客服</text>
  141. </button>
  142. </view>
  143. </view>
  144. </view>
  145. <scroll-view class="scroll-view" :scroll-x="true" v-if="brand_detail.goods.length!=0">
  146. <view class="scroll-content">
  147. <view class="goods-item"
  148. v-for="(item, index) in brand_detail.goods"
  149. :key="index"
  150. @click="$url('/pages/shop/goodsdetail?id='+ item.id)">
  151. <image class="goods-img" :src="item.img"></image>
  152. <view class="goods-info">
  153. <view class="lf-line-1">{{ item.name }}</view>
  154. <view>{{ item.sell_price }}</view>
  155. </view>
  156. </view>
  157. <view class="goods-item" @click="$url('/pages/shop/shopdetail?id='+ brand_detail.id)">
  158. <view class="more-box">
  159. <text>查看更多</text>
  160. <text class="lf-iconfont icon--2 lf-text-vertical"></text>
  161. </view>
  162. </view>
  163. </view>
  164. </scroll-view>
  165. </view>
  166. <!-- 商品详情 -->
  167. <view class="goods-detail">
  168. <view class="lf-font-32 lf-font-bold lf-m-b-20">商品详情</view>
  169. <rich-text :nodes="goods_content"></rich-text>
  170. <!-- <image class="goods-img" :src="item" v-for="(item, index) in goods_detail.content" :key="index" v-if="goods_detail.content_type == 'img'"></image> -->
  171. </view>
  172. <!-- 修饰专用 -->
  173. <view class="extra"></view>
  174. <!-- 吸底操作按钮 -->
  175. <view class="lf-row-between fixed-bottom">
  176. <view class="lf-flex lf-p-t-10 lf-p-b-10">
  177. <button class="lf-flex-column lf-row-center icon-item" open-type="contact">
  178. <text class="lf-iconfont icon-pinglun- icon-img"></text>
  179. <view class="lf-m-t-1">客服</view>
  180. </button>
  181. <view class="lf-flex-column lf-row-center icon-item" @click="switchCollect">
  182. <text class="lf-iconfont icon-shoucang2 icon-img lf-color-price" v-if="is_collect"></text>
  183. <text class="lf-iconfont icon-shoucang11 icon-img" v-else></text>
  184. <view class="lf-m-t-1">{{ is_collect ? '已收藏' : '收藏' }}</view>
  185. </view>
  186. <button class="lf-flex-column lf-row-center icon-item" @click="$url('/pages/store/cart/cart')">
  187. <text class="lf-iconfont icon-gouwulan icon-img"></text>
  188. <view class="lf-m-t-1">购物车</view>
  189. <block v-if="$isRight(car_num)">
  190. <view class="angle-mark" v-if="car_num<99">{{car_num || 0}}</view>
  191. <view class="angle-mark" v-else>99+</view>
  192. </block>
  193. </button>
  194. </view>
  195. <view v-if="type == 'seckill'">
  196. <button class="btn" style="width: 349rpx;" @click="shoot(2)">立即秒杀</button>
  197. </view>
  198. <view v-else-if="type == 'point'">
  199. <button class="btn" style="width: 349rpx;" @click="shoot(3)">立即兑换</button>
  200. </view>
  201. <view class="lf-flex" v-else>
  202. <button class="btn1" @click="shoot(1)">加入购物车</button>
  203. <button class="btn lf-m-l-15" @click="shoot(2)">立即购买</button>
  204. </view>
  205. </view>
  206. <!-- 分享生成海报时弹出 -->
  207. <view class="share-img-box" :class="share_img ? 'cur' : ''">
  208. <view class="imgs-box">
  209. <view class="img">
  210. <image mode="widthFix" :src="shareImg"></image>
  211. </view>
  212. <view class="text">
  213. 保存图片后可分享到朋友圈
  214. </view>
  215. <view class="save" :style="'background: ' + config.mainColor" @tap="downImg">
  216. 保存图片
  217. </view>
  218. <!-- <i class="iconfont icon-delete" @tap="changeImg"></i> -->
  219. <text class="lf-iconfont icon-status-error" @tap="changeImg" ></text>
  220. </view>
  221. </view>
  222. <!-- 加入购物车立即购买模态框选规格 -->
  223. <u-popup v-model="show_popup" mode="bottom" :round="true" borderRadius="20">
  224. <view class="popup-content">
  225. <!-- 商品信息及关闭按钮 -->
  226. <view class="popup-head">
  227. <view class="lf-flex">
  228. <image class="goods-img" :src="goods_detail.img"></image>
  229. <view class="goods-info">
  230. <view class="price">{{ showGoodsSpecPrice }}</view>
  231. <view class="goods-name">{{ goods_detail.name }}</view>
  232. </view>
  233. </view>
  234. <view @click="show_popup = false">
  235. <text class="lf-iconfont icon-cuo lf-font-50"></text>
  236. </view>
  237. </view>
  238. <!-- 规格 -->
  239. <view v-for="(value, key) in goods_stock.specs" :key="key">
  240. <view class="spec-title">{{ value.label }}</view>
  241. <view class="lf-flex-wrap">
  242. <view :class="{
  243. 'spec-item': true,
  244. 'spec-active': value.spec_current === index}"
  245. @click="activeSpec(key, index)"
  246. v-for="(item, index) in value.list"
  247. :key="index">{{ item.value }}
  248. </view>
  249. </view>
  250. </view>
  251. <!-- 数量 -->
  252. <view class="lf-row-between lf-m-t-40">
  253. <view class="lf-font-28 lf-color-555">数量</view>
  254. <view class="lf-flex">
  255. <view class="num-btn" @click="changeNum('less')">
  256. <text class="lf-iconfont icon-jian1 lf-font-30"></text>
  257. </view>
  258. <view>
  259. <input class="input" :value="goods_num" :disabled="true" />
  260. </view>
  261. <view class="num-btn lf-text-right" @click="changeNum('add')">
  262. <text class="lf-iconfont icon-jia lf-font-30"></text>
  263. </view>
  264. </view>
  265. </view>
  266. <!-- 操作按钮 -->
  267. <button class="comfirm-btn" @click="specConfirm">{{ click_type == 1 ? '加入购物车' : '立即购买' }}</button>
  268. </view>
  269. </u-popup>
  270. <!-- 回到顶部 -->
  271. <u-back-top :scroll-top="pageScrollTop"></u-back-top>
  272. </block>
  273. </skeleton>
  274. </view>
  275. </template>
  276. <script>
  277. import countdownTime from '@/components/uni-countdown/uni-countdown.vue';
  278. import Bigc from '@/common/js/bigc.js';
  279. export default {
  280. components: {
  281. countdownTime
  282. },
  283. data(){
  284. return {
  285. current: 0, // 轮播下标
  286. goods_id: 0,
  287. goods_detail: {},
  288. is_collect: false, // 1为当前收藏商品了,0为否
  289. skeletonLoading: false,
  290. pictures: [],
  291. show_popup: false, // 是否显示选规格模态框
  292. click_type: null, // 当前点击的是加入购物车[1]还是立即购买[2]
  293. type: 'mail', // 页面显示类型,mail普通可邮寄商品,point积分商品,seckill秒杀商品
  294. time: 0,
  295. goods_stock: {
  296. specs: {},
  297. stores: {}
  298. },
  299. seckill: {}, // 秒杀商品的信息
  300. brand_detail: {},
  301. token: '',
  302. coupons: [], // 优惠
  303. goods_num: 1,
  304. is_date_finish: false,
  305. car_num: 0,
  306. goods_content: '',
  307. shareImg: '',
  308. share_img: false,
  309. show_share: false,
  310. config: {mainColor: '#15716e'}
  311. }
  312. },
  313. computed: {
  314. showGoodsSpecPrice(){
  315. let goods_detail = this.goods_detail;
  316. let stores = this.goods_stock.stores;
  317. let specs = this.goods_stock.specs;
  318. if(!this.$isRight(specs[1])){
  319. return `${goods_detail.min_price} - ¥${goods_detail.max_price}`;
  320. }
  321. let spec_current_1 = specs[1].spec_current;
  322. let spec_current_2 = specs[2].spec_current;
  323. if(specs[1].spec_current != null && specs[2].spec_current != null){
  324. let id_1 = specs[1].list[spec_current_1].id;
  325. let id_2 = specs[2].list[spec_current_2].id;
  326. if(id_1 < id_2){
  327. let id_3 = id_2;
  328. id_2 = id_1;
  329. id_1 = id_3;
  330. }
  331. return "¥"+ stores[id_2 +'-'+ id_1].price;
  332. }else{
  333. return `${goods_detail.min_price} - ¥${goods_detail.max_price}`;
  334. }
  335. },
  336. showSpec(){
  337. let specs = this.goods_stock.specs;
  338. let str = '';
  339. for(let i in specs){
  340. if(specs[i].spec_current != null){
  341. str += specs[i].list[specs[i].spec_current].value +';';
  342. }
  343. }
  344. if(str == ''){
  345. str = '请选择规格'
  346. }
  347. return str;
  348. }
  349. },
  350. onLoad(options){
  351. console.log("options", options)
  352. this.token = this.$cookieStorage.get('user_token');
  353. this.goods_id = options.id;
  354. this.getNewdetail();
  355. this.getGoodsStock(); // 获取商品库存、规格信息
  356. this.getcarNum()
  357. },
  358. methods: {
  359. getcarNum() {
  360. this.$http
  361. .get({
  362. api: 'api/shopping/cart/count',
  363. header: {
  364. Authorization: this.$cookieStorage.get('user_token')
  365. },
  366. })
  367. .then(res => {
  368. if (res.data.code == 200) {
  369. if(res.data.data == null) {
  370. this.car_num = 0;
  371. }else {
  372. this.car_num = res.data.data;
  373. }
  374. }
  375. })
  376. .catch(() => {
  377. wx.showModal({
  378. content: '请求失败',
  379. showCancel: false
  380. });
  381. });
  382. },
  383. // 切换商品收藏
  384. switchCollect(){
  385. if(!this.token){
  386. this.$url('/pages/login/index');
  387. return;
  388. }
  389. this.addCollcet()
  390. },
  391. //收藏
  392. addCollcet() {
  393. this.$http.post({
  394. api: 'api/collect/create',
  395. data: {
  396. type:'jc_goods',
  397. collect_id: this.goods_detail.id,
  398. },
  399. header: {
  400. Authorization: this.token
  401. }
  402. }).then(res => {
  403. this.$msg(res.data.data);
  404. this.getNewdetail();
  405. }).catch(err => {
  406. console.log("====", err);
  407. })
  408. },
  409. // 加入购物车和立即购买
  410. shoot(type){
  411. this.click_type = type;
  412. if(this.$isRight(this.goods_stock.specs)){
  413. this.show_popup = true;
  414. }else{
  415. this.confirm();
  416. }
  417. },
  418. // 选规格提交
  419. specConfirm(){
  420. let specs = this.goods_stock.specs;
  421. let flag = true;
  422. for(let i in specs){
  423. if(specs[i].spec_current == null){
  424. flag = false;
  425. }
  426. }
  427. if(flag){
  428. this.confirm();
  429. }else{
  430. this.$msg('您未选完整规格')
  431. }
  432. },
  433. // 商品选规格
  434. activeSpec(key, index){
  435. let obj = this.goods_stock.specs;
  436. if(obj[key]['spec_current'] == index){
  437. obj[key]['spec_current'] = null;
  438. }else{
  439. obj[key]['spec_current'] = index;
  440. }
  441. this.$set(this.goods_stock, 'specs', obj);
  442. },
  443. // 商品加减
  444. changeNum(type){
  445. if(type == 'add'){
  446. if(this.goods_num < 10){
  447. this.goods_num++;
  448. }
  449. }else if(type == 'less'){
  450. if(this.goods_num > 1){
  451. this.goods_num--;
  452. }
  453. }
  454. },
  455. // 跳转至下单页TODO
  456. confirm(){
  457. if(this.is_date_finish){
  458. return this.$msg('活动已结束');
  459. }
  460. let goods_detail = this.goods_detail;
  461. let specs = this.goods_stock.specs;
  462. let stores = this.goods_stock.stores;
  463. let par = {};
  464. let have_specs = '';
  465. let no_specs = '';
  466. if(this.$isRight(specs)){
  467. let s_id_1 = 1;
  468. let s_id_2 = 2;
  469. for(let i in specs){
  470. if(specs[i].label_key == 'size'){
  471. s_id_1 = 1;
  472. }
  473. if(specs[i].label_key == 'color'){
  474. s_id_2 = 2;
  475. }
  476. }
  477. let spec_current_1 = specs[s_id_1].spec_current;
  478. let spec_current_2 = specs[s_id_2].spec_current;
  479. let id_1 = specs[s_id_1].list[spec_current_1].id;
  480. let id_2 = specs[s_id_2].list[spec_current_2].id;
  481. if(id_1 > id_2){
  482. let id_3 = id_2;
  483. id_2 = id_1;
  484. id_1 = id_3;
  485. }
  486. par = {
  487. attributes: {
  488. color: specs[s_id_2].list[specs[s_id_2].spec_current].value,
  489. com_id: goods_detail.id,
  490. img: goods_detail.img,
  491. size: specs[s_id_1].list[specs[s_id_1].spec_current].value,
  492. sku: goods_detail.goods_no +'-'+ specs[s_id_1].list[specs[s_id_1].spec_current].value
  493. },
  494. id: stores[id_1 +'-'+ id_2].id,
  495. product_id: stores[id_1 +'-'+ id_2].id,
  496. price: stores[id_1 +'-'+ id_2].price,
  497. store_count: stores[id_1 +'-'+ id_2].store,
  498. market_price: goods_detail.market_price,
  499. name: goods_detail.name,
  500. qty: this.goods_num
  501. }
  502. have_specs = stores[id_1 +'-'+ id_2].id;
  503. }else{
  504. par = {
  505. attributes: {
  506. com_id: goods_detail.id,
  507. img: goods_detail.img
  508. },
  509. id: goods_detail.id,
  510. product_id: goods_detail.id,
  511. price: goods_detail.sell_price,
  512. store_count: goods_detail.store_nums,
  513. market_price: goods_detail.market_price,
  514. name: goods_detail.name,
  515. qty: this.goods_num
  516. }
  517. no_specs = goods_detail.id;
  518. }
  519. // 秒杀商品
  520. if(this.$isRight(this.seckill)){
  521. delete par.product_id;
  522. par.seckill_goods_id = this.seckill.item_id;
  523. par.seckill_item_id = this.seckill.id;
  524. par.price = this.seckill.seckill_price;
  525. par.total = new Bigc(this.goods_num).times(this.seckill.seckill_price);
  526. }
  527. uni.showLoading({
  528. title: '正在提交'
  529. })
  530. this.show_popup = false;
  531. if(this.click_type == 1){
  532. // 加入购物车
  533. this.$http.post({
  534. api: 'api/shopping/cart',
  535. data: {"0": par},
  536. header: {
  537. Authorization: this.token
  538. }
  539. }).then(res => {
  540. if(res.data.code == 200){
  541. this.$msg('加入购物车成功', {icon: 'success'})
  542. this.getcarNum()
  543. }else{
  544. this.$msg('加入购物车失败', {icon: 'error'})
  545. }
  546. uni.hideLoading()
  547. }).catch(err => uni.hideLoading())
  548. }else if(this.click_type == 2){
  549. // 直接结算
  550. this.$cookieStorage.set('order_confirm', par);
  551. uni.hideLoading();
  552. this.$url('/pages/order/confirm/confirm');
  553. // this.$http.post({
  554. // api: 'api/shopping/order/checkout',
  555. // data: par,
  556. // header: {
  557. // Authorization: this.token
  558. // }
  559. // }).then(res => {
  560. // if(res.data.code == 200){
  561. // this.$url('/pages/order/confirm/confirm');
  562. // }else{
  563. // this.$msg('提交失败', {icon: 'error'})
  564. // }
  565. // uni.hideLoading()
  566. // }).catch(err => uni.hideLoading())
  567. }else if(this.click_type == 3) {
  568. let params = {};
  569. if(have_specs) {
  570. uni.hideLoading()
  571. this.$url('/pages/order/pointconfirm/confirm?quantity='+this.goods_num+'&product_id='+have_specs+'&goods_type=0')
  572. }else {
  573. uni.hideLoading()
  574. this.$url('/pages/order/pointconfirm/confirm?quantity='+this.goods_num+'&goods_id='+no_specs+'&goods_type=0')
  575. }
  576. }
  577. },
  578. // 点击页面分享按钮
  579. shareGraphic(){
  580. // this.getCreateShareImg();
  581. this.getShearImg();
  582. },
  583. // 获取分享图片
  584. getShearImg() {
  585. wx.showLoading({
  586. title: "生成中",
  587. mask: true
  588. });
  589. this.$http.get({
  590. api: 'api/distribution/createMiniShareImg',
  591. header: {
  592. Authorization: this.token
  593. },
  594. data: {
  595. goods_id: this.goods_id
  596. }
  597. }).then(res => {
  598. if (res.statusCode == 200) {
  599. res = res.data;
  600. if (res.status) {
  601. this.setData({
  602. shareImg: res.data.image
  603. });
  604. setTimeout(() => {
  605. this.changeImg();
  606. }, 100)
  607. } else {
  608. wx.showModal({
  609. content: res.message || '请求失败',
  610. showCancel: false
  611. });
  612. }
  613. } else {
  614. wx.showModal({
  615. content: '请求失败',
  616. showCancel: false
  617. });
  618. }
  619. wx.hideLoading();
  620. this.changeShare();
  621. }).catch(rej => {
  622. wx.showModal({
  623. content: '内部错误',
  624. showCancel: false
  625. });
  626. wx.hideLoading();
  627. this.changeShare();
  628. });
  629. },
  630. // 弹出图片
  631. changeImg() {
  632. this.share_img = !this.share_img;
  633. },
  634. // 弹出分享
  635. changeShare() {
  636. this.setData({
  637. show_share: !this.show_share
  638. });
  639. },
  640. // 下载图片
  641. downImg() {
  642. if (this.shareImg) {
  643. wx.showLoading({
  644. title: '正在下载',
  645. mask: true
  646. });
  647. this.$http.dowloadFile({
  648. api: this.shareImg
  649. }).then(res => {
  650. if (res.statusCode == 200) {
  651. wx.getSetting({
  652. success: ret => {
  653. // 如果之前没有授权
  654. if (!ret.authSetting['scope.writePhotosAlbum']) {
  655. wx.authorize({
  656. scope: 'scope.writePhotosAlbum',
  657. success: rej => {
  658. this.saveImg(res.tempFilePath);
  659. },
  660. // 用户拒绝授权
  661. fail: ret => {
  662. // this.setData({
  663. // is_refused: true
  664. // });
  665. wx.hideLoading();
  666. uni.showModal({
  667. title: '温馨提示',
  668. content: '由于您拒绝授权,保存图片失败!',
  669. showCancel: false
  670. })
  671. }
  672. });
  673. } else {
  674. this.saveImg(res.tempFilePath);
  675. }
  676. }
  677. });
  678. } else {
  679. wx.hideLoading();
  680. wx.showToast({
  681. title: '下载图片失败',
  682. icon: 'none'
  683. });
  684. }
  685. }, err => {});
  686. }
  687. },
  688. // 保存图片
  689. saveImg(path) {
  690. wx.saveImageToPhotosAlbum({
  691. filePath: path,
  692. success: res => {
  693. wx.hideLoading();
  694. wx.showToast({
  695. title: '保存图片成功',
  696. icon: 'success'
  697. });
  698. },
  699. fail: rej => {
  700. wx.hideLoading();
  701. wx.showToast({
  702. title: '保存图片失败',
  703. icon: 'none'
  704. });
  705. }
  706. });
  707. },
  708. //请求h5的图片接口
  709. getCreateShareImg(){
  710. wx.showLoading({
  711. title:"生成中",
  712. mask:true
  713. })
  714. let origin = window.location.origin;
  715. let share_url = origin+'/pages/store/detail/detail';
  716. this.$http.get({
  717. api:'api/distribution/createH5ShareImg',
  718. data:{
  719. goods_id:this.id,
  720. share_url:share_url
  721. }
  722. }).then(res=>{
  723. res = res.data;
  724. if(res.status){
  725. this.qr_code_image = res.data.image;
  726. if(this.qr_code_image){
  727. this.share_gaphic =!this.share_gaphic;
  728. this.is_toggle_share = false;
  729. }
  730. } else{
  731. wx.showModal({
  732. content: res.message || '请求失败,请重试',
  733. showCancel: false
  734. });
  735. }
  736. wx.hideLoading()
  737. }).catch(rej=>{
  738. wx.hideLoading()
  739. wx.showModal({
  740. content: rej.message || '内部错误,请重试',
  741. showCancel: false
  742. });
  743. })
  744. },
  745. // 商品详情
  746. getNewdetail(){
  747. this.$http.get({
  748. api: 'api/store/detail/'+ this.goods_id,
  749. header: {
  750. Authorization: this.token
  751. }
  752. }).then(res => {
  753. console.log("===---", res);
  754. if(res.data.status){
  755. let meta = res.data.meta;
  756. let goods_detail = res.data.data;
  757. this.goods_detail = goods_detail;
  758. this.pictures = [res.data.data.img];
  759. this.is_collect = Boolean(res.data.data.is_collect) || false;
  760. this.goods_content = this.formatRichText(goods_detail.content);
  761. let type = 'mail';
  762. if(this.$isRight(goods_detail.is_largess)){
  763. type = 'point';
  764. }
  765. if(this.$isRight(meta.seckill)){
  766. type = 'seckill';
  767. this.seckill = meta.seckill;
  768. let currentDate = this.$shared.recordTime();
  769. this.time = new Date(meta.seckill.ends_at).getTime() - new Date(currentDate).getTime()
  770. }
  771. if(type != 'point'){
  772. this.getBrandDetail(goods_detail.brand_id);
  773. }
  774. if(this.$isRight(meta.discounts)){
  775. this.coupons = meta.discounts.coupons;
  776. }
  777. this.type = type;
  778. }else{
  779. this.$msg(res.data.message || '网络繁忙请稍后再试').then(() => {
  780. this.$toBack();
  781. })
  782. }
  783. }).catch(err => {
  784. console.log("====", err);
  785. })
  786. },
  787. // 获取商家信息
  788. getBrandDetail(brand_id){
  789. this.$http.get({
  790. api: 'api/brand/detail',
  791. data: {
  792. brand_id: brand_id
  793. },
  794. header: {
  795. Authorization: this.token
  796. }
  797. }).then(res => {
  798. this.brand_detail = res.data.data;
  799. })
  800. },
  801. // 获取商品库存信息
  802. getGoodsStock(){
  803. this.$http.get({
  804. api: `api/store/detail/${this.goods_id}/stock`
  805. }).then(res => {
  806. let data = res.data.data;
  807. for(let i in data.specs){
  808. data.specs[i].spec_current = null;
  809. }
  810. this.goods_stock = data;
  811. })
  812. },
  813. // 拨打电话
  814. makePhoneCall(phoneStr){
  815. uni.makePhoneCall({
  816. phoneNumber: String(phoneStr)
  817. })
  818. },
  819. // 打开地图 PS.暂时用不到
  820. openMap(){
  821. let { address, lat, lng } = this.goods_detail?.store || {};
  822. uni.openLocation({
  823. longitude: Number(lat),
  824. latitude: Number(lng),
  825. scale: 20,
  826. name: address
  827. });
  828. },
  829. // 预览图片
  830. lookImg(index){
  831. this.$u.throttle(() => {
  832. let banners = this.pictures;
  833. uni.previewImage({
  834. urls: banners,
  835. current: index
  836. })
  837. }, 200);
  838. },
  839. // 倒计时结束
  840. dateFinish(){
  841. this.is_date_finish = true;
  842. },
  843. // 富文本处理
  844. formatRichText(richText){
  845. if(richText != null){
  846. let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){
  847. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  848. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  849. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  850. return match;
  851. });
  852. newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){
  853. match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
  854. return match;
  855. });
  856. newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
  857. newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
  858. return newRichText;
  859. }else{
  860. return null;
  861. }
  862. },
  863. setData: function (obj) {
  864. let that = this;
  865. let keys = [];
  866. let val, data;
  867. Object.keys(obj).forEach(function (key) {
  868. keys = key.split('.');
  869. val = obj[key];
  870. data = that.$data;
  871. keys.forEach(function (key2, index) {
  872. if (index + 1 == keys.length) {
  873. that.$set(data, key2, val);
  874. } else {
  875. if (!data[key2]) {
  876. that.$set(data, key2, {});
  877. }
  878. }
  879. data = data[key2];
  880. });
  881. });
  882. }
  883. },
  884. onShareAppMessage(){
  885. let goods = this.goods_detail;
  886. let title = goods.name;
  887. let imageUrl = goods.share_cover || goods.cover || goods.img;
  888. let path = '/pages/route/index?route=detail&id='+ goods.id;
  889. return {
  890. title,
  891. path,
  892. imageUrl
  893. }
  894. }
  895. }
  896. </script>
  897. <style>
  898. page{
  899. background-color: #f5f5f5;
  900. overflow-x: hidden;
  901. }
  902. </style>
  903. <style lang="scss" scoped="scoped">
  904. .angle-mark{
  905. position: absolute;
  906. right: 4rpx;
  907. top: 4rpx;
  908. width: 40rpx;
  909. height: 40rpx;
  910. background-color: #15716E;
  911. border-radius: 50%;
  912. font-size: 20rpx;
  913. display: flex;
  914. justify-content: center;
  915. align-items: center;
  916. color: #FFFFFF;
  917. }
  918. //商品上去scrollview部分
  919. .scroll-view{
  920. height: 310rpx;
  921. width: 100%;
  922. // margin-top: 20rpx;
  923. padding: 0 30rpx 30rpx 30rpx;
  924. background-color: white;
  925. .scroll-content{
  926. display: flex;
  927. width: 100%;
  928. .goods-item{
  929. margin-right: 15rpx;
  930. width: 180rpx;
  931. }
  932. .goods-img{
  933. width: 180rpx;
  934. height: 180rpx;
  935. background-color: #EEEEEE;
  936. }
  937. .goods-info{
  938. text-align: center;
  939. color: #222222;
  940. &>view:nth-child(1n){
  941. font-size: 24rpx;
  942. }
  943. &>view:nth-child(2n){
  944. font-size: 28rpx;
  945. font-weight: bold;
  946. text-align: left;
  947. color: #F63434;
  948. }
  949. }
  950. .more-box{
  951. width: 180rpx;
  952. height: 180rpx;
  953. background-color: #EEEEEE;
  954. text-align: center;
  955. line-height: 180rpx;
  956. font-size: 24rpx;
  957. }
  958. }
  959. }
  960. //scrollview结束
  961. .tag-father {
  962. position: relative;
  963. }
  964. .head-tag {
  965. color: white;
  966. display: flex;
  967. align-items: center;
  968. justify-content: center;
  969. text-align: center;
  970. font-size: 24rpx;
  971. width: 36rpx;
  972. height: 36rpx;
  973. border-radius: 50%;
  974. background-color: #15716E;
  975. border: 1rpx solid #FFFFFF;
  976. position: absolute;
  977. left: 76rpx;
  978. top: 86rpx;
  979. z-index: 99;
  980. }
  981. .qzone-img {
  982. width: 220rpx;
  983. height: 220rpx;
  984. border-radius: 10rpx;
  985. margin-right: 12rpx;
  986. &:nth-child(3n) {
  987. margin-right: 0;
  988. }
  989. &:nth-child(n + 4) {
  990. margin-top: 12rpx;
  991. }
  992. }
  993. .user-top {
  994. background-color: #F3F8F8;
  995. padding: 30rpx;
  996. display: flex;
  997. align-items: center;
  998. background-color: white;
  999. }
  1000. .head-img {
  1001. width: 80rpx;
  1002. height: 80rpx;
  1003. border-radius: 50%;
  1004. }
  1005. .head-btn {
  1006. display: flex;
  1007. width: max-content;
  1008. height: 45rpx;
  1009. background: white;
  1010. border: 2rpx solid #15716E;
  1011. align-items: center;
  1012. font-size: 22rpx;
  1013. color: #15716E;
  1014. justify-content: space-between;
  1015. border-radius: 35rpx;
  1016. padding: 10rpx!important;
  1017. }
  1018. .swiper-box{
  1019. width: 750rpx;
  1020. height: 750rpx;
  1021. background-color: #FFFFFF;
  1022. position: relative;
  1023. .seckill-box{
  1024. position: absolute;
  1025. bottom: 0;
  1026. left: 0;
  1027. display: flex;
  1028. justify-content: space-between;
  1029. align-items: center;
  1030. padding: 0 32rpx;
  1031. width: 100%;
  1032. height: 77rpx;
  1033. background-color: #15716E;
  1034. color: #FFFFFF;
  1035. font-size: 26rpx;
  1036. }
  1037. }
  1038. .head-info{
  1039. width: 750rpx;
  1040. height: auto;
  1041. box-sizing: border-box;
  1042. padding: 0 32rpx;
  1043. padding-top: 20rpx;
  1044. background-color: #FFFFFF;
  1045. // .price>view:nth-of-type(1){
  1046. // color: #FF0000;
  1047. // margin-right: 22rpx;
  1048. // font-weight: bold;
  1049. // }
  1050. .price>view:nth-of-type(1){
  1051. text-decoration: line-through;
  1052. color: #777777;
  1053. margin-right: 22rpx;
  1054. }
  1055. .price>view:nth-of-type(2){
  1056. width: max-content;
  1057. padding: 0 18rpx;
  1058. height: 46rpx;
  1059. background-color: #1998FE;
  1060. border-radius: 10rpx;
  1061. display: flex;
  1062. justify-content: center;
  1063. align-items: center;
  1064. color: #FFFFFF;
  1065. }
  1066. .label-box{
  1067. min-height: 130rpx;
  1068. width: 100%;
  1069. border-top: 1rpx solid #E5E5E5;
  1070. display: flex;
  1071. flex-wrap: wrap;
  1072. padding: 30rpx 0 10rpx 0;
  1073. .label-item{
  1074. width: max-content;
  1075. padding: 20rpx;
  1076. height: 70rpx;
  1077. border-radius: 10rpx;
  1078. border: 2rpx solid #1998FE;
  1079. display: flex;
  1080. justify-content: center;
  1081. align-items: center;
  1082. font-size: 28rpx;
  1083. color: #1998FE;
  1084. margin-right: 20rpx;
  1085. margin-bottom: 20rpx;
  1086. }
  1087. }
  1088. }
  1089. .address-box{
  1090. width: 750rpx;
  1091. height: auto;
  1092. box-sizing: border-box;
  1093. background-color: #FFFFFF;
  1094. padding: 32rpx;
  1095. margin-top: 20rpx;
  1096. .shop-img{
  1097. width: 60rpx;
  1098. height: 60rpx;
  1099. border-radius: 50%;
  1100. }
  1101. }
  1102. .goods-detail{
  1103. width: 750rpx;
  1104. height: auto;
  1105. background-color: #FFFFFF;
  1106. padding: 32rpx;
  1107. box-sizing: border-box;
  1108. margin-top: 20rpx;
  1109. .goods-img{
  1110. width: 100%;
  1111. }
  1112. }
  1113. .extra{
  1114. width: 100%;
  1115. height: 110rpx;
  1116. padding-bottom: constant(safe-area-inset-bottom);
  1117. padding-bottom: env(safe-area-inset-bottom);
  1118. box-sizing: content-box;
  1119. }
  1120. .fixed-bottom{
  1121. position: fixed;
  1122. bottom: 0;
  1123. left: 0;
  1124. background-color: #FFFFFF;
  1125. width: 100%;
  1126. height: auto;
  1127. padding: 0 32rpx;
  1128. border-top: 1rpx solid #e5e5e5;
  1129. padding-bottom: constant(safe-area-inset-bottom);
  1130. padding-bottom: env(safe-area-inset-bottom);
  1131. .icon-item{
  1132. text-align: center;
  1133. margin-right: 16rpx;
  1134. background-color: transparent;
  1135. margin: 0;
  1136. line-height: initial;
  1137. font-size: 28rpx;
  1138. font-weight: inherit;
  1139. margin-right: 10rpx;
  1140. padding: 0;
  1141. width: 88rpx;
  1142. position: relative;
  1143. color: #555555;
  1144. &:first-child{
  1145. padding-left: 0;
  1146. }
  1147. .icon-img{
  1148. height: 50rpx;
  1149. width: 50rpx;
  1150. font-size: 40rpx;
  1151. line-height: 1;
  1152. color: #555555;
  1153. }
  1154. }
  1155. .btn1{
  1156. margin: 0;
  1157. width: max-content;
  1158. height: 80rpx;
  1159. background-color: rgba(21, 113, 110, 0.1);
  1160. color: #15716E;
  1161. line-height: 80rpx;
  1162. font-size: 32rpx;
  1163. padding: 0 20rpx;
  1164. border-radius: 42rpx;
  1165. font-size: 26rpx;
  1166. border: 2rpx solid #15716E;
  1167. }
  1168. .btn{
  1169. margin: 0;
  1170. padding: 0 20rpx;
  1171. width: max-content;
  1172. height: 80rpx;
  1173. background-color: #15716E;
  1174. color: #FFFFFF;
  1175. line-height: 80rpx;
  1176. font-size: 26rpx;
  1177. border-radius: 42rpx;
  1178. }
  1179. }
  1180. .popup-content{
  1181. height: max-content;
  1182. width: 750rpx;
  1183. background: #FFFFFF;
  1184. border-radius: 20rpx 20rpx 0rpx 0rpx !important;
  1185. padding: 40rpx 32rpx;
  1186. max-height: 80vh;
  1187. overflow-y: scroll;
  1188. .popup-head{
  1189. display: flex;
  1190. justify-content: space-between;
  1191. .goods-img{
  1192. width: 150rpx;
  1193. height: 150rpx;
  1194. border-radius: 2rpx;
  1195. margin-right: 20rpx;
  1196. }
  1197. .goods-info{
  1198. width: 400rpx;
  1199. height: 150rpx;
  1200. display: flex;
  1201. flex-direction: column;
  1202. justify-content: space-around;
  1203. .price{
  1204. font-size: 48rpx;
  1205. font-weight: bold;
  1206. color: #F63434;
  1207. line-height: 1;
  1208. }
  1209. .goods-name{
  1210. font-size: 32rpx;
  1211. color: #222222;
  1212. line-height: 1.4;
  1213. }
  1214. }
  1215. }
  1216. .spec-title{
  1217. font-size: 28rpx;
  1218. color: #555555;
  1219. margin-top: 40rpx;
  1220. margin-bottom: 20rpx;
  1221. }
  1222. .spec-item{
  1223. min-width: 122rpx;
  1224. max-width: max-content;
  1225. height: 64rpx;
  1226. border-radius: 33rpx;
  1227. border: 2rpx solid #555555;
  1228. font-size: 28rpx;
  1229. color: #555555;
  1230. display: flex;
  1231. justify-content: center;
  1232. align-items: center;
  1233. margin-right: 20rpx;
  1234. margin-bottom: 20rpx;
  1235. padding: 0 20rpx;
  1236. // &:nth-child(4n){
  1237. // margin-right: 0rpx;
  1238. // }
  1239. // &:nth-child(n+5){
  1240. // margin-top: 20rpx;
  1241. // }
  1242. }
  1243. .spec-active{
  1244. border: none;
  1245. background-color: #15716E;
  1246. color: #FFFFFF;
  1247. }
  1248. .input{
  1249. width: 40rpx;
  1250. height: 45rpx;
  1251. border-radius: 2rpx;
  1252. background-color: #F3F8F7;
  1253. text-align: center;
  1254. }
  1255. .num-btn{
  1256. width: 36rpx;
  1257. }
  1258. .comfirm-btn{
  1259. width: 550rpx;
  1260. height: 100rpx;
  1261. background: #15716E;
  1262. border-radius: 50rpx;
  1263. color: #FFFFFF;
  1264. line-height: 100rpx;
  1265. margin-top: 62rpx;
  1266. }
  1267. }
  1268. //分享到朋友圈弹出
  1269. .share-img-box {
  1270. background:rgba(0,0,0,.8);
  1271. position: fixed;
  1272. bottom: 0;
  1273. width: 100%;
  1274. height: 0;
  1275. z-index: 50;
  1276. transition:all .3s linear;
  1277. .imgs-box {
  1278. background: #F3F3F3;
  1279. border-radius: 10px;
  1280. margin:20px;
  1281. overflow: hidden;
  1282. .img{
  1283. box-shadow:0px 4px 8px 0px rgba(155,155,155,0.5);
  1284. border-radius: 6px;
  1285. margin: 30px;
  1286. box-sizing: border-box;
  1287. image{
  1288. display: block;
  1289. width: 100%;
  1290. }
  1291. }
  1292. .text {
  1293. text-align: center;
  1294. margin-top: 22px;
  1295. font-size: 12px;
  1296. color: #9B9B9B;
  1297. }
  1298. .save {
  1299. background: #15716e;
  1300. height: 44px;
  1301. line-height: 44px;
  1302. color: #ffffff;
  1303. text-align: center;
  1304. border-radius: 10px;
  1305. margin: 10px 20px;
  1306. }
  1307. i{
  1308. position: absolute;
  1309. top: 0px;
  1310. right: 0px;
  1311. color: #CCCCCC;
  1312. font-size: 30px;
  1313. }
  1314. }
  1315. &.cur{
  1316. height: 100%;
  1317. }
  1318. }
  1319. </style>