goodsDetail.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. // lionfish_comshop/pages/goods/goodsDetail.js
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. var app = getApp();
  5. var detailClearTime = null;
  6. function count_down(that, total_micro_second) {
  7. var second = Math.floor(total_micro_second / 1000);
  8. var days = second / 3600 / 24;
  9. var daysRound = Math.floor(days);
  10. var hours = second / 3600 - (24 * daysRound);
  11. var hoursRound = Math.floor(hours);
  12. var minutes = second / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
  13. var minutesRound = Math.floor(minutes);
  14. var seconds = second - (24 * 3600 * daysRound) - (3600 * hoursRound) - (60 * minutesRound);
  15. that.setData({
  16. endtime: {
  17. days: fill_zero_prefix(daysRound),
  18. hours: fill_zero_prefix(hoursRound),
  19. minutes: fill_zero_prefix(minutesRound),
  20. seconds: fill_zero_prefix(seconds),
  21. show_detail: 1
  22. }
  23. });
  24. if (total_micro_second <= 0) {
  25. clearTimeout(detailClearTime);
  26. detailClearTime = null;
  27. if (that.data.goods.over_type == 0) {
  28. that.authSuccess();
  29. }
  30. that.setData({
  31. endtime: {
  32. days: "00",
  33. hours: "00",
  34. minutes: "00",
  35. seconds: "00",
  36. }
  37. });
  38. return;
  39. }
  40. detailClearTime = setTimeout(function () {
  41. total_micro_second -= 1000;
  42. count_down(that, total_micro_second);
  43. }, 1000)
  44. }
  45. // 位数不足补零
  46. function fill_zero_prefix(num) {
  47. return num < 10 ? "0" + num : num
  48. }
  49. Page({
  50. mixins: [require('../../mixin/globalMixin.js')],
  51. data: {
  52. needAuth: false,
  53. goodsIndex: 1,
  54. goods_id: 0,
  55. endtime: {
  56. days: "00",
  57. hours: "00",
  58. minutes: "00",
  59. seconds: "00",
  60. },
  61. is_share_html: true,
  62. imageSize: {
  63. imageWidth: "100%",
  64. imageHeight: 600
  65. },
  66. cartNum: 0,
  67. noIns: false,
  68. index_bottom_image: '',
  69. hideModal: true,
  70. shareImgUrl: '',
  71. goods_details_middle_image: '',
  72. is_show_buy_record: 0,
  73. stopNotify: true,
  74. iconArr: {
  75. home: '',
  76. car: ''
  77. },
  78. canvasWidth: 375,
  79. canvasHeight: 300,
  80. fmShow: true,
  81. pinListCount: 0,
  82. pinList: [],
  83. needPosition: false,
  84. groupInfo: {
  85. group_name: '社区',
  86. owner_name: '团长'
  87. }
  88. },
  89. $data: {
  90. id: '',
  91. scene: ''
  92. },
  93. imageUrl: '',
  94. goodsImg: '',
  95. currentOptions: [],
  96. buy_type: 'pindan',
  97. canPreSub: true,
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function (options) {
  102. app.setShareConfig();
  103. app.globalData.navBackUrl = '';
  104. var that = this;
  105. status.setNavBgColor();
  106. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  107. status.setIcon().then(function (iconArr) {
  108. that.setData({ iconArr });
  109. });
  110. var scene = decodeURIComponent(options.scene);
  111. this.$data.id = options.id;
  112. this.$data.scene = options.scene;
  113. if (scene !== 'undefined') {
  114. var opt_arr = scene.split("_");
  115. options.id = opt_arr[0];
  116. options.share_id = opt_arr[1];
  117. options.community_id = opt_arr[2];
  118. }
  119. if (options.community_id !== 'undefined' && options.community_id > 0) {
  120. this.$data.community_id = options.community_id;
  121. }
  122. wx.showLoading();
  123. if (options.share_id != 'undefined' && options.share_id > 0) wx.setStorage({ key: "share_id", data: options.share_id })
  124. this.get_goods_details(options.id);
  125. this.get_instructions();
  126. this.setData({
  127. canvasWidth: app.globalData.systemInfo.windowWidth,
  128. canvasHeight: 0.8 * app.globalData.systemInfo.windowWidth,
  129. goods_id: options.id
  130. })
  131. },
  132. get_goods_details: function (id) {
  133. let that = this;
  134. if (!id) {
  135. wx.hideLoading();
  136. wx.showModal({
  137. title: '提示',
  138. content: '参数错误',
  139. showCancel: false,
  140. confirmColor: '#F75451',
  141. success(res) {
  142. if (res.confirm) {
  143. wx.redirectTo({
  144. url: '/lionfish_comshop/pages/index/index',
  145. })
  146. }
  147. }
  148. })
  149. return false;
  150. }
  151. this.getFujinTuan(id);
  152. let token = wx.getStorageSync('token');
  153. let community = wx.getStorageSync('community');
  154. let community_id = community.communityId || 0;
  155. app.util.request({
  156. url: 'entry/wxapp/index',
  157. data: {
  158. controller: 'groupdo.get_goods_detail',
  159. token: token,
  160. id,
  161. community_id
  162. },
  163. dataType: 'json',
  164. success: function (res) {
  165. wx.hideLoading();
  166. let goods = (res.data.data && res.data.data.goods) || '';
  167. // 商品不存在
  168. if (!goods || goods.length == 0 || Object.keys(goods) == '') {
  169. wx.showModal({
  170. title: '提示',
  171. content: '该商品不存在,回首页',
  172. showCancel: false,
  173. confirmColor: '#F75451',
  174. success(res) {
  175. if (res.confirm) {
  176. wx.redirectTo({
  177. url: '/lionfish_comshop/moduleA/pin/index',
  178. })
  179. }
  180. }
  181. })
  182. }
  183. let comment_list = res.data.comment_list;
  184. comment_list.map(function (item) {
  185. 14 * item.content.length / app.globalData.systemInfo.windowWidth > 3 && (item.showOpen = true), item.isOpen = true;
  186. })
  187. // 幻灯片预览数组
  188. let goods_images = res.data.data.goods_image;
  189. let prevImgArr = [];
  190. goods_images.forEach(function (item) { prevImgArr.push(item.image); })
  191. that.currentOptions = res.data.data.options;
  192. let pin_info = res.data.data.pin_info || {};
  193. // 开启社区
  194. let pintuan_model_buy = res.data.pintuan_model_buy || 0;
  195. let is_comunity_rest = res.data.is_comunity_rest || 0;
  196. let needPosition = false;
  197. if (pintuan_model_buy==1) {
  198. needPosition = true;
  199. // 团长休息
  200. if (is_comunity_rest==1) {
  201. wx.showModal({
  202. title: '温馨提示',
  203. content: '团长休息中,欢迎下次光临!',
  204. showCancel: false,
  205. confirmColor: '#F75451',
  206. confirmText: '好的',
  207. success(res) { }
  208. })
  209. }
  210. that.needCommunity();
  211. }
  212. that.setData({
  213. needPosition,
  214. pintuan_model_buy,
  215. is_comunity_rest,
  216. order_comment_count: res.data.order_comment_count,
  217. comment_list: comment_list,
  218. goods: goods,
  219. options: res.data.data.options,
  220. order: {
  221. goods_id: res.data.data.goods.goods_id,
  222. pin_id: res.data.data.pin_id,
  223. },
  224. share_title: goods.share_title,
  225. buy_record_arr: res.data.data.buy_record_arr,
  226. goods_image: res.data.data.goods_image,
  227. goods_image_length: res.data.data.goods_image.length,
  228. service: goods.tag,
  229. showSkeleton: false,
  230. is_comunity_rest: res.data.is_comunity_rest,
  231. prevImgArr,
  232. open_man_orderbuy: res.data.open_man_orderbuy,
  233. man_orderbuy_money: res.data.man_orderbuy_money,
  234. goodsdetails_addcart_bg_color: res.data.goodsdetails_addcart_bg_color || 'linear-gradient(270deg, #f9c706 0%, #feb600 100%)',
  235. goodsdetails_buy_bg_color: res.data.goodsdetails_buy_bg_color || 'linear-gradient(90deg, #ff5041 0%, #ff695c 100%)',
  236. pin_info,
  237. pintuan_close_stranger: res.data.pintuan_close_stranger,
  238. is_need_subscript: res.data.is_need_subscript,
  239. need_subscript_template: res.data.need_subscript_template
  240. }, () => {
  241. let goods_share_image = goods.goods_share_image;
  242. if (goods_share_image) {
  243. console.log('draw分享图');
  244. status.download(goods_share_image + "?imageView2/1/w/500/h/400").then(function (a) {
  245. that.goodsImg = a.tempFilePath, that.drawImgNoPrice();
  246. });
  247. } else {
  248. console.log('draw价格');
  249. let shareImg = goods.image_thumb;
  250. status.download(shareImg + "?imageView2/1/w/500/h/400").then(function (a) {
  251. that.goodsImg = a.tempFilePath, that.drawImg();
  252. });
  253. }
  254. })
  255. let over_type = goods.over_type;
  256. var seconds = 0;
  257. if (over_type == 0) {
  258. seconds = (goods.begin_time - res.data.data.cur_time) * 1000;
  259. } else {
  260. seconds = (goods.end_time - res.data.data.cur_time) * 1000;
  261. }
  262. if (seconds > 0) {
  263. count_down(that, seconds);
  264. }
  265. }
  266. })
  267. },
  268. /**
  269. * 需要社区
  270. * 判断是否已绑定
  271. */
  272. needCommunity: function () {
  273. let that = this;
  274. console.log('需要社区')
  275. let token = wx.getStorageSync('token');
  276. //当前社区
  277. let currentCommunity = wx.getStorageSync('community');
  278. let currentCommunityId = (currentCommunity && currentCommunity.communityId) || '';
  279. let shareCommunityId = this.$data.community_id;
  280. console.log('shareCommunityId', shareCommunityId)
  281. // 单社区
  282. util.getCommunityById(shareCommunityId).then(res => {
  283. if (res.open_danhead_model == 1) {
  284. let default_head_info = res.default_head_info;
  285. app.globalData.community = default_head_info;
  286. app.globalData.changedCommunity = true;
  287. wx.setStorage({ key: "community", data: default_head_info })
  288. that.setData({ community: default_head_info })
  289. token && that.addhistory(default_head_info);
  290. } else {
  291. // 社区是否存在
  292. if (currentCommunityId != '') {
  293. // 存在并且不相同
  294. console.log('currentCommunityId存在 比较社区')
  295. if (currentCommunityId != shareCommunityId) {
  296. console.log('currentCommunityId存在 社区不同')
  297. if (res.data) {
  298. that.setData({
  299. showChangeCommunity: true,
  300. changeCommunity: res.data,
  301. community: currentCommunity
  302. })
  303. }
  304. }
  305. } else {
  306. // 不存在社区id
  307. //token 是否存在
  308. if (token) {
  309. util.getCommunityInfo().then(function (ret) {
  310. //比较社区
  311. console.log('token存在 比较社区')
  312. if (ret.community_id && ret.community_id != shareCommunityId) {
  313. that.setData({
  314. showChangeCommunity: true,
  315. changeCommunity: res.data,
  316. community: currentCommunity
  317. })
  318. }
  319. }).catch((param) => {
  320. console.log('step4 新人')
  321. if (Object.keys(param) != '') that.addhistory(param, true);
  322. });
  323. } else {
  324. console.log('token不存在 存社区')
  325. // 直接存本地
  326. app.globalData.community = res.data;
  327. app.globalData.changedCommunity = true;
  328. wx.setStorage({ key: "community", data: res.data })
  329. that.setData({ community: res.data })
  330. }
  331. }
  332. }
  333. })
  334. },
  335. /**
  336. * 切换提示
  337. */
  338. confrimChangeCommunity: function () {
  339. let community = this.data.changeCommunity;
  340. let token = wx.getStorageSync('token');
  341. app.globalData.community = community;
  342. app.globalData.changedCommunity = true;
  343. wx.setStorage({
  344. key: "community",
  345. data: community
  346. })
  347. token && this.addhistory(community);
  348. this.setData({ community, showChangeCommunity: false })
  349. this.get_goods_details(this.data.goods_id, community, community.communityId);
  350. console.log('用户点击确定')
  351. },
  352. /**
  353. * 历史社区
  354. */
  355. addhistory: function (community, isNew = false) {
  356. var community_id = community.communityId;
  357. console.log('addhistory');
  358. var token = wx.getStorageSync('token');
  359. app.util.request({
  360. url: 'entry/wxapp/index',
  361. data: {
  362. controller: 'index.addhistory_community',
  363. community_id: community_id,
  364. token: token
  365. },
  366. dataType: 'json',
  367. success: function (res) {
  368. if (isNew) {
  369. console.log('新人 社区')
  370. app.util.request({
  371. 'url': 'entry/wxapp/index',
  372. 'data': {
  373. controller: 'index.get_community_info',
  374. community_id: community_id
  375. },
  376. dataType: 'json',
  377. success: function (result) {
  378. if (result.data.code == 0) {
  379. let community = result.data.data;
  380. app.globalData.community = community;
  381. app.globalData.changedCommunity = true;
  382. wx.setStorage({ key: "community", data: community })
  383. }
  384. }
  385. })
  386. }
  387. }
  388. })
  389. },
  390. /**
  391. * 授权成功回调
  392. */
  393. authSuccess: function () {
  394. var id = this.$data.id;
  395. var scene = this.$data.scene;
  396. let url = '/lionfish_comshop/moduleA/pin/goodsDetail?id=' + id + '&scene=' + scene;
  397. app.globalData.navBackUrl = url;
  398. wx.redirectTo({ url })
  399. },
  400. authModal: function () {
  401. if (this.data.needAuth) {
  402. this.setData({ showAuthModal: !this.data.showAuthModal });
  403. return false;
  404. }
  405. return true;
  406. },
  407. /**
  408. * 生命周期函数--监听页面显示
  409. */
  410. onShow: function () {
  411. let that = this;
  412. util.check_login_new().then((res) => {
  413. if (!res) {
  414. that.setData({
  415. needAuth: true
  416. })
  417. } else {
  418. (0, status.cartNum)('', true).then((res) => {
  419. res.code == 0 && that.setData({
  420. cartNum: res.data
  421. })
  422. });
  423. }
  424. })
  425. this.setData({
  426. stopNotify: false
  427. });
  428. },
  429. /**
  430. * 图片信息
  431. */
  432. imageLoad: function (e) {
  433. var imageSize = util.imageUtil(e)
  434. this.setData({
  435. imageSize
  436. })
  437. },
  438. /**
  439. * 获取服务信息
  440. */
  441. get_instructions: function () {
  442. let that = this;
  443. app.util.request({
  444. 'url': 'entry/wxapp/index',
  445. 'data': {
  446. controller: 'goods.get_instructions'
  447. },
  448. dataType: 'json',
  449. success: function (res) {
  450. if (res.data.code == 0) {
  451. var instructions = res.data.data.value;
  452. if (instructions == '') that.setData({ noIns: true })
  453. that.setData({
  454. instructions,
  455. index_bottom_image: res.data.data.index_bottom_image,
  456. goods_details_middle_image: res.data.data.goods_details_middle_image,
  457. is_show_buy_record: res.data.data.is_show_buy_record,
  458. order_notify_switch: res.data.data.order_notify_switch,
  459. is_show_comment_list: res.data.data.is_show_comment_list,
  460. goods_details_price_bg: res.data.data.goods_details_price_bg,
  461. isShowContactBtn: res.data.data.index_service_switch || 0,
  462. goods_industrial_switch: res.data.data.goods_industrial_switch || 0,
  463. goods_industrial: res.data.data.goods_industrial || '',
  464. is_show_ziti_time: res.data.data.is_show_ziti_time || 0,
  465. hide_community_change_btn: res.data.data.hide_community_change_btn || 0,
  466. is_show_goodsdetails_communityinfo: res.data.data.is_show_goodsdetails_communityinfo || 0
  467. })
  468. }
  469. }
  470. })
  471. },
  472. getFujinTuan: function (goods_id){
  473. let that = this;
  474. let community = wx.getStorageSync('community');
  475. let head_id = community.communityId || 0;
  476. app.util.request({
  477. url: 'entry/wxapp/index',
  478. data: {
  479. controller: 'groupdo.get_goods_fujin_tuan',
  480. goods_id,
  481. limit: 4,
  482. head_id
  483. },
  484. dataType: 'json',
  485. success: function (res) {
  486. if (res.data.code == 0) {
  487. let { list, count } = res.data;
  488. if (list.length) {
  489. let timestamp = Date.parse(new Date());
  490. list.forEach((item, index)=>{
  491. list[index].seconds = (item.end_time - item.cur_interface_time)*1000 + timestamp;
  492. console.log((item.end_time - item.cur_interface_time))
  493. })
  494. }
  495. that.setData({
  496. pinList: list || [],
  497. pinListCount: count || 0
  498. })
  499. }
  500. }
  501. })
  502. },
  503. /**
  504. * 打开购物车
  505. */
  506. openSku: function (t) {
  507. if (!this.authModal()) return;
  508. this.canPreSub = true;
  509. var that = this;
  510. var is_just_addcar = 0;
  511. var goods_id = this.data.goods_id;
  512. var options = this.currentOptions;
  513. that.setData({ addCar_goodsid: goods_id })
  514. let list = options.list || [];
  515. let arr = [];
  516. if (list.length > 0) {
  517. for (let i = 0; i < list.length; i++) {
  518. let sku = list[i]['option_value'][0];
  519. let temp = {
  520. name: sku['name'],
  521. id: sku['option_value_id'],
  522. index: i,
  523. idx: 0
  524. };
  525. arr.push(temp);
  526. }
  527. //把单价剔除出来begin
  528. var id = '';
  529. for (let i = 0; i < arr.length; i++) {
  530. if (i == arr.length - 1) {
  531. id = id + arr[i]['id'];
  532. } else {
  533. id = id + arr[i]['id'] + "_";
  534. }
  535. }
  536. var cur_sku_arr = options.sku_mu_list[id];
  537. that.setData({
  538. sku: arr,
  539. sku_val: 1,
  540. cur_sku_arr: cur_sku_arr,
  541. skuList: options,
  542. visible: true,
  543. showSku: true,
  544. is_just_addcar
  545. });
  546. } else {
  547. let goods = this.data.goods;
  548. let danprice = this.data.pin_info.danprice || 0;
  549. let cur_sku_arr = {
  550. canBuyNum: goods.total,
  551. spuName: goods.goodsname,
  552. // actPrice: goods.actPrice,
  553. marketPrice: goods.marketPrice,
  554. stock: goods.total,
  555. skuImage: goods.image_thumb,
  556. pinprice: goods.actPrice,
  557. actPrice: danprice.split(".")
  558. }
  559. that.setData({
  560. sku: [],
  561. sku_val: 1,
  562. cur_sku_arr: cur_sku_arr,
  563. skuList: [],
  564. visible: true,
  565. showSku: true
  566. })
  567. }
  568. },
  569. /**
  570. * 确认购物车
  571. */
  572. gocarfrom: function (e) {
  573. var that = this;
  574. wx.showLoading();
  575. var token = wx.getStorageSync('token');
  576. app.util.request({
  577. 'url': 'entry/wxapp/user',
  578. 'data': {
  579. controller: 'user.get_member_form_id',
  580. 'token': token,
  581. "from_id": e.detail.formId
  582. },
  583. dataType: 'json',
  584. success: function (res) { }
  585. })
  586. that.goOrder();
  587. },
  588. /**
  589. * 关闭购物车
  590. */
  591. closeSku: function () {
  592. this.setData({
  593. visible: 0,
  594. stopClick: false,
  595. });
  596. },
  597. goOrder: function () {
  598. var that = this;
  599. if (that.data.can_car) {
  600. that.data.can_car = false;
  601. }
  602. let open_man_orderbuy = this.data.open_man_orderbuy;
  603. if (open_man_orderbuy == 1) {
  604. let man_orderbuy_money = this.data.man_orderbuy_money * 1;
  605. let sku_val = this.data.sku_val;
  606. let cur_sku_arr = this.data.cur_sku_arr;
  607. let actPrice = cur_sku_arr.actPrice[0] + '.' + cur_sku_arr.actPrice[1];
  608. console.log(actPrice * 1 * sku_val);
  609. if (actPrice * 1 * sku_val < man_orderbuy_money) {
  610. wx.showToast({
  611. title: '满' + man_orderbuy_money + '元可下单!',
  612. icon: 'none'
  613. })
  614. return false;
  615. }
  616. }
  617. var goods_id = that.data.addCar_goodsid;
  618. var quantity = that.data.sku_val;
  619. var cur_sku_arr = that.data.cur_sku_arr;
  620. var sku_str = '';
  621. var is_just_addcar = 0;
  622. let buy_type = this.buy_type;
  623. let community = wx.getStorageSync('community');
  624. let community_id = community.communityId || 0;
  625. if (cur_sku_arr && cur_sku_arr.option_item_ids) {
  626. sku_str = cur_sku_arr.option_item_ids;
  627. }
  628. let data = {
  629. goods_id,
  630. community_id,
  631. quantity,
  632. sku_str,
  633. buy_type,
  634. pin_id: 0,
  635. is_just_addcar
  636. }
  637. util.addCart(data).then(res=>{
  638. if(res.showVipModal==1) {
  639. let { pop_vipmember_buyimage } = res.data;
  640. wx.hideLoading();
  641. that.setData({ pop_vipmember_buyimage, showVipModal: true, visible: false })
  642. } else if (res.data.code == 3 || res.data.code == 7) {
  643. wx.showToast({
  644. title: res.data.msg,
  645. icon: 'none',
  646. duration: 2000
  647. })
  648. } else if (res.data.code == 4) {
  649. wx.hideLoading();
  650. that.setData({ needAuth: true, showAuthModal: true, visible: false })
  651. } else if (res.data.code == 6) {
  652. var msg = res.data.msg;
  653. let max_quantity = res.data.max_quantity || '';
  654. (max_quantity > 0) && that.setData({ sku_val: max_quantity })
  655. wx.showToast({
  656. title: msg,
  657. icon: 'none',
  658. duration: 2000
  659. })
  660. } else {
  661. var is_limit = res.data.is_limit_distance_buy;
  662. var pages_all = getCurrentPages();
  663. if (pages_all.length > 3) {
  664. wx.redirectTo({
  665. url: `/lionfish_comshop/pages/order/placeOrder?type=${buy_type}&is_limit=${is_limit}`
  666. })
  667. } else {
  668. wx.navigateTo({
  669. url: `/lionfish_comshop/pages/order/placeOrder?type=${buy_type}&is_limit=${is_limit}`
  670. })
  671. }
  672. }
  673. }).catch(res=>{
  674. app.util.message(res||'请求失败', '', 'error');
  675. })
  676. },
  677. selectSku: function (event) {
  678. var that = this;
  679. let str = event.currentTarget.dataset.type;
  680. let obj = str.split("_");
  681. let arr = that.data.sku;
  682. let temp = {
  683. name: obj[3],
  684. id: obj[2],
  685. index: obj[0],
  686. idx: obj[1]
  687. };
  688. arr.splice(obj[0], 1, temp);
  689. that.setData({
  690. sku: arr
  691. })
  692. var id = '';
  693. for (let i = 0; i < arr.length; i++) {
  694. if (i == arr.length - 1) {
  695. id = id + arr[i]['id'];
  696. } else {
  697. id = id + arr[i]['id'] + "_";
  698. }
  699. }
  700. var options = this.data.skuList;
  701. var cur_sku_arr = options.sku_mu_list[id];
  702. that.setData({
  703. cur_sku_arr: cur_sku_arr
  704. });
  705. console.log(id);
  706. },
  707. submit: function (e) {
  708. var from_id = e.detail.formId;
  709. var token = wx.getStorageSync('token');
  710. app.util.request({
  711. 'url': 'entry/wxapp/user',
  712. 'data': {
  713. controller: 'user.get_member_form_id',
  714. 'token': token,
  715. "from_id": from_id
  716. },
  717. dataType: 'json',
  718. success: function (res) { }
  719. })
  720. },
  721. /**
  722. * 开团订阅
  723. */
  724. preBalance: function(e){
  725. if (!this.authModal()) return;
  726. let that = this;
  727. if(!this.canPreSub) return;
  728. this.canPreSub = false;
  729. let is_need_subscript = this.data.is_need_subscript;
  730. let buy_type = e.currentTarget.dataset.type;
  731. this.buy_type = buy_type;
  732. this.setData({ buy_type })
  733. if(is_need_subscript==1) {
  734. //弹出订阅消息
  735. this.subscriptionNotice().then(()=>{
  736. that.openSku(buy_type);
  737. }).catch(()=>{
  738. that.openSku(buy_type);
  739. });
  740. } else {
  741. that.openSku(buy_type);
  742. }
  743. },
  744. /**
  745. * 订阅消息
  746. */
  747. subscriptionNotice: function() {
  748. console.log('subscriptionNotice')
  749. let that = this;
  750. return new Promise((resolve, reject)=>{
  751. let obj = that.data.need_subscript_template;
  752. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  753. if (wx.requestSubscribeMessage) {
  754. tmplIds.length && wx.requestSubscribeMessage({
  755. tmplIds: tmplIds,
  756. success(res) {
  757. let is_need_subscript = 1;
  758. let acceptId = [];
  759. Object.keys(obj).forEach(item=>{
  760. if (res[obj[item]] == 'accept') {
  761. //用户同意了订阅,添加进数据库
  762. acceptId.push(item);
  763. } else {
  764. //用户拒绝了订阅或当前游戏被禁用订阅消息
  765. is_need_subscript = 0;
  766. }
  767. })
  768. if(acceptId.length) {
  769. that.addAccept(acceptId);
  770. }
  771. that.setData({ is_need_subscript })
  772. resolve();
  773. },
  774. fail() {
  775. reject();
  776. }
  777. })
  778. } else {
  779. // 兼容处理
  780. reject();
  781. }
  782. })
  783. },
  784. // 用户点击订阅添加到数据库
  785. addAccept: function (acceptId) {
  786. let token = wx.getStorageSync('token');
  787. let type = acceptId.join(',');
  788. app.util.request({
  789. url: 'entry/wxapp/user',
  790. data: {
  791. controller: 'user.collect_subscriptmsg',
  792. token,
  793. type
  794. },
  795. dataType: 'json',
  796. method: 'POST',
  797. success: function () {}
  798. })
  799. },
  800. balance: function (e) {
  801. if (!this.authModal()) return;
  802. let that = this;
  803. let buy_type = e.currentTarget.dataset.type;
  804. // let isZreo = e.currentTarget.dataset.zero || 0;
  805. this.buy_type = buy_type;
  806. this.setData({ buy_type })
  807. // if (isZreo == 1) {
  808. // this.zeroModal(()=>{
  809. // that.openSku(buy_type);
  810. // });
  811. // } else {
  812. that.openSku(buy_type);
  813. // }
  814. },
  815. /**
  816. * 数量加减
  817. */
  818. setNum: function (event) {
  819. let types = event.currentTarget.dataset.type;
  820. var that = this;
  821. var num = 1;
  822. let sku_val = this.data.sku_val * 1;
  823. if (types == 'add') {
  824. num = sku_val + 1;
  825. } else if (types == 'decrease') {
  826. if (sku_val > 1) {
  827. num = sku_val - 1;
  828. }
  829. }
  830. let arr = that.data.sku;
  831. var options = this.data.skuList;
  832. if (arr.length > 0) {
  833. var id = '';
  834. for (let i = 0; i < arr.length; i++) {
  835. if (i == arr.length - 1) {
  836. id = id + arr[i]['id'];
  837. } else {
  838. id = id + arr[i]['id'] + "_";
  839. }
  840. }
  841. }
  842. if (options.length > 0) {
  843. var cur_sku_arr = options.sku_mu_list[id];
  844. if (num > cur_sku_arr['canBuyNum']) {
  845. num = num - 1;
  846. }
  847. } else {
  848. let cur_sku_arr = this.data.cur_sku_arr;
  849. if (num > cur_sku_arr['canBuyNum']) {
  850. num = num - 1;
  851. }
  852. }
  853. this.setData({
  854. sku_val: num
  855. })
  856. },
  857. scrollImagesChange: function (t) {
  858. this.videoContext.pause();
  859. this.setData({
  860. fmShow: true,
  861. goodsIndex: t.detail.current + 1
  862. });
  863. },
  864. share_handler: function () {
  865. this.setData({
  866. is_share_html: !this.data.is_share_html
  867. })
  868. },
  869. share_quan: function () {
  870. if (!this.authModal()) return;
  871. wx.showLoading({
  872. title: '获取中',
  873. })
  874. var token = wx.getStorageSync('token');
  875. var community = wx.getStorageSync('community');
  876. var goods_id = this.data.order.goods_id;
  877. var community_id = community.communityId;
  878. var that = this;
  879. app.util.request({
  880. url: 'entry/wxapp/index',
  881. data: {
  882. controller: 'goods.get_user_goods_qrcode',
  883. token: token,
  884. community_id: community_id,
  885. goods_id: goods_id
  886. },
  887. dataType: 'json',
  888. success: function (res) {
  889. if (res.data.code == 0) {
  890. setTimeout(function () {
  891. wx.hideLoading()
  892. }, 2000)
  893. var image_path = res.data.image_path;
  894. wx.getImageInfo({
  895. src: image_path,
  896. success: function (res) {
  897. var real_path = res.path;
  898. wx.saveImageToPhotosAlbum({
  899. filePath: real_path,
  900. success(res) {
  901. wx.showToast({
  902. title: '图片保存成功,可以分享了',
  903. icon: 'none',
  904. duration: 2000
  905. })
  906. that.setData({
  907. is_share_html: true
  908. });
  909. }
  910. })
  911. }
  912. })
  913. } else {
  914. that.setData({
  915. needAuth: true
  916. })
  917. }
  918. }
  919. })
  920. },
  921. onReady: function (res) {
  922. this.videoContext = wx.createVideoContext('myVideo');
  923. },
  924. /**
  925. * 生命周期函数--监听页面隐藏
  926. */
  927. onHide: function () {
  928. this.setData({ stopNotify: true })
  929. console.log('详情页hide', this.data.stopNotify)
  930. },
  931. /**
  932. * 生命周期函数--监听页面卸载
  933. */
  934. onUnload: function () {
  935. console.log('onUnload')
  936. this.setData({ stopNotify: true })
  937. console.log('详情页unload', this.data.stopNotify);
  938. detailClearTime = null;
  939. clearTimeout(detailClearTime);
  940. },
  941. /**
  942. * 获取分享图并显示
  943. * 20181225 新形式
  944. */
  945. get_share_img: function () {
  946. if (!this.authModal()) return;
  947. wx.showLoading();
  948. let shareImgUrl = this.data.shareImgUrl;
  949. if (shareImgUrl != '') {
  950. wx.hideLoading();
  951. this.setData({
  952. hideModal: false,
  953. is_share_html: true
  954. })
  955. } else {
  956. var token = wx.getStorageSync('token');
  957. var community = wx.getStorageSync('community');
  958. var goods_id = this.data.goods_id;
  959. var community_id = community.communityId;
  960. var that = this;
  961. app.util.request({
  962. url: 'entry/wxapp/index',
  963. data: {
  964. controller: 'goods.get_user_goods_qrcode',
  965. token: token,
  966. community_id: community_id,
  967. goods_id: goods_id
  968. },
  969. dataType: 'json',
  970. success: function (res) {
  971. if (res.data.code == 0) {
  972. wx.hideLoading();
  973. var image_path = res.data.image_path;
  974. wx.previewImage({
  975. current: image_path, // 当前显示图片的http链接
  976. urls: [image_path] // 需要预览的图片http链接列表
  977. })
  978. } else {
  979. that.setData({
  980. needAuth: true
  981. })
  982. }
  983. }
  984. })
  985. }
  986. },
  987. closeShareModal: function () {
  988. this.setData({ hideModal: true })
  989. },
  990. /**
  991. * 展开收起
  992. */
  993. bindOpen: function (t) {
  994. var idx = t.currentTarget.dataset.idx;
  995. console.log(idx)
  996. if (this.data.comment_list[idx].isOpen) {
  997. this.data.comment_list[idx].isOpen = false;
  998. var comment_list = this.data.comment_list;
  999. this.setData({
  1000. comment_list: comment_list
  1001. });
  1002. } else {
  1003. this.data.comment_list[idx].isOpen = true;
  1004. var comment_list = this.data.comment_list;
  1005. this.setData({
  1006. comment_list: comment_list
  1007. });
  1008. }
  1009. },
  1010. /**
  1011. * 保存分享图并显示
  1012. * 20181225 新形式
  1013. */
  1014. saveThumb: function (e) {
  1015. wx.showLoading();
  1016. let that = this;
  1017. var image_path = this.data.shareImgUrl;
  1018. wx.getImageInfo({
  1019. src: image_path,
  1020. success: function (res) {
  1021. var real_path = res.path;
  1022. real_path && wx.saveImageToPhotosAlbum({
  1023. filePath: real_path,
  1024. success(res) {
  1025. console.log(res)
  1026. wx.hideLoading();
  1027. wx.showToast({
  1028. title: '已保存相册',
  1029. icon: 'none',
  1030. duration: 2000
  1031. })
  1032. that.setData({
  1033. hideModal: true
  1034. });
  1035. },
  1036. fail: function (res) {
  1037. wx.hideLoading();
  1038. console.log(res)
  1039. if (res.errMsg === "saveImageToPhotosAlbum:fail:auth denied") {
  1040. wx.openSetting({
  1041. success(settingdata) {
  1042. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  1043. console.log("获取权限成功,再次点击图片保存到相册")
  1044. } else {
  1045. console.log("获取权限失败")
  1046. }
  1047. }
  1048. })
  1049. }
  1050. }
  1051. })
  1052. }
  1053. })
  1054. },
  1055. drawImgNoPrice: function () {
  1056. var t = this;
  1057. wx.createSelectorQuery().select(".canvas-img").boundingClientRect(function () {
  1058. const context = wx.createCanvasContext("myCanvas");
  1059. context.drawImage(t.goodsImg, 0, 0, status.getPx(375), status.getPx(300));
  1060. if (t.data.goods.video) context.drawImage("../../images/play.png", status.getPx(127.5), status.getPx(90), status.getPx(120), status.getPx(120));
  1061. context.save();
  1062. context.restore(), context.draw(false, t.checkCanvasNoPrice());
  1063. }).exec();
  1064. },
  1065. checkCanvasNoPrice: function () {
  1066. var that = this;
  1067. setTimeout(() => {
  1068. wx.canvasToTempFilePath({
  1069. canvasId: "myCanvas",
  1070. success: function (res) {
  1071. res.tempFilePath ? that.imageUrl = res.tempFilePath : that.drawImgNoPrice();
  1072. console.log('我画完了')
  1073. },
  1074. fail: function (a) {
  1075. that.drawImgNoPrice();
  1076. }
  1077. })
  1078. }, 500)
  1079. },
  1080. drawImg: function () {
  1081. let endtime = this.data.endtime;
  1082. let shareTime = (endtime.days > 0 ? endtime.days + '天' : '') + endtime.hours + ':' + endtime.minutes + ':' + endtime.seconds;
  1083. var t = this;
  1084. wx.createSelectorQuery().select(".canvas-img").boundingClientRect(function () {
  1085. const context = wx.createCanvasContext("myCanvas");
  1086. context.font = "28px Arial";
  1087. var e = context.measureText("¥").width + 2;
  1088. var o = context.measureText(t.data.goods.price_front + "." + t.data.goods.price_after).width;
  1089. context.font = "17px Arial";
  1090. var s = context.measureText("¥" + t.data.goods.productprice).width + 3,
  1091. n = context.measureText("累计销售 " + t.data.goods.seller_count).width,
  1092. u = context.measureText("· 剩余" + t.data.goods.total + " ").width + 10;
  1093. context.font = "18px Arial";
  1094. let over_type_text = t.data.goods.over_type == 0 ? '距开始' : '距结束';
  1095. var r = context.measureText(over_type_text).width;
  1096. var d = context.measureText(shareTime).width + 10;
  1097. context.drawImage(t.goodsImg, 0, 0, status.getPx(375), status.getPx(300));
  1098. context.drawImage("../../images/shareBottomBg.png", status.getPx(0), status.getPx(225), status.getPx(375), status.getPx(75));
  1099. if (t.data.goods.video) context.drawImage("../../images/play.png", status.getPx(127.5), status.getPx(70), status.getPx(120), status.getPx(120));
  1100. context.save();
  1101. status.drawText(context, { color: "#ffffff", size: 28, textAlign: "left" }, "¥", status.getPx(6), status.getPx(267), status.getPx(e));
  1102. status.drawText(context, { color: "#ffffff", size: 28, textAlign: "left" }, t.data.goods.price_front + "." + t.data.goods.price_after,
  1103. status.getPx(e), status.getPx(267), status.getPx(o));
  1104. context.restore();
  1105. context.save();
  1106. context.restore(),
  1107. context.save(),
  1108. (0, status.drawText)(context,
  1109. { color: "#ffffff", size: 15, textAlign: "left" },
  1110. "¥" + t.data.goods.productprice,
  1111. (0, status.getPx)(e + o + 10),
  1112. (0, status.getPx)(267),
  1113. (0, status.getPx)(s)
  1114. ),
  1115. context.restore(),
  1116. context.save(),
  1117. (0, status.drawText)(
  1118. context,
  1119. { color: "#ffffff", size: 17, textAlign: "left" },
  1120. "累计销售" + t.data.goods.seller_count,
  1121. (0, status.getPx)(10),
  1122. (0, status.getPx)(290),
  1123. (0, status.getPx)(n)
  1124. ),
  1125. context.restore(),
  1126. context.save(),
  1127. (0, status.drawText)(context,
  1128. { color: "#ffffff", size: 17, textAlign: "left" },
  1129. "· 剩余" + t.data.goods.total,
  1130. (0, status.getPx)(n + 10),
  1131. (0, status.getPx)(290),
  1132. (0, status.getPx)(u)
  1133. ),
  1134. context.restore(),
  1135. context.save(),
  1136. context.beginPath(),
  1137. context.setStrokeStyle("white"),
  1138. context.moveTo((0, status.getPx)(e + o + 10),
  1139. (0, status.getPx)(261)),
  1140. context.lineTo((0, status.getPx)(e + o + s + 15),
  1141. (0, status.getPx)(261)),
  1142. context.stroke(),
  1143. context.restore(),
  1144. context.save(),
  1145. (0, status.drawText)(context,
  1146. { color: "#F8E71C", size: 18, textAlign: "center" },
  1147. over_type_text,
  1148. (0, status.getPx)(318),
  1149. (0, status.getPx)(260),
  1150. (0, status.getPx)(r)
  1151. ),
  1152. context.restore(),
  1153. context.save(),
  1154. (0, status.drawText)(context, { color: "#F8E71C", size: 18, textAlign: "center" },
  1155. shareTime,
  1156. (0, status.getPx)(315),
  1157. (0, status.getPx)(288),
  1158. (0, status.getPx)(d)
  1159. ),
  1160. context.restore();
  1161. context.draw(false, t.checkCanvas());
  1162. }).exec();
  1163. },
  1164. checkCanvas: function () {
  1165. var that = this;
  1166. setTimeout(() => {
  1167. wx.canvasToTempFilePath({
  1168. canvasId: "myCanvas",
  1169. success: function (res) {
  1170. res.tempFilePath ? that.imageUrl = res.tempFilePath : that.drawImg();
  1171. console.log('我画完了')
  1172. },
  1173. fail: function (a) {
  1174. that.drawImg();
  1175. }
  1176. })
  1177. }, 500)
  1178. },
  1179. previewImg: function (e) {
  1180. let idx = e.currentTarget.dataset.idx || 0;
  1181. let prevImgArr = this.data.prevImgArr;
  1182. wx.previewImage({
  1183. current: prevImgArr[idx],
  1184. urls: prevImgArr
  1185. })
  1186. },
  1187. /**
  1188. * 播放视频隐藏封面图
  1189. */
  1190. btnPlay: function () {
  1191. this.setData({
  1192. fmShow: false
  1193. })
  1194. this.videoContext.play();
  1195. },
  1196. videEnd: function () {
  1197. this.videoContext.exitFullScreen();
  1198. this.setData({
  1199. fmShow: true
  1200. })
  1201. },
  1202. endPlay: function () {
  1203. this.videoContext.pause();
  1204. this.setData({
  1205. fmShow: true
  1206. })
  1207. },
  1208. goLink: function (e) {
  1209. var pages_all = getCurrentPages();
  1210. var url = e.currentTarget.dataset.link;
  1211. if (pages_all.length > 3) {
  1212. wx.redirectTo({ url })
  1213. } else {
  1214. wx.navigateTo({ url })
  1215. }
  1216. },
  1217. /**
  1218. * 0元开团提示
  1219. */
  1220. zeroModal: function(fn){
  1221. let pin_info = this.data.pin_info;
  1222. let notice = pin_info.pintuan_newman_notice || '';
  1223. if (notice) {
  1224. wx.showModal({
  1225. title: '温馨提示',
  1226. content: notice,
  1227. confirmColor: '#ff5041',
  1228. success(res) {
  1229. if (res.confirm) {
  1230. fn()
  1231. } else if (res.cancel) {
  1232. console.log('用户点击取消')
  1233. }
  1234. }
  1235. })
  1236. } else {
  1237. fn()
  1238. }
  1239. },
  1240. /**
  1241. * 0元开团
  1242. */
  1243. zeroTuanSub: function() {
  1244. if (!this.authModal()) return;
  1245. let that = this;
  1246. this.zeroModal(()=>{
  1247. that.zeroCartAdd()
  1248. });
  1249. },
  1250. zeroCartAdd: function(){
  1251. let goods_id = this.data.goods_id || '';
  1252. var token = wx.getStorageSync('token');
  1253. let community = wx.getStorageSync('community');
  1254. let community_id = community.communityId || 0;
  1255. goods_id && app.util.request({
  1256. url: 'entry/wxapp/user',
  1257. data: {
  1258. controller: 'car.add_newcar',
  1259. token: token,
  1260. goods_id: goods_id,
  1261. community_id
  1262. },
  1263. dataType: 'json',
  1264. success: function (res) {
  1265. if(res.data.code==0) {
  1266. let order_id = res.data.order_id;
  1267. wx.navigateTo({
  1268. url: `/lionfish_comshop/moduleA/pin/share?id=${order_id}`
  1269. })
  1270. } else {
  1271. wx.showToast({
  1272. title: res.data.msg || '开团失败',
  1273. icon: 'none'
  1274. })
  1275. }
  1276. }
  1277. })
  1278. },
  1279. /**
  1280. * 用户点击右上角分享
  1281. */
  1282. onShareAppMessage: function () {
  1283. let { goods_id, share_title, goods } = this.data;
  1284. var community = wx.getStorageSync('community');
  1285. var community_id = community.communityId;
  1286. var share_id = wx.getStorageSync('member_id');
  1287. var share_path = `lionfish_comshop/moduleA/pin/goodsDetail?id=${goods_id}&share_id=${share_id}&community_id=${community_id}`;
  1288. let shareImg = goods.goods_share_image;
  1289. // if(pin_info.is_zero_open!=1 && pin_info.pin_price) share_title = pin_info.pin_price + '元' + share_title;
  1290. var that = this;
  1291. that.setData({ is_share_html: true, hideModal: true });
  1292. return {
  1293. title: share_title,
  1294. path: share_path,
  1295. imageUrl: shareImg ? shareImg : that.imageUrl,
  1296. success: function (res) {
  1297. // 转发成功
  1298. },
  1299. fail: function (res) {
  1300. // 转发失败
  1301. }
  1302. }
  1303. },
  1304. onShareTimeline: function() {
  1305. let { goods_id, share_title, goods } = this.data;
  1306. var community = wx.getStorageSync('community');
  1307. var community_id = community.communityId;
  1308. var share_id = wx.getStorageSync('member_id');
  1309. let shareImg = goods.goods_share_image;
  1310. this.setData({ is_share_html: true, hideModal: true });
  1311. var query= `id=${goods_id}&share_id=${share_id}&community_id=${community_id}`;
  1312. return {
  1313. title: share_title,
  1314. imageUrl: shareImg ? shareImg : this.imageUrl,
  1315. query,
  1316. success: function() {},
  1317. fail: function() {}
  1318. };
  1319. }
  1320. })