placeOrder.js 51 KB

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