index.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. var util = require('../../utils/util.js');
  2. var WxParse = require('../../wxParse/wxParse.js');
  3. var app = getApp()
  4. function pintuancount_down(that, cur_time) {
  5. var pintuan = that.data.pintuan;
  6. for (var i in pintuan) {
  7. //end_time_html
  8. var total_micro_second = (pintuan[i].end_time - cur_time) * 1000;
  9. var second = Math.floor(total_micro_second / 1000);
  10. var days = second / 3600 / 24;
  11. var daysRound = Math.floor(days);
  12. var hours = second / 3600 - (24 * daysRound);
  13. var hoursRound = Math.floor(hours);
  14. var minutes = second / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  15. var minutesRound = Math.floor(minutes);
  16. var seconds = second - (24 * 3600 * daysRound) - (3600 * hoursRound) - (60 * minutesRound);
  17. var end_time_html = '';
  18. if (daysRound > 0) {
  19. end_time_html += daysRound + '天';
  20. }
  21. if (hoursRound > 0) {
  22. end_time_html += hoursRound + '时';
  23. }
  24. if (minutesRound > 0) {
  25. end_time_html += minutesRound + '分';
  26. }
  27. end_time_html += seconds + '秒';
  28. pintuan[i].end_time = pintuan[i].end_time - 1;
  29. pintuan[i].end_time_html = end_time_html;
  30. }
  31. that.setData({
  32. pintuan: pintuan
  33. });
  34. if (total_micro_second <= 0) {
  35. return;
  36. }
  37. setTimeout(function () {
  38. pintuancount_down(that, cur_time);
  39. }, 1000)
  40. }
  41. function count_down(that, total_micro_second) {
  42. var second = Math.floor(total_micro_second / 1000);
  43. var days = second / 3600 / 24;
  44. var daysRound = Math.floor(days);
  45. var hours = second / 3600 - (24 * daysRound);
  46. var hoursRound = Math.floor(hours);
  47. var minutes = second / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  48. var minutesRound = Math.floor(minutes);
  49. var seconds = second - (24 * 3600 * daysRound) - (3600 * hoursRound) - (60 * minutesRound);
  50. that.setData({
  51. endtime: {
  52. days: daysRound,
  53. hours: hoursRound,
  54. minutes: minutesRound,
  55. seconds: seconds,
  56. show_detail: 1
  57. }
  58. });
  59. if (total_micro_second <= 0) {
  60. that.setData({
  61. endtime: {
  62. days: "00",
  63. hours: "00",
  64. minutes: "00",
  65. seconds: "00",
  66. }
  67. });
  68. return;
  69. }
  70. setTimeout(function () {
  71. total_micro_second -= 1000;
  72. count_down(that, total_micro_second);
  73. }, 1000)
  74. }
  75. // 位数不足补零
  76. function fill_zero_prefix(num) {
  77. return num < 10 ? "0" + num : num
  78. }
  79. Page({
  80. data: {
  81. navState: 0,
  82. indicatorDots: false,
  83. hidetip: true,
  84. theme_type: '',
  85. autoplay: true,
  86. interval: 5000,
  87. duration: 1000,
  88. is_login: false,
  89. goods: {},
  90. member_level_info: {},
  91. seller_info: {},
  92. options: {},
  93. goods_image: {},
  94. pin_info: {},
  95. showModal: false,
  96. skustate: 0,
  97. can_car: true,
  98. share_title: '',
  99. isHidenotice: true,
  100. jarray: [],
  101. sku: [],
  102. skudanprice: 0,
  103. skupin_price: 0,
  104. show_detail: 1,
  105. is_addcar: false,
  106. endtime: {
  107. days: "00",
  108. hours: "00",
  109. minutes: "00",
  110. seconds: "00",
  111. },
  112. order: {},
  113. src: '',
  114. video_height: 0,
  115. video_size_width: 0,
  116. vedio_size_height: 0,
  117. is_video: 0,
  118. autoplay_video: false,
  119. hide_video: true,
  120. is_share_html: true,
  121. service: [],
  122. items: [],
  123. inputValue: 0,
  124. pintuan: {}
  125. },
  126. onLoad: function (options) {
  127. var that = this;
  128. var token = wx.getStorageSync('token');
  129. wx.setNavigationBarTitle({
  130. title: '商品详情'
  131. });
  132. wx.showLoading({})
  133. wx.hideLoading();
  134. if (util.check_login()) {
  135. this.setData({
  136. is_login: true
  137. })
  138. }
  139. var scene = decodeURIComponent(options.scene)
  140. if (scene != 'undefined') {
  141. //$goods_id.'_'.$member_id
  142. var opt_arr = scene.split("_");
  143. options.id = opt_arr[0];
  144. wx.setStorage({
  145. key: "share_id",
  146. data: opt_arr[1]
  147. })
  148. }
  149. // 13
  150. app.util.request({
  151. 'url': 'entry/wxapp/index',
  152. 'data': {
  153. controller: 'goods.get_goods_detail',
  154. 'token': token,
  155. 'id': options.id
  156. },
  157. dataType: 'json',
  158. success: function (res) {
  159. //src
  160. if (res.data.data.goods.is_video == 1) {
  161. that.videoContext = wx.createVideoContext('myVideo');
  162. wx.showToast({
  163. title: '轻触看视频',
  164. icon: 'none'
  165. })
  166. }
  167. if (res.data.data.is_show_max_level == 1) {
  168. console.log('会员等级--');
  169. var level_list = res.data.data.member_level_list;
  170. console.log(level_list);
  171. var s_items = [];
  172. var last_id = 0;
  173. for (var i in level_list) {
  174. var tp_g = {};
  175. tp_g.name = level_list[i].levelname + ' ' + level_list[i].level_money + '元/年' + ' 全场' + level_list[i].discount + '折';
  176. tp_g.value = level_list[i].id;
  177. last_id = level_list[i].id;
  178. if (res.data.data.member_level_info.level >= level_list[i].level) {
  179. tp_g.is_hide = 1;
  180. } else {
  181. tp_g.is_hide = 0;
  182. if (i == level_list.length - 1) tp_g.checked = "checked";
  183. }
  184. s_items.push(tp_g);
  185. }
  186. that.setData({
  187. items: s_items,
  188. })
  189. }
  190. that.setData({
  191. order_comment_count: res.data.order_comment_count,
  192. comment_list: res.data.comment_list,
  193. loadover: true,
  194. goods: res.data.data.goods,
  195. member_level_info: res.data.data.member_level_info,
  196. is_show_max_level: res.data.data.is_show_max_level,
  197. max_member_level: res.data.data.max_member_level,
  198. max_get_money: res.data.data.max_get_money,
  199. site_name: res.data.data.site_name,
  200. src: res.data.data.goods.video_src,
  201. is_video: res.data.data.goods.is_video,
  202. video_size_width: res.data.data.goods.video_size_width,
  203. vedio_size_height: res.data.data.goods.vedio_size_height,
  204. share_title: res.data.data.goods.share_title,
  205. options: res.data.data.options,
  206. goods_image: res.data.data.goods_image,
  207. pin_info: res.data.data.pin_info,
  208. lottery_info: res.data.data.lottery_info,
  209. service: res.data.data.goods.tag,
  210. favgoods: res.data.data.goods.favgoods,
  211. cur_time: res.data.data.cur_time,
  212. order: {
  213. goods_id: res.data.data.goods.goods_id,
  214. pin_id: res.data.data.pin_id,
  215. },
  216. })
  217. var seconds = (res.data.data.pin_info.end_time - res.data.data.cur_time) * 1000;
  218. if (seconds > 0) {
  219. count_down(that, seconds);
  220. }
  221. var article = res.data.data.goods.description;
  222. WxParse.wxParse('article', 'html', article, that, 0);
  223. }
  224. })
  225. /**
  226. wx.request({
  227. url: util.api() + 'index.php?s=/Apigoods/get_goods_fujin_tuan/id/' + options.id,
  228. success: function (res) {
  229. that.setData({
  230. pintuan: res.data.data
  231. })
  232. if (res.data.data.length > 0) {
  233. pintuancount_down(that, res.data.cur_time);
  234. }
  235. }
  236. })
  237. */
  238. // this.socketmsg();
  239. },
  240. onShow: function () {
  241. var that = this;
  242. var goods_id = this.data.order.goods_id;
  243. app.util.request({
  244. 'url': 'entry/wxapp/index',
  245. 'data': {
  246. controller: 'index.wepro_index_goods',
  247. "per_page": 20,
  248. "type":'all',
  249. "is_index_show":2,
  250. "orderby": 'rand',
  251. "exp": goods_id,
  252. "page":1
  253. },
  254. dataType: 'json',
  255. success: function (res) {
  256. if (res.data.code == 0) {
  257. console.log('猜你喜欢:');
  258. console.log(res.data.list);
  259. that.setData({
  260. showguess: false,
  261. guessdata: res.data.list
  262. });
  263. }
  264. }
  265. })
  266. },
  267. share_handler: function () {
  268. this.setData({
  269. is_share_html: false
  270. })
  271. },
  272. hide_share_handler: function () {
  273. this.setData({
  274. is_share_html: true
  275. })
  276. },
  277. share_quan: function () {
  278. wx.showLoading({
  279. title: '获取中',
  280. })
  281. var token = wx.getStorageSync('token');
  282. var goods_id = this.data.order.goods_id;
  283. var that = this;
  284. app.util.request({
  285. 'url': 'entry/wxapp/index',
  286. 'data': {
  287. controller: 'goods.get_user_goods_qrcode',
  288. "token": token,
  289. "goods_id": goods_id
  290. },
  291. dataType: 'json',
  292. success: function (res) {
  293. if (res.data.code == 0) {
  294. setTimeout(function () {
  295. wx.hideLoading()
  296. }, 2000)
  297. var image_path = res.data.image_path;
  298. wx.getImageInfo({
  299. src: image_path,
  300. success: function (res) {
  301. var real_path = res.path;
  302. wx.saveImageToPhotosAlbum({
  303. filePath: real_path,
  304. success(res) {
  305. wx.showToast({
  306. title: '图片保存成功,可以分享了',
  307. icon: 'none',
  308. duration: 2000
  309. })
  310. that.setData({
  311. is_share_html: true
  312. });
  313. }
  314. })
  315. }
  316. })
  317. }
  318. }
  319. })
  320. },
  321. goPlayVideo: function (e) {
  322. console.log('play video');
  323. var that = this;
  324. //获取屏幕宽高
  325. wx.getSystemInfo({
  326. success: function (res) {
  327. var windowWidth = res.windowWidth;
  328. windowWidth = windowWidth * 0.7;
  329. var windowHeight = res.windowHeight;
  330. var windowscale = windowHeight / windowWidth; //屏幕高宽比
  331. console.log('windowWidth: ' + windowWidth)
  332. console.log('windowHeight: ' + windowHeight)
  333. var direction = 0;
  334. if (that.data.vedio_size_height > that.data.video_size_width) {
  335. direction = -90;
  336. }
  337. console.log(direction);
  338. var need_height = (windowWidth * that.data.vedio_size_height) / that.data.video_size_width;
  339. if (need_height > windowHeight) {
  340. need_height = windowHeight - 8;
  341. }
  342. that.setData({
  343. video_height: need_height,
  344. hide_video: false,
  345. direction: direction
  346. })
  347. that.videoContext.play();
  348. that.videoContext.requestFullScreen();
  349. }
  350. })
  351. },
  352. imageLoad: function (e) {
  353. var imageSize = util.imageUtil(e)
  354. this.setData({
  355. imagewidth: imageSize.imageWidth,
  356. imageheight: imageSize.imageHeight
  357. })
  358. },
  359. close_video: function () {
  360. var that = this;
  361. that.videoContext.pause();
  362. that.setData({
  363. hide_video: true
  364. })
  365. },
  366. goOrderfrom: function (e) {
  367. var from_id = e.detail.formId;
  368. var token = wx.getStorageSync('token');
  369. app.util.request({
  370. 'url': 'entry/wxapp/user',
  371. 'data': {
  372. controller: 'user.get_member_form_id',
  373. 'token': token,
  374. "from_id": from_id
  375. },
  376. dataType: 'json',
  377. success: function (res) {
  378. }
  379. })
  380. this.goOrder();
  381. },
  382. goGoods: function (event) {
  383. let id = event.currentTarget.dataset.type;
  384. var pages_all = getCurrentPages();
  385. if (pages_all.length > 3) {
  386. wx.redirectTo({
  387. url: '/pages/goods/index?id=' + id
  388. })
  389. } else {
  390. wx.navigateTo({
  391. url: '/pages/goods/index?id=' + id
  392. })
  393. }
  394. },
  395. socketmsg: function () {
  396. wx.closeSocket();
  397. var domain = util.getdomain();
  398. var self = this;
  399. wx.connectSocket({
  400. url: 'wss://mall.shiziyu888.com/wss',
  401. header: {
  402. 'content-type': 'application/json'
  403. },
  404. method: "GET"
  405. })
  406. wx.onSocketOpen(function (res) {
  407. var login_data = '{ "type":"membre_login","domain":"' + domain + '"} ';
  408. wx.sendSocketMessage({
  409. data: login_data
  410. });
  411. setTimeout(function () {
  412. var ck_lo_pt = util.api() + "/index.php?s=/Apigoods/notify_order/rt/28163.html";
  413. wx.request({
  414. url: ck_lo_pt,
  415. type: 'get',
  416. dataType: 'json',
  417. success: function (res) {
  418. if (res.data.ret == 1) {
  419. self.send_bao_notify(res.data);
  420. }
  421. }
  422. })
  423. }, 1000);
  424. setInterval(function () {
  425. if (self.data.jarray.length > 0) {
  426. var res = self.data.jarray.pop();
  427. self.show_or(res);
  428. }
  429. }, 4000);
  430. })
  431. wx.onSocketMessage(function (res) {
  432. var data = util.stringToJson(res.data);
  433. console.log(data);
  434. switch (data.type) {
  435. // 服务端ping客户端
  436. case 'ping':
  437. var pong_data = '{"type":"pong"}';
  438. wx.sendSocketMessage({
  439. data: pong_data
  440. });
  441. break;
  442. case 'member_buy_msg':
  443. var jarray_str = self.data.jarray;
  444. jarray_str.push(data);
  445. self.setData({
  446. jarray: jarray_str
  447. });
  448. //this.on_member_buy_msg(data);
  449. break;
  450. }
  451. })
  452. wx.onSocketError(function (res) {
  453. console.log('WebSocket连接打开失败,请检查!')
  454. })
  455. },
  456. send_bao_notify: function (res) {
  457. var buy_data = '{ "type":"member_buy","avatar":"' + res.avatar + '","miao":"' + res.miao + '","username":"' + res.username + '","order_id":"' + res.order_id + '","order_url":"' + res.order_url + '"} ';
  458. wx.sendSocketMessage({
  459. data: buy_data
  460. });
  461. },
  462. show_or: function (res) {
  463. this.setData({
  464. notice_orderid: res.order_id,
  465. notice_avatar: res.avatar,
  466. notice_name: res.username,
  467. notice_miao: res.miao,
  468. isHidenotice: false
  469. });
  470. var self = this;
  471. setTimeout(function () {
  472. self.setData({
  473. isHidenotice: true
  474. })
  475. setTimeout(function () {
  476. if (self.data.jarray.length > 0) {
  477. var res = self.data.jarray.pop();
  478. self.show_or(res);
  479. }
  480. }, 3000);
  481. }, 2000);
  482. },
  483. ck_tab: function (e) {
  484. var rel = e.currentTarget.dataset.rel;
  485. this.setData({
  486. show_detail: rel
  487. })
  488. },
  489. goRewardList: function () {
  490. var goods_id = this.data.order.goods_id;
  491. var pages_all = getCurrentPages();
  492. if (pages_all.length > 3) {
  493. wx.redirectTo({
  494. url: '/pages/goods/lotteryinfo?id=' + goods_id
  495. })
  496. } else {
  497. wx.navigateTo({
  498. url: '/pages/goods/lotteryinfo?id=' + goods_id
  499. })
  500. }
  501. },
  502. noticego: function (e) {
  503. var orderid = e.currentTarget.dataset.orderid;
  504. var pages_all = getCurrentPages();
  505. if (pages_all.length > 3) {
  506. wx.redirectTo({
  507. url: '/pages/share/index?id=' + orderid
  508. })
  509. } else {
  510. wx.navigateTo({
  511. url: '/pages/share/index?id=' + orderid
  512. })
  513. }
  514. },
  515. navShow: function () {
  516. this.setData({
  517. navState: 1
  518. })
  519. },
  520. navHide: function () {
  521. this.setData({
  522. navState: 0
  523. })
  524. },
  525. bindGetUserInfo: function (e) {
  526. var id = this.data.goods.goods_id;
  527. util.login('/Snailfish_shop/pages/goods/index?id=' + id);
  528. this.setData({
  529. is_login: true
  530. })
  531. },
  532. goBuy: function (event) {
  533. var that = this;
  534. var buy_type = event.currentTarget.dataset.type;
  535. var is_car = event.currentTarget.dataset.is_car;
  536. if (is_car == undefined) {
  537. this.setData({
  538. is_addcar: false
  539. })
  540. } else {
  541. this.setData({
  542. is_addcar: true
  543. })
  544. }
  545. var order = that.data.order;
  546. order.buy_type = buy_type;
  547. order.quantity = 1;
  548. var skudanprice = this.data.skudanprice;
  549. var skupin_price = this.data.skupin_price;
  550. //goods.danprice:pin_info.pin_price
  551. //order.buy_type=='dan'?goods.danprice:pin_info.pin_price
  552. if (order.buy_type == 'dan') {
  553. skudanprice = this.data.goods.danprice;
  554. }
  555. else {
  556. skupin_price = this.data.pin_info.pin_price;
  557. }
  558. //skudanprice:skupin_price
  559. this.setData({
  560. order: order,
  561. skudanprice: skudanprice,
  562. skupin_price: skupin_price
  563. })
  564. if (that.data.options.list.length > 0) {
  565. let list = that.data.options.list;
  566. let arr = [];
  567. for (let i = 0; i < list.length; i++) {
  568. let sku = list[i]['option_value'][0];
  569. let temp = {
  570. name: sku['name'],
  571. id: sku['option_value_id'],
  572. index: i,
  573. idx: 0
  574. };
  575. arr.push(temp);
  576. }
  577. //把单价剔除出来begin
  578. var id = '';
  579. for (let i = 0; i < arr.length; i++) {
  580. if (i == arr.length - 1) {
  581. id = id + arr[i]['id'];
  582. } else {
  583. id = id + arr[i]['id'] + "_";
  584. }
  585. }
  586. var that = this;
  587. var token = wx.getStorageSync('token');
  588. app.util.request({
  589. 'url': 'entry/wxapp/index',
  590. 'data': {
  591. controller: 'goods.get_goods_option_data',
  592. 'id': that.data.goods.goods_id,
  593. 'sku_str': id,
  594. 'token': token
  595. },
  596. dataType: 'json',
  597. success: function (res) {
  598. var goods = that.data.goods;
  599. goods.quantity = res.data.data.value.quantity;
  600. goods.image = res.data.data.value.image;
  601. goods.danprice = res.data.data.value.dan_price;
  602. goods.memberprice = res.data.data.value.memberprice;
  603. that.setData({
  604. goods: goods,
  605. max_get_money: res.data.data.value.max_member_pin_price,
  606. skudanprice: goods.danprice
  607. })
  608. var pin_info = that.data.pin_info;
  609. pin_info.pin_price = res.data.data.value.pin_price;
  610. pin_info.member_pin_price = res.data.data.value.member_pin_price;
  611. that.setData({
  612. pin_info: pin_info,
  613. skupin_price: pin_info.pin_price
  614. })
  615. }
  616. })
  617. //end
  618. that.setData({
  619. sku: arr,
  620. skustate: 1
  621. })
  622. } else {
  623. that.goOrder();
  624. }
  625. },
  626. closeSku: function () {
  627. this.setData({
  628. skustate: 0
  629. })
  630. },
  631. goOrder: function () {
  632. var token = wx.getStorageSync('token');
  633. var that = this;
  634. if (that.data.can_car) {
  635. that.data.can_car = false;
  636. }
  637. var is_just_addcar = 0;
  638. if (that.data.is_addcar) {
  639. is_just_addcar = 1;
  640. }
  641. if (that.data.options.list.length > 0) {
  642. var id = '';
  643. let arr = that.data.sku;
  644. for (let i = 0; i < arr.length; i++) {
  645. if (i == arr.length - 1) {
  646. id = id + arr[i]['id'];
  647. } else {
  648. id = id + arr[i]['id'] + "_";
  649. }
  650. }
  651. var order = that.data.order;
  652. order.sku_str = id;
  653. that.setData({
  654. order: order
  655. })
  656. }
  657. app.util.request({
  658. 'url': 'entry/wxapp/user',
  659. 'data': {
  660. controller: 'car.add',
  661. 'token': token,
  662. "goods_id": that.data.order.goods_id,
  663. "quantity": that.data.order.quantity,
  664. "sku_str": that.data.order.sku_str,
  665. "buy_type": that.data.order.buy_type,
  666. "pin_id": that.data.order.pin_id,
  667. "is_just_addcar": is_just_addcar
  668. },
  669. dataType: 'json',
  670. method: 'POST',
  671. success: function (res) {
  672. //console.log(res);
  673. if (res.data.code == 3) {
  674. wx.showToast({
  675. title: res.data.msg,
  676. icon: 'none',
  677. duration: 2000
  678. })
  679. } else if (res.data.code == 4) {
  680. var id = that.data.goods.goods_id;
  681. wx.showToast({
  682. title: '您未登录',
  683. icon: 'loading',
  684. duration: 2000,
  685. complete:function(){
  686. wx.setStorage({
  687. key: "member_id",
  688. data: null
  689. })
  690. wx.redirectTo({
  691. url: '/Snailfish_shop/pages/goods/index?id=' + id
  692. })
  693. }
  694. })
  695. } else if (res.data.code == 6) {
  696. var msg = res.data.msg;
  697. wx.showToast({
  698. title: msg,
  699. icon: 'none',
  700. duration: 2000
  701. })
  702. } else {
  703. if (is_just_addcar == 1) {
  704. that.closeSku();
  705. wx.showToast({
  706. title: '加入购物车成功',
  707. duration: 2000
  708. })
  709. } else {
  710. var pages_all = getCurrentPages();
  711. if (pages_all.length > 3) {
  712. wx.redirectTo({
  713. url: '/Snailfish_shop/pages/buy/index?type=' + that.data.order.buy_type
  714. })
  715. } else {
  716. wx.navigateTo({
  717. url: '/Snailfish_shop/pages/buy/index?type=' + that.data.order.buy_type
  718. })
  719. }
  720. }
  721. }
  722. }
  723. })
  724. },
  725. setNum: function (event) {
  726. let types = event.currentTarget.dataset.type;
  727. var num = 1;
  728. if (types == 'add') {
  729. num = this.data.order.quantity + 1;
  730. } else if (types == 'decrease') {
  731. if (this.data.order.quantity > 1) {
  732. num = this.data.order.quantity - 1;
  733. }
  734. }
  735. var order = this.data.order;
  736. order.quantity = num;
  737. this.setData({
  738. order: order
  739. })
  740. },
  741. goShare: function (event) {
  742. let id = event.currentTarget.dataset.type;
  743. var pages_all = getCurrentPages();
  744. if (pages_all.length > 3) {
  745. wx.redirectTo({
  746. url: '/pages/share/index?id=' + id
  747. })
  748. } else {
  749. wx.navigateTo({
  750. url: '/pages/share/index?id=' + id
  751. })
  752. }
  753. },
  754. goLink_direct: function (event) {
  755. let link = event.currentTarget.dataset.link;
  756. var pages_all = getCurrentPages();
  757. wx.reLaunch({
  758. url: link
  759. })
  760. },
  761. goLink: function (event) {
  762. let link = event.currentTarget.dataset.link;
  763. var pages_all = getCurrentPages();
  764. wx.reLaunch({
  765. url: link
  766. })
  767. },
  768. go_goods_comment: function () {
  769. var goods = this.data.goods;
  770. var pages_all = getCurrentPages();
  771. if (pages_all.length > 3) {
  772. wx.redirectTo({
  773. url: '/Snailfish_shop/pages/goods/comment?id=' + goods.goods_id
  774. })
  775. } else {
  776. wx.navigateTo({
  777. url: '/Snailfish_shop/pages/goods/comment?id=' + goods.goods_id
  778. })
  779. }
  780. },
  781. gokefu: function () {
  782. //跳入客服
  783. },
  784. goStore: function (event) {
  785. let id = event.currentTarget.dataset.type;
  786. var pages_all = getCurrentPages();
  787. if (pages_all.length > 3) {
  788. wx.redirectTo({
  789. url: '/pages/store/index?id=' + id
  790. })
  791. } else {
  792. wx.navigateTo({
  793. url: '/pages/store/index?id=' + id
  794. })
  795. }
  796. },
  797. openSku: function (event) {
  798. var that = this;
  799. var buy_type = event.currentTarget.dataset.type;
  800. var order = that.data.order;
  801. order.buy_type = buy_type;
  802. order.quantity = 1;
  803. var skudanprice = this.data.skudanprice;
  804. var skupin_price = this.data.skupin_price;
  805. if (order.buy_type == 'dan') {
  806. skudanprice = this.data.goods.danprice;
  807. } else {
  808. skupin_price = this.data.pin_info.pin_price;
  809. }
  810. //skudanprice:skupin_price
  811. this.setData({
  812. order: order,
  813. skudanprice: skudanprice,
  814. skupin_price: skupin_price
  815. })
  816. if (that.data.options.list.length > 0) {
  817. let list = that.data.options.list;
  818. let arr = [];
  819. for (let i = 0; i < list.length; i++) {
  820. let sku = list[i]['option_value'][0];
  821. let temp = {
  822. name: sku['name'],
  823. id: sku['option_value_id'],
  824. index: i,
  825. idx: 0
  826. };
  827. arr.push(temp);
  828. }
  829. //把单价剔除出来begin
  830. var id = '';
  831. for (let i = 0; i < arr.length; i++) {
  832. if (i == arr.length - 1) {
  833. id = id + arr[i]['id'];
  834. } else {
  835. id = id + arr[i]['id'] + "_";
  836. }
  837. }
  838. var that = this;
  839. var token = wx.getStorageSync('token');
  840. app.util.request({
  841. 'url': 'entry/wxapp/index',
  842. 'data': {
  843. controller: 'goods.get_goods_option_data',
  844. 'id': that.data.goods.goods_id,
  845. 'sku_str': id,
  846. 'token': token
  847. },
  848. dataType: 'json',
  849. success: function (res) {
  850. var goods = that.data.goods;
  851. goods.quantity = res.data.data.value.quantity;
  852. goods.image = res.data.data.value.image;
  853. goods.danprice = res.data.data.value.dan_price;
  854. goods.memberprice = res.data.data.value.memberprice;
  855. that.setData({
  856. goods: goods,
  857. max_get_money: res.data.data.value.max_member_pin_price,
  858. skudanprice: goods.danprice
  859. })
  860. var pin_info = that.data.pin_info;
  861. pin_info.pin_price = res.data.data.value.pin_price;
  862. pin_info.member_pin_price = res.data.data.value.member_pin_price;
  863. that.setData({
  864. pin_info: pin_info,
  865. skupin_price: pin_info.pin_price
  866. })
  867. }
  868. })
  869. //end
  870. that.setData({
  871. sku: arr,
  872. skustate: 1
  873. })
  874. } else {
  875. that.goOrder();
  876. }
  877. },
  878. selectSku: function (event) {
  879. var that = this;
  880. let str = event.currentTarget.dataset.type;
  881. let obj = str.split("_");
  882. let arr = that.data.sku;
  883. let temp = {
  884. name: obj[3],
  885. id: obj[2],
  886. index: obj[0],
  887. idx: obj[1]
  888. };
  889. arr.splice(obj[0], 1, temp);
  890. that.setData({
  891. sku: arr
  892. })
  893. var id = '';
  894. for (let i = 0; i < arr.length; i++) {
  895. if (i == arr.length - 1) {
  896. id = id + arr[i]['id'];
  897. } else {
  898. id = id + arr[i]['id'] + "_";
  899. }
  900. }
  901. var token = wx.getStorageSync('token');
  902. app.util.request({
  903. 'url': 'entry/wxapp/index',
  904. 'data': {
  905. controller: 'goods.get_goods_option_data',
  906. 'id': that.data.goods.goods_id,
  907. 'sku_str': id,
  908. 'token': token
  909. },
  910. dataType: 'json',
  911. success: function (res) {
  912. var goods = that.data.goods;
  913. goods.quantity = res.data.data.value.quantity;
  914. goods.image_thumb = res.data.data.value.image;
  915. goods.danprice = res.data.data.value.dan_price;
  916. goods.memberprice = res.data.data.value.memberprice;
  917. that.setData({
  918. goods: goods,
  919. max_get_money: res.data.data.value.max_member_pin_price,
  920. skudanprice: goods.danprice
  921. })
  922. var pin_info = that.data.pin_info;
  923. pin_info.pin_price = res.data.data.value.pin_price;
  924. pin_info.member_pin_price = res.data.data.value.member_pin_price;
  925. that.setData({
  926. pin_info: pin_info,
  927. skupin_price: pin_info.pin_price
  928. })
  929. }
  930. })
  931. },
  932. radioChange: function (e) {
  933. this.setData({
  934. inputValue: e.detail.value
  935. })
  936. },
  937. showDialogBtn: function () {
  938. this.setData({
  939. showModal: true
  940. })
  941. },
  942. charge_form: function () {
  943. this.setData({
  944. showModal: true
  945. })
  946. },
  947. hideModal: function () {
  948. this.setData({
  949. showModal: false
  950. });
  951. },
  952. onCancel: function () {
  953. this.hideModal();
  954. },
  955. onConfirm: function () {
  956. if (this.data.member_level_info.level_id == this.data.inputValue) {
  957. this.hideModal();
  958. return false;
  959. }
  960. var money = parseFloat(this.data.inputValue);
  961. if (money <= 0) {
  962. wx.showToast({
  963. title: '请选择升级等级',
  964. icon: 'none',
  965. duration: 2000
  966. })
  967. } else {
  968. this.hideModal();
  969. var that = this;
  970. var token = wx.getStorageSync('token');
  971. wx.request({
  972. url: util.api() + 'index.php?s=/Apicheckout/wxcharge/token/' + token + '/money/' + money,
  973. success: function (res) {
  974. wx.requestPayment({
  975. "appId": res.data.appId,
  976. "timeStamp": res.data.timeStamp,
  977. "nonceStr": res.data.nonceStr,
  978. "package": res.data.package,
  979. "signType": res.data.signType,
  980. "paySign": res.data.paySign,
  981. 'success': function (wxres) {
  982. wx.showToast({
  983. title: '升级成功',
  984. })
  985. setTimeout(() => {
  986. var share_path = '/pages/goods/index?id=' + that.data.goods.goods_id + '&charge_suc=1';
  987. wx.redirectTo({
  988. url: share_path
  989. })
  990. }, 2000)
  991. },
  992. 'fail': function (res) {
  993. console.log(res);
  994. }
  995. })
  996. }
  997. })
  998. }
  999. },
  1000. favtoggle: function () {
  1001. let that = this;
  1002. var token = wx.getStorageSync('token');
  1003. app.util.request({
  1004. 'url': 'entry/wxapp/user',
  1005. 'data': {
  1006. controller: 'user.fav_toggle',
  1007. 'token': token,
  1008. goods_id: that.data.goods.goods_id
  1009. },
  1010. dataType: 'json',
  1011. success: function (res) {
  1012. that.setData({
  1013. favgoods: res.data.code
  1014. })
  1015. }
  1016. })
  1017. wx.request({
  1018. url: util.api() + 'index.php?s=/Apiuser/fav_toggle/goods_id/' + that.data.goods.goods_id + '/token/' + token,
  1019. success: function (res) {
  1020. that.setData({
  1021. favgoods: res.data.code
  1022. })
  1023. }
  1024. })
  1025. },
  1026. onShareAppMessage: function (res) {
  1027. var share_title = this.data.share_title;
  1028. var share_id = wx.getStorageSync('member_id');
  1029. var share_path = 'pages/goods/index?id=' + this.data.goods.goods_id + '&share_id=' + share_id;
  1030. var that = this;
  1031. return {
  1032. title: share_title,
  1033. path: share_path,
  1034. success: function (res) {
  1035. // 转发成功
  1036. that.setData({
  1037. is_share_html: true
  1038. })
  1039. },
  1040. fail: function (res) {
  1041. // 转发失败
  1042. that.setData({
  1043. is_share_html: true
  1044. })
  1045. }
  1046. }
  1047. }
  1048. })