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

1424 lines
39 KiB

  1. <template>
  2. <view class="details_contanier">
  3. <view class="details_head" v-if='detailsMessage && detailsMessage.user && detailsMessage.user.meta' >
  4. <view class="head_photo">
  5. <image :src="detailsMessage.user.meta.avatar" />
  6. </view>
  7. <view class="head_message">
  8. <view class="name">
  9. {{detailsMessage.user.meta.nick_name}}
  10. </view>
  11. <view class="notice">
  12. 在果酱小店发现好物一起来砍价拿
  13. </view>
  14. </view>
  15. <view class="rule" @tap="showRule">
  16. 活动规则
  17. </view>
  18. </view>
  19. <view class="details_body" v-if='detailsMessage'>
  20. <view class="goods_message" v-if='detailsMessage.reduce'>
  21. <view class="goods_left" v-if='detailsMessage.reduce.goods'>
  22. <image :src="detailsMessage.reduce.goods.img" mode="widthFix" />
  23. </view>
  24. <view class="goods_right" v-if='detailsMessage.reduce.goods'>
  25. <view class="goods_name">
  26. {{detailsMessage.reduce.goods.name}}
  27. </view>
  28. <view class="past_price" v-if='detailsMessage.reduce.goods'>
  29. 原价{{detailsMessage.reduce.goods.max_price}}
  30. </view>
  31. <view class="new_price">
  32. 砍后价{{detailsMessage.reduce.price}}
  33. </view>
  34. </view>
  35. </view>
  36. <view class="text_message" v-if="overTime == false && overActivity == false" :style="{marginLeft:left+'%'}">
  37. 已砍{{detailsMessage.reduce_amount}}
  38. </view>
  39. <view class="text-copy" v-if="overTime==true || overActivity==true" :style="{marginLeft:left+'%'}">
  40. 已砍{{detailsMessage.reduce_amount}}
  41. </view>
  42. <view class="bar">
  43. <progress :percent="detailsMessage.progress_par*100" :color="'#' + setColor" border-radius="3px" />
  44. </view>
  45. <view class="tips" v-if="overTime == false && overActivity == false">
  46. 已砍{{detailsMessage.reduce_amount}},还可砍{{detailsMessage.reduce_surplus_amount}}
  47. </view>
  48. <view class="tips" v-if="overTime == true && overActivity == false">
  49. 很遗憾超时了本次砍价失败
  50. </view>
  51. <view class="tips" v-if="overActivity == true">
  52. 很遗憾活动已结束
  53. </view>
  54. <view class="tips" v-if="is_leader == 0 && overActivity == false &&overTime == false">
  55. 帮我砍价你拿红包新人有礼
  56. </view>
  57. <!-- 后台没设置可提前购买-->
  58. <button class="btn" open-type='share' v-if="is_leader == 1 && buy == false && overTime == false && overActivity == false">
  59. <text>{{message}}</text>
  60. </button>
  61. <view class="btn" @tap="goStore" v-if="is_leader==1 &&overActivity==true">去商城看看</view>
  62. <view class="btn" @tap="goStore" v-if="is_leader==0 && overTime==true ">去商城看看</view>
  63. <!-- 后台设置了可提前购买-->
  64. <view class="can_buy" v-if="is_leader==1 && buy && overTime==false && overActivity==false">
  65. <!-- #ifdef MP-WEIXIN || APP-PLUS-->
  66. <view class="invite" v-if="over==false" @tap="helpShare">
  67. <text>{{message}}</text>
  68. </view>
  69. <!-- #endif -->
  70. <!-- #ifdef H5 -->
  71. <view class="invite" v-if="over==false" @tap="togglePopup('middle-img')">
  72. <text>{{message}}</text>
  73. </view>
  74. <!-- #endif -->
  75. <view class="now_buy" @tap="showSelect" v-if="over==false">马上购买</view>
  76. <!-- 活动未结束但是用户砍价已完成-->
  77. <view class="btn" @tap="showSelect" v-if="over==true && pay==false">{{detailsMessage.reduce_surplus_amount}}元购买商品</view>
  78. <view class="btn" @tap="goStore" v-if="over==true && pay==true">订单已支付去商城看看</view>
  79. </view>
  80. <!-- 用户时间结束-->
  81. <view class="btn2" v-if="is_leader==1 && overTime==true && overActivity==false">
  82. <view class="child_btn1" @tap="bargainAgin">
  83. 重新发起砍价
  84. </view>
  85. <view class="child_btn2" @tap.stop="goStore">
  86. 去商城看看
  87. </view>
  88. </view>
  89. <view class="btn" @tap="bargain" v-if="is_leader==0 && step==1 && overTime==false && overActivity==false">
  90. <text>{{message}}</text>
  91. </view>
  92. <view class="btn2" v-if="is_leader==0 && step==2 && overActivity==false">
  93. <view class="child_btn1" @tap="joinBargain">
  94. {{message}}
  95. </view>
  96. <!-- #ifdef MP-WEIXIN || APP-PLUS -->
  97. <view class="child_btn2" @tap="helpShare" v-if="over==false">
  98. 帮好友分享
  99. </view>
  100. <!-- #endif -->
  101. <!-- #ifdef H5 -->
  102. <view class="child_btn2" @tap="togglePopup('middle-img')" v-if="over==false">
  103. 帮好友分享
  104. </view>
  105. <!-- #endif -->
  106. <view class="child_btn2" @tap="goStore" v-else>
  107. 去商城看看
  108. </view>
  109. </view>
  110. <view class="count_down" v-if="overTime==false && overActivity==false">
  111. <!-- <seckill :end="detailsMessage.ends_at" :starts="detailsMessage.starts_at" :server="server" typename="砍价"></seckill> -->
  112. <countdown :value="detailsMessage.ends_at" detail-class="text-color"></countdown>
  113. </view>
  114. <view class="person_number" v-if="overActivity==false">
  115. <view class="left"></view>
  116. <view class="right"></view>
  117. <view class="title" v-if="overActivity==false">
  118. 砍价英雄榜
  119. </view>
  120. <view class="person_tips" v-if="detailsMessage.users && detailsMessage.users.length==0 && overActivity==false">
  121. 快去邀请英雄助力吧
  122. </view>
  123. <view class="person_list" v-if="detailsMessage.users && detailsMessage.users.length!==0 && overActivity==false">
  124. <view class="hero_box" v-for="(item,index) in detailsMessage.users" :key='index'>
  125. <view class="hero_message">
  126. <view class="head_img">
  127. <image :src="item.meta.avatar" />
  128. </view>
  129. <view class="message_box">
  130. <view class="message_name">
  131. {{item.meta.nick_name}}
  132. </view>
  133. <view class="message_share">
  134. 分享给好友免费拿好货
  135. </view>
  136. </view>
  137. </view>
  138. <view class="reduce_money">
  139. 已成功砍掉{{item.reduce_amount}}
  140. </view>
  141. </view>
  142. </view>
  143. </view>
  144. </view>
  145. <!-- 活动规则弹层-->
  146. <view class="box_body" v-if="show" @tap.stop="closeRule" @touchmove.stop="true">
  147. <scroll-view scroll-y class="rule_box" @tap.stop="showRule">
  148. <u-parse :content="rule" />
  149. </scroll-view>
  150. <view class="iconfont icon-close" @tap="closeRule"></view>
  151. </view>
  152. <!-- 砍价成功弹层-->
  153. <view class="box_body" @touchmove.stop="true" v-if="showNotice && is_leader==0" @tap="closeNotice">
  154. <view class="notice_box" @tap.stop="showNoticeInfo">
  155. <view class="iconfont icon-xiaolian1"></view>
  156. <view class="thanks">
  157. <text>谢英雄拔刀相助,为我</text>
  158. <text>砍掉{{reduce_amount}}</text>
  159. </view>
  160. <view class="true_btn" @tap.stop="closeNotice">
  161. 确定
  162. </view>
  163. <view class="gostore" @tap.stop="goStore">
  164. 去商城看看
  165. </view>
  166. </view>
  167. <view class="iconfont icon-close" @tap="closeNotice"></view>
  168. </view>
  169. <!-- 分享弹层-->
  170. <view class="box_body" @touchmove.stop="true" v-if="showShare">
  171. <view class="share_box">
  172. <view class="share_way">
  173. <!-- #ifdef MP-WEIXIN -->
  174. <button class="friends" open-type="share">
  175. <view class="iconfont icon--weixin">
  176. </view>
  177. <view class="text">
  178. 微信好友
  179. </view>
  180. </button>
  181. <!-- #endif -->
  182. <!-- #ifdef APP-PLUS -->
  183. <button class="friends" @click="shareapp">
  184. <view class="iconfont icon--weixin">
  185. </view>
  186. <view class="text">
  187. 微信好友
  188. </view>
  189. </button>
  190. <!-- #endif -->
  191. <view class="post" @tap="createShareImg">
  192. <view class="iconfont icon-tupian">
  193. </view>
  194. <view class="text">
  195. 海报分享
  196. </view>
  197. </view>
  198. </view>
  199. <view class="exit" @tap="closeShare">取消</view>
  200. </view>
  201. </view>
  202. <view class="maks" :class="!show_select ? 'cur' : ''" @tap="closeSelect">
  203. </view>
  204. <view class="detail-popup" v-show="!show_select">
  205. <view class="select_goods_container">
  206. <!--关闭按钮-->
  207. <view class="select_goods_cloese" @tap="closeSelect"></view>
  208. <view class="select_goods_header">
  209. <view class="img_box">
  210. <image v-if="select_product && select_product.img" :src="select_product.img" :alt="select_product.sku"></image>
  211. <image v-else :src="detailsMessage.reduce.goods.img" alt></image>
  212. </view>
  213. <view class="price_item">
  214. <span v-if="select_product">
  215. <text>{{time_price}}</text>
  216. </span>
  217. <span style="font-weight:bold;color:#ee2b1d;" v-else>
  218. {{price_interval}}
  219. </span>
  220. <!--<text v-else>{{price}}</text>-->
  221. <!--<text v-else>{{detailData.meta.groupon.groupon_price}}</text>-->
  222. <!-- <text v-if="detailData.data.shop_show_store == 1">库存{{store_count}}</text> -->
  223. </view>
  224. </view>
  225. <view class="select_spec">
  226. <view class="spec_line" v-for="(spec,index) in specs" :key="index">
  227. <view class="spec_title">{{spec.label}}</view>
  228. <view class="spec_value">
  229. <view class="spec_block" :class=" !!item.disabled ? 'disabled' : '' " v-for="(item,index) in spec.values"
  230. :key="index" :data-key="index" :data-index="item.index" :data-disabled="item.disabled ? 1 : 0" :data-id="item.id"
  231. :data-active="item.active ? 1 : 0" @tap="selectSpec">
  232. <view class="spec_text" v-if="(item.alias || item.value) && item.spec_img !== ''">
  233. {{item.alias || item.value}}
  234. <view v-if="!!item.active" class="border-color">
  235. </view>
  236. </view>
  237. <view class="spec_text" v-if="!item.spec_img && !item.color">
  238. {{item.alias || item.value}}
  239. <view v-if="!!item.active" class="border-color">
  240. </view>
  241. </view>
  242. </view>
  243. <!--<view class="spec_list" v-if="{{spec.id != 2}}">尺码表</view>-->
  244. </view>
  245. </view>
  246. <view class="spec_line">
  247. <view class="num_title">数量</view>
  248. <view class="num_value">
  249. <text :data-index="0">-</text>
  250. <view class="none_border">
  251. <input @input="modifyCount" :value="select_count" type="number" confirm-type="done" />
  252. </view>
  253. <text :data-index="1">+</text>
  254. </view>
  255. <!-- <view class="purchase" v-if="detailData.data.user_limit">
  256. 本商品每人限购{{detailData.data.user_limit}}
  257. </view> -->
  258. </view>
  259. <button class="button" v-if="!canBuy" type="primary" @tap="confirmF">确定</button>
  260. <button class="button" v-else type="primary" @tap="confirmF">确定</button>
  261. <!--<view class="button {{ canBuy ? 'disabled' : '' }}" bindtap="confirm">-->
  262. <!--&lt;!&ndash;<submit-button v-ref:button bindsubmit="confirm" :status="disallow_cart ? 'disabled' : 'normal'">确定</submit-button>&ndash;&gt;-->
  263. <!--</view>-->
  264. </view>
  265. </view>
  266. </view>
  267. <view class="share-img-box" :class="share_img ? 'cur' : ''" v-if="showShareImg">
  268. <view class="imgs-box">
  269. <view class="img">
  270. <image :src="shareImg"></image>
  271. </view>
  272. <view class="text">
  273. 保存图片后可分享到朋友圈
  274. </view>
  275. <view class="save" @tap="downImg">
  276. 保存图片
  277. </view>
  278. <i class="iconfont icon-delete" @tap="changeImg"></i>
  279. </view>
  280. </view>
  281. <!--用户拒绝下载图片授权弹出-->
  282. <alert :is_refused="is_refused" @close="closeAlert"></alert>
  283. <!-- h5分享 -->
  284. <!-- #ifdef H5 -->
  285. <view class='shoppop'>
  286. <uni-popup :show="type === 'middle-img'" position="top" mode="fixed" @hidePopup="togglePopup('')">
  287. <view class="uni-center center-box">
  288. <image style="position: absolute; top: 0;right:0" @tap="togglePopup('')" class="image" src="/static/ico-share-wechat.png" />
  289. </view>
  290. </uni-popup>
  291. </view>
  292. <!-- #endif -->
  293. </view>
  294. </template>
  295. <script>
  296. // 引入安卓权限
  297. import permision from "@/common/js/permission.js"
  298. import alert from "@/components/alert/alert";
  299. import countdown from "@/components/Countdown/Countdown.vue";
  300. import uParse from '@/components/gaoyia-parse/parse.vue';
  301. export default {
  302. data() {
  303. return{
  304. userInfo: {},
  305. left: 0,
  306. select_count: 1,
  307. show: false, //控制活动规则的显示
  308. rule: '', //活动规则
  309. number: 17,
  310. skuTable: {},
  311. is_leader: 0, //1为自己,0为好友
  312. message: '',
  313. showShare: false, //显示分享
  314. showNotice: false, //控制砍价后弹框显示
  315. theReduce: 10, //
  316. step: 1, //控制好友按钮显示,1为还未助力;2为助力成功;3为助力失败
  317. showTell: false, //控制活动结束,好友新开零元拿显示的弹层
  318. buy: true, //系统是否设置了可提前购买
  319. over: false, //砍价是否完成
  320. overTime: false, //用户时间是否超时
  321. overActivity: false, //活动是否结束
  322. ends_at: '', //结束时间
  323. starts_at: '', //开始时间
  324. setColor: 'fb5054', //进度条的颜色
  325. page: 1, //页
  326. show_select: true, //选尺寸
  327. heroList: [], //砍价英雄榜的数据
  328. showShareImg: false, //展示分享图片
  329. pay: false, //是否已经支付
  330. canBuy: true,
  331. detailsMessage:'',
  332. reduce_id:'',
  333. id:'',
  334. goods_id:'',
  335. name:'',
  336. store_count:'',
  337. market_price:'',
  338. time_price:'',
  339. select_product:{},
  340. price_interval:'',
  341. specs:[],
  342. price:'',
  343. show_ten:'',
  344. reduce_amount:'',
  345. share_img:'',
  346. shareImg:'',
  347. is_refused:false,
  348. reduce_items_id:'',
  349. type: 0
  350. }
  351. },
  352. components: {
  353. countdown,
  354. uParse,
  355. alert
  356. },
  357. onLoad(e) {
  358. // #ifdef H5
  359. var token = this.$cookieStorage.get('user_token');
  360. if(!token){
  361. var env = {
  362. isIPad: /ipad/i.test(window.navigator.userAgent),
  363. isIphone: /iphone|ipad|ipod/i.test(window.navigator.userAgent),
  364. isWechat: /MicroMessenger/i.test(window.navigator.userAgent)
  365. }
  366. if(env.isWechat){
  367. if(e.openid){
  368. this.$cookieStorage.set('openid',e.openid)
  369. }
  370. var openid = this.$cookieStorage.get('openid') || e.openid;
  371. if(openid){
  372. this.postNewQuickLogin(openid);
  373. } else{
  374. let origin = window.location.origin;
  375. let url = origin+'/pages/bargain/detail/detail?reduce_items_id='+e.reduce_items_id;
  376. window.location.href = this.$config.GLOBAL.baseUrl+'oauth/wxOauth?redirect_url='+encodeURIComponent(url);
  377. }
  378. } else{
  379. let url = getUrl()+'?reduce_items_id='+e.reduce_items_id;
  380. wx.navigateTo({
  381. url:'/pages/user/loginType/loginType?url='+url
  382. })
  383. }
  384. }
  385. // #endif
  386. var reduce_items_id = decodeURIComponent(e.scene)
  387. if (reduce_items_id > 0) {
  388. this.setData({
  389. reduce_items_id: reduce_items_id
  390. })
  391. this.getMessage()
  392. }
  393. this.getServer()
  394. if (e.reduce_items_id) {
  395. this.reduce_items_id = e.reduce_items_id;
  396. this.getMessage()
  397. }
  398. if (this.overTime == true || this.overActivity == true) {
  399. this.setData({
  400. setColor: 'AAAAAA'
  401. })
  402. }
  403. var windowHeight = wx.getSystemInfoSync().windowHeight //获取设备的高度
  404. this.Height = windowHeight;
  405. this.showWitch();
  406. },
  407. onShow() {
  408. this.getRule()
  409. },
  410. onShareAppMessage(res) {
  411. if (res.from === 'button') {
  412. // 来自页面内转发按钮
  413. this.closeShare();
  414. }
  415. return {
  416. title: '砍价帮帮忙',
  417. path: `/pages/bargain/detail/detail?reduce_items_id=${this.reduce_items_id}`
  418. }
  419. },
  420. onPullDownRefresh() {
  421. this.getMessage()
  422. },
  423. methods: {
  424. postNewQuickLogin(open_id){
  425. wx.showLoading({
  426. title: '正在登录',
  427. mask: true
  428. });
  429. this.$http.post({
  430. api:'api/oauth/newQuickLogin',
  431. data:{
  432. open_id:open_id
  433. }
  434. }).then(res=>{
  435. res = res.data;
  436. if(res.status){
  437. if(res.data.access_token){
  438. var access_token = res.data.token_type + ' ' + res.data.access_token;
  439. var expires_in = res.data.expires_in || 315360000;
  440. this.$cookieStorage.set("user_token", access_token, expires_in);
  441. //如果用户没有绑定手机号
  442. if(res.data.has_bind_mobile == 0){
  443. wx.reLaunch({
  444. url:'/pages/user/bindingphone/bindingphone'
  445. })
  446. }
  447. } else{
  448. wx.showModal({
  449. content: res.message || '请求失败,请重试',
  450. showCancel: false
  451. });
  452. }
  453. } else{
  454. wx.showModal({
  455. content: res.message || '请求失败,请重试',
  456. showCancel: false
  457. });
  458. }
  459. wx.hideLoading()
  460. }).catch(rej=>{
  461. wx.showModal({
  462. content: rej.message || '请求失败,请重试',
  463. showCancel: false
  464. });
  465. wx.hideLoading()
  466. })
  467. },
  468. togglePopup(type) {
  469. this.type = type;
  470. },
  471. closeAlert() {
  472. this.setData({
  473. is_refused: false
  474. });
  475. },
  476. shareapp(){
  477. var reduce_items_id = this.reduce_items_id;
  478. uni.getProvider({
  479. service:'share',
  480. success:function(res){
  481. uni.share({
  482. provider: "weixin",
  483. scene: "WXSceneSession",
  484. type: 5,
  485. title:'砍价帮帮忙',
  486. imageUrl:'https://cdn.guojiang.club/guojiang_logo.png',
  487. miniProgram:{
  488. id:'gh_72e65196278a',//小程序原始id
  489. path:'pages/bargain/details/details?reduce_items_id='+ reduce_items_id,
  490. type:0,
  491. webUrl:'https://guojiang.club'
  492. },
  493. success: function (res) {
  494. console.log("success:" + JSON.stringify(res));
  495. },
  496. fail: function (err) {
  497. console.log("fail:" + JSON.stringify(err));
  498. }
  499. });
  500. }
  501. })
  502. this.closeShare();
  503. },
  504. selectSpec(e) {
  505. var spec = {
  506. key: e.currentTarget.dataset.key,
  507. index: e.currentTarget.dataset.index,
  508. disabled: Number(e.currentTarget.dataset.disabled),
  509. active: Number(e.currentTarget.dataset.active),
  510. id: Number(e.currentTarget.dataset.id)
  511. };
  512. if (spec.disabled) return;
  513. var specs = this.specs;
  514. if (!spec.active) {
  515. for (let item of specs[spec.index].values) {
  516. if (item.active) {
  517. item.active = false;
  518. break;
  519. }
  520. }
  521. }
  522. specs[spec.index].values[spec.key].active = !specs[spec.index].values[spec.key].active;
  523. spec.active = !spec.active;
  524. specs[spec.index].select = spec.active ? spec.id : '';
  525. this.setData({
  526. specs: specs
  527. });
  528. var canBuy = this.disallow_cart();
  529. this.setData({
  530. canBuy: canBuy
  531. }); // this.queryCommodityStore(id, spec.index);
  532. this.specStore(this.result, spec.index);
  533. },
  534. specStore(result, key) {
  535. var query = {
  536. id:this.goods_id
  537. };
  538. var data = result.data;
  539. var specs = this.specs;
  540. if (key === undefined) {
  541. specs.forEach(spec => {
  542. for (let v of spec.values) {
  543. v.disabled = !data[v.id] || data[v.id].count == 0;
  544. }
  545. });
  546. this.setData({
  547. specs: specs,
  548. skuTable: result.table
  549. });
  550. specs = this.specs;
  551. var canBuy = this.disallow_cart();
  552. this.setData({
  553. canBuy: canBuy
  554. });
  555. specs.forEach(spec => {
  556. let name = 'spec[' + spec.id + ']';
  557. if (query[name]) {
  558. let id = query[name];
  559. for (let v of spec.values) {
  560. if (v.id == id && !v.disabled && data[v.id] && data[v.id].count) {
  561. v.active = true;
  562. spec.select = v.id;
  563. this.setData({
  564. specs: specs
  565. });
  566. specs = this.specs;
  567. var canBuy = this.disallow_cart();
  568. this.setData({
  569. canBuy: canBuy
  570. });
  571. this.specStore(result, v.index);
  572. return;
  573. }
  574. }
  575. }
  576. if (!spec.select) {
  577. for (let v of spec.values) {
  578. if (!v.disabled && data[v.id] && data[v.id].count) {
  579. v.active = true;
  580. spec.select = v.id;
  581. this.setData({
  582. specs: specs
  583. });
  584. specs = this.specs;
  585. var canBuy = this.disallow_cart();
  586. this.setData({
  587. canBuy: canBuy
  588. }); // this.$emit('specStore', result, v.index);
  589. this.specStore(result, v.index);
  590. return;
  591. }
  592. }
  593. return;
  594. }
  595. this.setData({
  596. specs: specs
  597. });
  598. });
  599. return;
  600. }
  601. var spec = specs[key];
  602. if (spec.select) {
  603. this.setData({
  604. store_count: data[spec.select].count
  605. });
  606. for (let i = 0; i < specs.length; i++) {
  607. if (i == key) continue;
  608. specs[i].values.forEach(v => {
  609. v.disabled = !data[spec.select].specs[v.id].count;
  610. });
  611. if (specs[i].select) {
  612. this.setData({
  613. store_count: data[spec.select].specs[specs[i].select].count
  614. });
  615. }
  616. this.setData({
  617. specs: specs
  618. });
  619. }
  620. } else {
  621. this.setData({
  622. store_count: this.detailsMessage.reduce.reduce_store_nums
  623. });
  624. for (let i = 0; i < specs.length; i++) {
  625. if (i == key) continue;
  626. specs[i].values.forEach(v => {
  627. v.disabled = !data[v.id] || !data[v.id].count;
  628. });
  629. if (specs[i].select) {
  630. this.setData({
  631. store_count: data[specs[i].select].count
  632. });
  633. }
  634. this.setData({
  635. specs: specs
  636. });
  637. }
  638. }
  639. if (parseInt(this.select_count) > this.store_count) {
  640. this.setData({
  641. select_count: String(this.store_count)
  642. });
  643. } else if (parseInt(this.select_count) == 0) {
  644. this.setData({
  645. select_count: '1'
  646. });
  647. }
  648. this.setData({
  649. specs: specs
  650. });
  651. var canBuy = this.disallow_cart();
  652. // this.setData({
  653. // canBuy: canBuy
  654. // });
  655. //
  656. this.canBuy=canBuy;
  657. },
  658. confirmF() {
  659. if (this.loading) return;
  660. if (this.disallow_cart()) return;
  661. this.loading = true;
  662. var select_product = this.select_product;
  663. var select_count = Number(this.select_count)
  664. var data = this.specs.length ? {
  665. id: select_product.id,
  666. name: this.name,
  667. qty: select_count,
  668. store_count: this.store_count,
  669. price: this.time_price,
  670. market_price: this.market_price,
  671. attributes: {
  672. img: select_product.img || this.detailsMessage.reduce.goods.img,
  673. size: select_product.size,
  674. color: select_product.color,
  675. com_id: this.goods_id
  676. }
  677. } : {
  678. id:this.goods_id,
  679. name: this.detailsMessage.name,
  680. qty: select_count,
  681. store_count: this.store_count,
  682. price: this.time_price,
  683. market_price: this.detailsMessage.market_price,
  684. attributes: {
  685. img: this.detailsMessage.reduce.goods.img,
  686. com_id:this.goods_id
  687. }
  688. };
  689. if (select_product.sku) {
  690. data.attributes.sku = select_product.sku;
  691. }
  692. this.checkoutImmdeOrder(data)
  693. },
  694. disallow_cart() {
  695. if (!this.specs.length) {
  696. return !this.store_count;
  697. }
  698. var ids = [],
  699. select_product = {},
  700. specs = this.specs; // console.log(this.commodity.sell_price)
  701. /* this.setData({
  702. price: Number(this.commodity.sell_price).toFixed(2)
  703. }); */
  704. for (let spec of specs) {
  705. if (!spec.select) {
  706. this.setData({
  707. /* price: Number(this.commodity.sell_price).toFixed(2), */
  708. select_product: null
  709. });
  710. return true;
  711. }
  712. ids.push(spec.select);
  713. for (let v of spec.values) {
  714. if (v.id == spec.select) {
  715. switch (spec.label_key) {
  716. case 'color':
  717. select_product.img = v.spec_img;
  718. select_product.color = v.alias || v.value;
  719. select_product.bac = v.color;
  720. break;
  721. default:
  722. select_product.size = v.alias || v.value;
  723. }
  724. break;
  725. }
  726. }
  727. }
  728. if (this.skuTable) {
  729. ids = ids[0] > ids[1] ? [ids[1], ids[0]] : ids;
  730. ids = ids.join('-');
  731. select_product = Object.assign(select_product, this.skuTable[ids]);
  732. }
  733. var new_bargin_price = Number(select_product.price)-Number(this.detailsMessage.reduce_amount);
  734. this.setData({
  735. time_price: new_bargin_price.toFixed(2),
  736. select_product: select_product
  737. });
  738. return false;
  739. },
  740. // 请求sku
  741. queryCommodityStore(id, key) {
  742. var that = this;
  743. this.$http.get({
  744. api: `api/store/detail/${id}/stock`
  745. }).then(res => {
  746. wx.hideLoading();
  747. res = res.data;
  748. if (!res.status || !res.data || !res.data.specs) return;
  749. if (res.data.specs && typeof key === 'undefined') {
  750. let specs = [];
  751. Object.keys(res.data.specs).forEach((key, index) => {
  752. let value = res.data.specs[key];
  753. value.select = '';
  754. value.values = value.list.map(v => {
  755. return Object.assign({
  756. index: index,
  757. active: false,
  758. disabled: false
  759. }, v);
  760. });
  761. delete value.list;
  762. specs.push(value);
  763. });
  764. that.setData({
  765. specs: specs
  766. }); // console.log(specs)
  767. var canBuy = this.disallow_cart();
  768. this.setData({
  769. canBuy: canBuy
  770. });
  771. }
  772. if (res.data.stores) {
  773. let data = {};
  774. Object.keys(res.data.stores).forEach(key => {
  775. let value = res.data.stores[key];
  776. value.ids.forEach(id => {
  777. data[id] = data[id] || {
  778. count: 0,
  779. specs: {}
  780. };
  781. data[id].count += Number(value.store);
  782. value.ids.forEach(i => {
  783. if (i == id) return;
  784. data[id].specs[i] = {
  785. count: Number(value.store)
  786. };
  787. });
  788. });
  789. }); // console.log(data);
  790. var result = {
  791. data,
  792. table: res.data.stores
  793. };
  794. // this.setData({
  795. // result: result
  796. // });
  797. this.result = result;
  798. that.specStore(result, key); // this.$emit('specStore', result, key);
  799. }
  800. });
  801. },
  802. //关闭sku
  803. closeSelect() {
  804. // var animation = new Animation('show');
  805. // animation.up().then(() => {
  806. this.setData({
  807. show_select: true
  808. })
  809. // })
  810. },
  811. //获取详情页信息
  812. getMessage() {
  813. var token = this.$cookieStorage.get('user_token');
  814. this.$http.get({
  815. api: `api/reduce/showItem?reduce_items_id=${this.reduce_items_id}`,
  816. header: {
  817. Authorization: token
  818. },
  819. }).then(res => {
  820. if (res.statusCode == 200) {
  821. if (res.data.data.status_text !== "进行中" && res.data.data.status_text !== "已下单待支付" && res.data.data.reduce.status_text ==
  822. "进行中" && res.data.data.time_price !== "0.00") {
  823. this.overTime = true;
  824. this.overActivity = false;
  825. this.setColor = 'AAAAAA';
  826. } else if (res.data.data.reduce.status_text !== "进行中") {
  827. this.overActivity = true;
  828. this.setColor = 'AAAAAA';
  829. } else if (res.data.data.status_text == "订单已支付") {
  830. this.pay = true;
  831. this.over = true;
  832. } else if (res.data.data.status_text == "进行中" && res.data.data.reduce.status_text == "进行中") {
  833. this.overTime = false;
  834. this.overActivity = false;
  835. this.setColor = 'fb5054';
  836. }
  837. if (res.data.data.reduce_surplus_amount == "0.00") {
  838. this.over = true;
  839. }
  840. this.setData({
  841. detailsMessage: res.data.data,
  842. is_leader: res.data.data.user_is_leader,
  843. // is_leader:0,
  844. reduce_id: res.data.data.reduce_id,
  845. id: res.data.data.id,
  846. goods_id: res.data.data.reduce.goods_id,
  847. name: res.data.data.reduce.goods.name,
  848. store_count: res.data.data.reduce.store_nums,
  849. market_price: res.data.data.reduce.goods.market_price,
  850. time_price: res.data.data.time_price
  851. })
  852. this.disallow_cart();
  853. this.queryCommodityStore(this.goods_id);
  854. this.showWitch();
  855. if (this.detailsMessage.progress_par > 0.17 && this.detailsMessage.progress_par < 0.83) {
  856. let percent = parseInt(this.detailsMessage.progress_par * 100) - 17
  857. this.setData({
  858. left: percent
  859. })
  860. } else if (this.detailsMessage.progress_par == 0.83 || this.detailsMessage.progress_par > 0.83) {
  861. this.setData({
  862. left: 67
  863. })
  864. } else {
  865. this.setData({
  866. left: 0
  867. })
  868. }
  869. // #ifdef H5
  870. if (this.$wechat && this.$wechat.isWechat()) {
  871. var origin = window.location.origin;
  872. var pathname = window.location.pathname;
  873. var path = origin+pathname+'?reduce_items_id='+this.reduce_items_id
  874. this.$wechat.share({
  875. title:' 砍价帮帮忙',
  876. img:'https://cdn.guojiang.club/h5_share_logo.png',
  877. desc:'果酱小店'
  878. },path);
  879. }
  880. // #endif
  881. } else {
  882. wx.showToast({
  883. title: res.data.data.message,
  884. icon: none,
  885. duration: 2000,
  886. })
  887. }
  888. })
  889. this.showWitch()
  890. },
  891. bargainAgin() {
  892. var token = this.$cookieStorage.get('user_token');
  893. var id = this.reduce_id;
  894. var data = {
  895. reduce_id: id,
  896. restart: 1
  897. }
  898. this.$http.post({
  899. api: `api/reduce`,
  900. header: {
  901. Authorization: token
  902. },
  903. data: data
  904. }).then(res => {
  905. if (res.statusCode == 200) {
  906. wx.showToast({
  907. title: '已重新发起砍价',
  908. duration: 2500
  909. })
  910. this.reduce_items_id = res.data.data.reduce_items_id;
  911. this.getMessage()
  912. this.showWitch()
  913. } else {}
  914. })
  915. },
  916. showWitch() {
  917. if (this.is_leader == 1) {
  918. this.setData({
  919. message: '邀请好友砍价'
  920. })
  921. } else if (this.is_leader == 0 && this.step == 1) {
  922. this.setData({
  923. message: '帮TA砍价'
  924. })
  925. } else if (this.is_leader == 0 && this.step == 2) {
  926. this.setData({
  927. message: '我也要去砍价'
  928. })
  929. }
  930. },
  931. downImg() {
  932. if (this.shareImg) {
  933. wx.showLoading({
  934. title: '正在下载',
  935. mask: true
  936. });
  937. this.$http.dowloadFile({
  938. api: this.shareImg
  939. }).then(res => {
  940. if (res.statusCode == 200) {
  941. // #ifdef MP-WEIXIN
  942. wx.getSetting({
  943. success: ret => {
  944. // 如果之前没有授权
  945. if (!ret.authSetting['scope.writePhotosAlbum']) {
  946. wx.authorize({
  947. scope: 'scope.writePhotosAlbum',
  948. success: rej => {
  949. this.saveImg(res.tempFilePath);
  950. },
  951. // 用户拒绝授权
  952. fail: ret => {
  953. this.setData({
  954. is_refused: true
  955. });
  956. wx.hideLoading();
  957. }
  958. });
  959. } else {
  960. this.saveImg(res.tempFilePath);
  961. }
  962. }
  963. });
  964. // #endif
  965. // #ifdef APP-PLUS
  966. var that = this;
  967. uni.getSystemInfo({
  968. success(result) {
  969. if(result.platform == 'android'){
  970. that.requestAndroidPermission(res.tempFilePath);
  971. } else if(result.platform == 'ios'){
  972. that.requestIosPermission(res.tempFilePath)
  973. }
  974. }
  975. })
  976. // #endif
  977. } else {
  978. wx.hideLoading();
  979. wx.showToast({
  980. title: '下载图片失败',
  981. icon: 'none'
  982. });
  983. }
  984. }, err => {});
  985. }
  986. },
  987. //ios授权
  988. requestIosPermission(url){
  989. var result = permision.judgeIosPermission('photoLibrary');
  990. if(result){
  991. this.saveImg(url);
  992. }else{
  993. //打开授权,iOS上如果没有调用过的权限,不会出现在权限设置界面。
  994. permision.gotoAppPermissionSetting()
  995. }
  996. },
  997. // 安卓app授权
  998. async requestAndroidPermission(url) {
  999. var result = await permision.requestAndroidPermission("android.permission.WRITE_EXTERNAL_STORAGE")
  1000. var strStatus
  1001. if (result == 1) {
  1002. strStatus = "已获得授权";
  1003. this.saveImg(url);
  1004. } else if (result == 0) {
  1005. strStatus = "未获得授权";
  1006. permision.gotoAppPermissionSetting()
  1007. } else {
  1008. strStatus = "被永久拒绝权限"
  1009. permision.gotoAppPermissionSetting()
  1010. }
  1011. },
  1012. // 保存图片
  1013. saveImg(path) {
  1014. wx.saveImageToPhotosAlbum({
  1015. filePath: path,
  1016. success: res => {
  1017. wx.hideLoading();
  1018. wx.showToast({
  1019. title: '保存图片成功',
  1020. icon: 'success'
  1021. });
  1022. },
  1023. fail: rej => {
  1024. wx.hideLoading();
  1025. wx.showToast({
  1026. title: '保存图片失败',
  1027. icon: 'none'
  1028. });
  1029. }
  1030. });
  1031. },
  1032. //获取当前时间
  1033. getServer() {
  1034. var date = new Date();
  1035. var seperator1 = "-";
  1036. var seperator2 = ":";
  1037. var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  1038. var strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  1039. var server = date.getFullYear() + seperator1 + month + seperator1 + strDate +
  1040. " " + date.getHours() + seperator2 + date.getMinutes() +
  1041. seperator2 + date.getSeconds();
  1042. this.server = server;
  1043. },
  1044. closeTell() {
  1045. this.setData({
  1046. showTell: false
  1047. })
  1048. },
  1049. showTellphone() {
  1050. this.setData({
  1051. showTell: true
  1052. })
  1053. },
  1054. closeShare() {
  1055. this.setData({
  1056. showShare: false
  1057. })
  1058. },
  1059. // 弹出分享
  1060. changeShare() {
  1061. this.setData({
  1062. showShareImg: true
  1063. })
  1064. },
  1065. // 生成海报
  1066. createShareImg() {
  1067. this.showShare = false;
  1068. wx.showLoading({
  1069. title: "生成中",
  1070. mask: true
  1071. })
  1072. var token = this.$cookieStorage.get('user_token') || '';
  1073. this.$http.get({
  1074. api: `api/reduce/share?reduce_items_id=${this.reduce_items_id}`,
  1075. header: {
  1076. Authorization: token
  1077. },
  1078. // data:{
  1079. // goods_id: this.data.showItemDate.multi_groupon_goods_id,
  1080. // }
  1081. }).then(res => {
  1082. if (res.statusCode == 200) {
  1083. var res = res.data
  1084. if (res.status) {
  1085. this.shareImg = res.data.image;
  1086. //this.getShearImg();
  1087. } else {
  1088. wx.showModal({
  1089. content: res.message || '请求失败',
  1090. showCancel: false
  1091. })
  1092. }
  1093. } else {
  1094. wx.showModal({
  1095. content: '请求失败',
  1096. showCancel: false
  1097. });
  1098. }
  1099. wx.hideLoading();
  1100. this.changeShare();
  1101. })
  1102. },
  1103. closeAlert() {
  1104. this.setData({
  1105. is_refused: false
  1106. })
  1107. },
  1108. helpShare() {
  1109. this.setData({
  1110. showShare: true
  1111. })
  1112. },
  1113. showNoticeInfo() {
  1114. this.setData({
  1115. showNotice: true
  1116. })
  1117. },
  1118. closeNotice() {
  1119. this.setData({
  1120. showNotice: false
  1121. })
  1122. this.getMessage()
  1123. },
  1124. //好友也要零元拿
  1125. joinBargain() {
  1126. if (this.overActivity == true) {
  1127. this.setData({
  1128. showTell: true
  1129. })
  1130. } else {
  1131. wx.navigateTo({
  1132. url: '/pages/bargain/index/index'
  1133. })
  1134. }
  1135. },
  1136. goStore() {
  1137. wx.switchTab({
  1138. url: '/pages/index/index/index'
  1139. })
  1140. },
  1141. bargain() {
  1142. var token = this.$cookieStorage.get('user_token');
  1143. if (this.is_leader == 0) {
  1144. this.$http.post({
  1145. api: `api/reduce/help?reduce_items_id=${this.reduce_items_id}`,
  1146. header: {
  1147. Authorization: token
  1148. }
  1149. }).then(res => {
  1150. if (res.statusCode == 200) {
  1151. this.setData({
  1152. step: 2
  1153. })
  1154. if (res.data.code == 400) {
  1155. wx.showToast({
  1156. title: res.data.message,
  1157. icon: 'none',
  1158. duration: 2000
  1159. })
  1160. setTimeout(function() {
  1161. this.setData({
  1162. step: 2
  1163. })
  1164. this.showWitch();
  1165. }, 2000)
  1166. } else {
  1167. this.setData({
  1168. showNotice: true,
  1169. step: 2
  1170. })
  1171. }
  1172. if (res.data.data.reduce_amount) {
  1173. this.setData({
  1174. reduce_amount: res.data.data.reduce_amount,
  1175. step: 2
  1176. })
  1177. }
  1178. this.showWitch();
  1179. } else {
  1180. wx.showToast({
  1181. title: '您暂时不能帮好友砍价',
  1182. icon: 'none',
  1183. //duration: 3000
  1184. })
  1185. setTimeout(function() {
  1186. this.setData({
  1187. step: 2
  1188. })
  1189. wx.hideToast()
  1190. //that.showWitch();
  1191. }, 3000)
  1192. }
  1193. this.getMessage()
  1194. })
  1195. this.getMessage()
  1196. }
  1197. this.getMessage()
  1198. this.showWitch();
  1199. },
  1200. showRule() {
  1201. this.setData({
  1202. show: true
  1203. })
  1204. },
  1205. closeRule() {
  1206. this.setData({
  1207. show: false
  1208. })
  1209. },
  1210. // 获取用户信息
  1211. getUserInfo() {
  1212. var token = this.$cookieStorage.get('user_token')
  1213. this.$http.get({
  1214. api: 'api/me',
  1215. header: {
  1216. Authorization: token
  1217. },
  1218. }).then(res => {
  1219. res = res.data;
  1220. if (res.status) {
  1221. this.setData({
  1222. userInfo: res.data,
  1223. }, () => {
  1224. if (res.data.agent_code) {
  1225. wx.updateShareMenu();
  1226. }
  1227. })
  1228. }
  1229. })
  1230. },
  1231. //选择sku
  1232. showSelect(e) {
  1233. this.setData({
  1234. show_select: false
  1235. })
  1236. },
  1237. // 立即购买
  1238. checkoutImmdeOrder(data) {
  1239. var token = this.$cookieStorage.get('user_token');
  1240. this.$http.post({
  1241. api: 'api/shopping/order/checkout?product_id=' + data.id + '&reduce_items_id='+this.reduce_items_id,
  1242. header: {
  1243. Authorization: token
  1244. },
  1245. data: data
  1246. }).then(res => {
  1247. if (res.statusCode == 200) {
  1248. res = res.data;
  1249. if (res.status) {
  1250. this.$cookieStorage.set('local_order', res.data);
  1251. wx.navigateTo({
  1252. url: `/pages/store/order/order?reduce_items_id=${this.reduce_items_id}&bargain=true`
  1253. });
  1254. } else {
  1255. if (res.data && res.data.server_busy) {
  1256. this.show_ten = true;
  1257. } else if (res.message == 'User unbind mobile') {
  1258. wx.showModal({
  1259. content: '请先绑定手机号',
  1260. showCancel: false,
  1261. success: res => {
  1262. if (res.confirm || !res.cancel && !res.confirm) {
  1263. wx.navigateTo({
  1264. url: '/pages/user/phone/phone?url=' + getUrl()
  1265. });
  1266. }
  1267. }
  1268. });
  1269. } else {
  1270. wx.showModal({
  1271. content: res.message || '请求失败',
  1272. showCancel: false
  1273. });
  1274. }
  1275. this.loading = false;
  1276. }
  1277. }
  1278. });
  1279. },
  1280. showToast() {
  1281. wx.showToast({
  1282. title: '请选择商品的规格',
  1283. icon: 'none',
  1284. duration: 2000
  1285. })
  1286. },
  1287. changeImg() {
  1288. this.setData({
  1289. showShareImg: false
  1290. })
  1291. },
  1292. //活动规则
  1293. getRule() {
  1294. this.$http.get({
  1295. api: 'api/reduce/help/text'
  1296. }).then(res => {
  1297. if (res.statusCode == 200) {
  1298. this.setData({
  1299. rule: res.data.data.reduce_help_text
  1300. })
  1301. }
  1302. })
  1303. },
  1304. setData: function(obj) {
  1305. let that = this;
  1306. let keys = [];
  1307. let val, data;
  1308. Object.keys(obj).forEach(function(key) {
  1309. keys = key.split('.');
  1310. val = obj[key];
  1311. data = that.$data;
  1312. keys.forEach(function(key2, index) {
  1313. if (index + 1 == keys.length) {
  1314. that.$set(data, key2, val);
  1315. } else {
  1316. if (!data[key2]) {
  1317. that.$set(data, key2, {});
  1318. }
  1319. }
  1320. data = data[key2];
  1321. });
  1322. });
  1323. }
  1324. }
  1325. }
  1326. </script>
  1327. <style rel="stylesheet/less" lang="less">
  1328. @import "detail";
  1329. </style>