金诚优选前端代码
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.

1377 lines
36 KiB

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