goodsDetail.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  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. $name: 'goodsDetail',
  51. mixins: [require('../../mixin/globalMixin.js')],
  52. data: {
  53. needAuth: false,
  54. goodsIndex: 1,
  55. goods_id: 0,
  56. endtime: {
  57. days: "00",
  58. hours: "00",
  59. minutes: "00",
  60. seconds: "00",
  61. },
  62. is_share_html: true,
  63. stickyFlag: false,
  64. showSkeleton: true,
  65. imageSize: {
  66. imageWidth: "100%",
  67. imageHeight: 375
  68. },
  69. cartNum: 0,
  70. noIns: false,
  71. index_bottom_image: '',
  72. hideModal: true,
  73. shareImgUrl: '',
  74. goods_details_middle_image: '',
  75. is_show_buy_record: 0,
  76. stopNotify: true,
  77. iconArr: {
  78. home: '',
  79. car: ''
  80. },
  81. canvasWidth: 375,
  82. canvasHeight: 300,
  83. fmShow: true,
  84. relative_goods_list: [],
  85. needPosition: false,
  86. groupInfo: {
  87. group_name: '社区',
  88. owner_name: '团长'
  89. },
  90. showCoverVideo: false, // Todo
  91. loaded: false,
  92. presale_goods_info: '', // 预售信息
  93. presaleState: 0, //预售状态 0未开始 1 进行中 2 已结束
  94. presaleBalance: 0 //预售尾款
  95. },
  96. $data: {
  97. stickyFlag: false,
  98. id: '',
  99. scene: '',
  100. community_id: 0
  101. },
  102. imageUrl: '',
  103. goodsImg: '',
  104. currentOptions: [],
  105. focusFlag: false,
  106. buy_type: '',
  107. show_goods_preview: 0,
  108. /**
  109. * 生命周期函数--监听页面加载
  110. */
  111. onLoad: function(options) {
  112. var that = this;
  113. app.setShareConfig();
  114. let webImages = wx.getStorageSync('webImages');
  115. let goods_image = [];
  116. if(webImages && webImages[0]) {
  117. let local_path = webImages[0].local_path;
  118. let imageSize = { imageHeight: webImages[0].height }
  119. goods_image.push({ image: local_path, imageSize })
  120. wx.setStorageSync('webImages', '');
  121. }
  122. this.setData({ goods_image });
  123. app.globalData.navBackUrl = '';
  124. status.setNavBgColor();
  125. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  126. status.setIcon().then(function (iconArr){
  127. that.setData({ iconArr });
  128. });
  129. let room_id = options.room_id || '';
  130. let buy_type = options.type || '';
  131. if(!room_id){
  132. var scene = decodeURIComponent(options.scene);
  133. if (scene !== 'undefined') {
  134. var opt_arr = scene.split("_");
  135. options.id = opt_arr[0];
  136. options.share_id = opt_arr[1];
  137. options.community_id = opt_arr[2];
  138. }
  139. } else {
  140. buy_type = '';
  141. }
  142. this.buy_type = buy_type;
  143. if (options.share_id != 'undefined' && options.share_id > 0) wx.setStorage({ key: "share_id", data: options.share_id });
  144. this.$data.id = options.id;
  145. this.$data.community_id = options.community_id;
  146. this.$data.scene = options.scene;
  147. let h = {
  148. canvasWidth: app.globalData.systemInfo.windowWidth,
  149. canvasHeight: 0.8 * app.globalData.systemInfo.windowWidth,
  150. buy_type,
  151. goods_id: options.id
  152. };
  153. // 当前本地社区
  154. let currentCommunity = wx.getStorageSync('community');
  155. let currentCommunity_id = (currentCommunity && currentCommunity.communityId) || '';
  156. wx.showLoading();
  157. if (options.community_id != 'undefined' && options.community_id > 0 && buy_type!='integral') {
  158. // 存在分享社区进行比较
  159. if (currentCommunity_id) {
  160. console.log('step3 本地社区存在')
  161. this.paramHandle(options, currentCommunity);
  162. } else {
  163. // 当前本地社区不存在
  164. let community = {};
  165. community.communityId = options.community_id;
  166. util.getCommunityInfo().then(function(res){
  167. console.log('step1 分享来的社区', res);
  168. that.paramHandle(options, res);
  169. }).catch((param)=>{
  170. console.log('step4 新人')
  171. if(Object.keys(param) != '') util.addhistory(param, true);
  172. });
  173. }
  174. } else {
  175. // 没有分享社区直接访问
  176. util.getCommunityById(0).then(ret=>{
  177. console.log('没有分享社区直接访问', ret)
  178. if (ret.open_danhead_model == 1) {
  179. let default_head_info = ret.default_head_info;
  180. console.log('default_head_info', default_head_info)
  181. app.globalData.community = default_head_info;
  182. if(currentCommunity && (currentCommunity.communityId != default_head_info.communityId)) app.globalData.changedCommunity = true;
  183. util.addhistory(default_head_info);
  184. wx.setStorage({ key: "community", data: default_head_info })
  185. that.setData({ community: default_head_info })
  186. that.get_goods_details(options.id, default_head_info, '');
  187. } else {
  188. util.getCommunityInfo().then(res=>{
  189. if(res) {
  190. that.setData({ community: res })
  191. that.get_goods_details(options.id, '', res.communityId);
  192. } else {
  193. that.setData({ community: currentCommunity });
  194. that.get_goods_details(options.id, '', currentCommunity_id);
  195. }
  196. })
  197. }
  198. })
  199. }
  200. that.setData(h);
  201. this.get_instructions();
  202. },
  203. /**
  204. * 比较社区
  205. * @param {分享参数} options
  206. * @param {本地社区信息} currentCommunity
  207. */
  208. paramHandle: function (options, currentCommunity=""){
  209. console.log('step2')
  210. let that = this;
  211. let { id, community_id } = options;
  212. app.util.request({
  213. url: 'entry/wxapp/index',
  214. data: {
  215. controller: 'index.get_community_info',
  216. community_id
  217. },
  218. dataType: 'json',
  219. success: function (res) {
  220. if (res.data.code == 0) {
  221. let shareCommunity = res.data.data;
  222. console.log(shareCommunity)
  223. let currentCommunityId = currentCommunity.communityId;
  224. //单社区
  225. if (res.data.open_danhead_model == 1) {
  226. let default_head_info = res.data.default_head_info;
  227. app.globalData.community = default_head_info;
  228. if(currentCommunity && (currentCommunity.communityId != default_head_info.communityId)) app.globalData.changedCommunity = true;
  229. util.addhistory(default_head_info);
  230. wx.setStorage({ key: "community", data: default_head_info })
  231. that.setData({ community: default_head_info })
  232. that.get_goods_details(id, default_head_info, '');
  233. } else {
  234. if (currentCommunityId == community_id || shareCommunity=='') {
  235. console.log('step5 分享与本地相同')
  236. wx.setStorageSync('community', shareCommunity);
  237. that.setData({ community: shareCommunity })
  238. that.get_goods_details(options.id, '', community_id);
  239. } else {
  240. if (currentCommunityId) {
  241. that.setData({
  242. showChangeCommunity: true,
  243. changeCommunity: shareCommunity,
  244. community: currentCommunity
  245. })
  246. that.get_goods_details(options.id, '', currentCommunityId, Number(!res.data.hide_community_change_btn));
  247. } else {
  248. that.setData({ changeCommunity: shareCommunity }, () => {
  249. that.confrimChangeCommunity();
  250. })
  251. }
  252. }
  253. }
  254. }
  255. }
  256. })
  257. },
  258. /**
  259. * 不可购买提示
  260. */
  261. canBuyTip: function(){
  262. let groupInfo = this.data.groupInfo;
  263. app.util.message(`此商品在您所属${groupInfo.group_name}不可参与`, 'switchTo:/lionfish_comshop/pages/index/index','error');
  264. },
  265. get_goods_details: function (id, communityInfo='', currentCommunity_id, laterShowCanBuy=0){
  266. let that = this;
  267. if(!id) {
  268. wx.hideLoading();
  269. wx.showModal({
  270. title: '提示',
  271. content: '参数错误',
  272. showCancel: false,
  273. confirmColor: '#F75451',
  274. success(res) {
  275. if (res.confirm) {
  276. wx.redirectTo({
  277. url: '/lionfish_comshop/pages/index/index',
  278. })
  279. }
  280. }
  281. })
  282. return false;
  283. }
  284. let token = wx.getStorageSync('token');
  285. if(communityInfo) currentCommunity_id = communityInfo.communityId;
  286. app.util.request({
  287. url: 'entry/wxapp/index',
  288. data: {
  289. controller: 'goods.get_goods_detail',
  290. token: token,
  291. id,
  292. community_id: currentCommunity_id
  293. },
  294. dataType: 'json',
  295. success: function (res) {
  296. setTimeout(function(){ wx.hideLoading(); },1000);
  297. let { goods, is_can_headsales } = res.data.data;
  298. // 商品不存在
  299. if (!goods || goods.nogoods || Object.keys(goods) == '') {
  300. return wx.showModal({
  301. title: '提示',
  302. content: '该商品不存在,回首页',
  303. showCancel: false,
  304. confirmColor: '#F75451',
  305. success(res) {
  306. if (res.confirm) {
  307. wx.switchTab({
  308. url: '/lionfish_comshop/pages/index/index',
  309. })
  310. }
  311. }
  312. })
  313. }
  314. console.log('is_can_headsales', is_can_headsales, laterShowCanBuy)
  315. if(is_can_headsales==0&&that.buy_type!='integral') {
  316. if(laterShowCanBuy==0) {
  317. that.canBuyTip();
  318. }
  319. }
  320. let comment_list = res.data.comment_list;
  321. comment_list.map(function (item) {
  322. 14 * item.content.length / app.globalData.systemInfo.windowWidth > 3 && (item.showOpen = true), item.isOpen = true;
  323. })
  324. // 幻灯片预览数组
  325. let goods_images = res.data.data.goods_image || '';
  326. let prevImgArr = [];
  327. if (Object.prototype.toString.call(goods_images) == '[object Array]' && goods_images.length > 0) {
  328. goods_images.forEach(function (item) { prevImgArr.push(item.image); })
  329. }
  330. //群分享
  331. let isopen_community_group_share = res.data.isopen_community_group_share || 0;
  332. let group_share_info = res.data.group_share_info;
  333. // 关联商品
  334. let relative_goods_list = res.data.data.relative_goods_list || [];
  335. let relative_goods_list_arr = [];
  336. if (Object.prototype.toString.call(relative_goods_list) == '[object Object]' && Object.keys(relative_goods_list).length > 0) {
  337. Object.keys(relative_goods_list).forEach(function (item) {
  338. relative_goods_list_arr.push(relative_goods_list[item]);
  339. })
  340. } else {
  341. relative_goods_list_arr = relative_goods_list;
  342. }
  343. // 会员
  344. let { is_need_subscript, need_subscript_template, is_open_vipcard_buy, modify_vipcard_name, is_vip_card_member, modify_vipcard_logo, is_member_level_buy, is_only_hexiao, hexiao_arr, is_hide_details_count } = res.data;
  345. let goodsPrice = goods.price || 0;
  346. let goodsCardPrice = goods.card_price || 0;
  347. goods.feePrice = (goodsPrice - goodsCardPrice).toFixed(2);
  348. // 佣金
  349. let { is_commiss_mb, commiss_mb_money, is_goods_head_mb, goods_head_money } = res.data.data;
  350. hexiao_arr = hexiao_arr?hexiao_arr:[];
  351. let hx_len = Object.keys(hexiao_arr).length;
  352. that.currentOptions = res.data.data.options;
  353. //开启全屏视频
  354. let showCoverVideo = false;
  355. if(goods.video && res.data.is_open_goods_full_video==1) {
  356. showCoverVideo = true
  357. }
  358. let goodsImg = res.data.data.goods_image || [];
  359. that.show_goods_preview = res.data.show_goods_preview || 0;
  360. let is_close_details_time = res.data.is_close_details_time || 0;
  361. // 预售信息
  362. let preData = {};
  363. if(that.buy_type=='presale') {
  364. let presale_goods_info = res.data.data.presale_goods_info;
  365. preData.presale_goods_info = presale_goods_info;
  366. let presaleBalance = 0;
  367. let { presale_ding_money, presale_deduction_money } = presale_goods_info;
  368. let presaleDeduction = presale_deduction_money>0?presale_deduction_money*1:presale_ding_money*1;
  369. presaleBalance = goods.price*1 - presaleDeduction;
  370. preData.presaleBalance = presaleBalance>0?presaleBalance.toFixed(2):'0.00';
  371. preData.presale_goods_info.presale_deduction_money = presaleDeduction;
  372. }
  373. // 礼品卡
  374. let virtualcard_goods_info = res.data.data.virtualcard_goods_info;
  375. that.setData({
  376. showCoverVideo,
  377. order_comment_count: res.data.order_comment_count,
  378. comment_list: comment_list,
  379. goods,
  380. options: res.data.data.options,
  381. order: {
  382. goods_id: res.data.data.goods.goods_id,
  383. pin_id: res.data.data.pin_id,
  384. },
  385. share_title: goods.share_title,
  386. buy_record_arr: res.data.data.buy_record_arr,
  387. goods_image: goodsImg,
  388. goods_image_length: goodsImg.length,
  389. service: goods.tag,
  390. showSkeleton: false,
  391. is_comunity_rest: res.data.is_comunity_rest,
  392. prevImgArr,
  393. open_man_orderbuy: res.data.open_man_orderbuy,
  394. man_orderbuy_money: res.data.man_orderbuy_money,
  395. localtown_moneytype_fixed_freemoney: res.data.localtown_moneytype_fixed_freemoney,
  396. is_only_distribution: res.data.is_only_distribution,
  397. goodsdetails_addcart_bg_color: res.data.goodsdetails_addcart_bg_color || 'linear-gradient(270deg, #f9c706 0%, #feb600 100%)',
  398. goodsdetails_buy_bg_color: res.data.goodsdetails_buy_bg_color || 'linear-gradient(90deg, #ff5041 0%, #ff695c 100%)',
  399. isopen_community_group_share,
  400. group_share_info,
  401. relative_goods_list: relative_goods_list_arr,
  402. needPosition: currentCommunity_id ? true : false,
  403. is_close_details_time,
  404. is_open_vipcard_buy: is_open_vipcard_buy || 0,
  405. modify_vipcard_name,
  406. is_vip_card_member: is_vip_card_member || 0,
  407. modify_vipcard_logo,
  408. is_commiss_mb,
  409. commiss_mb_money,
  410. is_goods_head_mb,
  411. goods_head_money,
  412. is_member_level_buy,
  413. is_need_subscript,
  414. need_subscript_template,
  415. is_can_headsales,
  416. is_only_hexiao,
  417. hexiao_arr,
  418. hx_len,
  419. is_hide_details_count,
  420. goods_details_title_bg: res.data.goods_details_title_bg,
  421. needAuth: res.data.needauth,
  422. ishide_details_desc: res.data.ishide_details_desc,
  423. delivery_type_ziti: res.data.delivery_type_ziti || '',
  424. loaded: true,
  425. ...preData,
  426. virtualcard_goods_info
  427. }, () => {
  428. let goods_share_image = goods.goods_share_image;
  429. if (goods_share_image) {
  430. console.log('draw分享图');
  431. status.download(goods_share_image + "?imageView2/1/w/500/h/400").then(function (a) {
  432. that.goodsImg = a.tempFilePath, that.drawImgNoPrice();
  433. });
  434. } else {
  435. console.log('draw价格');
  436. let shareImg = goods.image_thumb;
  437. status.download(shareImg + "?imageView2/1/w/500/h/400").then(function (a) {
  438. that.goodsImg = a.tempFilePath, that.drawImg();
  439. });
  440. }
  441. })
  442. if (res.data.is_comunity_rest == 1) {
  443. wx.showModal({
  444. title: '温馨提示',
  445. content: `${that.data.groupInfo.owner_name}休息中,欢迎下次光临!`,
  446. showCancel: false,
  447. confirmColor: '#F75451',
  448. confirmText: '好的',
  449. success(res) { }
  450. })
  451. }
  452. if(that.buy_type=='presale') {
  453. // 预售商品计时
  454. // 判断状态 presale_ding_time_start 开始时间 presale_ding_time_end 结束时间
  455. let { presale_goods_info, cur_time } = res.data.data;
  456. let { presale_ding_time_start, presale_ding_time_end } = presale_goods_info;
  457. let presaleState = 1;
  458. let seconds = (presale_ding_time_end*1 - cur_time) * 1000;
  459. if(presale_ding_time_start*1>cur_time) {
  460. // 未开始
  461. presaleState = 0;
  462. seconds = (presale_ding_time_start*1 - cur_time) * 1000;
  463. }
  464. if(presale_ding_time_end*1<cur_time) {
  465. // 已结束
  466. presaleState = 2;
  467. seconds = 0;
  468. }
  469. that.setData({ presaleState });
  470. seconds>0&&count_down(that, seconds);
  471. } else {
  472. // 普通商品计时
  473. let over_type = goods.over_type;
  474. var seconds = 0;
  475. if (over_type == 0) {
  476. seconds = (goods.begin_time - res.data.data.cur_time) * 1000;
  477. } else {
  478. seconds = (goods.end_time - res.data.data.cur_time) * 1000;
  479. }
  480. if (seconds > 0&&is_close_details_time==0) {
  481. count_down(that, seconds);
  482. }
  483. }
  484. }
  485. })
  486. },
  487. confrimChangeCommunity: function(){
  488. let community = this.data.changeCommunity;
  489. let token = wx.getStorageSync('token');
  490. app.globalData.community = community;
  491. app.globalData.changedCommunity = true;
  492. wx.setStorage({
  493. key: "community",
  494. data: community
  495. })
  496. token && util.addhistory(community);
  497. this.setData({ community, showChangeCommunity: false })
  498. this.get_goods_details(this.data.goods_id, community, community.communityId);
  499. console.log('用户点击确定')
  500. },
  501. cancelChangeCommunity: function() {
  502. let is_can_headsales = this.data.is_can_headsales;
  503. if(is_can_headsales==0) {
  504. this.canBuyTip();
  505. }
  506. console.log('取消切换')
  507. },
  508. /**
  509. * 授权成功回调
  510. */
  511. authSuccess: function() {
  512. var id = this.$data.id;
  513. var scene = this.$data.scene;
  514. var community_id = this.$data.community_id;
  515. let url = '/lionfish_comshop/pages/goods/goodsDetail?id=' + id + '&community_id=' + community_id + '&scene=' + scene+ '&type=' + this.data.buy_type;
  516. app.globalData.navBackUrl = url;
  517. let currentCommunity = wx.getStorageSync('community');
  518. let needPosition = this.data.needPosition;
  519. this.setData({ needAuth: false })
  520. if (currentCommunity) needPosition = false;
  521. needPosition || wx.redirectTo({ url })
  522. },
  523. authModal: function () {
  524. if (this.data.needAuth) {
  525. this.setData({ showAuthModal: !this.data.showAuthModal });
  526. return false;
  527. }
  528. return true;
  529. },
  530. /**
  531. * 图片信息
  532. */
  533. imageLoad: function(e) {
  534. var imageSize = util.imageUtil(e)
  535. this.setData({
  536. imageSize
  537. })
  538. },
  539. /**
  540. * 获取服务信息
  541. */
  542. get_instructions: function() {
  543. let that = this;
  544. let goods_id = this.$data.id;
  545. app.util.request({
  546. 'url': 'entry/wxapp/index',
  547. 'data': {
  548. controller: 'goods.get_instructions',
  549. goods_id
  550. },
  551. dataType: 'json',
  552. success: function(res) {
  553. if (res.data.code == 0) {
  554. var instructions = res.data.data.value;
  555. if (instructions == '') that.setData({ noIns: true })
  556. that.setData({
  557. instructions,
  558. index_bottom_image: res.data.data.index_bottom_image,
  559. goods_details_middle_image: res.data.data.goods_details_middle_image,
  560. is_show_buy_record: res.data.data.is_show_buy_record,
  561. order_notify_switch: res.data.data.order_notify_switch,
  562. is_show_comment_list: res.data.data.is_show_comment_list,
  563. goods_details_price_bg: res.data.data.goods_details_price_bg,
  564. isShowContactBtn: res.data.data.index_service_switch || 0,
  565. goods_industrial_switch: res.data.data.goods_industrial_switch || 0,
  566. goods_industrial: res.data.data.goods_industrial || '',
  567. is_show_ziti_time: res.data.data.is_show_ziti_time || 0,
  568. hide_community_change_btn: res.data.data.hide_community_change_btn || 0,
  569. is_show_goodsdetails_communityinfo: res.data.data.is_show_goodsdetails_communityinfo || 0
  570. })
  571. }
  572. }
  573. })
  574. },
  575. /**
  576. * 返回顶部
  577. */
  578. returnTop: function() {
  579. this.stickyFlag = false;
  580. this.setData({
  581. stickyFlag: false
  582. });
  583. wx.pageScrollTo({
  584. scrollTop: 0,
  585. duration: 500
  586. });
  587. },
  588. /**
  589. * 加入购物车
  590. */
  591. addToCart: function(e) {
  592. if (!this.authModal()) return;
  593. var that = this;
  594. var from_id = e.detail.formId;
  595. var token = wx.getStorageSync('token');
  596. app.util.request({
  597. 'url': 'entry/wxapp/user',
  598. 'data': {
  599. controller: 'user.get_member_form_id',
  600. 'token': token,
  601. "from_id": from_id
  602. },
  603. dataType: 'json',
  604. success: function(res) {}
  605. })
  606. that.setData({
  607. is_just_addcar: 1
  608. })
  609. //加入购物车
  610. that.openSku();
  611. },
  612. /**
  613. * 打开购物车
  614. */
  615. openSku: function(t=null) {
  616. if (!this.authModal()) return;
  617. var that = this;
  618. var is_just_addcar = this.data.is_just_addcar;
  619. let oneday_limit_count = 0;
  620. let total_limit_count = 0;
  621. let one_limit_count = 0;
  622. let goods_start_count = 1;
  623. var options = null;
  624. let car_quantity = 0;
  625. if(t) {
  626. var e = t.detail;
  627. var goods_id = e.actId;
  628. options = e.skuList;
  629. is_just_addcar = 1;
  630. oneday_limit_count = e.allData && e.allData.oneday_limit_count || 0;
  631. total_limit_count = e.allData && e.allData.total_limit_count || 0;
  632. one_limit_count = e.allData && e.allData.one_limit_count || 0;
  633. goods_start_count = e.allData && e.allData.goods_start_count || 1;
  634. } else {
  635. let goods = this.data.goods;
  636. var goods_id = this.data.goods_id;
  637. options = this.currentOptions;
  638. oneday_limit_count = goods.oneday_limit_count || 0;
  639. total_limit_count = goods.total_limit_count || 0;
  640. one_limit_count = goods.one_limit_count || 0;
  641. goods_start_count = goods.goods_start_count || 1;
  642. }
  643. // 起始sku数量
  644. let sku_val = 1;
  645. that.setData({
  646. addCar_goodsid: goods_id
  647. })
  648. let list = options.list || [];
  649. let arr = [];
  650. if (list.length > 0) {
  651. for (let i = 0; i < list.length; i++) {
  652. let sku = list[i]['option_value'][0];
  653. let temp = {
  654. name: sku['name'],
  655. id: sku['option_value_id'],
  656. index: i,
  657. idx: 0
  658. };
  659. arr.push(temp);
  660. }
  661. //把单价剔除出来begin
  662. var id = '';
  663. for (let i = 0; i < arr.length; i++) {
  664. if (i == arr.length - 1) {
  665. id = id + arr[i]['id'];
  666. } else {
  667. id = id + arr[i]['id'] + "_";
  668. }
  669. }
  670. console.log(id)
  671. console.log('options', options)
  672. var cur_sku_arr = {};
  673. if(options.sku_mu_list[id]) {
  674. cur_sku_arr = options.sku_mu_list[id] || {};
  675. console.log('cur_sku_arr1', cur_sku_arr)
  676. } else {
  677. let idArr = id.split("_");
  678. idArr = idArr.reverse();
  679. id = idArr.join("_");
  680. cur_sku_arr = options.sku_mu_list[id] || {};
  681. console.log('cur_sku_arr2', cur_sku_arr)
  682. }
  683. cur_sku_arr.oneday_limit_count = oneday_limit_count || 0;
  684. cur_sku_arr.total_limit_count = total_limit_count || 0;
  685. cur_sku_arr.one_limit_count = one_limit_count || 0;
  686. cur_sku_arr.goods_start_count = goods_start_count || 1;
  687. let car_quantity = cur_sku_arr.car_quantity || 0;
  688. if(car_quantity && car_quantity>=goods_start_count && is_just_addcar==0) {
  689. sku_val = car_quantity;
  690. } else {
  691. sku_val = goods_start_count || 1;
  692. }
  693. if(this.data.buy_type=='integral') {
  694. sku_val = 1;
  695. }
  696. that.setData({
  697. sku: arr,
  698. sku_val,
  699. cur_sku_arr,
  700. skuList: options,
  701. visible: true,
  702. showSku: true,
  703. is_just_addcar
  704. });
  705. } else {
  706. if(t) {
  707. let goodsInfo = e.allData;
  708. that.setData({
  709. sku: [],
  710. sku_val: 1,
  711. skuList: [],
  712. cur_sku_arr: goodsInfo,
  713. is_just_addcar
  714. })
  715. let formIds = {
  716. detail: {
  717. formId: ""
  718. }
  719. };
  720. formIds.detail.formId = "the formId is a mock one";
  721. that.gocarfrom(formIds);
  722. } else {
  723. let goods = this.data.goods;
  724. let card_price = goods.card_price || "0.00";
  725. let levelprice = goods.levelprice || "0.00";
  726. let goods_start_count = goods.goods_start_count || 1;
  727. let cart_quantity = goods.cart_quantity || 0;
  728. let cur_sku_arr = {
  729. canBuyNum: goods.total,
  730. spuName: goods.goodsname,
  731. actPrice: goods.actPrice,
  732. marketPrice: goods.marketPrice,
  733. stock: goods.total,
  734. skuImage: goods.image_thumb,
  735. card_price,
  736. levelprice,
  737. goods_start_count
  738. }
  739. let buy_type = this.data.buy_type || '';
  740. let sku_val = 1;
  741. if(buy_type!='integral') {
  742. sku_val = goods_start_count;
  743. if(cart_quantity>0&&cart_quantity>goods_start_count&&is_just_addcar==0) {
  744. sku_val = cart_quantity;
  745. cur_sku_arr.car_quantity = cart_quantity;
  746. } else if(cart_quantity>0&&cart_quantity>=goods_start_count){
  747. sku_val = 1;
  748. }
  749. }
  750. that.setData({
  751. sku: [],
  752. sku_val,
  753. cur_sku_arr: cur_sku_arr,
  754. skuList: [],
  755. visible: true,
  756. showSku: true
  757. })
  758. }
  759. }
  760. },
  761. /**
  762. * 确认购物车
  763. */
  764. gocarfrom: function(e) {
  765. var that = this;
  766. wx.showLoading();
  767. var token = wx.getStorageSync('token');
  768. app.util.request({
  769. 'url': 'entry/wxapp/user',
  770. 'data': {
  771. controller: 'user.get_member_form_id',
  772. 'token': token,
  773. "from_id": e.detail.formId
  774. },
  775. dataType: 'json',
  776. success: function(res) {}
  777. })
  778. that.goOrder();
  779. },
  780. /**
  781. * 关闭购物车
  782. */
  783. closeSku: function() {
  784. this.setData({
  785. visible: 0,
  786. stopClick: false,
  787. });
  788. },
  789. goOrder: function() {
  790. var that = this;
  791. if (that.data.can_car) {
  792. that.data.can_car = false;
  793. }
  794. let open_man_orderbuy = this.data.open_man_orderbuy;
  795. if (open_man_orderbuy == 1 && this.data.is_just_addcar==0){
  796. let man_orderbuy_money = this.data.man_orderbuy_money*1;
  797. let sku_val = this.data.sku_val;
  798. let cur_sku_arr = this.data.cur_sku_arr;
  799. let actPrice = cur_sku_arr.actPrice[0] + '.' + cur_sku_arr.actPrice[1];
  800. console.log(actPrice * 1 * sku_val);
  801. if (actPrice * 1 * sku_val < man_orderbuy_money){
  802. wx.showToast({
  803. title: '满' + man_orderbuy_money + '元可下单!',
  804. icon: 'none'
  805. })
  806. return false;
  807. }
  808. }
  809. let localtown_moneytype_fixed_freemoney = this.data.localtown_moneytype_fixed_freemoney*1;
  810. let is_only_distribution = this.data.is_only_distribution;
  811. if (localtown_moneytype_fixed_freemoney >= 0 && is_only_distribution ==1 && this.data.is_just_addcar==0){
  812. let sku_val = this.data.sku_val;
  813. let cur_sku_arr = this.data.cur_sku_arr;
  814. let actPrice = cur_sku_arr.actPrice[0] + '.' + cur_sku_arr.actPrice[1];
  815. if (actPrice * 1 * sku_val < localtown_moneytype_fixed_freemoney){
  816. wx.showToast({
  817. title: '同城配送商品满' + localtown_moneytype_fixed_freemoney + '元可下单!',
  818. icon: 'none'
  819. })
  820. return false;
  821. }
  822. }
  823. var community = wx.getStorageSync('community');
  824. var goods_id = that.data.addCar_goodsid;
  825. var community_id = community.communityId;
  826. var quantity = that.data.sku_val;
  827. var cur_sku_arr = that.data.cur_sku_arr;
  828. var sku_str = '';
  829. var is_just_addcar = that.data.is_just_addcar;
  830. if (cur_sku_arr && cur_sku_arr.option_item_ids) {
  831. sku_str = cur_sku_arr.option_item_ids;
  832. }
  833. console.log(cur_sku_arr);
  834. //20200622
  835. if(cur_sku_arr.car_quantity&&cur_sku_arr.car_quantity>0&&is_just_addcar==1) {
  836. quantity -= cur_sku_arr.car_quantity*1;
  837. }
  838. quantity = quantity<=0 ? 1 : quantity;
  839. let buy_type = this.data.buy_type ? this.data.buy_type : 'dan';
  840. let data = {
  841. goods_id: goods_id,
  842. community_id,
  843. quantity,
  844. sku_str,
  845. buy_type,
  846. pin_id: 0,
  847. is_just_addcar
  848. }
  849. util.addCart(data).then(res=>{
  850. if(res.showVipModal==1) {
  851. let { pop_vipmember_buyimage } = res.data;
  852. wx.hideLoading();
  853. that.setData({ pop_vipmember_buyimage, showVipModal: true, visible: false })
  854. } else if (res.data.code == 3 || res.data.code == 7) {
  855. wx.showToast({
  856. title: res.data.msg,
  857. icon: 'none',
  858. duration: 2000
  859. })
  860. } else {
  861. if (buy_type =='integral'){
  862. // 积分
  863. if (res.data.code == 6) {
  864. var msg = res.data.msg;
  865. wx.showToast({
  866. title: msg,
  867. icon: 'none',
  868. duration: 2000
  869. })
  870. } else {
  871. //跳转结算页面
  872. wx.navigateTo({
  873. url: `/lionfish_comshop/pages/order/placeOrder?type=integral`,
  874. })
  875. }
  876. }else {
  877. if (res.data.code == 4) {
  878. wx.hideLoading();
  879. that.setData({ needAuth: true, showAuthModal: true, visible: false })
  880. } else if (res.data.code == 6) {
  881. var msg = res.data.msg;
  882. let max_quantity = res.data.max_quantity || '';
  883. (max_quantity > 0) && that.setData({ sku_val: max_quantity })
  884. wx.showToast({
  885. title: msg,
  886. icon: 'none',
  887. duration: 2000
  888. })
  889. } else {
  890. if (is_just_addcar == 1) {
  891. that.closeSku();
  892. wx.showToast({
  893. title: "已加入购物车",
  894. image: "../../images/addShopCart.png"
  895. })
  896. app.globalData.cartNum = res.data.total;
  897. // 20200622
  898. let goods = that.data.goods;
  899. let h = { goods };
  900. if(goods.id == goods_id) { h.goods.cart_quantity = res.data.cur_count }
  901. that.setData({
  902. cartNum: res.data.total,
  903. ...h
  904. });
  905. status.indexListCarCount(goods_id, res.data.cur_count);
  906. } else {
  907. var is_limit = res.data.is_limit_distance_buy;
  908. var pages_all = getCurrentPages();
  909. if (pages_all.length > 3) {
  910. wx.redirectTo({
  911. url: '/lionfish_comshop/pages/order/placeOrder?type='+buy_type+'&is_limit=' + is_limit
  912. })
  913. } else {
  914. wx.navigateTo({
  915. url: '/lionfish_comshop/pages/order/placeOrder?type='+buy_type+'&is_limit=' + is_limit
  916. })
  917. }
  918. }
  919. }
  920. }
  921. }
  922. }).catch(res=>{
  923. app.util.message(res||'请求失败', '', 'error');
  924. })
  925. },
  926. vipModal: function(t) {
  927. this.setData(t.detail)
  928. },
  929. selectSku: function(event) {
  930. var that = this;
  931. let str = event.currentTarget.dataset.type;
  932. let obj = str.split("_");
  933. let { sku, skuList, sku_val, cur_sku_arr } = this.data;
  934. let temp = {
  935. name: obj[3],
  936. id: obj[2],
  937. index: obj[0],
  938. idx: obj[1]
  939. };
  940. sku.splice(obj[0], 1, temp);
  941. var id = '';
  942. for (let i = 0; i < sku.length; i++) {
  943. if (i == sku.length - 1) {
  944. id = id + sku[i]['id'];
  945. } else {
  946. id = id + sku[i]['id'] + "_";
  947. }
  948. }
  949. let new_sku_arr = skuList.sku_mu_list[id];
  950. cur_sku_arr = {...cur_sku_arr, ...new_sku_arr};
  951. let h = {};
  952. h.noEougnStock = false;
  953. sku_val = sku_val || 1;
  954. let { canBuyNum, car_quantity, goods_start_count } = cur_sku_arr;
  955. if(sku_val > canBuyNum*1) {
  956. h.sku_val = canBuyNum==0?1:canBuyNum;
  957. (canBuyNum>0) && wx.showToast({
  958. title: `最多只能购买${cur_sku_arr.canBuyNum}件`,
  959. icon: 'none'
  960. })
  961. }
  962. // 20200622
  963. console.log(car_quantity)
  964. if(car_quantity && car_quantity>=goods_start_count) {
  965. sku_val = car_quantity;
  966. } else {
  967. sku_val = goods_start_count || 1;
  968. }
  969. // 库存小于起购数量 按钮变灰 数量变起购
  970. if(canBuyNum*1<goods_start_count) {
  971. h.sku_val = goods_start_count;
  972. h.noEougnStock = true;
  973. } else {
  974. h.sku_val = sku_val;
  975. }
  976. if(this.data.buy_type=='integral') {
  977. h.sku_val = 1;
  978. }
  979. that.setData({
  980. cur_sku_arr,
  981. sku,
  982. showLimitTip: false,
  983. ...h
  984. });
  985. },
  986. submit: function(e) {
  987. var from_id = e.detail.formId;
  988. var token = wx.getStorageSync('token');
  989. app.util.request({
  990. 'url': 'entry/wxapp/user',
  991. 'data': {
  992. controller: 'user.get_member_form_id',
  993. 'token': token,
  994. "from_id": from_id
  995. },
  996. dataType: 'json',
  997. success: function(res) {}
  998. })
  999. },
  1000. balance: function(e) {
  1001. if (this.authModal()) {
  1002. this.setData({
  1003. is_just_addcar: 0
  1004. })
  1005. let is_need_subscript = this.data.is_need_subscript;
  1006. if(is_need_subscript==1) {
  1007. //弹出订阅消息
  1008. this.subscriptionNotice().then(()=>{
  1009. this.openSku();
  1010. }).catch(()=>{
  1011. this.openSku();
  1012. });
  1013. } else {
  1014. //加入购物车
  1015. this.openSku();
  1016. }
  1017. }
  1018. },
  1019. /**
  1020. * 数量加减
  1021. */
  1022. setNum: function(event) {
  1023. let types = event.currentTarget.dataset.type;
  1024. var that = this;
  1025. var num = 1;
  1026. let sku_val = this.data.sku_val * 1;
  1027. let showLimitTip = false;
  1028. let showLimitType = 0;
  1029. if (types == 'add') {
  1030. num = sku_val + 1;
  1031. let {one_limit_count, total_limit_count, oneday_limit_count} = this.data.cur_sku_arr;
  1032. if(one_limit_count>0 && num > one_limit_count) {
  1033. wx.showToast({
  1034. title: `您本次只能购买${one_limit_count}份`,
  1035. icon: 'none'
  1036. })
  1037. num = one_limit_count;
  1038. showLimitTip = true;
  1039. showLimitType = 1;
  1040. } else if(oneday_limit_count>0 && num > oneday_limit_count) {
  1041. wx.showToast({
  1042. title: `您今天只能购买${oneday_limit_count}份`,
  1043. icon: 'none'
  1044. })
  1045. num = oneday_limit_count;
  1046. showLimitTip = true;
  1047. showLimitType = 2;
  1048. } else if(total_limit_count>0 && num > total_limit_count) {
  1049. wx.showToast({
  1050. title: `您最多只能购买${total_limit_count}份`,
  1051. icon: 'none'
  1052. })
  1053. num = total_limit_count;
  1054. showLimitTip = true;
  1055. showLimitType = 3;
  1056. }
  1057. } else if (types == 'decrease') {
  1058. let goods_start_count = this.data.cur_sku_arr.goods_start_count;
  1059. if (sku_val > 1) {
  1060. num = sku_val - 1;
  1061. if(num<goods_start_count){
  1062. num = goods_start_count;
  1063. wx.showToast({
  1064. title: `${goods_start_count}件起售`,
  1065. icon: 'none'
  1066. })
  1067. }
  1068. }
  1069. }
  1070. let arr = that.data.sku;
  1071. var options = this.data.skuList;
  1072. if (arr.length > 0) {
  1073. var id = '';
  1074. for (let i = 0; i < arr.length; i++) {
  1075. if (i == arr.length - 1) {
  1076. id = id + arr[i]['id'];
  1077. } else {
  1078. id = id + arr[i]['id'] + "_";
  1079. }
  1080. }
  1081. }
  1082. if (options.length > 0) {
  1083. var cur_sku_arr = options.sku_mu_list[id];
  1084. if (num > cur_sku_arr['canBuyNum']) {
  1085. num = num - 1;
  1086. }
  1087. } else {
  1088. let cur_sku_arr = this.data.cur_sku_arr;
  1089. if (num > cur_sku_arr['canBuyNum']) {
  1090. num = num - 1;
  1091. }
  1092. }
  1093. this.setData({
  1094. sku_val: num,
  1095. showLimitTip,
  1096. showLimitType
  1097. })
  1098. },
  1099. scrollImagesChange: function(t) {
  1100. this.videoContext && this.videoContext.pause();
  1101. this.setData({
  1102. fmShow: true,
  1103. goodsIndex: t.detail.current + 1
  1104. });
  1105. },
  1106. share_handler: function() {
  1107. this.setData({
  1108. is_share_html: false
  1109. })
  1110. },
  1111. hide_share_handler: function() {
  1112. this.setData({
  1113. is_share_html: true
  1114. })
  1115. },
  1116. share_quan: function() {
  1117. if (!this.authModal()) return;
  1118. wx.showLoading({
  1119. title: '获取中',
  1120. })
  1121. var token = wx.getStorageSync('token');
  1122. var community = wx.getStorageSync('community');
  1123. var goods_id = this.data.order.goods_id;
  1124. var community_id = community.communityId;
  1125. var that = this;
  1126. app.util.request({
  1127. url: 'entry/wxapp/index',
  1128. data: {
  1129. controller: 'goods.get_user_goods_qrcode',
  1130. token: token,
  1131. community_id: community_id,
  1132. goods_id: goods_id
  1133. },
  1134. dataType: 'json',
  1135. success: function(res) {
  1136. if (res.data.code == 0) {
  1137. setTimeout(function() {
  1138. wx.hideLoading()
  1139. }, 2000)
  1140. var image_path = res.data.image_path;
  1141. wx.getImageInfo({
  1142. src: image_path,
  1143. success: function(res) {
  1144. var real_path = res.path;
  1145. wx.saveImageToPhotosAlbum({
  1146. filePath: real_path,
  1147. success(res) {
  1148. wx.showToast({
  1149. title: '图片保存成功,可以分享了',
  1150. icon: 'none',
  1151. duration: 2000
  1152. })
  1153. that.setData({
  1154. is_share_html: true
  1155. });
  1156. }
  1157. })
  1158. }
  1159. })
  1160. } else {
  1161. that.setData({
  1162. needAuth: true
  1163. })
  1164. }
  1165. }
  1166. })
  1167. },
  1168. /**
  1169. * 生命周期函数--监听页面显示
  1170. */
  1171. onShow: function() {
  1172. let that = this;
  1173. util.check_login_new().then((res) => {
  1174. console.log('onShow', res)
  1175. if(!res) {
  1176. that.setData({
  1177. needAuth: true
  1178. })
  1179. } else {
  1180. (0, status.cartNum)('', true).then((res) => {
  1181. res.code == 0 && that.setData({
  1182. cartNum: res.data
  1183. })
  1184. });
  1185. }
  1186. })
  1187. this.setData({
  1188. stopNotify: false
  1189. });
  1190. },
  1191. onReady: function (res) {
  1192. this.videoContext = wx.createVideoContext('myVideo');
  1193. this.coverVideoContext = wx.createVideoContext('coverVideo');
  1194. },
  1195. /**
  1196. * 生命周期函数--监听页面隐藏
  1197. */
  1198. onHide: function() {
  1199. this.setData({ stopNotify: true })
  1200. console.log('详情页hide', this.data.stopNotify)
  1201. },
  1202. /**
  1203. * 生命周期函数--监听页面卸载
  1204. */
  1205. onUnload: function() {
  1206. console.log('onUnload')
  1207. this.setData({ stopNotify: true })
  1208. console.log('详情页unload', this.data.stopNotify);
  1209. detailClearTime = null;
  1210. clearTimeout(detailClearTime);
  1211. },
  1212. /**
  1213. * 获取分享图并显示
  1214. * 20181225 新形式
  1215. */
  1216. get_share_img: function () {
  1217. if (!this.authModal()) return;
  1218. wx.showLoading();
  1219. let shareImgUrl = this.data.shareImgUrl;
  1220. if (shareImgUrl != '') {
  1221. wx.hideLoading();
  1222. this.setData({
  1223. hideModal: false,
  1224. is_share_html: true
  1225. })
  1226. } else {
  1227. var token = wx.getStorageSync('token');
  1228. var community = wx.getStorageSync('community');
  1229. var goods_id = this.data.goods_id;
  1230. var community_id = community.communityId;
  1231. var that = this;
  1232. app.util.request({
  1233. url: 'entry/wxapp/index',
  1234. data: {
  1235. controller: 'goods.get_user_goods_qrcode',
  1236. token: token,
  1237. community_id: community_id,
  1238. goods_id: goods_id
  1239. },
  1240. dataType: 'json',
  1241. success: function (res) {
  1242. if (res.data.code == 0) {
  1243. wx.hideLoading();
  1244. var image_path = res.data.image_path;
  1245. wx.previewImage({
  1246. current: image_path, // 当前显示图片的http链接
  1247. urls: [image_path] // 需要预览的图片http链接列表
  1248. })
  1249. } else {
  1250. that.setData({
  1251. needAuth: true
  1252. })
  1253. }
  1254. }
  1255. })
  1256. }
  1257. },
  1258. closeShareModal: function () {
  1259. this.setData({ hideModal: true })
  1260. },
  1261. /**
  1262. * 展开收起
  1263. */
  1264. bindOpen: function (t) {
  1265. var idx = t.currentTarget.dataset.idx;
  1266. console.log(idx)
  1267. if (this.data.comment_list[idx].isOpen) {
  1268. this.data.comment_list[idx].isOpen = false;
  1269. var comment_list = this.data.comment_list;
  1270. this.setData({
  1271. comment_list: comment_list
  1272. });
  1273. } else {
  1274. this.data.comment_list[idx].isOpen = true;
  1275. var comment_list = this.data.comment_list;
  1276. this.setData({
  1277. comment_list: comment_list
  1278. });
  1279. }
  1280. },
  1281. /**
  1282. * 保存分享图并显示
  1283. * 20181225 新形式
  1284. */
  1285. saveThumb: function (e) {
  1286. wx.showLoading();
  1287. let that = this;
  1288. var image_path = this.data.shareImgUrl;
  1289. wx.getImageInfo({
  1290. src: image_path,
  1291. success: function (res) {
  1292. var real_path = res.path;
  1293. real_path && wx.saveImageToPhotosAlbum({
  1294. filePath: real_path,
  1295. success(res) {
  1296. console.log(res)
  1297. wx.hideLoading();
  1298. wx.showToast({
  1299. title: '已保存相册',
  1300. icon: 'none',
  1301. duration: 2000
  1302. })
  1303. that.setData({
  1304. hideModal: true
  1305. });
  1306. },
  1307. fail: function (res) {
  1308. wx.hideLoading();
  1309. console.log(res)
  1310. if (res.errMsg === "saveImageToPhotosAlbum:fail:auth denied") {
  1311. wx.openSetting({
  1312. success(settingdata) {
  1313. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  1314. console.log("获取权限成功,再次点击图片保存到相册")
  1315. } else {
  1316. console.log("获取权限失败")
  1317. }
  1318. }
  1319. })
  1320. }
  1321. }
  1322. })
  1323. }
  1324. })
  1325. },
  1326. drawImgNoPrice: function () {
  1327. var t = this;
  1328. wx.createSelectorQuery().select(".canvas-img").boundingClientRect(function () {
  1329. const context = wx.createCanvasContext("myCanvas");
  1330. context.drawImage(t.goodsImg, 0, 0, status.getPx(375), status.getPx(300));
  1331. if (t.data.goods.video) context.drawImage("../../images/play.png", status.getPx(127.5), status.getPx(90), status.getPx(120), status.getPx(120));
  1332. context.save();
  1333. context.restore(), context.draw(false, t.checkCanvasNoPrice());
  1334. }).exec();
  1335. },
  1336. checkCanvasNoPrice: function () {
  1337. var that = this;
  1338. setTimeout(() => {
  1339. wx.canvasToTempFilePath({
  1340. canvasId: "myCanvas",
  1341. success: function (res) {
  1342. res.tempFilePath ? that.imageUrl = res.tempFilePath : that.drawImgNoPrice();
  1343. console.log('我画完了')
  1344. },
  1345. fail: function (a) {
  1346. that.drawImgNoPrice();
  1347. }
  1348. })
  1349. }, 500)
  1350. },
  1351. drawImg: function () {
  1352. let endtime = this.data.endtime;
  1353. let shareTime = (endtime.days > 0 ? endtime.days + '天' : '') + endtime.hours + ':' + endtime.minutes + ':' + endtime.seconds;
  1354. console.log('endtime', shareTime);
  1355. var t = this;
  1356. wx.createSelectorQuery().select(".canvas-img").boundingClientRect(function () {
  1357. const context = wx.createCanvasContext("myCanvas");
  1358. context.font = "28px Arial";
  1359. if(t.data.buy_type=='integral') {
  1360. var e = context.measureText(" ").width;
  1361. var o = context.measureText(t.data.goods.price + "积分").width;
  1362. } else {
  1363. var e = context.measureText("¥").width + 2;
  1364. var o = context.measureText(t.data.goods.price_front + "." + t.data.goods.price_after).width;
  1365. }
  1366. context.font = "17px Arial";
  1367. var s = context.measureText("¥" + t.data.goods.productprice).width + 3,
  1368. n = context.measureText("累计销售 " + t.data.goods.seller_count).width,
  1369. u = context.measureText("· 剩余" + t.data.goods.total + " ").width + 10;
  1370. context.font = "18px Arial";
  1371. let over_type_text = t.data.goods.over_type == 0 ? '距开始' : '距结束';
  1372. var r = context.measureText(over_type_text).width;
  1373. var d = context.measureText(shareTime).width + 10;
  1374. context.drawImage(t.goodsImg, 0, 0, status.getPx(375), status.getPx(300));
  1375. context.drawImage("../../images/shareBottomBg.png", status.getPx(0), status.getPx(225), status.getPx(375), status.getPx(75));
  1376. if (t.data.goods.video) context.drawImage("../../images/play.png", status.getPx(127.5), status.getPx(70), status.getPx(120), status.getPx(120));
  1377. context.save();
  1378. if(t.data.buy_type=='integral') {
  1379. status.drawText(context, { color: "#ffffff", size: 28, textAlign: "left" }, t.data.goods.price + "积分",
  1380. status.getPx(e), status.getPx(267), status.getPx(o));
  1381. } else {
  1382. status.drawText(context, { color: "#ffffff", size: 28, textAlign: "left" }, "¥", status.getPx(6), status.getPx(267), status.getPx(e));
  1383. status.drawText(context, { color: "#ffffff", size: 28, textAlign: "left" }, t.data.goods.price_front + "." + t.data.goods.price_after,
  1384. status.getPx(e), status.getPx(267), status.getPx(o));
  1385. }
  1386. context.restore();
  1387. context.save();
  1388. context.restore(),
  1389. context.save(),
  1390. (0, status.drawText)(context,
  1391. { color: "#ffffff", size: 15, textAlign: "left" },
  1392. "¥" + t.data.goods.productprice,
  1393. (0, status.getPx)(e + o + 10),
  1394. (0, status.getPx)(267),
  1395. (0, status.getPx)(s)
  1396. ),
  1397. context.restore();
  1398. if(t.data.is_hide_details_count==0) {
  1399. context.save(),
  1400. (0, status.drawText)(
  1401. context,
  1402. { color: "#ffffff", size: 17, textAlign: "left" },
  1403. "累计销售" + t.data.goods.seller_count,
  1404. (0, status.getPx)(10),
  1405. (0, status.getPx)(290),
  1406. (0, status.getPx)(n)
  1407. ),
  1408. context.restore(),
  1409. context.save(),
  1410. (0, status.drawText)(context,
  1411. { color: "#ffffff", size: 17, textAlign: "left" },
  1412. "· 剩余" + t.data.goods.total,
  1413. (0, status.getPx)(n + 10),
  1414. (0, status.getPx)(290),
  1415. (0, status.getPx)(u)
  1416. ),
  1417. context.restore();
  1418. }
  1419. context.save(),
  1420. context.beginPath(),
  1421. context.setStrokeStyle("white"),
  1422. context.moveTo((0, status.getPx)(e + o + 10),
  1423. (0, status.getPx)(261)),
  1424. context.lineTo((0, status.getPx)(e + o + s + 15),
  1425. (0, status.getPx)(261)),
  1426. context.stroke(),
  1427. context.restore(),
  1428. context.save(),
  1429. (0, status.drawText)(context,
  1430. { color: "#F8E71C", size: 18, textAlign: "center" },
  1431. over_type_text,
  1432. (0, status.getPx)(318),
  1433. (0, status.getPx)(260),
  1434. (0, status.getPx)(r)
  1435. ),
  1436. context.restore(),
  1437. context.save(),
  1438. (0, status.drawText)(context, { color: "#F8E71C", size: 18, textAlign: "center" },
  1439. shareTime,
  1440. (0, status.getPx)(315),
  1441. (0, status.getPx)(288),
  1442. (0, status.getPx)(d)
  1443. ),
  1444. context.restore();
  1445. context.draw(false, t.checkCanvas());
  1446. }).exec();
  1447. },
  1448. checkCanvas: function () {
  1449. var that = this;
  1450. setTimeout(() => {
  1451. wx.canvasToTempFilePath({
  1452. canvasId: "myCanvas",
  1453. success: function (res) {
  1454. res.tempFilePath ? that.imageUrl = res.tempFilePath : that.drawImg();
  1455. console.log('我画完了')
  1456. },
  1457. fail: function (a) {
  1458. that.drawImg();
  1459. }
  1460. })
  1461. }, 500)
  1462. },
  1463. drawImg1: function () {
  1464. let endtime = this.data.endtime;
  1465. let shareTime = (endtime.days > 0 ? endtime.days + '天' : '') + endtime.hours + ':' + endtime.minutes + ':' + endtime.seconds;
  1466. var t = this;
  1467. let option = [];
  1468. let price = 0;
  1469. if(t.data.buy_type=='integral') {
  1470. price = t.data.goods.price + "积分";
  1471. var e = context.measureText(" ").width;
  1472. var o = context.measureText(t.data.goods.price + "积分").width;
  1473. } else {
  1474. price = "¥" + t.data.goods.price_front + "." + t.data.goods.price_after;
  1475. }
  1476. // if (t.data.buy_type=='integral') {
  1477. // option.push()
  1478. // }
  1479. this.setData({
  1480. template: {
  1481. "width": "375px",
  1482. "height": "300px",
  1483. "background": "#fff",
  1484. "views": [
  1485. {
  1486. "type": "image",
  1487. "url": t.goodsImg,
  1488. "css":
  1489. {
  1490. "width": "375px",
  1491. "height": "300px",
  1492. "top": "0px",
  1493. "left": "0px",
  1494. "rotate": "0",
  1495. "borderRadius": "0px",
  1496. "borderWidth": "",
  1497. "borderColor": "#000000",
  1498. "shadow": "",
  1499. "mode": "aspectFill"
  1500. }
  1501. },
  1502. {
  1503. "type": "image",
  1504. "url": "../../images/shareBottomBg.png",
  1505. "css":
  1506. {
  1507. "width": "375px",
  1508. "height": "53px",
  1509. "bottom": "0",
  1510. "left": "0px",
  1511. "rotate": "0",
  1512. "borderRadius": "",
  1513. "borderWidth": "",
  1514. "borderColor": "#000000",
  1515. "shadow": "",
  1516. "mode": "scaleToFill"
  1517. }
  1518. },
  1519. {
  1520. "type": "text",
  1521. "text": price,
  1522. "css":
  1523. {
  1524. "color": "#ffffff",
  1525. "background": "",
  1526. "width": "375px",
  1527. "height": "28px",
  1528. "bottom": "30px",
  1529. "left": "10px",
  1530. "rotate": "0",
  1531. "borderRadius": "",
  1532. "borderWidth": "",
  1533. "borderColor": "#000000",
  1534. "shadow": "",
  1535. "padding": "0px",
  1536. "fontSize": "28px",
  1537. "fontWeight": "normal",
  1538. "maxLines": "1",
  1539. "lineHeight": "28px",
  1540. "textStyle": "fill",
  1541. "textDecoration": "none",
  1542. "fontFamily": "Arial",
  1543. "textAlign": "left"
  1544. }
  1545. },
  1546. ...option
  1547. ]
  1548. }
  1549. });
  1550. },
  1551. onImgOK(e) {
  1552. this.imagePath = e.detail.path;
  1553. this.imageUrl = this.imagePath;
  1554. },
  1555. previewImg: function(e){
  1556. if(this.show_goods_preview==1) return;
  1557. let idx = e.currentTarget.dataset.idx || 0;
  1558. let prevImgArr = this.data.prevImgArr;
  1559. wx.previewImage({
  1560. current: prevImgArr[idx],
  1561. urls: prevImgArr
  1562. })
  1563. },
  1564. /**
  1565. * 播放视频隐藏封面图
  1566. */
  1567. btnPlay: function () {
  1568. this.setData({
  1569. fmShow: false
  1570. })
  1571. this.videoContext.play();
  1572. },
  1573. videEnd: function(){
  1574. this.videoContext.exitFullScreen();
  1575. this.setData({
  1576. fmShow: true
  1577. })
  1578. },
  1579. endPlay: function(){
  1580. this.videoContext.pause();
  1581. this.setData({
  1582. fmShow: true
  1583. })
  1584. },
  1585. // 显示群主二维码
  1586. showGroupCode: function(){
  1587. let group_share_info = this.data.group_share_info;
  1588. let imgUrl = group_share_info.share_wxcode || '';
  1589. if(imgUrl) {
  1590. wx.previewImage({
  1591. current: imgUrl, // 当前显示图片的http链接
  1592. urls: [imgUrl] // 需要预览的图片http链接列表
  1593. })
  1594. } else {
  1595. wx.showModal({
  1596. title: "提示",
  1597. content: "未设置联系方式,请联系管理员",
  1598. showCancel: false
  1599. })
  1600. }
  1601. },
  1602. changeCommunity: function() {
  1603. if (this.data.hide_community_change_btn==0) {
  1604. var id = this.$data.id;
  1605. var scene = this.$data.scene;
  1606. var community_id = this.$data.community_id;
  1607. let url = '/lionfish_comshop/pages/goods/goodsDetail?id=' + id + '&community_id=' + community_id + '&scene=' + scene;
  1608. app.globalData.navBackUrl = url;
  1609. wx.redirectTo({
  1610. url: '/lionfish_comshop/pages/position/community',
  1611. })
  1612. }
  1613. },
  1614. changeCartNum: function (t) {
  1615. let that = this;
  1616. let e = t.detail;
  1617. (0, status.cartNum)(that.setData({ cartNum: e }));
  1618. },
  1619. goLink: function (event) {
  1620. if (!this.authModal()) return;
  1621. let link = event.currentTarget.dataset.link;
  1622. var pages_all = getCurrentPages();
  1623. if (pages_all.length > 3) {
  1624. wx.redirectTo({
  1625. url: link
  1626. })
  1627. } else {
  1628. wx.navigateTo({
  1629. url: link
  1630. })
  1631. }
  1632. },
  1633. // 输入框获得焦点
  1634. handleFocus: function () {
  1635. this.focusFlag = true;
  1636. },
  1637. handleBlur: function (t) {
  1638. let a = t.detail;
  1639. let val = parseInt(a.value);
  1640. if (val == '' || isNaN(val)) {
  1641. let goods_start_count = this.data.cur_sku_arr.goods_start_count;
  1642. wx.showToast({
  1643. title: `${goods_start_count}件起售`,
  1644. icon: 'none'
  1645. })
  1646. this.setData({ sku_val: goods_start_count })
  1647. }
  1648. },
  1649. // 监控输入框变化
  1650. changeNumber: function (t) {
  1651. let { cur_sku_arr, sku_val } = this.data;
  1652. let max = cur_sku_arr.stock * 1;
  1653. let a = t.detail;
  1654. this.focusFlag = false;
  1655. if (a) {
  1656. let val = parseInt(a.value);
  1657. val = val < 1 ? 1 : val;
  1658. if (val > max) {
  1659. wx.showToast({
  1660. title: `最多只能购买${max}件`,
  1661. icon: 'none'
  1662. })
  1663. sku_val = max;
  1664. } else {
  1665. sku_val = val;
  1666. }
  1667. }
  1668. this.setData({ sku_val })
  1669. },
  1670. handleHexiaoModal: function() {
  1671. this.setData({
  1672. showHexiaoModal: !this.data.showHexiaoModal
  1673. })
  1674. },
  1675. coverVideoEnd: function(){
  1676. this.setData({
  1677. showCoverVideo: false
  1678. })
  1679. },
  1680. closeCoverVideo: function(){
  1681. this.coverVideoContext.pause();
  1682. this.setData({
  1683. showCoverVideo: false
  1684. })
  1685. },
  1686. handleLoadedMetaData(e) {
  1687. const { width, height } = e.detail;
  1688. let platform = app.globalData.systemInfo.platform || '';
  1689. console.log(platform)
  1690. if (platform === 'android') {
  1691. let ww = this.data.imageSize.imageHeight;
  1692. this.setData({
  1693. videoStyle: `width: calc(${ww * width / height})px`,
  1694. });
  1695. }
  1696. },
  1697. bindimgtap: function(e, ignore) {
  1698. (this.show_goods_preview==1)&&e.detail.ignore();
  1699. },
  1700. /**
  1701. * 订阅消息
  1702. */
  1703. subscriptionNotice: function() {
  1704. let that = this;
  1705. return new Promise((resolve, reject)=>{
  1706. let obj = that.data.need_subscript_template;
  1707. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  1708. if (wx.requestSubscribeMessage) {
  1709. tmplIds.length && wx.requestSubscribeMessage({
  1710. tmplIds: tmplIds,
  1711. success(res) {
  1712. let is_need_subscript = 1;
  1713. let acceptId = [];
  1714. Object.keys(obj).forEach(item=>{
  1715. if (res[obj[item]] == 'accept') {
  1716. //用户同意了订阅,添加进数据库
  1717. acceptId.push(item);
  1718. } else {
  1719. //用户拒绝了订阅或当前游戏被禁用订阅消息
  1720. is_need_subscript = 0;
  1721. }
  1722. })
  1723. if(acceptId.length) {
  1724. that.addAccept(acceptId);
  1725. }
  1726. that.setData({ is_need_subscript })
  1727. resolve();
  1728. },
  1729. fail(err) {
  1730. console.log(err)
  1731. reject();
  1732. }
  1733. })
  1734. } else {
  1735. // 兼容处理
  1736. reject();
  1737. }
  1738. })
  1739. },
  1740. // 用户点击订阅添加到数据库
  1741. addAccept: function (acceptId) {
  1742. let token = wx.getStorageSync('token');
  1743. let type = acceptId.join(',');
  1744. app.util.request({
  1745. url: 'entry/wxapp/user',
  1746. data: {
  1747. controller: 'user.collect_subscriptmsg',
  1748. token,
  1749. type
  1750. },
  1751. dataType: 'json',
  1752. method: 'POST',
  1753. success: function () {}
  1754. })
  1755. },
  1756. /**
  1757. * 用户点击右上角分享
  1758. */
  1759. onShareAppMessage: function() {
  1760. var community = wx.getStorageSync('community');
  1761. let { goods_id, buy_type } = this.data;
  1762. var community_id = community.communityId;
  1763. var share_title = this.data.share_title;
  1764. var share_id = wx.getStorageSync('member_id');
  1765. var share_path = 'lionfish_comshop/pages/goods/goodsDetail?id=' + goods_id + '&share_id=' + share_id + '&community_id=' + community_id + '&type=' + buy_type;
  1766. let shareImg = this.data.goods.goods_share_image || '';
  1767. console.log('商品分享地址:');
  1768. console.log(share_path);
  1769. var that = this;
  1770. that.setData({is_share_html: true, hideModal: true, hideCommissInfo: true})
  1771. setTimeout(()=>{
  1772. this.setData({
  1773. hideCommissInfo: false
  1774. })
  1775. }, 1000)
  1776. return {
  1777. title: share_title,
  1778. path: share_path,
  1779. imageUrl: shareImg ? shareImg : that.imageUrl,
  1780. success: function(res) {
  1781. // 转发成功
  1782. },
  1783. fail: function(res) {
  1784. // 转发失败
  1785. }
  1786. }
  1787. },
  1788. onShareTimeline: function(res) {
  1789. let shareImg = this.data.goods.goods_share_image || '';
  1790. var share_id = wx.getStorageSync('member_id');
  1791. var community = wx.getStorageSync('community');
  1792. var community_id = community.communityId;
  1793. let { goods_id, buy_type } = this.data;
  1794. var query= `id=${goods_id}&share_id=${share_id}&community_id=${community_id}&buy_type=${buy_type}`;
  1795. return {
  1796. title: this.data.share_title,
  1797. query,
  1798. imageUrl: shareImg ? shareImg : this.imageUrl,
  1799. success: function() {},
  1800. fail: function() {}
  1801. };
  1802. }
  1803. })