product.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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="#ee2f72"
  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: #ee2f72;
  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: #ee2f72;
  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: #ef041f;
  1114. display: flex;
  1115. align-items: baseline;
  1116. height: 64rpx;
  1117. font-size: 50rpx;
  1118. font-family: PingFang SC;
  1119. font-weight: 800;
  1120. .price {
  1121. font-size: 50rpx;
  1122. }
  1123. image {
  1124. height: 30rpx;
  1125. width: 30rpx;
  1126. }
  1127. .jf {
  1128. font-size: 30rpx;
  1129. }
  1130. }
  1131. .mask {
  1132. position: fixed;
  1133. top: 0;
  1134. left: 0;
  1135. width: 100%;
  1136. height: 100%;
  1137. z-index: 999;
  1138. background-color: rgba(0, 0, 0, 0.4);
  1139. image {
  1140. width: 100%;
  1141. height: 100%;
  1142. opacity: 0.8;
  1143. }
  1144. }
  1145. </style>