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

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