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

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