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

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