product.vue 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. <template>
  2. <view class="container">
  3. <!-- 轮播图 -->
  4. <top-swiper :imgList="imgList"></top-swiper>
  5. <view class="sckill-top" v-if="isSckill">
  6. <view class="bg"><image src="https://zccy.liuniu946.com/static/img/base-sckill.png" mode=""></image></view>
  7. <view class="top-left">
  8. <view class="left-top">限时秒杀价</view>
  9. <view class="left-btm">
  10. <text class="now-pri">{{ goodsObjact.price }}</text>
  11. <text class="old-pri">¥{{ goodsObjact.ot_price }}</text>
  12. </view>
  13. </view>
  14. <view class="top-right">
  15. <view class="right-top">距离本场结束还剩</view>
  16. <uni-countdown
  17. class="timeBox"
  18. color="#901b21"
  19. background-color="#fff"
  20. splitor-color="#fff"
  21. :show-day="true"
  22. :hour="seckillObj.stopTimeH"
  23. :minute="seckillObj.stopTimeM"
  24. :second="seckillObj.stopTimeS"
  25. ></uni-countdown>
  26. </view>
  27. </view>
  28. <!-- 标题 -->
  29. <view class="introduce-section" v-if="goodsType == 0">
  30. <button class="shareDate" style="border: none;" open-type="share"><image class="share-img" src="../../static/icon/share.png"></image></button>
  31. <view class="price-box">
  32. <text class="price-tip">¥</text>
  33. <view class="price">
  34. {{ actionPrice }}
  35. <text class="m-price" v-if="actionPrice * 1 < goodsObjact.ot_price * 1">¥{{ goodsObjact.ot_price }}</text>
  36. </view>
  37. </view>
  38. <text class="title clamp2" v-if="goodsObjact.title">{{ goodsObjact.title }}</text>
  39. <text class="title clamp2" v-else>{{ goodsObjact.store_name }}</text>
  40. </view>
  41. <view class="introduce-section" v-if="goodsType == 3">
  42. <button class="shareDate" style="border: none;" open-type="share"><image class="share-img" src="../../static/icon/share.png"></image></button>
  43. <view class="price-box">
  44. <text class="price-tip">¥</text>
  45. <view class="price">
  46. {{ goodsObjact.price }}
  47. <text class="m-price">¥{{ goodsObjact.ot_price }}</text>
  48. </view>
  49. </view>
  50. <text class="title clamp2" v-if="goodsObjact.title">{{ goodsObjact.title }}</text>
  51. <text class="title clamp2" v-else>{{ goodsObjact.store_name }}</text>
  52. </view>
  53. <view class="introduce-section" v-if="goodsType == 2">
  54. <button class="shareDate" style="border: none;" open-type="share"><image class="share-img" src="../../static/icon/share.png"></image></button>
  55. <view class="price-box-jf">
  56. <text class="price-tip">¥</text>
  57. <view class="price">
  58. {{ goodsObjact.price }}+
  59. <image src="../../static/icon/jf.png" mode=""></image>
  60. <text>{{ goodsObjact.integral }}</text>
  61. <text class="jf">积分</text>
  62. <text class="m-price">¥{{ goodsObjact.ot_price }}</text>
  63. </view>
  64. </view>
  65. <text class="title clamp2" v-if="goodsObjact.title">{{ goodsObjact.title }}</text>
  66. <text class="title clamp2" v-else>{{ goodsObjact.store_name }}</text>
  67. </view>
  68. <!-- <product-content :goodsObjact="goodsObjact" v-if="!isSckill "></product-content> -->
  69. <view class="good-title " v-if="isSckill">{{ goodsObjact.title }}</view>
  70. <!-- 兑换说明 -->
  71. <!-- <view class="dhsm" v-if="goodsType == 2 || goodsType == 3">
  72. <view class="title">{{ dhtitle }}</view>
  73. <view class="info" v-html="dhcontent"></view>
  74. </view> -->
  75. <!-- 评价 -->
  76. <!-- <estimate @navTo="navTo('/pages/product/reply?id=' + goodsObjact.id)" v-if="reply" :reply="reply" :list="list"></estimate> -->
  77. <!-- 规格信息 -->
  78. <!-- <fresh-detail :goodsObjact="goodsObjact"></fresh-detail> -->
  79. <!-- 图文详情 -->
  80. <content-text :description="description"></content-text>
  81. <!-- 底部高度撑开 -->
  82. <view class="contentBottomHeight"></view>
  83. <!-- 底部操作菜单 -->
  84. <product-bottom @buy="buy" :goodsid="goodsid" @specOPne="specOPne" :goodsType="goodsType"></product-bottom>
  85. <!-- 规格-模态层弹窗 -->
  86. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="stopPrevent" @click="toggleSpec">
  87. <!-- 遮罩层 -->
  88. <view class="mask"></view>
  89. <view class="layer attr-content" @click.stop="stopPrevent">
  90. <view class="a-t">
  91. <image :src="actionImage"></image>
  92. <view class="right">
  93. <text class="name">{{ goodsObjact.title }}</text>
  94. <text class="price">¥{{ actionPrice * goodsNumber }}</text>
  95. <text class="stock">库存:{{ goodsStore }}件</text>
  96. <view class="selected" v-if="specList != ''">
  97. 已选:
  98. <text class="selected-text" v-for="(sItem, sIndex) in specSelected" :key="sIndex">{{ sItem }}</text>
  99. </view>
  100. </view>
  101. </view>
  102. <view v-for="(item, index) in specList" :key="index" class="attr-list">
  103. <text>{{ item.attr_name }}</text>
  104. <view class="item-list">
  105. <text
  106. v-for="(childItem, childIndex) in item.attr_value"
  107. :key="childIndex"
  108. class="tit"
  109. :class="{ selected: childItem.check }"
  110. @click="selectSpec(childItem, item, index)"
  111. >
  112. {{ childItem.attr }}
  113. </text>
  114. </view>
  115. </view>
  116. <view class="attr-list">
  117. <text>购买数量</text>
  118. <view class="item-list">
  119. <uni-number-box class="step" :isMin="true" :value="goodsNumber" :min="1" :max="goodsNumberMax" @eventChange="numberChange"></uni-number-box>
  120. </view>
  121. </view>
  122. <button class="btn" @click.stop="buy" v-show="buys_show">完成</button>
  123. <button class="btn" style="background-color: #999999;" v-show="buys_shows">售罄</button>
  124. </view>
  125. </view>
  126. <view class="mask" v-if="show"><image @click="onTap" src="../../static/img/shareimg.png"></image></view>
  127. </view>
  128. </template>
  129. <script>
  130. import { getArticleDetail } from '@/api/index.js';
  131. import { goodsDetail, cartAdd, seckillGoods, getIntegraDetail } from '@/api/product.js';
  132. import { mapState } from 'vuex';
  133. import store from '@/store/index.js';
  134. import { saveUrl } from '@/utils/loginUtils.js';
  135. // #ifdef H5
  136. import { weixindata } from '@/utils/wxAuthorized';
  137. // #endif
  138. // 头部轮播图
  139. import topSwiper from './common/topSwiper.vue';
  140. // 标题
  141. // import productContent from './common/productContent.vue';
  142. // 到货时间及优惠
  143. // 规格信息
  144. // import freshDetail from './common/freshDetail.vue';
  145. // 图文详情
  146. import contentText from './common/contentText.vue';
  147. // 底部按钮
  148. import productBottom from './common/productBottom.vue';
  149. // 猜你喜欢
  150. // import guessLike from './common/guessLike.vue';
  151. // 评价
  152. import { timeComputed } from '@/utils/rocessor.js';
  153. import uniNumberBox from '@/components/uni-number-box.vue';
  154. export default {
  155. components: {
  156. // guessLike,
  157. topSwiper,
  158. // productContent,
  159. // freshDetail,
  160. contentText,
  161. productBottom,
  162. uniNumberBox
  163. },
  164. data() {
  165. return {
  166. show: false,
  167. isSckill: false, //是否为秒杀
  168. goodsStore: 0, //选中库存
  169. specList: [],
  170. buys_show: true,
  171. buys_shows: false,
  172. specSelected: [], //选中的分类
  173. specClass: 'none', //显示隐藏弹窗
  174. many: 1, //1是单规格 2是多规格
  175. reply: '', //评论
  176. list: '', //商品详情的数据
  177. type: 1, //默认支付方式add为
  178. goodsType: 0, //商品类型 0:普通,1:秒杀 ,2:积分 3兑换券
  179. goodsNumber: 1, //购买数量
  180. goodsid: '', //商品id
  181. description: '', //商品描述
  182. goodsObjact: {
  183. percent: 1
  184. }, //保存商品数据
  185. //图片循环
  186. imgList: [],
  187. // 对比对象
  188. actionPrice: 0, //默认选中商品价格
  189. actionImage: '', //默认选中图片
  190. good_list: '', //猜你喜欢列表
  191. goodsNumberMax: 0, //最大可购买数量
  192. goodsNumberMin: 0, //最小可购买数量
  193. // 倒计时数据保存
  194. seckillObj: {
  195. stopTime: 0, //结束时间
  196. stop: false, //是否结束
  197. stopTimeH: 0, //小时
  198. stopTimeM: 0, //分钟
  199. stopTimeS: 0, //秒钟
  200. stopTimeD: 0, //天
  201. upTime: 0 //更新组件内部组件用
  202. },
  203. // 拼团数据保存
  204. pink: {
  205. id: '', //拼团编号
  206. uid: '', //用户编号
  207. people: '', //拼团人数
  208. price: '', //拼团价格
  209. stop_time: '', //拼团结束时间
  210. nickname: '', //团长昵称
  211. avatar: '', //团长头像
  212. count: '', //拼团剩余人数
  213. h: '', //时
  214. i: '', //分
  215. s: '' //秒
  216. },
  217. userInfo: '',
  218. dhtitle: '', //兑换说明标题
  219. dhcontent: '' //兑换说明
  220. };
  221. },
  222. filters: {
  223. parseIntTo(percent) {
  224. percent = +percent * 100;
  225. if (percent % 1 === 0) {
  226. return percent;
  227. } else {
  228. percent = percent.toFixed(1);
  229. return percent;
  230. }
  231. }
  232. },
  233. async onLoad(options) {
  234. let obj = this;
  235. obj.userInfo = uni.getStorageSync('userInfo');
  236. //保存商品id
  237. this.goodsid = options.id;
  238. this.goodsType = options.type * 1 || 0;
  239. if (this.goodsType == 3) {
  240. //获取兑换券的兑换说明
  241. // this.getDhsm(2);
  242. } else if (this.goodsType == 2) {
  243. // this.getDhsm(1);
  244. }
  245. if (options.type == 1) {
  246. obj.isSckill = true;
  247. }
  248. if (options.scene) {
  249. // 存储小程序邀请人
  250. uni.setStorage({
  251. key: 'spread_code',
  252. data: options.scene
  253. });
  254. }
  255. // // 判断有无人邀请
  256. // if (options.scene) {
  257. // // 存储邀请人
  258. // uni.setStorageSync('spread', options.spread);
  259. // }
  260. saveUrl();
  261. this.goodsDetail();
  262. // 注册邀请信息
  263. // #ifdef H5
  264. let bool = uni.getStorageSync('weichatBrowser') || '';
  265. if (bool) {
  266. weixindata();
  267. }
  268. // #endif
  269. },
  270. computed: {
  271. ...mapState(['weichatObj', 'baseURL', 'urlFile'])
  272. },
  273. // 分享
  274. onShareAppMessage(options) {
  275. // 设置菜单中的转发按钮触发转发事件时的转发内容
  276. let pages = getCurrentPages(); //获取加载的页面
  277. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  278. let url = currentPage.route; //当前页面url
  279. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  280. let name = this.goodsObjact.store_name || this.goodsObjact.title;
  281. let shareObj = {
  282. title: name + ' 价格:' + this.actionPrice, // 默认是小程序的名称(可以写slogan等)
  283. path: url + '?id=' + item.id + '&scene=' + this.userInfo.uid + '&type=' + this.goodsType, // 默认是当前页面,必须是以‘/’开头的完整路径
  284. imageUrl: this.goodsObjact.image,
  285. success: function(res) {
  286. console.log(shareObj.path, 'path+++++++++++++++++++');
  287. // 转发成功之后的回调
  288. if (res.errMsg == 'shareAppMessage:ok') {
  289. }
  290. },
  291. fail: function() {
  292. // 转发失败之后的回调
  293. if (res.errMsg == 'shareAppMessage:fail cancel') {
  294. // 用户取消转发
  295. } else if (res.errMsg == 'shareAppMessage:fail') {
  296. // 转发失败,其中 detail message 为详细失败信息
  297. }
  298. }
  299. };
  300. return shareObj;
  301. },
  302. methods: {
  303. //获取兑换说明
  304. getDhsm(id) {
  305. getArticleDetail({}, id).then(({ data }) => {
  306. console.log(data);
  307. this.dhcontent = data.content;
  308. this.dhtitle = data.title;
  309. });
  310. },
  311. //选择规格
  312. selectSpec(item, arr, ind) {
  313. arr.attr_value.forEach(function(e) {
  314. e.check = false;
  315. });
  316. item.check = true;
  317. let obj = this;
  318. obj.specSelected[ind] = item.attr;
  319. let str = obj.specSelected.join(',');
  320. // 获取当前选中的对象
  321. if (obj.productValue[str]) {
  322. obj.buys_show = true;
  323. obj.buys_shows = false;
  324. obj.actionPrice = obj.productValue[str].price;
  325. // obj.goodsNumberMax = obj.productValue[str].quota;
  326. obj.actionImage = obj.productValue[str].image;
  327. obj.uniqueId = obj.productValue[str].unique;
  328. obj.goodsStore = obj.productValue[str].stock;
  329. } else {
  330. (obj.buys_show = false), (obj.buys_shows = true);
  331. }
  332. if (obj.goodsStore == 0) {
  333. obj.buys_show = false;
  334. obj.buys_shows = true;
  335. }
  336. obj.specSelected[ind] = item.attr;
  337. },
  338. // 打開彈窗
  339. specOPne(type = 1) {
  340. console.log(type, 'ddddddddddddddddddddddddddddddddddddddddd');
  341. let obj = this;
  342. obj.specClass = 'show';
  343. obj.type = type;
  344. },
  345. //规格弹窗开关
  346. toggleSpec(str) {
  347. if (this.specClass === 'show') {
  348. this.specClass = 'hide';
  349. setTimeout(() => {
  350. this.specClass = 'none';
  351. }, 250);
  352. } else if (this.specClass === 'none') {
  353. this.specClass = 'show';
  354. }
  355. // 保存当前购买类型
  356. this.type = str;
  357. },
  358. //领取优惠券
  359. Getcoupon() {
  360. uni.navigateTo({
  361. url: '/pages/coupon/getcoupon'
  362. });
  363. },
  364. //详情页
  365. navToDetailPage(item) {
  366. let id = item.id;
  367. uni.navigateTo({
  368. url: '/pages/product/product?id=' + id
  369. });
  370. },
  371. // 跳转页面
  372. navTo(url) {
  373. uni.navigateTo({
  374. url: url
  375. });
  376. },
  377. //加入购物车
  378. Addcar(item) {
  379. let obj = this;
  380. cartAdd({
  381. cartNum: '1', //商品数量
  382. uniqueId: '', //商品标签
  383. new: 0, //商品是否新增加到购物车1为不加入0为加入
  384. mer_id: '',
  385. productId: item.id //商品编号
  386. })
  387. .then(function(e) {
  388. uni.showToast({
  389. title: '成功加入购物车',
  390. type: 'top',
  391. duration: 500,
  392. icon: 'none'
  393. });
  394. obj.goodsDetail();
  395. })
  396. .catch(e => {
  397. console.log(e);
  398. });
  399. },
  400. goodsDetail() {
  401. let obj = this;
  402. // 获取普通商品信息
  403. console.log('获取商品信息++++++++++++++');
  404. console.log(obj.goodsType);
  405. if (obj.goodsType == 0 || obj.goodsType == 3) {
  406. console.log('获取普通商品信息++++++++++++++');
  407. goodsDetail({}, this.goodsid).then(function({ data }) {
  408. obj.list = data;
  409. console.log(obj.list, '普通商品数据');
  410. obj.good_list = data.good_list; //保存猜你喜欢列表
  411. obj.reply = data.reply; //保存评论列表
  412. console.log(obj.reply, 'data.reply');
  413. let goods = data.storeInfo;
  414. obj.goodsObjact = goods;
  415. if (obj.goodsObjact.description != null) {
  416. obj.description = obj.goodsObjact.description.replace(/\<img/gi, '<img class="rich-img"');
  417. } //小程序商品详情图超出屏幕问题
  418. obj.imgList = goods.slider_image; //保存轮播图
  419. obj.specList = data.productAttr; //保存分类列表
  420. if (Array.isArray(data.productValue) != true) {
  421. obj.many = 2;
  422. obj.specList = data.productAttr; //保存产品属性
  423. obj.productValue = data.productValue; //保存属性值
  424. obj.specSelected = []; //初始化默认选择对象
  425. for (let i = 0; i < obj.specList.length; i++) {
  426. // 设置默认数据
  427. let attrValue = obj.specList[i].attr_value[0];
  428. attrValue.check = true;
  429. obj.specSelected.push(attrValue.attr);
  430. }
  431. let str = obj.specSelected.join(',');
  432. console.log(str, 'str');
  433. // 设置默认值
  434. obj.actionPrice = obj.productValue[str].price;
  435. console.log(obj.actionPrice, 'obj.actionPrice');
  436. obj.goodsNumberMax = obj.productValue[str].stock;
  437. if (obj.goodsType == 3) {
  438. obj.goodsNumberMax = 1;
  439. }
  440. obj.actionImage = obj.productValue[str].image;
  441. obj.uniqueId = obj.productValue[str].unique;
  442. obj.goodsStore = obj.productValue[str].stock;
  443. } else {
  444. obj.many = 1;
  445. obj.productValue = data.productValue; //保存分类查询数据
  446. obj.actionPrice = goods.price; //保存默认选中商品价格
  447. obj.actionImage = goods.image_base; //保存默认选中商品图片
  448. obj.goodsNumberMax = goods.stock; //保存默认选中最大可购买商品数量
  449. if (obj.goodsType == 3) {
  450. obj.goodsNumberMax = 1;
  451. }
  452. obj.shopId = data.mer_id; //保存商店id
  453. }
  454. });
  455. }
  456. if (obj.goodsType == 1) {
  457. seckillGoods({}, this.goodsid).then(({ data }) => {
  458. obj.list = data;
  459. console.log(obj.list, '秒杀商品数据++++++++++');
  460. // obj.good_list = data.good_list; //保存猜你喜欢列表
  461. obj.reply = data.reply; //保存评论列表
  462. let goods = data.storeInfo;
  463. obj.goodsNumberMax = goods.num;
  464. // console.log('obj.goodsNumberMin+++++++++',obj.goodsNumberMin)
  465. const time = timeComputed(goods.stop_time * 1000);
  466. obj.seckillObj = {
  467. stop: time.tpye, //是否结束
  468. stopTimeH: time.hours + time.day * 24, //小时
  469. stopTimeM: time.minutes, //分钟
  470. stopTimeS: time.seconds //秒钟
  471. };
  472. console.log(obj.seckillObj, '数据');
  473. // console.log(obj.seckillObj,'obj.seckillObj++++++++++++++++++++++')
  474. obj.goodsObjact = goods;
  475. if (obj.goodsObjact.description != null) {
  476. obj.description = obj.goodsObjact.description.replace(/\<img/gi, '<img class="rich-img"');
  477. } //小程序商品详情图超出屏幕问题
  478. obj.imgList = goods.images; //保存轮播图
  479. obj.specList = data.productAttr; //保存分类列表
  480. if (Array.isArray(data.productValue) != true) {
  481. console.log('多规格+++++++++++++');
  482. obj.many = 2;
  483. obj.specList = data.productAttr; //保存产品属性
  484. obj.productValue = data.productValue; //保存属性值
  485. obj.specSelected = []; //初始化默认选择对象
  486. for (let i = 0; i < obj.specList.length; i++) {
  487. // 设置默认数据
  488. let attrValue = obj.specList[i].attr_value[0];
  489. attrValue.check = true;
  490. obj.specSelected.push(attrValue.attr);
  491. }
  492. let str = obj.specSelected.join(',');
  493. console.log(str, 'str');
  494. // 设置默认值
  495. obj.actionPrice = obj.productValue[str].price;
  496. // obj.goodsNumberMax = obj.productValue[str].quota;
  497. // console.log(obj.goodsNumberMax,'obj.goodsNumberMax++++++++++++')
  498. obj.actionImage = obj.productValue[str].image;
  499. obj.uniqueId = obj.productValue[str].unique;
  500. obj.goodsStore = obj.productValue[str].stock;
  501. } else {
  502. console.log('单规格+++++++++++++');
  503. obj.many = 1;
  504. obj.productValue = data.productValue; //保存分类查询数据
  505. obj.actionPrice = goods.price; //保存默认选中商品价格
  506. obj.actionImage = goods.image_base; //保存默认选中商品图片
  507. // obj.goodsNumberMax = goods.quota; //保存默认选中最大可购买商品数量
  508. console.log(obj.goodsNumberMax, 'obj.goodsNumberMax---------------');
  509. obj.shopId = data.mer_id; //保存商店id
  510. }
  511. });
  512. }
  513. if (obj.goodsType == 2) {
  514. getIntegraDetail({}, this.goodsid).then(({ data }) => {
  515. obj.list = data;
  516. console.log(obj.list, '积分商品数据++++++++++');
  517. // obj.good_list = data.good_list; //保存猜你喜欢列表
  518. obj.reply = data.reply; //保存评论列表
  519. let goods = data.storeInfo;
  520. obj.goodsNumberMax = goods.num;
  521. // console.log('obj.goodsNumberMin+++++++++',obj.goodsNumberMin)
  522. // obj.seckillObj = timeComputed( goods.stop_time*1000);
  523. // console.log(obj.seckillObj,'obj.seckillObj++++++++++++++++++++++')
  524. obj.goodsObjact = goods;
  525. if (obj.goodsObjact.description != null) {
  526. obj.description = obj.goodsObjact.description.replace(/\<img/gi, '<img class="rich-img"');
  527. } //小程序商品详情图超出屏幕问题
  528. obj.imgList = goods.images; //保存轮播图
  529. obj.specList = data.productAttr; //保存分类列表
  530. if (Array.isArray(data.productValue) != true) {
  531. obj.many = 2;
  532. obj.specList = data.productAttr; //保存产品属性
  533. obj.productValue = data.productValue; //保存属性值
  534. obj.specSelected = []; //初始化默认选择对象
  535. for (let i = 0; i < obj.specList.length; i++) {
  536. // 设置默认数据
  537. let attrValue = obj.specList[i].attr_value[0];
  538. attrValue.check = true;
  539. obj.specSelected.push(attrValue.attr);
  540. }
  541. let str = obj.specSelected.join(',');
  542. console.log(str, 'str');
  543. // 设置默认值
  544. obj.actionPrice = obj.productValue[str].price;
  545. // obj.goodsNumberMax = obj.productValue[str].quota;
  546. // console.log(obj.goodsNumberMax,'obj.goodsNumberMax++++++++++++')
  547. obj.actionImage = obj.productValue[str].image;
  548. obj.uniqueId = obj.productValue[str].unique;
  549. obj.goodsStore = obj.productValue[str].stock;
  550. } else {
  551. obj.many = 1;
  552. obj.productValue = data.productValue; //保存分类查询数据
  553. obj.actionPrice = goods.price; //保存默认选中商品价格
  554. obj.actionImage = goods.image_base; //保存默认选中商品图片
  555. // obj.goodsNumberMax = goods.quota; //保存默认选中最大可购买商品数量
  556. console.log(obj.goodsNumberMax, 'obj.goodsNumberMax---------------');
  557. obj.shopId = data.mer_id; //保存商店id
  558. }
  559. });
  560. }
  561. },
  562. // 立即购买
  563. buy() {
  564. let obj = this;
  565. // 创建传值对象
  566. let data = {
  567. productId: obj.goodsid, //商品编号
  568. cartNum: obj.goodsNumber, //商品数量
  569. uniqueId: obj.uniqueId, //分类编号
  570. new: 0,
  571. secKillId: '',
  572. integralId: '',
  573. free_check: 0
  574. };
  575. if (obj.type == 2) {
  576. console.log('加入购物车');
  577. data.new = 0;
  578. } else if (obj.type == 1) {
  579. data.new = 1;
  580. }
  581. console.log(obj.goodsType, 'obj.goodsType77777777777777777777');
  582. if (obj.goodsType == 1) {
  583. data.secKillId = obj.goodsObjact.id;
  584. data.new = 1;
  585. }
  586. if (obj.goodsType == 2) {
  587. data.new = 1;
  588. data.integralId = obj.goodsObjact.id;
  589. }
  590. if (obj.goodsType == 3) {
  591. data.new = 1;
  592. data.free_check = 1;
  593. }
  594. cartAdd(data)
  595. .then(function(e) {
  596. let da = e.data;
  597. if (obj.type == 1) {
  598. // 跳转到支付页
  599. console.log(obj.goodsType, 'this.goodsType456444444444444444');
  600. uni.navigateTo({
  601. url: '/pages/order/createOrder?id=' + da.cartId + '&goodsType=' + obj.goodsType
  602. });
  603. }
  604. if (obj.type == 2) {
  605. uni.showToast({
  606. title: '成功加入购物车',
  607. type: 'top',
  608. duration: 2000,
  609. icon: 'none'
  610. });
  611. obj.goodsDetail();
  612. }
  613. obj.toggleSpec();
  614. })
  615. .catch(e => {
  616. console.log(e);
  617. });
  618. },
  619. // 阻止触发上级事件
  620. stopPrevent() {},
  621. //选择数量
  622. numberChange(e) {
  623. console.log(e);
  624. this.goodsNumber = e.number;
  625. },
  626. callf() {
  627. this.show = true;
  628. },
  629. onTap() {
  630. console.log(this.callf);
  631. if (!this.callf) return;
  632. this.close();
  633. },
  634. close() {
  635. this.show = false;
  636. }
  637. }
  638. };
  639. </script>
  640. <style lang="scss" scoped>
  641. /* 弹出层 */
  642. .popup {
  643. position: fixed;
  644. left: 0;
  645. top: 0;
  646. right: 0;
  647. bottom: 0;
  648. z-index: 99;
  649. &.show {
  650. display: block;
  651. .mask {
  652. animation: showPopup 0.2s linear both;
  653. }
  654. .layer {
  655. animation: showLayer 0.2s linear both;
  656. }
  657. }
  658. &.hide {
  659. .mask {
  660. animation: hidePopup 0.2s linear both;
  661. }
  662. .layer {
  663. animation: hideLayer 0.2s linear both;
  664. }
  665. }
  666. &.none {
  667. display: none;
  668. }
  669. .mask {
  670. position: fixed;
  671. top: 0;
  672. width: 100%;
  673. height: 100%;
  674. z-index: 1;
  675. background-color: rgba(0, 0, 0, 0.4);
  676. }
  677. .layer {
  678. position: fixed;
  679. z-index: 99;
  680. bottom: 0;
  681. width: 100%;
  682. min-height: 35vh;
  683. border-radius: 10rpx 10rpx 0 0;
  684. background-color: #fff;
  685. .btn {
  686. height: 66rpx;
  687. line-height: 66rpx;
  688. border-radius: 100rpx;
  689. background: #901b21;
  690. font-size: $font-base + 2rpx;
  691. color: #fff;
  692. margin: 30rpx auto 20rpx;
  693. }
  694. }
  695. @keyframes showPopup {
  696. 0% {
  697. opacity: 0;
  698. }
  699. 100% {
  700. opacity: 1;
  701. }
  702. }
  703. @keyframes hidePopup {
  704. 0% {
  705. opacity: 1;
  706. }
  707. 100% {
  708. opacity: 0;
  709. }
  710. }
  711. @keyframes showLayer {
  712. 0% {
  713. transform: translateY(120%);
  714. }
  715. 100% {
  716. transform: translateY(0%);
  717. }
  718. }
  719. @keyframes hideLayer {
  720. 0% {
  721. transform: translateY(0);
  722. }
  723. 100% {
  724. transform: translateY(120%);
  725. }
  726. }
  727. }
  728. /* 规格选择弹窗 */
  729. .attr-content {
  730. padding: 25rpx 30rpx;
  731. .a-t {
  732. display: flex;
  733. image {
  734. width: 170rpx;
  735. height: 170rpx;
  736. flex-shrink: 0;
  737. border-radius: 8rpx;
  738. }
  739. .right {
  740. display: flex;
  741. flex-direction: column;
  742. padding-left: 24rpx;
  743. font-size: $font-sm + 2rpx;
  744. color: $font-color-base;
  745. line-height: 42rpx;
  746. width: 75%;
  747. .price {
  748. font-size: $font-lg;
  749. color: #901b21;
  750. margin: 10rpx 0rpx;
  751. }
  752. .name {
  753. font-size: 32rpx;
  754. color: $font-color-dark;
  755. height: 50rpx;
  756. overflow: hidden;
  757. text-overflow: ellipsis;
  758. white-space: nowrap;
  759. display: block;
  760. }
  761. .selected-text {
  762. margin-right: 10rpx;
  763. }
  764. }
  765. }
  766. .attr-list {
  767. display: flex;
  768. flex-direction: column;
  769. font-size: $font-base + 2rpx;
  770. color: $font-color-base;
  771. padding-top: 30rpx;
  772. padding-left: 10rpx;
  773. }
  774. .item-list {
  775. padding: 20rpx 0 0;
  776. display: flex;
  777. flex-wrap: wrap;
  778. text {
  779. display: flex;
  780. align-items: center;
  781. justify-content: center;
  782. background: #eee;
  783. margin-right: 20rpx;
  784. margin-bottom: 20rpx;
  785. border-radius: 100rpx;
  786. min-width: 60rpx;
  787. height: 60rpx;
  788. padding: 0 20rpx;
  789. font-size: $font-base;
  790. color: $font-color-dark;
  791. }
  792. .selected {
  793. background: #ddffdf;
  794. color: $uni-color-primary;
  795. }
  796. }
  797. }
  798. //默认商品底部高度
  799. .goodsBottom {
  800. height: 160rpx;
  801. }
  802. page {
  803. background: #f0f0f0;
  804. }
  805. //秒杀、拼团底部高度
  806. .contentBottomHeight {
  807. height: 130rpx;
  808. }
  809. //默认商品底部高度
  810. .goodsBottom {
  811. height: 160rpx;
  812. }
  813. /deep/ .iconenter {
  814. font-size: $font-base + 2rpx;
  815. color: #888;
  816. }
  817. /deep/ .con_image {
  818. width: 130rpx;
  819. height: 130rpx;
  820. display: inline-block;
  821. padding: 15rpx;
  822. image {
  823. width: 100%;
  824. height: 100%;
  825. }
  826. }
  827. /* 商品详情中限制图片大小 */
  828. /deep/ .rich-img {
  829. width: 100% !important;
  830. height: auto;
  831. }
  832. .cho-num {
  833. margin: 20rpx 0;
  834. width: 750rpx;
  835. height: 83rpx;
  836. background: #ffffff;
  837. padding: 29rpx 24rpx 30rpx 25rpx;
  838. font-size: 26rpx;
  839. font-weight: 500;
  840. color: #606972;
  841. }
  842. .row {
  843. display: flex;
  844. align-items: center;
  845. position: relative;
  846. padding: 0 30rpx;
  847. height: 110rpx;
  848. background: #fff;
  849. .refund {
  850. font-size: 30rpx;
  851. color: $font-color-dark;
  852. padding-left: 128rpx;
  853. }
  854. .noRefund {
  855. font-size: 30rpx;
  856. color: $font-color-light;
  857. padding-left: 128rpx;
  858. }
  859. .tit {
  860. flex-shrink: 0;
  861. width: 120rpx;
  862. font-size: 30rpx;
  863. color: $font-color-dark;
  864. }
  865. .input {
  866. flex: 1;
  867. font-size: 30rpx;
  868. color: $font-color-dark;
  869. padding-left: 128rpx;
  870. &.payColor {
  871. color: $color-red;
  872. }
  873. }
  874. .iconlocation {
  875. font-size: 36rpx;
  876. color: $font-color-light;
  877. }
  878. }
  879. .shop-info {
  880. width: 750rpx;
  881. height: 140rpx;
  882. margin: 20rpx 0;
  883. padding: 28rpx 24rpx 22rpx 16rpx;
  884. background-color: #fff;
  885. display: flex;
  886. position: relative;
  887. .shop-logo {
  888. width: 90rpx;
  889. height: 90rpx;
  890. border-radius: 50%;
  891. // background-color: red;
  892. // overflow: hidden;
  893. image {
  894. width: 90rpx;
  895. height: 90rpx;
  896. }
  897. }
  898. .shop-base {
  899. padding-left: 15rpx;
  900. // width: 376rpx;
  901. width: 100%;
  902. font-size: 24rpx;
  903. font-weight: 500;
  904. color: #999999;
  905. line-height: 1;
  906. .base-name {
  907. padding-top: 14rpx;
  908. font-size: 30rpx;
  909. padding-bottom: 16rpx;
  910. font-weight: 500;
  911. color: #333333;
  912. }
  913. }
  914. .shop-dis {
  915. padding-top: 31rpx;
  916. position: absolute;
  917. font-size: 24rpx;
  918. font-weight: 500;
  919. color: #901b21;
  920. // line-height: 140rpx;
  921. right: 24rpx;
  922. image {
  923. padding-right: 5rpx;
  924. width: 21rpx;
  925. height: 21rpx;
  926. }
  927. }
  928. }
  929. .sckill-top {
  930. width: 750rpx;
  931. height: 165rpx;
  932. position: relative;
  933. top: -40rpx;
  934. margin-bottom: -40rpx;
  935. display: flex;
  936. justify-content: space-between;
  937. .bg {
  938. width: 750rpx;
  939. height: 165rpx;
  940. position: absolute;
  941. left: 0;
  942. top: 0;
  943. image {
  944. width: 100%;
  945. height: 100%;
  946. }
  947. }
  948. .top-left {
  949. position: relative;
  950. z-index: 10;
  951. line-height: 1;
  952. .left-top {
  953. padding: 35rpx 0 23rpx 22rpx;
  954. font-size: 44rpx;
  955. font-weight: 500;
  956. color: #ffffff;
  957. line-height: 1;
  958. }
  959. .left-btm {
  960. line-height: 1;
  961. font-size: 30rpx;
  962. font-weight: 500;
  963. padding-left: 25rpx;
  964. // text-decoration: line-through;
  965. color: #ffffff;
  966. .now-pri {
  967. display: inline-block;
  968. padding-right: 8rpx;
  969. font-size: 44rpx;
  970. font-weight: 800;
  971. color: #ffffff;
  972. }
  973. .old-pri {
  974. text-decoration: line-through;
  975. }
  976. }
  977. }
  978. .top-right {
  979. position: relative;
  980. z-index: 10;
  981. padding: 67rpx 20rpx 18rpx 0;
  982. .right-top {
  983. font-size: 22rpx;
  984. font-weight: 400;
  985. color: #ffffff;
  986. line-height: 1;
  987. padding-bottom: 8rpx;
  988. }
  989. }
  990. }
  991. .good-title {
  992. background-color: #fff;
  993. // height: 142rpx;
  994. padding: 24rpx 19rpx 24rpx 34rpx;
  995. line-height: 1.5;
  996. font-size: 36rpx;
  997. font-weight: 800;
  998. color: #333333;
  999. }
  1000. .introduce-section {
  1001. position: relative;
  1002. background: #fff;
  1003. padding: 35rpx 0rpx;
  1004. padding-left: 20rpx;
  1005. .title {
  1006. font-size: 32rpx;
  1007. color: $font-color-dark;
  1008. padding-right: 34rpx;
  1009. .tip-o {
  1010. color: #ff3334;
  1011. padding-left: 15rpx;
  1012. }
  1013. }
  1014. .shareDate {
  1015. position: absolute;
  1016. top: 25rpx;
  1017. right: 10rpx;
  1018. font-size: 26rpx;
  1019. color: #3d3f46;
  1020. border-radius: 15rpx;
  1021. background-color: #ffffff;
  1022. height: 60rpx;
  1023. line-height: 60rpx;
  1024. &::after {
  1025. border: none;
  1026. }
  1027. }
  1028. .share-img {
  1029. width: 30rpx;
  1030. height: 30rpx;
  1031. position: relative;
  1032. top: 5rpx;
  1033. left: 0;
  1034. margin-right: 10rpx;
  1035. }
  1036. .info {
  1037. color: #999999;
  1038. font-size: 26rpx;
  1039. padding-bottom: 15rpx;
  1040. }
  1041. .progress-box {
  1042. width: 260rpx;
  1043. position: relative;
  1044. margin-top: 15rpx;
  1045. line-height: 10px;
  1046. .number {
  1047. font-size: 17rpx;
  1048. position: absolute;
  1049. z-index: 999;
  1050. top: 3rpx;
  1051. left: 15rpx;
  1052. color: #ffffff;
  1053. }
  1054. }
  1055. .price-box {
  1056. display: flex;
  1057. align-items: baseline;
  1058. height: 64rpx;
  1059. padding: 10rpx 0;
  1060. font-size: 27rpx;
  1061. color: #ef041f;
  1062. }
  1063. .price {
  1064. font-size: $font-lg + 6rpx;
  1065. .text {
  1066. padding-left: 5rpx;
  1067. color: #b0b0b0;
  1068. font-size: 22rpx !important;
  1069. }
  1070. }
  1071. .price-green {
  1072. color: #2dbd59;
  1073. font-size: 28rpx !important;
  1074. text {
  1075. background: #2dbd59;
  1076. color: #ffffff;
  1077. padding: 0rpx 10rpx;
  1078. border-radius: 5rpx;
  1079. font-size: 22rpx !important;
  1080. margin-left: 15rpx;
  1081. }
  1082. }
  1083. .m-price {
  1084. margin: 0 12rpx;
  1085. color: $font-color-light;
  1086. text-decoration: line-through;
  1087. margin-left: 25rpx;
  1088. font-size: 24rpx;
  1089. }
  1090. }
  1091. .dhsm {
  1092. display: flex;
  1093. margin: 20rpx 0;
  1094. background-color: #fff;
  1095. padding: 34rpx 50rpx 30rpx 24rpx;
  1096. .title {
  1097. font-size: 32rpx;
  1098. font-family: PingFang SC;
  1099. font-weight: bold;
  1100. color: #333333;
  1101. margin-right: 32rpx;
  1102. flex-shrink: 0;
  1103. }
  1104. .info {
  1105. font-size: 26rpx;
  1106. font-family: PingFang SC;
  1107. font-weight: 500;
  1108. color: #8a8a8a;
  1109. line-height: 38rpx;
  1110. }
  1111. }
  1112. .price-box-jf {
  1113. color: #901b21;
  1114. display: flex;
  1115. align-items: baseline;
  1116. height: 64rpx;
  1117. font-size: 50rpx;
  1118. font-family: PingFang SC;
  1119. font-weight: 800;
  1120. color: #901b21;
  1121. .price {
  1122. font-size: 50rpx;
  1123. }
  1124. image {
  1125. height: 30rpx;
  1126. width: 30rpx;
  1127. }
  1128. .jf {
  1129. font-size: 30rpx;
  1130. }
  1131. }
  1132. .mask {
  1133. position: fixed;
  1134. top: 0;
  1135. left: 0;
  1136. width: 100%;
  1137. height: 100%;
  1138. z-index: 999;
  1139. background-color: rgba(0, 0, 0, 0.4);
  1140. image {
  1141. width: 100%;
  1142. height: 100%;
  1143. opacity: 0.8;
  1144. }
  1145. }
  1146. </style>