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

1420 lines
41 KiB

  1. <template>
  2. <view class="">
  3. <view id="call">
  4. <view class="call-box" @tap="jumpDetail">
  5. <image mode="widthFix" :src="info.free.img?info.free.img:''" alt></image>
  6. <view class="name" v-if="info.free.label!=undefined">
  7. {{info.free.label}}
  8. </view>
  9. </view>
  10. <view class="time-box" :class="info.free.activity_status == 'OnGoing' ? 'active' : ''" v-if="info.free.activity_status == 'NoBegin'">
  11. <seckill :end="info.free.ends_at" :starts="info.free.starts_at" typename="集call" :server="info.free.server_time" mold="list" @starts="isStarts" @end="isEnd"></seckill>
  12. </view>
  13. <view class="call-user">
  14. <image :src="info.task_user_avatar"></image>
  15. <view class="call-status">
  16. <view v-if="info.gap_task != 0">还差 <span>{{info.gap_task}}</span> 个Call就可以免费领取礼品了求助攻~</view>
  17. <view v-if="info.gap_task == 0 && !info.is_get">您已完成目标可免费领取礼品</view>
  18. <view v-if="info.gap_task == 0 && info.is_get">您领取过该礼品</view>
  19. </view>
  20. </view>
  21. <view class="no-active" v-if="info.free.activity_status == 'NoBegin'">
  22. 活动未开始
  23. </view>
  24. <view class="no-active get" :style="'background: ' + config.mainColor" v-if="info.gap_task == 0 && !info.is_get" @tap="showSelect">立即领取</view>
  25. <view class="share-box" v-if="info.free.activity_status == 'OnGoing' && info.gap_task != 0">
  26. <button class="friend" :style="'border-color: ' + config.mainColor + '; color: ' + config.mainColor" open-type="share">分享给好友</button>
  27. <view class="friends" :style="'background: ' + config.mainColor" @tap="shareImg">生成海报</view>
  28. </view>
  29. <view class="call-num">
  30. <view class="text mx-1px-bottom">
  31. 已有 {{info.count_task}} 人为你打Call快去分享吧
  32. </view>
  33. <view class="item-box">
  34. <view class="call-num-item" :style="'height: ' + itemHeight + 'px;'" v-for="(item, index) in callList" :key="index">
  35. <view class="info">
  36. <image v-if="item.id && !item.meta.avatar" :src="info.task_user_avatar"></image>
  37. <image v-else :src="item.meta.avatar"></image>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="text-info mx-1px-top" @tap="infoF">
  42. 集Call说明
  43. </view>
  44. </view>
  45. <view class="home" @tap="jump">
  46. <i class="iconfont icon-home"></i>
  47. 首页
  48. </view>
  49. <view class="ibrand-author" v-if="author" @tap="jumpAuthor">
  50. <i class="iconfont icon-dibu"></i>
  51. </view>
  52. </view>
  53. <view class="maks" :class="!show_select ? 'cur' : ''" @tap="closeSelect">
  54. </view>
  55. <view class="detail-popup" :hidden="show_select" :animation="show.animation">
  56. <view class="select_goods_container">
  57. <!--关闭按钮-->
  58. <view class="select_goods_cloese" @tap="closeSelect"></view>
  59. <view class="select_goods_header">
  60. <view class="img_box">
  61. <image v-if="select_product && select_product.img" :src="select_product.img" :alt="select_product.sku"></image>
  62. <image v-else :src="commodity.img + ' '" alt></image>
  63. </view>
  64. <!--<view class="img_box" style="background-color: {{select_product.bac}};width: 78px;height: 78px;" wx:if="{{!select_product.img && !!select_product.color}}"></view>-->
  65. <view class="price_item">
  66. <text> {{price}}</text>
  67. <text v-if="detailData.data.shop_show_store == 1">库存{{store_count}}</text>
  68. </view>
  69. </view>
  70. <view class="select_spec">
  71. <view class="spec_line" v-for="(spec, index) in specs" :key="index">
  72. <view class="spec_title">{{spec.label}}</view>
  73. <view class="spec_value">
  74. <view class :class=" !!item.disabled ? 'disabled' : '' " v-for="(item, index) in spec.values" :key="index" :data-key="index" :data-index="item.index" :data-disabled="item.disabled ? 1 : 0" :data-id="item.id" :data-active="item.active ? 1 : 0" @tap="selectSpec">
  75. <!--<view class="spec_icon spec_text" wx:if="{{item.spec_img}}">-->
  76. <!--<image src="{{item.spec_img}}" data-alt="{{item.alias || item.value}}"></image>-->
  77. <!--</view>-->
  78. <!--<text class="spec_icon" style="background-color:{{item.color}}" wx:if="{{!item.spec_img && item.color}}"></text>-->
  79. <view class="spec_text" v-if="(item.alias || item.value) && item.spec_img !== undefined">
  80. {{item.alias || item.value}}
  81. <view v-if="!!item.active" :style="'border-color: ' + config.mainColor" class="border-color">
  82. </view>
  83. </view>
  84. <view class="spec_text" v-if="!item.spec_img && !item.color">
  85. {{item.alias || item.value}}
  86. <view v-if="!!item.active" :style="'border-color: ' + config.mainColor" class="border-color">
  87. </view>
  88. </view>
  89. </view>
  90. <!--<view class="spec_list" wx:if="{{spec.id != 2}}">尺码表</view>-->
  91. </view>
  92. </view>
  93. <view class="spec_line">
  94. <view class="num_title">数量</view>
  95. <view class="num_value">
  96. <!--<text bindtap="changeCount" data-index="0">-</text>-->
  97. <view class="none_border">
  98. <input @input="modifyCount" disabled="true" :value="select_count" type="number" confirm-type="done"></input>
  99. </view>
  100. <!--<text bindtap="changeCount" data-index="1">+</text>-->
  101. </view>
  102. <view class="purchase" v-if="detailData.data.user_limit">
  103. 本商品每人限购{{detailData.data.user_limit}}
  104. </view>
  105. </view>
  106. <button class="button disabled" v-if="canBuy" type="primary" :loading="loading" @tap="confirm">确定</button>
  107. <button class="button" v-else type="primary" :style="'background: ' + config.mainColor" :loading="loading" @tap="confirmF">确定</button>
  108. <!--<view class="button {{ canBuy ? 'disabled' : '' }}" bindtap="confirm">-->
  109. <!--&lt;!&ndash;<submit-button v-ref:button bindsubmit="confirm" :status="disallow_cart ? 'disabled' : 'normal'">确定</submit-button>&ndash;&gt;-->
  110. <!--</view>-->
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  118. import Animation from '@/common/js/animation.js';
  119. import seckill from "@/components/seckill/seckill";
  120. export default {
  121. data() {
  122. return {
  123. itemHeight: '',
  124. callList: '',
  125. info: {
  126. free:''
  127. },
  128. userInfo: '',
  129. cart_status: {
  130. status: false,
  131. message: '商品已下架'
  132. },
  133. id: '',
  134. skuTable: {},
  135. price: 0,
  136. commodity: {},
  137. detailData: {data:''},
  138. specs: [],
  139. showToTop: false,
  140. show_select: true,
  141. //选尺寸
  142. select_product: {},
  143. //当前选中商品
  144. store_count: 0,
  145. store_num: 0,
  146. select_count: 1,
  147. canBuy: false,
  148. query: {},
  149. animationSelect: {},
  150. loading: false,
  151. show_cart: false,
  152. // 加入购物车弹窗
  153. message: '',
  154. purchaseInfo: {
  155. status: false,
  156. num: 0
  157. },
  158. // 限购
  159. active: false,
  160. type: 0,
  161. config: '',
  162. author: '',
  163. animation:'',
  164. show:''
  165. };
  166. },
  167. components:{
  168. seckill
  169. },
  170. onShareAppMessage(res) {
  171. return {
  172. title: '快来帮我免费领取|' + this.info.free.label,
  173. imageUrl: this.info.free.img,
  174. path: '/pages/store/shareCall/shareCall?task_id=' + this.info.id
  175. };
  176. },
  177. onShow() {
  178. var token = this.$cookieStorage.get('user_token');
  179. if (token) {
  180. this.queryTaskInfo(this.id);
  181. } else {
  182. pageLogin(getUrl());
  183. }
  184. },
  185. onLoad(e) {
  186. // 第三方平台配置颜色
  187. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  188. var init = this.$cookieStorage.get('init');
  189. this.setData({
  190. config: gbConfig,
  191. author: init ? init.other_technical_support : ''
  192. });
  193. wx.getSystemInfo({
  194. success: res => {
  195. // this.setData({
  196. // itemHeight: (res.screenWidth - 14) / 12.5
  197. // });
  198. this.itemHeight=(res.screenWidth - 14)/12.5;
  199. }
  200. });
  201. this.setData({
  202. id: e.id
  203. });
  204. },
  205. components: {
  206. seckill
  207. },
  208. props: {},
  209. methods: {
  210. jumpAuthor() {
  211. wx.navigateTo({
  212. url: '/pages/index/author/author'
  213. });
  214. },
  215. jump() {
  216. wx.switchTab({
  217. url: '/pages/index/index/index'
  218. });
  219. },
  220. shareImg() {
  221. wx.navigateTo({
  222. url: '/pages/store/shareImg/shareImg?task_id=' + this.info.id
  223. });
  224. },
  225. jumpDetail() {
  226. wx.navigateTo({
  227. url: '/pages/store/detail/detail?id=' + this.info.free.freeable_id
  228. });
  229. },
  230. jumpEnd() {
  231. wx.redirectTo({
  232. url: '/pages/store/detail/detail?id=' + this.info.free.freeable_id
  233. });
  234. },
  235. receive() {
  236. /*wx.showLoading({
  237. title: "加载中",
  238. mask: true
  239. });*/
  240. this.getGoodsDetail({
  241. api: `api/store/detail/${this.info.free.freeable_id}`,
  242. data: {
  243. include: 'photos,oneComment,guessYouLike,point'
  244. }
  245. }).then(() => {
  246. // this.setData({
  247. // price: Number(this.commodity.sell_price).toFixed(2),
  248. // store_count: this.commodity.store_nums
  249. // });
  250. this.price=Number(this.commodity.sell_price).toFixed(2);
  251. this.store_count=this.commodity.store_nums;
  252. this.disallow_cart();
  253. this.queryCommodityStore(this.info.free.freeable_id);
  254. });
  255. },
  256. infoF() {
  257. wx.showModal({
  258. title: '集Call说明',
  259. content: this.info.free.content || '暂无说明',
  260. showCancel: false
  261. });
  262. },
  263. changeStatus() {
  264. var token = this.$cookieStorage.get('user_token');
  265. if (token) {
  266. this.changeFavorite(this.id, 'goods');
  267. } else {
  268. var url = getUrl();
  269. wx.showModal({
  270. title: '',
  271. content: '请先登录',
  272. success: res => {
  273. if (res.confirm) {
  274. wx.navigateTo({
  275. url: '/pages/user/register/register?url=' + url
  276. });
  277. }
  278. }
  279. });
  280. }
  281. },
  282. changeText() {
  283. var ret;
  284. var commodity = this.commodity;
  285. var seckill = this.detailData.meta.seckill;
  286. if (!commodity) {
  287. return;
  288. }
  289. if (commodity.is_del != 0 || commodity.is_largess != 0) {
  290. ret = {
  291. status: false,
  292. message: '商品已下架'
  293. };
  294. } else if (commodity.store_nums <= 0) {
  295. ret = {
  296. status: false,
  297. message: '商品缺货中'
  298. };
  299. } else {
  300. ret = {
  301. status: true,
  302. message: '加入购物车'
  303. };
  304. }
  305. if (seckill && seckill.init_status == 2) {
  306. ret = {
  307. seckill: false,
  308. message: '原价购买'
  309. };
  310. } else if (seckill && seckill.init_status == 1) {
  311. ret = {
  312. seckill: true,
  313. message: '立即抢购'
  314. };
  315. }
  316. this.setData({
  317. cart_status: ret
  318. });
  319. },
  320. showSelect(e) {
  321. this.setData({
  322. show_select: false
  323. });
  324. var animation = new Animation('show');
  325. animation.positionInit();
  326. },
  327. closeSelect() {
  328. var animation = new Animation('show');
  329. animation.up().then(() => {
  330. this.setData({
  331. show_select: true
  332. });
  333. });
  334. },
  335. changeCount(e) {
  336. var select_count = parseInt(this.select_count);
  337. var index = e.target.dataset.index;
  338. var val = select_count + (parseInt(index) ? 1 : -1);
  339. if (val > 0 && val <= parseInt(this.store_count)) {
  340. this.setData({
  341. select_count: val
  342. }); // 用户登录并且开启了限购
  343. if (this.purchaseInfo.status && this.is_login) {
  344. if (this.select_count > this.purchaseInfo.num) {
  345. this.setData({
  346. select_count: this.select_count - 1
  347. });
  348. wx.showToast({
  349. title: '超过限购数量',
  350. image: '../../../static/error.png'
  351. });
  352. }
  353. }
  354. } else if (val <= 0) {
  355. wx.showToast({
  356. title: '小于最小库存',
  357. image: '../../../static/error.png'
  358. });
  359. } else if (val > parseInt(this.store_count)) {
  360. wx.showToast({
  361. title: '超出最大库存',
  362. image: '../../../static/error.png'
  363. });
  364. }
  365. },
  366. modifyCount(e) {
  367. var val = parseInt(e.detail.value);
  368. if (!val) {
  369. val = 1;
  370. } else if (!/^[1-9]\d*$/.test(val)) {
  371. val = val.replace(/[^\d].*$/, '');
  372. val = parseInt(val) || 1;
  373. }
  374. if (this.purchaseInfo.status && this.is_login) {
  375. if (val < 0) {
  376. val = 1;
  377. } else if (val > this.purchaseInfo.num) {
  378. val = this.purchaseInfo.num || 1;
  379. wx.showToast({
  380. title: '超过限购数量',
  381. image: '../../../static/error.png'
  382. });
  383. }
  384. } else {
  385. if (val < 0) {
  386. val = 1;
  387. } else if (val > this.store_count) {
  388. wx.showToast({
  389. title: '超过最大库存',
  390. image: '../../../static/error.png'
  391. });
  392. val = parseInt(this.store_count);
  393. }
  394. }
  395. this.setData({
  396. select_count: val
  397. });
  398. },
  399. showCoupons() {
  400. this.setData({
  401. show_coupons: !this.show_coupons
  402. });
  403. },
  404. showDiscounts() {
  405. this.setData({
  406. show_discounts: !this.show_discounts
  407. });
  408. },
  409. getCoupon(e) {
  410. var is_login = this.$cookieStorage.get('user_token');
  411. var code = e.currentTarget.dataset.code;
  412. var index = e.currentTarget.dataset.index;
  413. if (is_login) {
  414. this.goodsConvertCoupon(code, index);
  415. } else {
  416. var url = getUrl();
  417. wx.showModal({
  418. tiele: '',
  419. content: '请先登录',
  420. success: res => {
  421. if (res.confirm) {
  422. wx.navigateTo({
  423. url: '/pages/user/register/register?url=' + url
  424. });
  425. }
  426. }
  427. });
  428. }
  429. },
  430. selectSpec(e) {
  431. var spec = {
  432. key: e.currentTarget.dataset.key,
  433. index: e.currentTarget.dataset.index,
  434. disabled: Number(e.currentTarget.dataset.disabled),
  435. active: Number(e.currentTarget.dataset.active),
  436. id: Number(e.currentTarget.dataset.id)
  437. };
  438. if (spec.disabled) return;
  439. var specs = this.specs;
  440. if (!spec.active) {
  441. for (let item of specs[spec.index].values) {
  442. if (item.active) {
  443. item.active = false;
  444. break;
  445. }
  446. }
  447. }
  448. specs[spec.index].values[spec.key].active = !specs[spec.index].values[spec.key].active;
  449. spec.active = !spec.active;
  450. specs[spec.index].select = spec.active ? spec.id : '';
  451. this.setData({
  452. specs: specs
  453. });
  454. var canBuy = this.disallow_cart();
  455. this.setData({
  456. canBuy: canBuy
  457. }); // this.queryCommodityStore(id, spec.index);
  458. this.specStore(this.result, spec.index);
  459. },
  460. specStore(result, key) {
  461. var query = this.query;
  462. var data = result.data;
  463. var specs = this.specs;
  464. if (key === undefined) {
  465. specs.forEach(spec => {
  466. for (let v of spec.values) {
  467. v.disabled = !data[v.id] || data[v.id].count == 0;
  468. }
  469. });
  470. this.setData({
  471. specs: specs,
  472. skuTable: result.table
  473. });
  474. specs = this.specs;
  475. var canBuy = this.disallow_cart();
  476. this.setData({
  477. canBuy: canBuy
  478. });
  479. specs.forEach(spec => {
  480. let name = 'spec[' + spec.id + ']';
  481. if (query[name]) {
  482. let id = query[name];
  483. for (let v of spec.values) {
  484. if (v.id == id && !v.disabled && data[v.id] && data[v.id].count) {
  485. v.active = true;
  486. spec.select = v.id;
  487. this.setData({
  488. specs: specs
  489. });
  490. specs = this.specs;
  491. var canBuy = this.disallow_cart();
  492. this.setData({
  493. canBuy: canBuy
  494. });
  495. this.specStore(result, v.index);
  496. return;
  497. }
  498. }
  499. }
  500. if (!spec.select) {
  501. for (let v of spec.values) {
  502. if (!v.disabled && data[v.id] && data[v.id].count) {
  503. v.active = true;
  504. spec.select = v.id;
  505. this.setData({
  506. specs: specs
  507. });
  508. specs = this.specs;
  509. var canBuy = this.disallow_cart();
  510. this.setData({
  511. canBuy: canBuy
  512. }); // this.$emit('specStore', result, v.index);
  513. this.specStore(result, v.index);
  514. return;
  515. }
  516. }
  517. return;
  518. }
  519. this.setData({
  520. specs: specs
  521. });
  522. });
  523. return;
  524. }
  525. var spec = specs[key];
  526. if (spec.select) {
  527. // this.setData({
  528. // store_count: data[spec.select].count
  529. // });
  530. this.store_count=data[spec.select].count;
  531. for (let i = 0; i < specs.length; i++) {
  532. if (i === key) continue;
  533. specs[i].values.forEach(v => {
  534. v.disabled = !data[spec.select].specs[v.id].count;
  535. });
  536. if (specs[i].select) {
  537. // this.setData({
  538. // store_count: data[spec.select].specs[specs[i].select].count
  539. // });
  540. this.store_count=data[spec.select].specs[specs[i].select].count;
  541. }
  542. this.setData({
  543. specs: specs
  544. });
  545. }
  546. } else {
  547. this.setData({
  548. store_count: this.commodity.store
  549. });
  550. for (let i = 0; i < specs.length; i++) {
  551. if (i === key) continue;
  552. specs[i].values.forEach(v => {
  553. v.disabled = !data[v.id] || !data[v.id].count;
  554. });
  555. if (specs[i].select) {
  556. // this.setData({
  557. // store_count: data[specs[i].select].count
  558. // });
  559. //
  560. this.store_count=data[specs[i].select].count;
  561. }
  562. this.setData({
  563. specs: specs
  564. });
  565. console.log(specs);
  566. }
  567. }
  568. if (parseInt(this.select_count) > this.store_count) {
  569. this.setData({
  570. select_count: String(this.store_count)
  571. });
  572. } else if (parseInt(this.select_count) === 0) {
  573. this.setData({
  574. select_count: '1'
  575. });
  576. }
  577. this.setData({
  578. specs: specs
  579. });
  580. var canBuy = this.disallow_cart();
  581. this.setData({
  582. canBuy: canBuy
  583. });
  584. },
  585. confirmF() {
  586. if (this.loading) return;
  587. if (this.disallow_cart()) return;
  588. this.setData({
  589. loading: true
  590. });
  591. var select_product = this.select_product;
  592. var select_count = Number(this.select_count);
  593. var data = this.specs.length ? {
  594. id: select_product.id,
  595. name: this.commodity.name,
  596. qty: select_count,
  597. store_count: this.store_count,
  598. price: select_product.price,
  599. attributes: {
  600. img: select_product.img || this.detailData.data.photos[0].url,
  601. size: select_product.size,
  602. color: select_product.color,
  603. com_id: this.commodity.id
  604. }
  605. } : {
  606. id: this.commodity.id,
  607. name: this.commodity.name,
  608. qty: select_count,
  609. store_count: this.store_count,
  610. price: this.commodity.price,
  611. attributes: {
  612. img: this.commodity.img || this.detailData.data.photos[0].url,
  613. com_id: this.commodity.id
  614. }
  615. }; // if (this.channel) data.attributes.channel = 'employee';
  616. if (select_product.sku) data.attributes.sku = select_product.sku; // 秒杀开始添加信息
  617. if (this.detailData.meta.seckill && this.detailData.meta.seckill.init_status == 1) {
  618. var newData = {};
  619. newData.attributes = {};
  620. newData.id = data.id;
  621. newData.img = data.attributes.img || this.detailData.data.photos[0].url;
  622. newData.name = data.name;
  623. newData.price = data.price;
  624. newData.qty = data.qty;
  625. newData.total = data.qty * data.price;
  626. newData.seckill_goods_id = this.detailData.meta.seckill.item_id;
  627. newData.seckill_item_id = this.detailData.meta.seckill.id;
  628. newData.attributes['dynamic_sku'] = {};
  629. newData.attributes['dynamic_sku'].id = data.id;
  630. newData.attributes['dynamic_sku'].size = data.attributes.size;
  631. newData.attributes['dynamic_sku'].color = data.attributes.color;
  632. } // 判断是否登录
  633. // var is_login = !!Cache.get(cache_keys.token);
  634. // 判断是否参与秒杀并且秒杀开始
  635. if (this.detailData.meta.seckill && this.detailData.meta.seckill.init_status == 1) {
  636. if (!this.is_login) {
  637. var url = getUrl();
  638. wx.showModal({
  639. content: '请先登录',
  640. success: res => {
  641. if (res.confirm) {
  642. wx.navigateTo({
  643. url: '/pages/user/register/register?url=' + url
  644. });
  645. }
  646. }
  647. });
  648. } else {
  649. this.checkoutSeckillOrder(newData);
  650. }
  651. } else {
  652. if (this.is_login) {
  653. this.appendToCart(data);
  654. this.addStoreNum();
  655. } else {
  656. data.local = true;
  657. data.total = Number(data.qty) * Number(data.price);
  658. data.color = data.attributes.color;
  659. data.size = data.attributes.size;
  660. data.img = data.attributes.img;
  661. var locals = this.$cookieStorage.get('cart') || [];
  662. locals.unshift(data);
  663. var skus = {};
  664. var save = [];
  665. locals.forEach(v => {
  666. let sku, index;
  667. if (v.attributes && v.attributes.sku) {
  668. sku = v.attributes.sku;
  669. } else {
  670. sku = v.id;
  671. }
  672. if (skus[sku] === undefined) {
  673. index = save.length;
  674. v.index = index;
  675. v.checked = true;
  676. save.push(v);
  677. skus[sku] = index;
  678. } else {
  679. let i = skus[sku];
  680. save[i].qty += v.qty;
  681. save[i].total += v.total;
  682. save[i].store_count = this.store_count;
  683. }
  684. });
  685. console.log(skus, save);
  686. this.$cookieStorage.set('cart', save);
  687. this.setData({
  688. store_num: 0
  689. });
  690. this.addStoreNum();
  691. this.addCart(true);
  692. }
  693. }
  694. },
  695. addStoreNum() {
  696. // 判断是否登录
  697. // var is_login = !!Cache.get(cache_keys.token);
  698. // var cache_store_num = Cache.get(cache_keys.cart);
  699. var cache_store_num = this.$cookieStorage.get('cart');
  700. if (this.is_login) {
  701. this.queryShoppingCount();
  702. } else {
  703. if (cache_store_num && cache_store_num.length) {
  704. var store_num = this.store_num;
  705. cache_store_num.forEach(v => {
  706. store_num += v.qty;
  707. });
  708. this.setData({
  709. store_num: store_num
  710. });
  711. }
  712. }
  713. },
  714. disallow_cart() {
  715. if (!this.specs.length) {
  716. return !this.store_count;
  717. }
  718. var ids = [],
  719. select_product = {},
  720. specs = this.specs;
  721. console.log(this.commodity.sell_price);
  722. this.setData({
  723. price: Number(this.commodity.sell_price).toFixed(2)
  724. });
  725. for (let spec of specs) {
  726. if (!spec.select) {
  727. this.setData({
  728. price: Number(this.commodity.sell_price).toFixed(2),
  729. select_product: null
  730. });
  731. return true;
  732. }
  733. ids.push(spec.select);
  734. for (let v of spec.values) {
  735. if (v.id === spec.select) {
  736. switch (spec.label_key) {
  737. case 'color':
  738. select_product.img = v.img;
  739. select_product.color = v.alias || v.value;
  740. select_product.bac = v.color;
  741. break;
  742. default:
  743. select_product.size = v.alias || v.value;
  744. }
  745. break;
  746. }
  747. }
  748. }
  749. if (this.skuTable) {
  750. ids = ids[0] > ids[1] ? [ids[1], ids[0]] : ids;
  751. ids = ids.join('-');
  752. select_product = Object.assign(select_product, this.skuTable[ids]);
  753. }
  754. console.log(ids);
  755. console.warn(this.skuTable);
  756. console.warn(this.skuTable[ids]);
  757. console.log(select_product.price);
  758. this.setData({
  759. price: Number(select_product.price).toFixed(2),
  760. select_product: select_product
  761. });
  762. return false;
  763. },
  764. attributesList(meta) {
  765. var topList = [];
  766. var bottomList = [];
  767. if (meta && meta.attributes) {
  768. var attributes = meta.attributes;
  769. for (var item of attributes) {
  770. if (item.is_chart === 1) {
  771. bottomList.push(item);
  772. } else {
  773. topList.push(item);
  774. }
  775. }
  776. }
  777. this.setData({
  778. 'attributesList.top': topList,
  779. 'attributesList.bottom': bottomList
  780. });
  781. },
  782. // 重要!!!!
  783. move() {},
  784. goCart() {
  785. wx.switchTab({
  786. url: '/pages/store/cart/cart'
  787. });
  788. this.changeCart();
  789. },
  790. changeCart() {
  791. this.setData({
  792. show_cart: !this.show_cart
  793. });
  794. },
  795. queryCommodityStore(id, key) {
  796. var that = this;
  797. this.$http.get({
  798. api: `api/store/detail/${id}/stock`
  799. }).then(res => {
  800. wx.hideLoading();
  801. res = res.data;
  802. if (!res.status || !res.data || !res.data.specs) return;
  803. if (res.data.specs && typeof key === 'undefined') {
  804. let specs = [];
  805. Object.keys(res.data.specs).forEach((key, index) => {
  806. let value = res.data.specs[key];
  807. value.select = '';
  808. value.values = value.list.map(v => {
  809. return Object.assign({
  810. index: index,
  811. active: false,
  812. disabled: false
  813. }, v);
  814. });
  815. delete value.list;
  816. specs.push(value);
  817. });
  818. that.setData({
  819. specs: specs
  820. });
  821. console.log(specs);
  822. var canBuy = this.disallow_cart();
  823. this.setData({
  824. canBuy: canBuy
  825. });
  826. }
  827. if (res.data.stores) {
  828. let data = {};
  829. Object.keys(res.data.stores).forEach(key => {
  830. let value = res.data.stores[key];
  831. value.ids.forEach(id => {
  832. data[id] = data[id] || {
  833. count: 0,
  834. specs: {}
  835. };
  836. data[id].count += Number(value.store);
  837. value.ids.forEach(i => {
  838. if (i === id) return;
  839. data[id].specs[i] = {
  840. count: Number(value.store)
  841. };
  842. });
  843. });
  844. }); // console.log(data);
  845. var result = {
  846. data,
  847. table: res.data.stores
  848. };
  849. this.setData({
  850. result: result
  851. });
  852. that.specStore(result, key); // this.$emit('specStore', result, key);
  853. }
  854. }).catch(err => {});
  855. },
  856. appendToCart(data) {
  857. if (!Array.isArray(data)) {
  858. data = [data];
  859. }
  860. var oauth = this.is_login;
  861. var json = {};
  862. data.forEach((v, i) => json[i] = v);
  863. data = json;
  864. var that = this;
  865. this.$http.post({
  866. api: 'api/shopping/cart',
  867. header: {
  868. Authorization: oauth
  869. },
  870. data: data
  871. }).then(res => {
  872. res = res.data;
  873. if (res.status) {
  874. that.addCart(true);
  875. } else {
  876. that.addCart(false, res.message);
  877. }
  878. }).catch(rej => {
  879. that.addCart(false);
  880. });
  881. },
  882. addCart(success, message) {
  883. // this.$refs.button.finish();
  884. this.setData({
  885. loading: false
  886. });
  887. if (success) {
  888. this.closeSelect();
  889. this.changeCart(); // wx.showModal({
  890. // content: '商品成功加入购物车!',
  891. // cancelText: '进购物车',
  892. // confirmText: '继续购物',
  893. // success: function (res) {
  894. // if (res.confirm) {
  895. // console.log('用户点击取消')
  896. // } else if (res.cancel) {
  897. // wx.navigateTo({
  898. // url: '/pages/store/cart/cart'
  899. // })
  900. // }
  901. // },
  902. // fail: function () {
  903. // wx.showToast({
  904. // title: '添加失败',
  905. // image: '../../../static/error.png',
  906. // })
  907. // }
  908. // })
  909. // if (typeof window.__analytics == 'function') {
  910. // console.log('11212132323')
  911. // var cart = {
  912. // action :'add to cart',
  913. // product:{
  914. // sku: this.$brand.name == 'JackWolfskin' ? this.select_product.id :this.select_product.sku,
  915. // title: this.commodity.name,
  916. // category: this.commodity.tags,
  917. // quantity: this.store_count
  918. // }
  919. // }
  920. //
  921. // window.__analytics({cart})
  922. // }
  923. } else {
  924. if (message) {
  925. wx.showToast({
  926. title: message
  927. });
  928. } else {
  929. wx.showToast({
  930. title: '添加到购物车失败,请重试'
  931. });
  932. }
  933. }
  934. },
  935. getGoodsDetail(obj) {
  936. var that = this;
  937. return new Promise((resolve, reject) => {
  938. this.$http.get(obj).then(res => {
  939. console.log(res);
  940. res = res.data;
  941. that.setData({
  942. detailData: res,
  943. commodity: res.data
  944. });
  945. if (res.meta.seckill) {
  946. var interval = setInterval(this.countStartsTime, 1000);
  947. that.setData({
  948. 'startsTime.interval': interval
  949. });
  950. }
  951. if (res.meta.discounts) {
  952. res.meta.discounts.coupons.forEach(v => v.receive = false);
  953. that.setData({
  954. coupons: res.meta.discounts.coupons,
  955. discounts: res.meta.discounts.discounts
  956. });
  957. }
  958. resolve();
  959. }).catch(err => {
  960. console.log(err);
  961. reject();
  962. });
  963. });
  964. },
  965. // 查询打Call信息
  966. queryTaskInfo(id) {
  967. var token = this.$cookieStorage.get('user_token');
  968. wx.showLoading({
  969. title: "加载中",
  970. mask: true
  971. });
  972. this.$http.get({
  973. api: 'api/free_event/task/' + id,
  974. header: {
  975. Authorization: token
  976. }
  977. }).then(res => {
  978. if (res.statusCode == 200) {
  979. res = res.data;
  980. if (res.status) {
  981. var list = Array(res.data.free.per_count - res.data.count_task).fill({
  982. meta: {
  983. avatar: ''
  984. }
  985. });
  986. var newList = res.data.items.concat(list);
  987. this.setData({
  988. info: res.data,
  989. callList: newList
  990. });
  991. /*
  992. NoBegin 未开始
  993. OnGoing 进行中
  994. End 结束
  995. */
  996. // 如果活动未开始,不显示转发按钮
  997. if (res.data.free.activity_status == 'NoBegin') {
  998. wx.hideShareMenu();
  999. }
  1000. if (res.data.gap_task == 0 && !res.data.is_get) {
  1001. this.receive();
  1002. } else {
  1003. wx.hideLoading();
  1004. }
  1005. } else {
  1006. wx.hideLoading();
  1007. wx.showModal({
  1008. content: res.message || '请求失败',
  1009. showCancel: false,
  1010. success: res => {
  1011. if (res.confirm || !res.cancel && !res.confirm) {
  1012. wx.redirectTo({
  1013. url: '/pages/store/callList/callList'
  1014. });
  1015. }
  1016. }
  1017. });
  1018. }
  1019. } else {
  1020. wx.hideLoading();
  1021. wx.showModal({
  1022. content: res.message || '请求失败',
  1023. showCancel: false,
  1024. success: res => {
  1025. if (res.confirm || !res.cancel && !res.confirm) {
  1026. wx.redirectTo({
  1027. url: '/pages/store/callList/callList'
  1028. });
  1029. }
  1030. }
  1031. });
  1032. }
  1033. }).catch(rej => {
  1034. wx.hideLoading();
  1035. wx.showModal({
  1036. content: '请求失败',
  1037. showCancel: false,
  1038. success: res => {
  1039. if (res.confirm || !res.cancel && !res.confirm) {
  1040. wx.redirectTo({
  1041. url: '/pages/store/callList/callList'
  1042. });
  1043. }
  1044. }
  1045. });
  1046. });
  1047. },
  1048. // 点击确定
  1049. confirm() {
  1050. if (this.loading) return;
  1051. if (this.disallow_cart()) return;
  1052. this.setData({
  1053. loading: true
  1054. });
  1055. var select_product = this.select_product;
  1056. var select_count = Number(this.select_count);
  1057. var data = this.specs.length ? {
  1058. id: select_product.id,
  1059. name: this.commodity.name,
  1060. qty: select_count,
  1061. store_count: this.store_count,
  1062. price: select_product.price,
  1063. market_price: this.commodity.market_price,
  1064. attributes: {
  1065. img: select_product.img || this.detailData.data.photos[0].url,
  1066. size: select_product.size,
  1067. color: select_product.color,
  1068. com_id: this.commodity.id
  1069. }
  1070. } : {
  1071. id: this.commodity.id,
  1072. name: this.commodity.name,
  1073. qty: select_count,
  1074. store_count: this.store_count,
  1075. price: this.commodity.sell_price,
  1076. market_price: this.commodity.market_price,
  1077. attributes: {
  1078. img: this.commodity.img || this.detailData.data.photos[0].url,
  1079. com_id: this.commodity.id
  1080. }
  1081. };
  1082. var newData = {};
  1083. newData.attributes = {};
  1084. newData.id = data.id;
  1085. newData.img = data.attributes.img || this.detailData.data.photos[0].url;
  1086. newData.name = data.name;
  1087. newData.price = data.price;
  1088. newData.qty = data.qty;
  1089. newData.total = data.qty * data.price;
  1090. newData.free_id = this.info.free_id;
  1091. newData.task_id = this.info.id;
  1092. if (this.specs.length) {
  1093. newData.attributes['dynamic_sku'] = {};
  1094. newData.attributes['dynamic_sku'].id = data.id;
  1095. newData.attributes['dynamic_sku'].size = data.attributes.size;
  1096. newData.attributes['dynamic_sku'].color = data.attributes.color;
  1097. } // if (this.channel) data.attributes.channel = 'employee';
  1098. if (select_product.sku) data.attributes.sku = select_product.sku; // 关闭弹出层
  1099. this.closeSelect();
  1100. this.checkoutFreeOrder(newData); // 秒杀开始添加信息
  1101. /*if (this.detailData.meta.seckill && this.detailData.meta.seckill.init_status == 1) {
  1102. var newData = {};
  1103. newData.attributes={};
  1104. newData.id = data.id;
  1105. newData.img = data.attributes.img || this.detailData.data.photos[0].url;
  1106. newData.name = data.name;
  1107. newData.price = data.price;
  1108. newData.qty = data.qty;
  1109. newData.total = data.qty * data.price;
  1110. newData.seckill_goods_id = this.detailData.meta.seckill.item_id;
  1111. newData.seckill_item_id = this.detailData.meta.seckill.id;
  1112. newData.attributes['dynamic_sku'] = {};
  1113. newData.attributes['dynamic_sku'].id = data.id;
  1114. newData.attributes['dynamic_sku'].size = data.attributes.size;
  1115. newData.attributes['dynamic_sku'].color = data.attributes.color;
  1116. }*/
  1117. // 判断是否登录
  1118. // var is_login = !!Cache.get(cache_keys.token);
  1119. // 判断是否参与秒杀并且秒杀开始
  1120. /*if (this.detailData.meta.seckill && this.detailData.meta.seckill.init_status == 1) {
  1121. if (!this.is_login) {
  1122. var url = getUrl();
  1123. wx.showModal({
  1124. content: '请先登录',
  1125. success: res => {
  1126. if (res.confirm) {
  1127. wx.navigateTo({
  1128. url: '/pages/user/register/register?url=' + url
  1129. })
  1130. }
  1131. }
  1132. })
  1133. } else {
  1134. this.checkoutSeckillOrder(newData);
  1135. }
  1136. } else {
  1137. if (this.is_login) {
  1138. this.appendToCart(data);
  1139. this.addStoreNum();
  1140. } else {
  1141. data.local = true;
  1142. data.total = Number(data.qty) * Number(data.price);
  1143. data.color = data.attributes.color;
  1144. data.size = data.attributes.size;
  1145. data.img = data.attributes.img;
  1146. var locals = this.$cookieStorage.get('cart') || [];
  1147. locals.unshift(data);
  1148. var skus = {};
  1149. var save = [];
  1150. locals.forEach(v => {
  1151. let sku, index;
  1152. if (v.attributes && v.attributes.sku) {
  1153. sku = v.attributes.sku;
  1154. } else {
  1155. sku = v.id;
  1156. }
  1157. if (skus[sku] === undefined) {
  1158. index = save.length;
  1159. v.index = index;
  1160. v.checked = true;
  1161. save.push(v);
  1162. skus[sku] = index;
  1163. } else {
  1164. let i = skus[sku];
  1165. save[i].qty += v.qty;
  1166. save[i].total += v.total;
  1167. save[i].store_count = this.store_count;
  1168. }
  1169. });
  1170. console.log(skus, save)
  1171. this.$cookieStorage.set('cart', save);
  1172. this.setData({
  1173. store_num: 0
  1174. })
  1175. this.addStoreNum();
  1176. this.addCart(true)
  1177. }
  1178. }*/
  1179. },
  1180. // 订单结算
  1181. checkoutFreeOrder(data) {
  1182. console.log(data);
  1183. var token = this.$cookieStorage.get('user_token');
  1184. this.$http.post({
  1185. api: 'api/shopping/order/checkout?free_id=' + data.free_id,
  1186. header: {
  1187. Authorization: token
  1188. },
  1189. data: data
  1190. }).then(res => {
  1191. if (res.statusCode == 200) {
  1192. res = res.data;
  1193. if (res.status) {
  1194. this.$cookieStorage.set('local_order', res.data);
  1195. this.setData({
  1196. loading: false
  1197. });
  1198. wx.navigateTo({
  1199. url: '/pages/store/order/order?type=free&task_id=' + data.task_id
  1200. });
  1201. } else {
  1202. if (res.data && res.data.server_busy) {
  1203. this.setData({
  1204. show_ten: true
  1205. });
  1206. } else if (res.message == 'User unbind mobile') {
  1207. wx.showModal({
  1208. content: '请先绑定手机号',
  1209. showCancel: false,
  1210. success: res => {
  1211. if (res.confirm || !res.cancel && !res.confirm) {
  1212. wx.navigateTo({
  1213. url: '/pages/user/phone/phone?url=' + getUrl()
  1214. });
  1215. }
  1216. }
  1217. });
  1218. } else {
  1219. wx.showModal({
  1220. content: res.message || '请求失败',
  1221. showCancel: false
  1222. });
  1223. }
  1224. this.setData({
  1225. loading: false
  1226. });
  1227. }
  1228. } else {
  1229. wx.showModal({
  1230. content: '请求失败',
  1231. showCancel: false
  1232. });
  1233. this.setData({
  1234. loading: false
  1235. });
  1236. }
  1237. });
  1238. },
  1239. // 开始
  1240. isStarts(e) {
  1241. if (this.info.free.activity_status == 'NoBegin') {
  1242. this.queryTaskInfo(this.id);
  1243. }
  1244. },
  1245. // 结束
  1246. isEnd(e) {
  1247. if (this.info.free.activity_status == 'OnGoing') {
  1248. this.jumpEnd();
  1249. }
  1250. },
  1251. setData: function (obj) {
  1252. let that = this;
  1253. let keys = [];
  1254. let val, data;
  1255. Object.keys(obj).forEach(function (key) {
  1256. keys = key.split('.');
  1257. val = obj[key];
  1258. data = that.$data;
  1259. keys.forEach(function (key2, index) {
  1260. if (index + 1 == keys.length) {
  1261. that.$set(data, key2, val);
  1262. } else {
  1263. if (!data[key2]) {
  1264. that.$set(data, key2, {});
  1265. }
  1266. }
  1267. data = data[key2];
  1268. });
  1269. });
  1270. }
  1271. },
  1272. computed: {},
  1273. watch: {}
  1274. };
  1275. </script>
  1276. <style rel="stylesheet/less" lang="less">
  1277. @import "call";
  1278. </style>