placeOrder.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. var app = getApp()
  2. var locat = require('../../utils/Location.js');
  3. var util = require('../../utils/util.js');
  4. var status = require('../../utils/index.js');
  5. var wcache = require('../../utils/wcache.js');
  6. Page({
  7. mixins: [require('../../mixin/globalMixin.js')],
  8. data: {
  9. payBtnLoading: false,
  10. showConfirmModal: false,
  11. receiverAddress: "", //快递送货地址
  12. tuan_send_address: "", //团长送货地址
  13. showGetPhone: false,
  14. lou_meng_hao:'',
  15. pickUpAddress: "",
  16. disUserName: "",
  17. pickUpCommunityName: "",
  18. is_limit_distance_buy: 0,
  19. tabList: [
  20. { id: 0, name: '社区自提', dispatching: 'pickup', enabled: false },
  21. { id: 1, name: '团长配送', dispatching: 'tuanz_send', enabled: false },
  22. { id: 2, name: '快递配送', dispatching: 'express', enabled: false },
  23. { id: 3, name: '同城配送', dispatching: 'localtown_delivery', enabled: false},
  24. { id: 4, name: '到店核销', dispatching: 'hexiao', enabled: false}
  25. ],
  26. originTabList: [
  27. { id: 0, name: '社区自提', dispatching: 'pickup' },
  28. { id: 1, name: '团长配送', dispatching: 'tuanz_send'},
  29. { id: 2, name: '快递配送', dispatching: 'express'},
  30. { id: 3, name: '同城配送', dispatching: 'localtown_delivery'},
  31. { id: 4, name: '到店核销', dispatching: 'hexiao'}
  32. ],
  33. tabIdx: 0,
  34. region: ['选择地址', '', ''],
  35. tot_price: 0,
  36. needAuth: false,
  37. reduce_money: 0,
  38. hide_quan: true,
  39. tuan_region: ['选择地址','',''],
  40. groupInfo: {
  41. group_name: '社区',
  42. owner_name: '团长',
  43. placeorder_tuan_name: '配送费',
  44. placeorder_trans_name: '快递费'
  45. },
  46. comment: '',
  47. is_yue_open: 0,
  48. can_yupay: 0,
  49. ck_yupay: 0,
  50. use_score: 0,
  51. commentArr: {},
  52. note_content: '',
  53. showAlertTime: false,
  54. curAlertTime: -1,
  55. isAgreePresale: false,
  56. presale_info: '',
  57. presalePickup: ['自提','配送','发货','配送','核销'],
  58. allform: ""
  59. },
  60. canPay: true,
  61. canPreSub: true,
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad: function(options) {
  66. var that = this;
  67. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  68. var token = wx.getStorageSync('token');
  69. var community = wx.getStorageSync('community');
  70. var community_id = community.communityId;
  71. util.check_login() ? this.setData({ needAuth: false }) : (this.setData({ needAuth: true }));
  72. // let is_limit = options.is_limit || 0;
  73. this.setData({
  74. buy_type: options.type || '',
  75. soli_id: options.soli_id || '',
  76. pickUpAddress: community.fullAddress || '',
  77. pickUpCommunityName: community.communityName || '',
  78. disUserName: community.disUserName || ''
  79. })
  80. wx.showLoading()
  81. app.util.request({
  82. url: 'entry/wxapp/user',
  83. data: {
  84. controller: 'car.checkout',
  85. token: token,
  86. community_id,
  87. buy_type: options.type,
  88. soli_id: options.soli_id
  89. },
  90. dataType: 'json',
  91. method: 'POST',
  92. success: function (res) {
  93. // wx.hideLoading();
  94. setTimeout(function(){ wx.hideLoading(); },1000);
  95. let rdata = res.data;
  96. // 提货方式
  97. let tabIdx = -1;
  98. let tabLength = 0;
  99. let tabList = that.data.tabList || {};
  100. let sortTabList = [];
  101. let {
  102. delivery_express_name,
  103. delivery_tuanzshipping_name,
  104. delivery_ziti_name,
  105. delivery_diy_sort,
  106. delivery_type_express,
  107. delivery_type_tuanz,
  108. delivery_type_ziti,
  109. delivery_tuanz_money,
  110. is_vip_card_member,
  111. vipcard_save_money,
  112. level_save_money,
  113. is_open_vipcard_buy,
  114. is_member_level_buy,
  115. total_integral,
  116. is_need_subscript,
  117. need_subscript_template,
  118. delvery_type_hexiao,
  119. order_note_open,
  120. order_note_name,
  121. order_note_content,
  122. delivery_type_localtown,
  123. localtown_dispatchtime, //预计配送需要多少分钟
  124. pickingup_fare, //订单包装费,只有在 同城快递的时
  125. localtown_shipping_fare, //同城配送费
  126. localtown_modifypickingname,
  127. localtown_shipping_fare_arr,
  128. localtown_moneytype_fixed_freemoney,
  129. localtown_makeup_delivery_money,
  130. localtown_expected_delivery,
  131. order_lou_meng_hao,
  132. order_lou_meng_hao_placeholder,
  133. presale_info,
  134. cashondelivery_data,
  135. allform
  136. } = res.data;
  137. let {
  138. isopen_cashondelivery,
  139. isopen_cashondelivery_communityhead,
  140. isopen_cashondelivery_express,
  141. isopen_cashondelivery_hexiao,
  142. isopen_cashondelivery_localtown
  143. } = cashondelivery_data;
  144. presale_info = Object.keys(presale_info).length ? presale_info : '';
  145. // 同城满免运费
  146. if(localtown_shipping_fare_arr) {
  147. let shipping_fare = 0;
  148. shipping_fare = localtown_shipping_fare_arr.total_yl_shipping_fare*1 - localtown_shipping_fare_arr.total_shipping_fare*1;
  149. localtown_shipping_fare_arr.shipping_fare = shipping_fare.toFixed(2);
  150. }
  151. if (delivery_type_localtown == 1) tabList[3].enabled = true, tabLength++;
  152. if (delivery_type_express == 1) tabList[2].enabled = true, tabLength++;
  153. if (delivery_type_tuanz == 1) tabList[1].enabled = true, tabLength++;
  154. if (delivery_type_ziti == 1) tabList[0].enabled = true, tabLength++;
  155. if (delivery_diy_sort) {
  156. let sortArr = delivery_diy_sort.split(',');
  157. if (sortArr[2] && tabList[sortArr[2]] && tabList[sortArr[2]].enabled) tabIdx = sortArr[2];
  158. if (sortArr[1] && tabList[sortArr[1]] && tabList[sortArr[1]].enabled) tabIdx = sortArr[1];
  159. if (sortArr[0] && tabList[sortArr[0]] && tabList[sortArr[0]].enabled) tabIdx = sortArr[0];
  160. sortArr.forEach(function(item){
  161. sortTabList.push(tabList[item]);
  162. })
  163. }
  164. delivery_express_name && (tabList[2].name = delivery_express_name);
  165. delivery_tuanzshipping_name && (tabList[1].name = delivery_tuanzshipping_name);
  166. delivery_ziti_name && (tabList[0].name = delivery_ziti_name);
  167. // 同城配送TODO...
  168. sortTabList.push({id: 3, name: '同城配送', dispatching: 'localtown_delivery', enabled: (delivery_type_localtown==1) });
  169. if(tabIdx==-1&&delivery_type_localtown==1) tabIdx=3;
  170. let localtown_delivery_space_month = '';
  171. if(localtown_expected_delivery&&localtown_expected_delivery.localtown_delivery_space_month) {
  172. localtown_delivery_space_month = localtown_expected_delivery.localtown_delivery_space_month;
  173. }
  174. // 到店核销
  175. sortTabList.push({id: 4, name: '到店核销', dispatching: 'hexiao', enabled: (delvery_type_hexiao==1) });
  176. if(tabIdx==-1&&delvery_type_hexiao) { tabIdx = 4; }
  177. var addres = 0;
  178. addres = 1;
  179. var seller_chose_id = 0;
  180. var seller_chose_store_id = 0;
  181. var seller_goods = rdata.seller_goodss;
  182. let commentArr = {};
  183. for (let key in seller_goods) commentArr[key] = '';
  184. let sel_chose_vouche = '';
  185. let sgvKey = 0;
  186. let goodsTotNum = 0;
  187. for (var i in seller_goods) {
  188. if (seller_goods[i].show_voucher == 1) {
  189. if (seller_goods[i].chose_vouche.id) seller_chose_id = seller_goods[i].chose_vouche.id;
  190. if (seller_goods[i].chose_vouche.store_id) seller_chose_store_id = seller_goods[i].chose_vouche.store_id;
  191. if (Object.prototype.toString.call(seller_goods[i].chose_vouche) == '[object Object]'){
  192. sel_chose_vouche = seller_goods[i].chose_vouche;
  193. }
  194. if(Object.keys(seller_goods[i].chose_vouche).length>0) sgvKey = i;
  195. }
  196. seller_goods[i].goodsnum = Object.keys(seller_goods[i].goods).length;
  197. for (var j in seller_goods[i].goods) {
  198. goodsTotNum += seller_goods[i].goods[j].quantity*1;
  199. if (seller_goods[i].goods[j].header_disc > 0 && seller_goods[i].goods[j].header_disc < 100) {
  200. seller_goods[i].goods[j].header_disc = (seller_goods[i].goods[j].header_disc / 10).toFixed(1);
  201. }
  202. }
  203. }
  204. let current_distance = rdata.current_distance || '';
  205. let current_distance_str = that.changeDistance(current_distance);
  206. order_note_content = order_note_content!=null?order_note_content:'';
  207. if(presale_info&&presale_info.goods_price) {
  208. let deduction_money = presale_info.deduction_money;
  209. deduction_money = deduction_money>0?deduction_money:presale_info.presale_ding_money;
  210. let totDeduction = deduction_money*goodsTotNum;
  211. presale_info.balance = (presale_info.goods_price*1 - totDeduction).toFixed(2);
  212. presale_info.totdingMoney = (goodsTotNum*presale_info.presale_ding_money).toFixed(2);
  213. presale_info.totDeduction = totDeduction.toFixed(2);
  214. }
  215. let param = {
  216. sgvKey,
  217. is_hexiao: delvery_type_hexiao,
  218. loadover: true,
  219. commentArr,
  220. sel_chose_vouche,
  221. tabList: sortTabList,
  222. is_limit_distance_buy: rdata.is_limit_distance_buy || 0,
  223. tabIdx: tabIdx,
  224. tabLength: tabLength,
  225. tuan_send_address: rdata.tuan_send_address,
  226. is_open_order_message: rdata.is_open_order_message,
  227. is_yue_open: rdata.is_yue_open,
  228. can_yupay: rdata.can_yupay,
  229. show_voucher: rdata.show_voucher,
  230. current_distance,
  231. man_free_tuanzshipping: rdata.man_free_tuanzshipping*1 || 0,
  232. man_free_shipping: rdata.man_free_shipping*1 || 0,
  233. index_hide_headdetail_address: rdata.index_hide_headdetail_address || 0,
  234. open_score_buy_score: rdata.open_score_buy_score || 0,
  235. score: rdata.score || 0,
  236. score_for_money: rdata.score_for_money || 0,
  237. bue_use_score: rdata.bue_use_score || 0,
  238. is_man_delivery_tuanz_fare: rdata.is_man_delivery_tuanz_fare, //是否达到满xx减团长配送费
  239. fare_man_delivery_tuanz_fare_money: rdata.fare_man_delivery_tuanz_fare_money, //达到满xx减团长配送费, 减了多少钱
  240. is_man_shipping_fare: rdata.is_man_shipping_fare, //是否达到满xx减运费
  241. fare_man_shipping_fare_money: rdata.fare_man_shipping_fare_money, //达到满xx减运费,司机减了多少运费
  242. is_vip_card_member,
  243. vipcard_save_money,
  244. level_save_money,
  245. is_open_vipcard_buy,
  246. is_member_level_buy,
  247. // canLevelBuy,
  248. total_integral: total_integral || '',
  249. is_need_subscript,
  250. need_subscript_template,
  251. current_distance_str,
  252. order_note_open,
  253. order_note_name,
  254. order_note_content,
  255. note_content: order_note_content,
  256. localtown_dispatchtime,
  257. pickingup_fare,
  258. localtown_shipping_fare,
  259. localtown_modifypickingname: localtown_modifypickingname || '包装费',
  260. localtown_shipping_fare_arr,
  261. localtown_moneytype_fixed_freemoney,
  262. localtown_makeup_delivery_money,
  263. localtown_expected_delivery,
  264. localtown_delivery_space_month,
  265. order_lou_meng_hao: order_lou_meng_hao|| '楼号门牌',
  266. order_lou_meng_hao_placeholder: order_lou_meng_hao_placeholder || '例如:A座106室',
  267. presale_info,
  268. cashondelivery_data,
  269. allform
  270. }
  271. let addrObj = rdata.address || {};
  272. let tuan_send_address_info = rdata.tuan_send_address_info || {};
  273. let tuanAddress = tuan_send_address_info.address || '选择位置';
  274. if(tuan_send_address_info.city_name == "" || tuan_send_address_info.city_id==3708 || tuan_send_address_info.country_name == "" || tuan_send_address_info.country_id==3708){
  275. tuanAddress = '选择位置';
  276. }
  277. // 20200710 TODO
  278. // addrObj = tuan_send_address_info;
  279. param.tabAddress = [
  280. {
  281. name: rdata.ziti_name || '',
  282. mobile: rdata.ziti_mobile || ''
  283. },
  284. {
  285. name: tuan_send_address_info.name || '',
  286. mobile: tuan_send_address_info.telephone || '',
  287. receiverAddress: tuanAddress,
  288. lou_meng_hao: tuan_send_address_info.lou_meng_hao || '',
  289. region: [tuan_send_address_info.province_name || "", tuan_send_address_info.city_name || "", tuan_send_address_info.country_name || ""]
  290. },
  291. {
  292. name: addrObj.name || '',
  293. mobile: addrObj.telephone || '',
  294. receiverAddress: addrObj.address || '',
  295. region: [addrObj.province_name || "选择地址", addrObj.city_name || "", addrObj.country_name || ""]
  296. },
  297. {
  298. name: addrObj.name || '',
  299. mobile: addrObj.telephone || '',
  300. receiverAddress: addrObj.address || '',
  301. region: [addrObj.province_name || "选择地址", addrObj.city_name || "", addrObj.country_name || ""]
  302. },
  303. {
  304. name: rdata.ziti_name || '',
  305. mobile: rdata.ziti_mobile || ''
  306. }
  307. ];
  308. if(JSON.stringify(addrObj)!='[]') {
  309. if(addrObj.lon_lat=='') {
  310. if(tabIdx==3){
  311. param.tabAddress[3] = {
  312. name: addrObj.name || '',
  313. mobile: addrObj.telephone || '',
  314. receiverAddress: '',
  315. region: ["选择地址", "", ""]
  316. }
  317. }
  318. } else if(addrObj.lon_lat) {
  319. let lat_lon = addrObj.lon_lat.split(',');
  320. wcache.put('latitude2', lat_lon[1]);
  321. wcache.put('longitude2', lat_lon[0]);
  322. }
  323. }
  324. if (addres == 1) {
  325. that.setData({
  326. ...param,
  327. pick_up_time: res.data.pick_up_time,
  328. pick_up_type: res.data.pick_up_type,
  329. pick_up_weekday: res.data.pick_up_weekday,
  330. addressState: true,
  331. is_integer: res.data.is_integer,
  332. is_ziti: res.data.is_ziti,
  333. pick_up_arr: res.data.pick_up_arr,
  334. seller_goodss: res.data.seller_goodss,
  335. seller_chose_id: seller_chose_id,
  336. seller_chose_store_id: seller_chose_store_id,
  337. goods: res.data.goods,
  338. buy_type: res.data.buy_type,
  339. yupay: res.data.can_yupay,
  340. is_yue_open: res.data.is_yue_open,
  341. yu_money: res.data.yu_money,
  342. total_free: res.data.total_free,
  343. trans_free_toal: res.data.trans_free_toal,
  344. delivery_tuanz_money: res.data.delivery_tuanz_money,
  345. reduce_money: res.data.reduce_money,
  346. is_open_fullreduction: res.data.is_open_fullreduction,
  347. cha_reduce_money: res.data.cha_reduce_money
  348. }, () => {
  349. that.calcPrice();
  350. })
  351. } else {
  352. that.setData({
  353. ...param,
  354. is_integer: res.data.is_integer,
  355. addressState: false,
  356. goods: res.data.goods,
  357. is_ziti: res.data.is_ziti,
  358. pick_up_arr: res.data.pick_up_arr,
  359. seller_goodss: res.data.seller_goodss,
  360. seller_chose_id: seller_chose_id,
  361. seller_chose_store_id: seller_chose_store_id,
  362. buy_type: res.data.buy_type,
  363. yupay: res.data.can_yupay,
  364. is_yue_open: res.data.is_yue_open,
  365. yu_money: res.data.yu_money,
  366. total_free: res.data.total_free,
  367. trans_free_toal: res.data.trans_free_toal,
  368. delivery_tuanz_money: res.data.delivery_tuanz_money,
  369. reduce_money: res.data.reduce_money,
  370. is_open_fullreduction: res.data.is_open_fullreduction,
  371. cha_reduce_money: res.data.cha_reduce_money
  372. },()=>{
  373. that.calcPrice();
  374. })
  375. }
  376. }
  377. })
  378. },
  379. changeDistance: function(current_distance) {
  380. if(current_distance) {
  381. current_distance = parseFloat(current_distance);
  382. if(current_distance > 1000) {
  383. let current_distance_int = current_distance/1000;
  384. return current_distance_int.toFixed(2) + 'km';
  385. }
  386. return current_distance + 'm';
  387. }
  388. return current_distance;
  389. },
  390. /**
  391. * 授权成功回调
  392. */
  393. authSuccess: function () {
  394. this.onLoad();
  395. },
  396. /**
  397. * 设置手机号
  398. */
  399. getReceiveMobile: function (e) {
  400. var num = e.detail;
  401. this.setData({
  402. t_ziti_mobile: num,
  403. showGetPhone: false
  404. });
  405. },
  406. ck_wxpays: function () {
  407. this.setData({
  408. ck_yupay: 0
  409. })
  410. },
  411. ck_yupays: function () {
  412. this.setData({
  413. ck_yupay: 1
  414. })
  415. },
  416. ck_cash: function () {
  417. this.setData({
  418. ck_yupay: 2
  419. })
  420. },
  421. scoreChange: function (e) {
  422. console.log('是否使用', e.detail.value)
  423. let tdata = this.data;
  424. let score_for_money = tdata.score_for_money*1;
  425. let tot_price = tdata.tot_price*1;
  426. let disAmount = tdata.disAmount*1;
  427. if (e.detail.value){
  428. tot_price = tot_price - score_for_money;
  429. disAmount += score_for_money;
  430. } else {
  431. tot_price = tot_price + score_for_money;
  432. disAmount -= score_for_money;
  433. }
  434. this.setData({
  435. use_score: e.detail.value?1:0,
  436. tot_price: tot_price.toFixed(2),
  437. disAmount: disAmount.toFixed(2)
  438. })
  439. },
  440. /**
  441. * 未登录
  442. */
  443. needAuth: function(){
  444. this.setData({
  445. needAuth: true
  446. });
  447. },
  448. /**
  449. * 关闭手机授权
  450. */
  451. close: function () {
  452. this.setData({
  453. showGetPhone: false
  454. });
  455. },
  456. // 生成订单号 Step1
  457. preOrderConfirm() {
  458. if(this.data.allform&&this.data.allform.is_open_orderform) {
  459. this.selectComponent("#sForm").formSubmit();
  460. return false;
  461. } else {
  462. this.goOrderfrom();
  463. }
  464. },
  465. // 生成订单号 Step2
  466. goOrderfrom: function(formData={detail: {}}) {
  467. let that = this;
  468. let { tabAddress, tabIdx, note_content, order_note_open, order_note_name, isAgreePresale, buy_type, presale_info } = this.data;
  469. this.setData({ formData: formData.detail })
  470. var t_ziti_name = tabAddress[tabIdx].name;
  471. var t_ziti_mobile = tabAddress[tabIdx].mobile;
  472. var receiverAddress = tabAddress[tabIdx].receiverAddress;
  473. var region = tabAddress[tabIdx].region;
  474. var tuan_send_address = tabAddress[tabIdx].receiverAddress;
  475. var lou_meng_hao = tabAddress[tabIdx].lou_meng_hao;
  476. if (t_ziti_name == '') {
  477. this.setData({
  478. focus_name: true
  479. })
  480. let tip = '请填写收货人';
  481. if (tabIdx == 0) tip = '请填写提货人';
  482. wx.showToast({
  483. title: tip,
  484. icon: 'none'
  485. })
  486. return false;
  487. }
  488. if (t_ziti_mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(t_ziti_mobile))) {
  489. this.setData({
  490. focus_mobile: true
  491. })
  492. wx.showToast({
  493. title: '手机号码有误',
  494. icon: 'none'
  495. })
  496. return false;
  497. }
  498. if((tabIdx==0||tabIdx==1||tabIdx==3)&&this.data.buy_type!='virtualcard') {
  499. if(order_note_open==1 && note_content=='') {
  500. wx.showToast({
  501. title: '请填写' + order_note_name,
  502. icon: 'none'
  503. })
  504. return false;
  505. }
  506. } else {
  507. note_content = '';
  508. }
  509. if(order_note_open==0) note_content = '';
  510. if ((tabIdx == 2 || tabIdx == 3) && region[0] == '选择地址') {
  511. wx.showToast({
  512. title: '请选择所在地区',
  513. icon: 'none'
  514. })
  515. return false;
  516. }
  517. if ((tabIdx == 2 || tabIdx == 3) && receiverAddress == ''){
  518. this.setData({
  519. focus_addr: true
  520. })
  521. wx.showToast({
  522. title: '请填写详细地址',
  523. icon: 'none'
  524. })
  525. return false;
  526. }
  527. if (tabIdx == 1) {
  528. if (tuan_send_address == '选择位置' || tuan_send_address == '') {
  529. wx.showToast({
  530. title: '请选择位置',
  531. icon: 'none'
  532. })
  533. return false;
  534. }
  535. if (lou_meng_hao == ''){
  536. wx.showToast({
  537. title: '输入楼号门牌',
  538. icon: 'none'
  539. })
  540. return false;
  541. }
  542. }
  543. if(buy_type=='presale'&&!isAgreePresale) {
  544. wx.showModal({
  545. title: '提示',
  546. content: '预售商品定金不支持退款,同意后可继续下单',
  547. showCancel: true,
  548. cancelText: '我再想想',
  549. cancelColor: '#ff5344',
  550. confirmText: '同意下单',
  551. success (res) {
  552. if (res.confirm) {
  553. that.setData({ isAgreePresale: true });
  554. if (tabIdx == 2){
  555. that.preSubscript();
  556. } else {
  557. that.conformOrder();
  558. }
  559. } else if (res.cancel) {
  560. console.log('用户点击取消')
  561. }
  562. }
  563. })
  564. return;
  565. }
  566. if (tabIdx == 2||this.data.buy_type=="virtualcard"){
  567. this.preSubscript();
  568. } else {
  569. this.conformOrder();
  570. }
  571. },
  572. /**
  573. * 支付防抖
  574. */
  575. preSubscript: function(event) {
  576. let that = this;
  577. if(!this.canPreSub) return;
  578. this.canPreSub = false;
  579. let is_need_subscript = this.data.is_need_subscript;
  580. if(is_need_subscript==1) {
  581. //弹出订阅消息
  582. this.subscriptionNotice().then(()=>{
  583. that.prepay();
  584. }).catch(()=>{
  585. that.prepay();
  586. });
  587. } else {
  588. that.prepay();
  589. }
  590. },
  591. prepay: function() {
  592. this.canPreSub = true;
  593. let { tabAddress, tabIdx, is_limit_distance_buy, note_content, seller_goodss, commentArr, formData } = this.data;
  594. let isVirtualcard = 0;
  595. if(this.data.buy_type=='virtualcard') isVirtualcard = 1;
  596. if (is_limit_distance_buy == 1 && (tabIdx == 1) && isVirtualcard==0){
  597. wx.showModal({
  598. title: '提示',
  599. content: '离团长太远了,暂不支持下单',
  600. showCancel: false,
  601. confirmColor: '#F75451'
  602. })
  603. return false;
  604. }
  605. console.log('this.canPay', this.canPay)
  606. if(this.canPay){
  607. this.setData({ payBtnLoading: true })
  608. this.canPay = false;
  609. var that = this;
  610. var token = wx.getStorageSync('token');
  611. let { seller_chose_id, seller_chose_store_id, ck_yupay, tabList } = this.data;
  612. var voucher_id = seller_chose_id;
  613. var dispatching = '';
  614. tabList.forEach(function(item){
  615. if (item.id == tabIdx) dispatching = item.dispatching;
  616. })
  617. let arr = [];
  618. for (let key in seller_goodss) {
  619. let goodsid = '';
  620. let goods = seller_goodss[key].goods;
  621. Object.keys(goods).forEach(kk=>{
  622. goodsid += goods[kk].goods_id+'_';
  623. })
  624. commentArr[key] = key+'_'+goodsid + commentArr[key];
  625. }
  626. for (let key in commentArr) arr.push(commentArr[key]);
  627. let comment = arr.join('@EOF@');
  628. var receiverAddress = tabAddress[tabIdx].receiverAddress || '';
  629. var region = tabAddress[tabIdx].region || [];
  630. var t_ziti_name = tabAddress[tabIdx].name;
  631. var t_ziti_mobile = tabAddress[tabIdx].mobile;
  632. let lou_meng_hao = tabAddress[tabIdx].lou_meng_hao || '';
  633. var quan_arr = [];
  634. if (voucher_id > 0) {
  635. var t_tmp = seller_chose_store_id + '_' + voucher_id;
  636. quan_arr.push(t_tmp);
  637. }
  638. let tuan_send_address = '';
  639. let tuan_region = '';
  640. let address_name = '';
  641. let province_name = '';
  642. let city_name = '';
  643. let country_name = '';
  644. if (tabIdx==1){
  645. tuan_send_address = receiverAddress;
  646. tuan_region = region;
  647. province_name = tuan_region[0];
  648. city_name = tuan_region[1];
  649. country_name = tuan_region[2];
  650. } else if (tabIdx == 2 || tabIdx == 3) {
  651. address_name = receiverAddress;
  652. province_name = region[0];
  653. city_name = region[1];
  654. country_name = region[2];
  655. }
  656. var community = wx.getStorageSync('community');
  657. var community_id = community.communityId;
  658. var pick_up_id = community_id;
  659. let latitude = wx.getStorageSync('latitude2');
  660. let longitude = wx.getStorageSync('longitude2');
  661. let { use_score, buy_type, soli_id } = this.data;
  662. // 送达时间
  663. let expected_delivery_time = '';
  664. let localtown_delivery_space_month = '';
  665. if(tabIdx==3){
  666. let { localtown_expected_delivery, curAlertTime, localtown_dispatchtime, localtown_delivery_space_month } = this.data;
  667. if(curAlertTime==-1) {
  668. expected_delivery_time = localtown_dispatchtime;
  669. } else {
  670. expected_delivery_time = localtown_expected_delivery.localtown_delivery_space_time_list[localtown_delivery_space_month][curAlertTime].time;
  671. }
  672. expected_delivery_time = localtown_delivery_space_month + ' ' + expected_delivery_time;
  673. }
  674. let cashon_delivery = (ck_yupay)==2?1:0
  675. wx.showLoading();
  676. app.util.request({
  677. url: 'entry/wxapp/user',
  678. data: {
  679. controller: 'car.sub_order',
  680. token: token,
  681. pay_method: 'wxpay',
  682. buy_type,
  683. pick_up_id,
  684. dispatching,
  685. ziti_name: t_ziti_name,
  686. quan_arr,
  687. comment,
  688. ziti_mobile: t_ziti_mobile,
  689. latitude,
  690. longitude,
  691. ck_yupay,
  692. tuan_send_address,
  693. lou_meng_hao,
  694. address_name,
  695. province_name,
  696. city_name,
  697. country_name,
  698. use_score,
  699. soli_id,
  700. note_content,
  701. expected_delivery_time,
  702. scene: app.globalData.scene,
  703. cashon_delivery,
  704. ...formData
  705. },
  706. dataType: 'json',
  707. method: 'POST',
  708. success: function (res) {
  709. wx.hideLoading();
  710. let has_yupay = res.data.has_yupay || 0;
  711. var order_id = res.data.order_id;
  712. let h = {};
  713. console.log('支付日志:', res);
  714. if (res.data.code == 0) {
  715. // 交易组件
  716. if(res.data.isRequestOrderPayment==1) {
  717. wx.requestOrderPayment({
  718. "orderInfo": res.data.order_info,
  719. "timeStamp": res.data.timeStamp,
  720. "nonceStr": res.data.nonceStr,
  721. "package": res.data.package,
  722. "signType": res.data.signType,
  723. "paySign": res.data.paySign,
  724. 'success': function (wxres) {
  725. that.canPay = true;
  726. if (buy_type == "dan" || buy_type == "pindan" || buy_type == "integral" || buy_type == "soitaire" || buy_type == "presale" || buy_type == "virtualcard") {
  727. if (res.data.is_go_orderlist<=1){
  728. wx.redirectTo({
  729. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1&delivery=' + dispatching
  730. })
  731. } else {
  732. wx.redirectTo({
  733. url: '/lionfish_comshop/pages/order/index?is_show=1'
  734. })
  735. }
  736. } else {
  737. wx.redirectTo({
  738. url: `/lionfish_comshop/moduleA/pin/share?id=${order_id}`
  739. })
  740. }
  741. },
  742. 'fail': function (error) {
  743. if (res.data.is_go_orderlist <= 1) {
  744. wx.redirectTo({
  745. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&isfail=1&delivery=' + dispatching
  746. })
  747. } else {
  748. wx.redirectTo({
  749. url: '/lionfish_comshop/pages/order/index?isfail=1'
  750. })
  751. }
  752. }
  753. })
  754. } else {
  755. that.changeIndexList();
  756. if (has_yupay == 1) {
  757. that.canPay = true;
  758. if (buy_type == "dan" || buy_type == "pindan" || buy_type == "integral" || buy_type == "soitaire" || buy_type == "presale" || buy_type == "virtualcard") {
  759. if (res.data.is_go_orderlist <= 1) {
  760. wx.redirectTo({
  761. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1&delivery=' + dispatching
  762. })
  763. } else {
  764. wx.redirectTo({
  765. url: '/lionfish_comshop/pages/order/index?is_show=1'
  766. })
  767. }
  768. } else {
  769. wx.redirectTo({
  770. url: `/lionfish_comshop/moduleA/pin/share?id=${order_id}`
  771. })
  772. }
  773. } else {
  774. wx.requestPayment({
  775. "appId": res.data.appId,
  776. "timeStamp": res.data.timeStamp,
  777. "nonceStr": res.data.nonceStr,
  778. "package": res.data.package,
  779. "signType": res.data.signType,
  780. "paySign": res.data.paySign,
  781. 'success': function (wxres) {
  782. that.canPay = true;
  783. if (buy_type == "dan" || buy_type == "pindan" || buy_type == "integral" || buy_type == "soitaire" || buy_type == "presale" || buy_type == "virtualcard") {
  784. if (res.data.is_go_orderlist<=1){
  785. wx.redirectTo({
  786. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1&delivery=' + dispatching
  787. })
  788. } else {
  789. wx.redirectTo({
  790. url: '/lionfish_comshop/pages/order/index?is_show=1'
  791. })
  792. }
  793. } else {
  794. wx.redirectTo({
  795. url: `/lionfish_comshop/moduleA/pin/share?id=${order_id}`
  796. })
  797. }
  798. },
  799. 'fail': function (error) {
  800. if (res.data.is_go_orderlist <= 1) {
  801. wx.redirectTo({
  802. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&isfail=1&delivery=' + dispatching
  803. })
  804. } else {
  805. wx.redirectTo({
  806. url: '/lionfish_comshop/pages/order/index?isfail=1'
  807. })
  808. }
  809. }
  810. })
  811. }
  812. }
  813. } else if (res.data.code == 1) {
  814. that.canPay = true;
  815. wx.showModal({
  816. title: '提示',
  817. content: res.data.RETURN_MSG || '支付失败',
  818. showCancel: false,
  819. confirmColor: '#F75451',
  820. success (ret) {
  821. if (ret.confirm) {
  822. if (res.data.is_go_orderlist <= 1) {
  823. wx.redirectTo({
  824. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&isfail=1&delivery=' + dispatching
  825. })
  826. } else {
  827. wx.redirectTo({
  828. url: '/lionfish_comshop/pages/order/index?is_show=1&isfail=1'
  829. })
  830. }
  831. }
  832. }
  833. })
  834. } else if (res.data.code == 2) {
  835. that.canPay = true;
  836. if( res.data.is_forb ==1 ){ h.btnDisable = true; h.btnText="已抢光"; }
  837. wx.showToast({
  838. title: res.data.msg,
  839. icon: "none"
  840. });
  841. } else {
  842. console.log(res);
  843. }
  844. that.setData({ btnLoading: false, payBtnLoading:false, ...h })
  845. },
  846. fail: function() {
  847. wx.redirectTo({
  848. url: '/lionfish_comshop/pages/order/index?is_show=1&isfail=1'
  849. })
  850. }
  851. })
  852. }
  853. },
  854. /**
  855. * 监听收货人
  856. */
  857. changeReceiverName: function(e) {
  858. let { tabAddress, tabIdx } = this.data;
  859. let receiverName = e.detail.value.trim();
  860. Object.keys(tabAddress).length && (tabAddress[tabIdx].name = receiverName);
  861. if (!receiverName) {
  862. let tip = '请填写收货人';
  863. if (tabIdx == 0) tip = '请填写提货人';
  864. wx.showToast({
  865. title: tip,
  866. icon: "none"
  867. });
  868. }
  869. this.setData({ tabAddress })
  870. return {
  871. value: receiverName
  872. }
  873. },
  874. /**
  875. * 监听备注
  876. */
  877. changeNoteName: function(e) {
  878. let noteName = e.detail.value.trim();
  879. let order_note_name = this.data.order_note_name;
  880. if (!noteName) {
  881. let tip = '请填写' + order_note_name;
  882. wx.showToast({
  883. title: tip,
  884. icon: "none"
  885. });
  886. }
  887. this.setData({ note_content: noteName })
  888. return {
  889. value: noteName
  890. }
  891. },
  892. /**
  893. * 监听手机号
  894. */
  895. bindReceiverMobile: function(e) {
  896. let { tabAddress, tabIdx } = this.data;
  897. let mobile = e.detail.value.trim();
  898. tabAddress[tabIdx].mobile = mobile;
  899. this.setData({ tabAddress });
  900. return {
  901. value: mobile
  902. }
  903. },
  904. /**
  905. * 监控快递地址变化
  906. */
  907. changeReceiverAddress: function(e){
  908. let { tabAddress, tabIdx } = this.data;
  909. tabAddress[tabIdx].receiverAddress = e.detail.value.trim();
  910. this.setData({ tabAddress });
  911. return {
  912. value: e.detail.value.trim()
  913. }
  914. },
  915. /**
  916. * 监控团长送货地址变化
  917. */
  918. changeTuanAddress: function (e) {
  919. let { tabAddress, tabIdx } = this.data;
  920. tabAddress[tabIdx].lou_meng_hao = e.detail.value.trim();
  921. this.setData({ tabAddress });
  922. return {
  923. value: e.detail.value.trim()
  924. }
  925. },
  926. /**
  927. * 结算
  928. */
  929. conformOrder: function() {
  930. this.setData({
  931. showConfirmModal: true
  932. });
  933. },
  934. /**
  935. * 关闭结算
  936. */
  937. closeConfirmModal: function() {
  938. this.canPay = true;
  939. this.setData({
  940. showConfirmModal: false
  941. });
  942. },
  943. /**
  944. * 地区选择
  945. */
  946. bindRegionChange: function (e) {
  947. let region = e.detail.value;
  948. region && this.checkOut(region[1]);
  949. this.setData({ region })
  950. },
  951. checkOut: function (mb_city_name) {
  952. var that = this;
  953. var token = wx.getStorageSync('token');
  954. var community = wx.getStorageSync('community');
  955. var community_id = community.communityId;
  956. let latitude = wx.getStorageSync('latitude2');
  957. let longitude = wx.getStorageSync('longitude2');
  958. let buy_type = this.data.buy_type;
  959. let soli_id = this.data.soli_id;
  960. app.util.request({
  961. url: 'entry/wxapp/user',
  962. data: {
  963. controller: 'car.checkout',
  964. token,
  965. community_id,
  966. mb_city_name,
  967. latitude: latitude,
  968. longitude: longitude,
  969. buy_type,
  970. soli_id
  971. },
  972. dataType: 'json',
  973. method: 'POST',
  974. success: function (res) {
  975. if(res.data.code==1){
  976. let rdata = res.data;
  977. let {
  978. vipcard_save_money,
  979. shop_buy_distance,
  980. is_limit_distance_buy,
  981. current_distance,
  982. level_save_money,
  983. score,
  984. score_for_money,
  985. bue_use_score,
  986. localtown_shipping_fare_arr,
  987. localtown_moneytype_fixed_freemoney,
  988. localtown_makeup_delivery_money
  989. } = rdata;
  990. if (that.data.tabIdx == 1 && is_limit_distance_buy == 1 && (current_distance > shop_buy_distance)) {
  991. wx.showModal({
  992. title: '提示',
  993. content: '超出配送范围,请重新选择',
  994. showCancel: false,
  995. confirmColor: '#F75451'
  996. })
  997. }
  998. current_distance = current_distance || '';
  999. let current_distance_str = that.changeDistance(current_distance);
  1000. // 同城满免运费
  1001. if(localtown_shipping_fare_arr) {
  1002. let shipping_fare = 0;
  1003. shipping_fare = localtown_shipping_fare_arr.total_yl_shipping_fare*1 - localtown_shipping_fare_arr.total_shipping_fare*1;
  1004. localtown_shipping_fare_arr.shipping_fare = shipping_fare.toFixed(2);
  1005. }
  1006. that.setData({
  1007. score: score || 0,
  1008. score_for_money: score_for_money || 0,
  1009. bue_use_score: bue_use_score || 0,
  1010. vipcard_save_money,
  1011. level_save_money,
  1012. is_limit_distance_buy: is_limit_distance_buy || 0,
  1013. current_distance,
  1014. current_distance_str,
  1015. trans_free_toal: rdata.trans_free_toal,
  1016. is_man_delivery_tuanz_fare: rdata.is_man_delivery_tuanz_fare, //是否达到满xx减团长配送费
  1017. fare_man_delivery_tuanz_fare_money: rdata.fare_man_delivery_tuanz_fare_money, //达到满xx减团长配送费, 减了多少钱
  1018. is_man_shipping_fare: rdata.is_man_shipping_fare, //是否达到满xx减运费
  1019. fare_man_shipping_fare_money: rdata.fare_man_shipping_fare_money, //达到满xx减运费,司机减了多少运费
  1020. localtown_shipping_fare_arr,
  1021. localtown_moneytype_fixed_freemoney,
  1022. localtown_makeup_delivery_money
  1023. }, () => { that.calcPrice() })
  1024. }
  1025. }
  1026. })
  1027. },
  1028. /**
  1029. * 定位获取地址
  1030. */
  1031. choseLocation: function() {
  1032. let { tabAddress, tabIdx } = this.data;
  1033. var that = this;
  1034. wx.chooseLocation({
  1035. success: function (e) {
  1036. console.log(e);
  1037. var s_region = that.data.region;
  1038. var filename = e.name;
  1039. let addr = e.address || '';
  1040. var reg = /.+?(省|市|自治区|自治州|县|区|特别行政区)/g;
  1041. // var result = addr.match(reg);
  1042. var result = null;
  1043. console.log('patt', result);
  1044. if (result == null || filename=="") {
  1045. locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
  1046. console.log('反推了', res);
  1047. if (res) {
  1048. s_region[0] = res.province;
  1049. s_region[1] = res.city;
  1050. s_region[2] = res.district;
  1051. filename || (filename = res.street);
  1052. }
  1053. setRes();
  1054. });
  1055. } else {
  1056. s_region[0] = result[0];
  1057. s_region[1] = result[1];
  1058. s_region[2] = result[2] || '';
  1059. var dol_path = addr.replace(s_region.join(''), '');
  1060. filename = dol_path + e.name;
  1061. setRes();
  1062. }
  1063. wcache.put('latitude2', e.latitude);
  1064. wcache.put('longitude2', e.longitude);
  1065. function setRes(){
  1066. console.log('setData');
  1067. s_region && (s_region[1] != "市") && that.checkOut(s_region[1]);
  1068. tabAddress[tabIdx].region = s_region;
  1069. tabAddress[tabIdx].receiverAddress = filename;
  1070. that.setData({ tabAddress })
  1071. }
  1072. },
  1073. fail: function (error) {
  1074. console.log(error)
  1075. if (error.errMsg =='chooseLocation:fail auth deny') {
  1076. console.log('无权限')
  1077. locat.checkGPS(app, locat.openSetting())
  1078. }
  1079. }
  1080. })
  1081. },
  1082. /**
  1083. * 微信获取地址
  1084. */
  1085. getWxAddress: function() {
  1086. let { tabAddress, tabIdx } = this.data;
  1087. let region = tabAddress[tabIdx].region || [];
  1088. let that = this;
  1089. wx.getSetting({
  1090. success(res) {
  1091. if (res.authSetting['scope.address']) {
  1092. wx.chooseAddress({
  1093. success(res) {
  1094. console.log("step1")
  1095. region[0] = res.provinceName || "选择地址";
  1096. region[1] = res.cityName || "";
  1097. region[2] = res.countyName || "";
  1098. let receiverAddress = res.detailInfo;
  1099. tabAddress[tabIdx].name = res.userName;
  1100. tabAddress[tabIdx].mobile = res.telNumber;
  1101. tabAddress[tabIdx].region = region;
  1102. tabAddress[tabIdx].receiverAddress = receiverAddress;
  1103. that.setData({ tabAddress })
  1104. region && (region[1] != "市") && that.checkOut(region[1]);
  1105. },
  1106. fail(res){
  1107. console.log("step4")
  1108. console.log(res)
  1109. }
  1110. })
  1111. } else {
  1112. if (res.authSetting['scope.address'] == false) {
  1113. wx.openSetting({
  1114. success(res) {
  1115. console.log(res.authSetting)
  1116. }
  1117. })
  1118. } else {
  1119. console.log("step2")
  1120. wx.chooseAddress({
  1121. success(res) {
  1122. console.log("step3")
  1123. region[0] = res.provinceName || "选择地址";
  1124. region[1] = res.cityName || "";
  1125. region[2] = res.countyName || "";
  1126. let receiverAddress = res.detailInfo;
  1127. region && (region[1] != "市") && that.checkOut(region[1]);
  1128. tabAddress[tabIdx].name = res.userName;
  1129. tabAddress[tabIdx].mobile = res.telNumber;
  1130. tabAddress[tabIdx].region = region;
  1131. tabAddress[tabIdx].receiverAddress = receiverAddress;
  1132. that.setData({ tabAddress })
  1133. }
  1134. })
  1135. }
  1136. }
  1137. }
  1138. })
  1139. },
  1140. /**
  1141. * tab切换
  1142. */
  1143. tabSwitch: function (t) {
  1144. let idx = 1 * t.currentTarget.dataset.idx;
  1145. (idx != 0) && wx.showToast({ title: '配送变更,费用已变化', icon: "none"});
  1146. this.setData({
  1147. tabIdx: idx
  1148. },function(){
  1149. this.calcPrice(1);
  1150. })
  1151. },
  1152. /**
  1153. * 打开优惠券
  1154. */
  1155. show_voucher: function (event) {
  1156. var that = this;
  1157. var serller_id = event.currentTarget.dataset.seller_id;
  1158. var voucher_list = [];
  1159. var seller_chose_id = this.data.seller_chose_id;
  1160. var seller_chose_store_id = this.data.seller_chose_store_id;
  1161. var seller_goods = this.data.seller_goodss;
  1162. for (var i in seller_goods) {
  1163. var s_id = seller_goods[i].store_info.s_id;
  1164. if (s_id == serller_id) {
  1165. voucher_list = seller_goods[i].voucher_list;
  1166. if (seller_chose_id == 0) {
  1167. seller_chose_id = seller_goods[i].chose_vouche.id || 0;
  1168. seller_chose_store_id = seller_goods[i].chose_vouche.store_id || 0;
  1169. }
  1170. }
  1171. }
  1172. that.setData({
  1173. ssvoucher_list: voucher_list,
  1174. voucher_serller_id: serller_id,
  1175. seller_chose_id: seller_chose_id,
  1176. seller_chose_store_id: seller_chose_store_id,
  1177. hide_quan: false
  1178. })
  1179. },
  1180. // 选择优惠券
  1181. chose_voucher_id: function (event) {
  1182. wx.showLoading();
  1183. var voucher_id = event.currentTarget.dataset.voucher_id;
  1184. var seller_id = event.currentTarget.dataset.seller_id;
  1185. var that = this;
  1186. var token = wx.getStorageSync('token');
  1187. var use_quan_str = seller_id + "_" + voucher_id;
  1188. let latitude = wx.getStorageSync('latitude2');
  1189. let longitude = wx.getStorageSync('longitude2');
  1190. var buy_type = that.data.buy_type;
  1191. let soli_id = this.data.soli_id;
  1192. var community_id = wx.getStorageSync('community').communityId || '';
  1193. app.util.request({
  1194. url: 'entry/wxapp/user',
  1195. data: {
  1196. controller: 'car.checkout',
  1197. token,
  1198. community_id,
  1199. voucher_id,
  1200. use_quan_str,
  1201. buy_type,
  1202. latitude,
  1203. longitude,
  1204. soli_id
  1205. },
  1206. dataType: 'json',
  1207. method: 'POST',
  1208. success: function (res) {
  1209. wx.hideLoading();
  1210. if(res.data.code ==1){
  1211. let seller_goodss = res.data.seller_goodss;
  1212. let sel_chose_vouche = '';
  1213. for (var i in seller_goodss) {
  1214. seller_goodss[i].goodsnum = Object.keys(seller_goodss[i].goods).length;
  1215. if (Object.prototype.toString.call(seller_goodss[i].chose_vouche) == '[object Object]') {
  1216. sel_chose_vouche = seller_goodss[i].chose_vouche;
  1217. }
  1218. }
  1219. const rdata = res.data;
  1220. let current_distance = rdata.current_distance || '';
  1221. let current_distance_str = that.changeDistance(current_distance);
  1222. let {score,score_for_money,bue_use_score} = rdata;
  1223. let h = {};
  1224. if(bue_use_score*1<=0) h.use_score = '';
  1225. that.setData({
  1226. ...h,
  1227. score: score || 0,
  1228. score_for_money: score_for_money || 0,
  1229. bue_use_score: bue_use_score || 0,
  1230. seller_goodss: seller_goodss,
  1231. seller_chose_id: voucher_id,
  1232. seller_chose_store_id: seller_id,
  1233. hide_quan: true,
  1234. goods: rdata.goods,
  1235. buy_type: rdata.buy_type || 'dan',
  1236. yupay: rdata.can_yupay,
  1237. is_yue_open: rdata.is_yue_open,
  1238. total_free: rdata.total_free,
  1239. sel_chose_vouche: sel_chose_vouche,
  1240. current_distance,
  1241. current_distance_str
  1242. },()=>{
  1243. that.calcPrice(1);
  1244. })
  1245. }
  1246. }
  1247. })
  1248. },
  1249. //关闭优惠券
  1250. closeCouponModal: function(){
  1251. this.setData({
  1252. hide_quan: true
  1253. })
  1254. },
  1255. /**
  1256. * 计算总额
  1257. */
  1258. calcPrice: function(isTabSwitch = 0){
  1259. let tdata = this.data;
  1260. let {
  1261. total_free,
  1262. delivery_tuanz_money,
  1263. fare_man_shipping_fare_money,
  1264. trans_free_toal,
  1265. tabIdx, goods,
  1266. is_open_vipcard_buy,
  1267. is_vip_card_member,
  1268. fare_man_delivery_tuanz_fare_money,
  1269. pickingup_fare,
  1270. localtown_makeup_delivery_money,
  1271. buy_type
  1272. } = tdata;
  1273. total_free *= 1; //合计金额(扣除满减、优惠券,不含运费)
  1274. delivery_tuanz_money *= 1; //配送费
  1275. fare_man_shipping_fare_money *= 1; //免多少运费
  1276. trans_free_toal = trans_free_toal*1;
  1277. let tot_price = 0; //计算后合计+运费
  1278. // 商品总额
  1279. let total_goods_price = 0;
  1280. let levelAmount = 0; //等级优惠
  1281. for (let gidx of Object.keys(goods)) {
  1282. let item = goods[gidx];
  1283. total_goods_price += item.total;
  1284. if(is_open_vipcard_buy==1&&item.is_take_vipcard==1&&is_vip_card_member==1) {
  1285. // 会员优惠
  1286. } else if (item.is_mb_level_buy) {
  1287. levelAmount += item.total * 1 - item.level_total * 1;
  1288. }
  1289. }
  1290. let total_all = total_goods_price; //总额
  1291. // 商品总额+配送费
  1292. if(tabIdx==0){
  1293. tot_price = total_free;
  1294. } else if (tabIdx==1){
  1295. // 满免运费
  1296. let is_man_delivery_tuanz_fare = tdata.is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
  1297. if (is_man_delivery_tuanz_fare==0) {
  1298. tot_price = delivery_tuanz_money + total_free;
  1299. } else {
  1300. tot_price = total_free + delivery_tuanz_money - fare_man_delivery_tuanz_fare_money*1;
  1301. }
  1302. total_all += delivery_tuanz_money;
  1303. } else if(tabIdx==2) {
  1304. // 满免快递费
  1305. let is_man_shipping_fare = tdata.is_man_shipping_fare; //是否达到满xx减运费
  1306. total_all += trans_free_toal;
  1307. if (is_man_shipping_fare == 0) {
  1308. tot_price = trans_free_toal + total_free;
  1309. } else {
  1310. if(buy_type=="pintuan") {
  1311. tot_price = trans_free_toal + total_free;
  1312. } else {
  1313. tot_price = trans_free_toal + total_free - fare_man_shipping_fare_money*1;
  1314. }
  1315. }
  1316. } else if(tabIdx==3) {
  1317. // 同城配送
  1318. let localtown_shipping_fare_arr = this.data.localtown_shipping_fare_arr;
  1319. let total_yl_shipping_fare = localtown_shipping_fare_arr.total_yl_shipping_fare*1 || 0;
  1320. let total_shipping_fare = localtown_shipping_fare_arr.total_shipping_fare*1 || 0;
  1321. total_all += total_yl_shipping_fare;
  1322. //包装费
  1323. total_all += pickingup_fare*1 + localtown_makeup_delivery_money*1;
  1324. tot_price = total_free + localtown_makeup_delivery_money*1;
  1325. tot_price += pickingup_fare*1+total_shipping_fare*1;
  1326. } else if (tabIdx==4) {
  1327. tot_price = total_free;
  1328. }
  1329. //使用积分
  1330. let use_score = tdata.use_score;
  1331. if (isTabSwitch && use_score) {
  1332. let score_for_money = tdata.score_for_money * 1;
  1333. tot_price = tot_price - score_for_money;
  1334. }
  1335. let disAmount = 0; //优惠金额
  1336. disAmount = (total_all - tot_price*1).toFixed(2);
  1337. this.setData({
  1338. total_all: total_all.toFixed(2),
  1339. disAmount,
  1340. tot_price: tot_price.toFixed(2),
  1341. total_goods_price: total_goods_price.toFixed(2),
  1342. levelAmount: levelAmount.toFixed(2)
  1343. })
  1344. },
  1345. /**
  1346. * 订单留言 20190219
  1347. */
  1348. bindInputMessage: function (event) {
  1349. let commentArr = this.data.commentArr;
  1350. let idx = event.currentTarget.dataset.idx;
  1351. var val = event.detail.value;
  1352. commentArr[idx] = val;
  1353. this.setData({ commentArr })
  1354. },
  1355. /**
  1356. * 修改首页列表商品购物车数量
  1357. */
  1358. changeIndexList: function(){
  1359. let goods = this.data.goods || [];
  1360. if(goods.length>0){
  1361. goods.forEach((item)=>{
  1362. item.option.length == 0 && status.indexListCarCount(item.goods_id, 0);
  1363. })
  1364. }
  1365. },
  1366. /**
  1367. * 订阅消息
  1368. */
  1369. subscriptionNotice: function() {
  1370. let that = this;
  1371. return new Promise((resolve, reject)=>{
  1372. let obj = that.data.need_subscript_template;
  1373. let tmplIds = Object.keys(obj).map(key => obj[key]); // 订阅消息模版id
  1374. if (wx.requestSubscribeMessage) {
  1375. tmplIds.length && wx.requestSubscribeMessage({
  1376. tmplIds: tmplIds,
  1377. success(res) {
  1378. let is_need_subscript = 1;
  1379. let acceptId = [];
  1380. Object.keys(obj).forEach(item=>{
  1381. if (res[obj[item]] == 'accept') {
  1382. //用户同意了订阅,添加进数据库
  1383. acceptId.push(item);
  1384. } else {
  1385. //用户拒绝了订阅或当前游戏被禁用订阅消息
  1386. is_need_subscript = 0;
  1387. }
  1388. })
  1389. if(acceptId.length) {
  1390. that.addAccept(acceptId);
  1391. }
  1392. that.setData({ is_need_subscript })
  1393. resolve();
  1394. },
  1395. fail(err) {
  1396. console.log(err)
  1397. reject();
  1398. }
  1399. })
  1400. } else {
  1401. // 兼容处理
  1402. reject();
  1403. }
  1404. })
  1405. },
  1406. // 用户点击订阅添加到数据库
  1407. addAccept: function (acceptId) {
  1408. let token = wx.getStorageSync('token');
  1409. let type = acceptId.join(',');
  1410. app.util.request({
  1411. url: 'entry/wxapp/user',
  1412. data: {
  1413. controller: 'user.collect_subscriptmsg',
  1414. token,
  1415. type
  1416. },
  1417. dataType: 'json',
  1418. method: 'POST',
  1419. success: function () {}
  1420. })
  1421. },
  1422. handleTimeModal: function(){
  1423. let localtown_expected_delivery = this.data.localtown_expected_delivery;
  1424. if(localtown_expected_delivery.localtown_expected_delivery_status&&localtown_expected_delivery.localtown_delivery_space_month) {
  1425. this.setData({
  1426. showAlertTime: !this.data.showAlertTime
  1427. })
  1428. }
  1429. },
  1430. selectAlertTime: function(event){
  1431. let idx = event.currentTarget.dataset.idx;
  1432. console.log(idx)
  1433. this.setData({
  1434. curAlertTime: idx
  1435. })
  1436. },
  1437. selectAlertDate: function(event){
  1438. let idx = event.currentTarget.dataset.idx;
  1439. console.log(idx)
  1440. let curAlertTime = 0;
  1441. if(this.data.localtown_expected_delivery.localtown_delivery_space_month==idx) curAlertTime = -1;
  1442. this.setData({
  1443. localtown_delivery_space_month: idx,
  1444. curAlertTime
  1445. })
  1446. },
  1447. agreePresaleChange: function(e) {
  1448. let state = e.detail.value;
  1449. console.log('统一支付定金', state);
  1450. this.setData({ isAgreePresale: state })
  1451. },
  1452. hanlePresaleModal: function(e) {
  1453. this.setData({
  1454. showPresaleDesc: !this.data.showPresaleDesc
  1455. })
  1456. },
  1457. showPresaleAmoutDesc: function(){
  1458. wx.showModal({
  1459. title: '优惠说明',
  1460. content: '优惠金额将在支付尾款时使用',
  1461. showCancel: false
  1462. })
  1463. }
  1464. })