placeOrder.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. payBtnLoading: false,
  12. showConfirmModal: false,
  13. receiverAddress: "", //快递送货地址
  14. tuan_send_address: "", //团长送货地址
  15. showGetPhone: 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. ],
  26. tabIdx: 0,
  27. region: ['选择地址', '', ''],
  28. tot_price: 0,
  29. needAuth: false,
  30. reduce_money: 0,
  31. hide_quan: true,
  32. tuan_region: ['选择地址','',''],
  33. groupInfo: {
  34. group_name: '社区',
  35. owner_name: '团长'
  36. },
  37. comment: '',
  38. is_yue_open: 0,
  39. can_yupay: 0,
  40. ck_yupay: 0,
  41. use_score: 0,
  42. commentArr: []
  43. },
  44. canPay: true,
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function(options) {
  49. var that = this;
  50. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  51. var token = wx.getStorageSync('token');
  52. var community = wx.getStorageSync('community');
  53. var community_id = community.communityId;
  54. util.check_login() ? this.setData({ needAuth: false }) : (this.setData({ needAuth: true }), wx.hideTabBar());
  55. let is_limit = options.is_limit || 0;
  56. this.setData({
  57. buy_type: options.type,
  58. pickUpAddress: community.fullAddress,
  59. pickUpCommunityName: community.communityName,
  60. disUserName: community.disUserName
  61. })
  62. wx.showLoading()
  63. let latitude = wx.getStorageSync('latitude2');
  64. let longitude = wx.getStorageSync('longitude2');
  65. if (is_limit==1) {
  66. if (latitude && longitude) {
  67. console.log('---------is here ?-----------');
  68. checkOut();
  69. } else {
  70. /**
  71. locat.getGps().then(function (res) {
  72. console.log(res);
  73. latitude = res.latitude;
  74. longitude = res.longitude;
  75. checkOut();
  76. }).catch(function (res) {
  77. latitude = res.latitude || '';
  78. longitude = res.longitude || '';
  79. checkOut();
  80. })
  81. */
  82. checkOut();
  83. }
  84. } else {
  85. checkOut();
  86. }
  87. function checkOut(){
  88. app.util.request({
  89. 'url': 'entry/wxapp/user',
  90. 'data': {
  91. controller: 'car.checkout',
  92. 'token': token,
  93. 'community_id': community_id,
  94. "buy_type": options.type,
  95. },
  96. dataType: 'json',
  97. method: 'POST',
  98. success: function (res) {
  99. let rdata = res.data;
  100. // 提货方式
  101. let tabIdx = 0;
  102. let tabLength = 0;
  103. let tabList = that.data.tabList;
  104. if (res.data.delivery_type_express == 1) tabList[2].enabled = true, tabLength++, tabIdx = 2;
  105. if (res.data.delivery_type_tuanz == 1) tabList[1].enabled = true, tabLength++, tabIdx = 1;
  106. if (res.data.delivery_type_ziti == 1) tabList[0].enabled = true, tabLength++, tabIdx = 0;
  107. let delivery_express_name = res.data.delivery_express_name || '快递配送';
  108. tabList[2].name = delivery_express_name;
  109. let shippingFee = 0;
  110. if (tabIdx == 1) { shippingFee = res.data.delivery_tuanz_money; } else if (tabIdx == 2) { shippingFee = rdata.trans_free_toal;}
  111. // let tot_price = parseFloat(res.data.total_free) + parseFloat(shippingFee);
  112. var addres = 0;
  113. addres = 1;
  114. wx.hideLoading();
  115. var seller_chose_id = 0;
  116. var seller_chose_store_id = 0;
  117. var seller_goods = rdata.seller_goodss;
  118. let len = Object.keys(seller_goods).length;
  119. let commentArr = Array.apply(null, Array(len)).map(() => '');
  120. let sel_chose_vouche = '';
  121. for (var i in seller_goods) {
  122. if (seller_goods[i].show_voucher == 1) {
  123. if (seller_goods[i].chose_vouche.id) seller_chose_id = seller_goods[i].chose_vouche.id;
  124. if (seller_goods[i].chose_vouche.store_id) seller_chose_store_id = seller_goods[i].chose_vouche.store_id;
  125. if (Object.prototype.toString.call(seller_goods[i].chose_vouche) == '[object Object]'){
  126. sel_chose_vouche = seller_goods[i].chose_vouche;
  127. }
  128. }
  129. seller_goods[i].goodsnum = Object.keys(seller_goods[i].goods).length;
  130. for (var j in seller_goods[i].goods) {
  131. if (seller_goods[i].goods[j].header_disc > 0 && seller_goods[i].goods[j].header_disc < 100) {
  132. seller_goods[i].goods[j].header_disc = (seller_goods[i].goods[j].header_disc / 10).toFixed(1);
  133. }
  134. }
  135. }
  136. let param = {
  137. loadover: true,
  138. commentArr,
  139. sel_chose_vouche,
  140. tabList: tabList,
  141. is_limit_distance_buy: rdata.is_limit_distance_buy || 0,
  142. tabIdx: tabIdx,
  143. tabLength: tabLength,
  144. tuan_send_address: rdata.tuan_send_address,
  145. is_open_order_message: rdata.is_open_order_message,
  146. is_yue_open: rdata.is_yue_open,
  147. can_yupay: rdata.can_yupay,
  148. show_voucher: rdata.show_voucher,
  149. current_distance: rdata.current_distance || '',
  150. man_free_tuanzshipping: rdata.man_free_tuanzshipping*1 || 0,
  151. man_free_shipping: rdata.man_free_shipping*1 || 0,
  152. index_hide_headdetail_address: rdata.index_hide_headdetail_address || 0,
  153. open_score_buy_score: rdata.open_score_buy_score || 0,
  154. score: rdata.score || 0,
  155. score_for_money: rdata.score_for_money || 0,
  156. bue_use_score: rdata.bue_use_score || 0,
  157. is_man_delivery_tuanz_fare: rdata.is_man_delivery_tuanz_fare, //是否达到满xx减团长配送费
  158. fare_man_delivery_tuanz_fare_money: rdata.fare_man_delivery_tuanz_fare_money, //达到满xx减团长配送费, 减了多少钱
  159. is_man_shipping_fare: rdata.is_man_shipping_fare, //是否达到满xx减运费
  160. fare_man_shipping_fare_money: rdata.fare_man_shipping_fare_money //达到满xx减运费,司机减了多少运费
  161. }
  162. let addrObj = rdata.address;
  163. if (Object.keys(addrObj) && Object.keys(addrObj).length > 0){
  164. param.ziti_name = rdata.address.name
  165. param.ziti_mobile = addrObj.telephone
  166. param.receiverAddress = addrObj.address
  167. param.region = [addrObj.province_name || "选择地址", addrObj.city_name || "", addrObj.country_name || ""]
  168. } else {
  169. param.ziti_name = rdata.ziti_name
  170. param.ziti_mobile = rdata.ziti_mobile
  171. }
  172. let tuan_send_address_info = rdata.tuan_send_address_info;
  173. if (Object.keys(tuan_send_address_info) && Object.keys(tuan_send_address_info).length > 0) {
  174. param.tuan_region = [tuan_send_address_info.province_name, tuan_send_address_info.city_name, tuan_send_address_info.country_name]
  175. param.lou_meng_hao = tuan_send_address_info.lou_meng_hao
  176. }
  177. if (addres == 1) {
  178. that.setData({
  179. ...param,
  180. pick_up_time: res.data.pick_up_time,
  181. pick_up_type: res.data.pick_up_type,
  182. pick_up_weekday: res.data.pick_up_weekday,
  183. addressState: true,
  184. is_integer: res.data.is_integer,
  185. is_ziti: res.data.is_ziti,
  186. pick_up_arr: res.data.pick_up_arr,
  187. seller_goodss: res.data.seller_goodss,
  188. seller_chose_id: seller_chose_id,
  189. seller_chose_store_id: seller_chose_store_id,
  190. goods: res.data.goods,
  191. buy_type: res.data.buy_type,
  192. yupay: res.data.can_yupay,
  193. is_yue_open: res.data.is_yue_open,
  194. yu_money: res.data.yu_money,
  195. total_free: res.data.total_free,
  196. trans_free_toal: res.data.trans_free_toal,
  197. delivery_tuanz_money: res.data.delivery_tuanz_money,
  198. reduce_money: res.data.reduce_money,
  199. is_open_fullreduction: res.data.is_open_fullreduction,
  200. cha_reduce_money: res.data.cha_reduce_money
  201. }, () => {
  202. that.calcPrice();
  203. })
  204. } else {
  205. that.setData({
  206. ...param,
  207. is_integer: res.data.is_integer,
  208. addressState: false,
  209. goods: res.data.goods,
  210. is_ziti: res.data.is_ziti,
  211. pick_up_arr: res.data.pick_up_arr,
  212. seller_goodss: res.data.seller_goodss,
  213. seller_chose_id: seller_chose_id,
  214. seller_chose_store_id: seller_chose_store_id,
  215. buy_type: res.data.buy_type,
  216. yupay: res.data.can_yupay,
  217. is_yue_open: res.data.is_yue_open,
  218. yu_money: res.data.yu_money,
  219. total_free: res.data.total_free,
  220. trans_free_toal: res.data.trans_free_toal,
  221. delivery_tuanz_money: res.data.delivery_tuanz_money,
  222. reduce_money: res.data.reduce_money,
  223. is_open_fullreduction: res.data.is_open_fullreduction,
  224. cha_reduce_money: res.data.cha_reduce_money
  225. },()=>{
  226. that.calcPrice();
  227. })
  228. }
  229. // if (!that.data.ziti_mobile && !wx.getStorageSync('mobile')){
  230. // that.setData({ showGetPhone: true })
  231. // }
  232. }
  233. })
  234. }
  235. },
  236. /**
  237. * 授权成功回调
  238. */
  239. authSuccess: function () {
  240. this.onLoad();
  241. },
  242. /**
  243. * 设置手机号
  244. */
  245. getReceiveMobile: function (e) {
  246. var num = e.detail;
  247. this.setData({
  248. t_ziti_mobile: num,
  249. showGetPhone: false
  250. });
  251. },
  252. ck_wxpays: function () {
  253. this.setData({
  254. ck_yupay: 0
  255. })
  256. },
  257. ck_yupays: function () {
  258. this.setData({
  259. ck_yupay: 1
  260. })
  261. },
  262. scoreChange: function (e) {
  263. console.log('是否使用', e.detail.value)
  264. let tdata = this.data;
  265. let score_for_money = tdata.score_for_money*1;
  266. let tot_price = tdata.tot_price*1;
  267. let disAmount = tdata.disAmount*1;
  268. if (e.detail.value){
  269. tot_price = (tot_price - score_for_money).toFixed(2);
  270. disAmount += score_for_money;
  271. } else {
  272. tot_price = (tot_price + score_for_money).toFixed(2);
  273. disAmount -= score_for_money;
  274. }
  275. this.setData({
  276. use_score: e.detail.value?1:0,
  277. tot_price,
  278. disAmount: disAmount.toFixed(2)
  279. })
  280. },
  281. /**
  282. * 未登录
  283. */
  284. needAuth: function(){
  285. this.setData({
  286. needAuth: true
  287. });
  288. },
  289. /**
  290. * 关闭手机授权
  291. */
  292. close: function () {
  293. this.setData({
  294. showGetPhone: false
  295. });
  296. },
  297. goOrderfrom: function() {
  298. var t_ziti_name = this.data.ziti_name;
  299. var t_ziti_mobile = this.data.ziti_mobile;
  300. var receiverAddress = this.data.receiverAddress;
  301. var region = this.data.region;
  302. var tuan_send_address = this.data.tuan_send_address;
  303. var lou_meng_hao = this.data.lou_meng_hao;
  304. if (t_ziti_name == '') {
  305. this.setData({
  306. focus_name: true
  307. })
  308. let tip = '请填写收货人';
  309. if (this.data.tabIdx == 0) tip = '请填写提货人';
  310. wx.showToast({
  311. title: tip,
  312. icon: 'none'
  313. })
  314. return false;
  315. }
  316. if (t_ziti_mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(t_ziti_mobile))) {
  317. this.setData({
  318. focus_mobile: true
  319. })
  320. wx.showToast({
  321. title: '手机号码有误',
  322. icon: 'none'
  323. })
  324. return false;
  325. }
  326. if (this.data.tabIdx == 2 && region[0] == '选择地址') {
  327. wx.showToast({
  328. title: '请选择所在地区',
  329. icon: 'none'
  330. })
  331. return false;
  332. }
  333. if (this.data.tabIdx == 2 && receiverAddress == ''){
  334. this.setData({
  335. focus_addr: true
  336. })
  337. wx.showToast({
  338. title: '请填写详细地址',
  339. icon: 'none'
  340. })
  341. return false;
  342. }
  343. if (this.data.tabIdx == 1) {
  344. if (tuan_send_address == '选择位置' || tuan_send_address == '') {
  345. wx.showToast({
  346. title: '请选择位置',
  347. icon: 'none'
  348. })
  349. return false;
  350. }
  351. if (lou_meng_hao == ''){
  352. wx.showToast({
  353. title: '输入楼号门牌',
  354. icon: 'none'
  355. })
  356. return false;
  357. }
  358. }
  359. if (this.data.tabIdx == 2){ this.prepay(); } else { this.conformOrder(); }
  360. },
  361. prepay: function() {
  362. console.log(this.canPay)
  363. if (this.data.is_limit_distance_buy == 1 && (this.data.tabIdx == 1)){
  364. wx.showModal({
  365. title: '提示',
  366. content: '离团长太远了,暂不支持下单',
  367. showCancel: false,
  368. confirmColor: '#F75451'
  369. })
  370. return false;
  371. }
  372. if(this.canPay){
  373. this.setData({ payBtnLoading: true })
  374. this.canPay = false;
  375. var that = this;
  376. var token = wx.getStorageSync('token');
  377. var voucher_id = this.data.seller_chose_id;
  378. var seller_chose_store_id = this.data.seller_chose_store_id;
  379. var ck_yupay = this.data.ck_yupay;
  380. var tabIdx = this.data.tabIdx;
  381. var dispatching = this.data.tabList[tabIdx].dispatching;
  382. // var addressState = this.data.addressState;
  383. // var can_sub = this.data.can_sub;
  384. var commentArr = this.data.commentArr;
  385. let comment = commentArr.join('@EOF@');
  386. var receiverAddress = this.data.receiverAddress;
  387. var region = this.data.region;
  388. var t_ziti_name = this.data.ziti_name;
  389. var t_ziti_mobile = this.data.ziti_mobile;
  390. var quan_arr = [];
  391. if (voucher_id > 0) {
  392. var t_tmp = seller_chose_store_id + '_' + voucher_id;
  393. quan_arr.push(t_tmp);
  394. }
  395. let tuan_send_address = '';
  396. let tuan_region = '';
  397. let address_name = '';
  398. let province_name = '';
  399. let city_name = '';
  400. let country_name = '';
  401. if (tabIdx==1){
  402. tuan_send_address = this.data.tuan_send_address;
  403. tuan_region = this.data.tuan_region;
  404. province_name = tuan_region[0];
  405. city_name = tuan_region[1];
  406. country_name = tuan_region[2];
  407. } else if (tabIdx == 2) {
  408. address_name = receiverAddress;
  409. province_name = region[0];
  410. city_name = region[1];
  411. country_name = region[2];
  412. }
  413. var community = wx.getStorageSync('community');
  414. var community_id = community.communityId;
  415. var pick_up_id = community_id;
  416. let latitude = wx.getStorageSync('latitude2');
  417. let longitude = wx.getStorageSync('longitude2');
  418. let use_score = this.data.use_score;
  419. app.util.request({
  420. 'url': 'entry/wxapp/user',
  421. 'data': {
  422. controller: 'car.sub_order',
  423. token: token,
  424. pay_method: 'wxpay',
  425. buy_type: that.data.buy_type,
  426. pick_up_id: pick_up_id,
  427. dispatching: dispatching,
  428. ziti_name: t_ziti_name,
  429. quan_arr: quan_arr,
  430. comment: comment,
  431. ziti_mobile: t_ziti_mobile,
  432. latitude: latitude,
  433. longitude: longitude,
  434. ck_yupay,
  435. tuan_send_address,
  436. lou_meng_hao: that.data.lou_meng_hao,
  437. address_name,
  438. province_name,
  439. city_name,
  440. country_name,
  441. use_score
  442. },
  443. dataType: 'json',
  444. method: 'POST',
  445. success: function (res) {
  446. let has_yupay = res.data.has_yupay || 0;
  447. var order_id = res.data.order_id;
  448. console.log('支付日志:');
  449. console.log(res);
  450. if (res.data.code == 0) {
  451. that.changeIndexList();
  452. if (has_yupay == 1) {
  453. that.canPay = true;
  454. if (res.data.is_go_orderlist <= 1) {
  455. wx.redirectTo({
  456. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1'
  457. })
  458. } else {
  459. wx.redirectTo({
  460. url: '/lionfish_comshop/pages/order/index?is_show=1'
  461. })
  462. }
  463. } else {
  464. wx.requestPayment({
  465. "appId": res.data.appId,
  466. "timeStamp": res.data.timeStamp,
  467. "nonceStr": res.data.nonceStr,
  468. "package": res.data.package,
  469. "signType": res.data.signType,
  470. "paySign": res.data.paySign,
  471. 'success': function (wxres) {
  472. that.canPay = true;
  473. if (res.data.is_go_orderlist<=1){
  474. wx.redirectTo({
  475. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&is_show=1'
  476. })
  477. } else {
  478. wx.redirectTo({
  479. url: '/lionfish_comshop/pages/order/index?is_show=1'
  480. })
  481. }
  482. },
  483. 'fail': function (error) {
  484. if (res.data.is_go_orderlist <= 1) {
  485. wx.redirectTo({
  486. url: '/lionfish_comshop/pages/order/order?id=' + order_id + '&?isfail=1'
  487. })
  488. } else {
  489. wx.redirectTo({
  490. url: '/lionfish_comshop/pages/order/index?isfail=1'
  491. })
  492. }
  493. }
  494. })
  495. }
  496. } else if (res.data.code == 1) {
  497. that.canPay = true;
  498. wx.showToast({
  499. title: '支付失败',
  500. icon: "none"
  501. });
  502. } else if (res.data.code == 2) {
  503. that.canPay = true;
  504. wx.showToast({
  505. title: res.data.msg,
  506. icon: "none"
  507. });
  508. }
  509. that.setData({ btnLoading: false, payBtnLoading:false })
  510. }
  511. })
  512. }
  513. },
  514. /**
  515. * 监听收货人
  516. */
  517. changeReceiverName: function(e) {
  518. var receiverName = e.detail.value.trim();
  519. if (receiverName) {
  520. this.setData({
  521. ziti_name: receiverName
  522. })
  523. } else {
  524. let tip = '请填写收货人';
  525. if (this.data.tabIdx == 0) tip = '请填写提货人';
  526. wx.showToast({
  527. title: tip,
  528. icon: "none"
  529. });
  530. this.setData({
  531. ziti_name: receiverName
  532. });
  533. }
  534. return {
  535. value: e.detail.value.trim()
  536. }
  537. },
  538. /**
  539. * 监听手机号
  540. */
  541. bindReceiverMobile: function(e) {
  542. this.setData({
  543. receiverMobile: e.detail.value.trim()
  544. });
  545. var mobile = e.detail.value.trim();
  546. this.setData({
  547. ziti_mobile: mobile
  548. });
  549. return {
  550. value: e.detail.value.trim()
  551. }
  552. },
  553. /**
  554. * 监控快递地址变化
  555. */
  556. changeReceiverAddress: function(e){
  557. this.setData({
  558. receiverAddress: e.detail.value.trim()
  559. });
  560. return {
  561. value: e.detail.value.trim()
  562. }
  563. },
  564. /**
  565. * 监控团长送货地址变化
  566. */
  567. changeTuanAddress: function (e) {
  568. this.setData({
  569. lou_meng_hao: e.detail.value.trim()
  570. });
  571. return {
  572. value: e.detail.value.trim()
  573. }
  574. },
  575. /**
  576. * 结算
  577. */
  578. conformOrder: function() {
  579. this.setData({
  580. showConfirmModal: true
  581. });
  582. },
  583. /**
  584. * 关闭结算
  585. */
  586. closeConfirmModal: function() {
  587. this.canPay = true;
  588. this.setData({
  589. showConfirmModal: false
  590. });
  591. },
  592. /**
  593. * 地区选择
  594. */
  595. bindRegionChange: function (e) {
  596. let region = e.detail.value;
  597. region && this.checkOut(region[1]);
  598. this.setData({ region })
  599. },
  600. checkOut: function (mb_city_name) {
  601. var that = this;
  602. var token = wx.getStorageSync('token');
  603. var community = wx.getStorageSync('community');
  604. var community_id = community.communityId;
  605. let latitude = wx.getStorageSync('latitude2');
  606. let longitude = wx.getStorageSync('longitude2');
  607. app.util.request({
  608. 'url': 'entry/wxapp/user',
  609. 'data': {
  610. controller: 'car.checkout',
  611. token: token,
  612. community_id: community_id,
  613. mb_city_name,
  614. latitude: latitude,
  615. longitude: longitude
  616. },
  617. dataType: 'json',
  618. method: 'POST',
  619. success: function (res) {
  620. if(res.data.code==1){
  621. let rdata = res.data;
  622. let shop_buy_distance = rdata.shop_buy_distance || 0;
  623. let is_limit_distance_buy = rdata.is_limit_distance_buy || 0;
  624. let current_distance = rdata.current_distance || '';
  625. if (that.data.tabIdx == 1 && is_limit_distance_buy == 1 && (current_distance > shop_buy_distance)) {
  626. wx.showModal({
  627. title: '提示',
  628. content: '超出配送范围,请重新选择',
  629. showCancel: false,
  630. confirmColor: '#F75451'
  631. })
  632. }
  633. that.setData({
  634. is_limit_distance_buy,
  635. current_distance,
  636. trans_free_toal: rdata.trans_free_toal,
  637. is_man_delivery_tuanz_fare: rdata.is_man_delivery_tuanz_fare, //是否达到满xx减团长配送费
  638. fare_man_delivery_tuanz_fare_money: rdata.fare_man_delivery_tuanz_fare_money, //达到满xx减团长配送费, 减了多少钱
  639. is_man_shipping_fare: rdata.is_man_shipping_fare, //是否达到满xx减运费
  640. fare_man_shipping_fare_money: rdata.fare_man_shipping_fare_money //达到满xx减运费,司机减了多少运费
  641. }, () => { that.calcPrice() })
  642. }
  643. }
  644. })
  645. },
  646. /**
  647. * 定位获取地址
  648. */
  649. choseLocation: function() {
  650. var that = this;
  651. wx.chooseLocation({
  652. success: function (e) {
  653. var path = e;
  654. var s_region = that.data.region;
  655. var dol_path = '';
  656. var str = path;
  657. var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
  658. var result = patt.exec(str);
  659. if (result == null) {
  660. patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
  661. result = patt.exec(str);
  662. if (result == null) {
  663. patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
  664. result = patt.exec(str);
  665. if (result == null) {
  666. } else {
  667. s_region[0] = result[1];
  668. s_region[1] = result[2];
  669. s_region[2] = result[3];
  670. dol_path = path.replace(result[0], '');
  671. }
  672. } else {
  673. s_region[0] = result[1];
  674. s_region[1] = result[2];
  675. s_region[2] = result[3];
  676. dol_path = path.replace(result[0], '');
  677. }
  678. } else {
  679. s_region[0] = result[1];
  680. s_region[1] = result[2];
  681. s_region[2] = result[3];
  682. dol_path = path.replace(result[0], '');
  683. }
  684. var filename = dol_path + e.name;
  685. // if (s_region[0] == '省')
  686. let address_component = '';
  687. wcache.put('latitude2', e.latitude);
  688. wcache.put('longitude2', e.longitude);
  689. locat.getGpsLocation(e.latitude, e.longitude).then((res) => {
  690. console.log('反推了')
  691. address_component = res;
  692. if (address_component) {
  693. s_region[0] = address_component.province;
  694. s_region[1] = address_component.city;
  695. s_region[2] = address_component.district;
  696. }
  697. setRes();
  698. });
  699. function setRes(){
  700. console.log('setData')
  701. s_region && (s_region[1] != "市") && that.checkOut(s_region[1]);
  702. let tuan_region = ['选择地址', '', ''];
  703. if (that.data.tabIdx == 1){
  704. console.log('选择地图后返回,tabIdx=1:'+s_region);
  705. tuan_region = s_region;
  706. that.setData({
  707. tuan_send_address: filename,
  708. tuan_region
  709. })
  710. } else {
  711. that.setData({
  712. region: s_region,
  713. receiverAddress: filename
  714. })
  715. }
  716. }
  717. },
  718. fail: function (error) {
  719. console.log(error)
  720. if (error.errMsg =='chooseLocation:fail auth deny') {
  721. console.log('无权限')
  722. locat.checkGPS(app, locat.openSetting())
  723. // app.globalData.canGetGPS || locat.openSetting()
  724. }
  725. }
  726. })
  727. },
  728. /**
  729. * 微信获取地址
  730. */
  731. getWxAddress: function() {
  732. let region = this.data.region;
  733. let that = this;
  734. wx.getSetting({
  735. success(res) {
  736. console.log("vres.authSetting['scope.address']:", res.authSetting['scope.address'])
  737. if (res.authSetting['scope.address']) {
  738. wx.chooseAddress({
  739. success(res) {
  740. console.log("step1")
  741. region[0] = res.provinceName || "选择地址";
  742. region[1] = res.cityName || "";
  743. region[2] = res.countyName || "";
  744. let receiverAddress = res.detailInfo;
  745. let ziti_name = res.userName;
  746. let ziti_mobile = res.telNumber;
  747. let tuan_region = that.data.tuan_region;
  748. if (that.data.tabIdx == 1){
  749. tuan_region = region;
  750. that.setData({
  751. tuan_send_address: receiverAddress, tuan_region
  752. })
  753. } else {
  754. that.setData({
  755. region, receiverAddress
  756. })
  757. }
  758. that.setData({
  759. ziti_name, ziti_mobile
  760. })
  761. region && (region[1] != "市") && that.checkOut(region[1]);
  762. },
  763. fail(res){
  764. console.log("step4")
  765. console.log(res)
  766. }
  767. })
  768. } else {
  769. if (res.authSetting['scope.address'] == false) {
  770. wx.openSetting({
  771. success(res) {
  772. console.log(res.authSetting)
  773. }
  774. })
  775. } else {
  776. console.log("step2")
  777. wx.chooseAddress({
  778. success(res) {
  779. console.log("step3")
  780. region[0] = res.provinceName || "选择地址";
  781. region[1] = res.cityName || "";
  782. region[2] = res.countyName || "";
  783. let receiverAddress = res.detailInfo;
  784. let ziti_name = res.userName;
  785. let ziti_mobile = res.telNumber;
  786. region && (region[1] != "市") && that.checkOut(region[1]);
  787. let tuan_region = that.data.tuan_region;
  788. if (that.data.tabIdx == 1) {
  789. tuan_region = region;
  790. that.setData({
  791. tuan_send_address: receiverAddress, tuan_region
  792. })
  793. } else {
  794. that.setData({
  795. region, receiverAddress
  796. })
  797. }
  798. that.setData({
  799. ziti_name, ziti_mobile
  800. })
  801. }
  802. })
  803. }
  804. }
  805. }
  806. })
  807. },
  808. /**
  809. * tab切换
  810. */
  811. tabSwitch: function (t) {
  812. let idx = 1 * t.currentTarget.dataset.idx;
  813. (idx != 0) && wx.showToast({ title: '配送变更,费用已变化', icon: "none"});
  814. this.setData({
  815. tabIdx: idx
  816. },function(){
  817. this.calcPrice(1);
  818. })
  819. },
  820. /**
  821. * 打开优惠券
  822. */
  823. show_voucher: function (event) {
  824. var that = this;
  825. var serller_id = event.currentTarget.dataset.seller_id;
  826. var voucher_list = [];
  827. var seller_chose_id = this.data.seller_chose_id;
  828. var seller_chose_store_id = this.data.seller_chose_store_id;
  829. var seller_goods = this.data.seller_goodss;
  830. for (var i in seller_goods) {
  831. var s_id = seller_goods[i].store_info.s_id;
  832. if (s_id == serller_id) {
  833. voucher_list = seller_goods[i].voucher_list;
  834. if (seller_chose_id == 0) {
  835. seller_chose_id = seller_goods[i].chose_vouche.id || 0;
  836. seller_chose_store_id = seller_goods[i].chose_vouche.store_id || 0;
  837. }
  838. }
  839. }
  840. that.setData({
  841. ssvoucher_list: voucher_list,
  842. voucher_serller_id: serller_id,
  843. seller_chose_id: seller_chose_id,
  844. seller_chose_store_id: seller_chose_store_id,
  845. hide_quan: false
  846. })
  847. },
  848. // 选择优惠券
  849. chose_voucher_id: function (event) {
  850. wx.showLoading();
  851. var voucher_id = event.currentTarget.dataset.voucher_id;
  852. var seller_id = event.currentTarget.dataset.seller_id;
  853. var that = this;
  854. var token = wx.getStorageSync('token');
  855. var use_quan_str = seller_id + "_" + voucher_id;
  856. let latitude = wx.getStorageSync('latitude2');
  857. let longitude = wx.getStorageSync('longitude2');
  858. var buy_type = that.data.buy_type;
  859. var community_id = wx.getStorageSync('community').communityId;
  860. app.util.request({
  861. url: 'entry/wxapp/user',
  862. data: {
  863. controller: 'car.checkout',
  864. token: token,
  865. community_id: community_id,
  866. voucher_id: voucher_id,
  867. use_quan_str,
  868. buy_type,
  869. latitude,
  870. longitude
  871. },
  872. dataType: 'json',
  873. method: 'POST',
  874. success: function (res) {
  875. wx.hideLoading();
  876. if(res.data.code ==1){
  877. let seller_goodss = res.data.seller_goodss;
  878. let sel_chose_vouche = '';
  879. for (var i in seller_goodss) {
  880. seller_goodss[i].goodsnum = Object.keys(seller_goodss[i].goods).length;
  881. if (Object.prototype.toString.call(seller_goodss[i].chose_vouche) == '[object Object]') {
  882. sel_chose_vouche = seller_goodss[i].chose_vouche;
  883. }
  884. }
  885. that.setData({
  886. seller_goodss: seller_goodss,
  887. seller_chose_id: voucher_id,
  888. seller_chose_store_id: seller_id,
  889. hide_quan: true,
  890. goods: res.data.goods,
  891. buy_type: res.data.buy_type,
  892. yupay: res.data.can_yupay,
  893. is_yue_open: res.data.is_yue_open,
  894. total_free: res.data.total_free,
  895. sel_chose_vouche: sel_chose_vouche,
  896. current_distance: res.data.current_distance || ''
  897. },()=>{
  898. that.calcPrice();
  899. })
  900. }
  901. }
  902. })
  903. },
  904. //关闭优惠券
  905. closeCouponModal: function(){
  906. this.setData({
  907. hide_quan: true
  908. })
  909. },
  910. /**
  911. * 计算总额
  912. */
  913. calcPrice: function(isTabSwitch = 0){
  914. let tdata = this.data;
  915. // let is_open_fullreduction = this.data.is_open_fullreduction; //是否开启满减
  916. let total_free = tdata.total_free*1; //合计金额(扣除满减、优惠券,不含运费)
  917. let delivery_tuanz_money = tdata.delivery_tuanz_money*1; //配送费
  918. let trans_free_toal = tdata.trans_free_toal*1; //运费
  919. let tabIdx = tdata.tabIdx; //提货类型
  920. let goods = tdata.goods;
  921. let tot_price = 0; //计算后合计+运费
  922. // 商品总额
  923. let total_goods_price = 0;
  924. if (Object.prototype.toString.call(goods) == '[object Object]'){
  925. Object.keys(goods).forEach(function(key){
  926. total_goods_price += goods[key].total;
  927. });
  928. } else {
  929. goods.forEach(function (item) {
  930. total_goods_price += item.total;
  931. })
  932. }
  933. let total_all = total_goods_price; //总额
  934. // 商品总额+配送费
  935. if(tabIdx==0){
  936. tot_price = total_free;
  937. } else if (tabIdx==1){
  938. // 满免运费
  939. let is_man_delivery_tuanz_fare = tdata.is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
  940. if (is_man_delivery_tuanz_fare==0) {
  941. tot_price = delivery_tuanz_money + total_free;
  942. } else {
  943. tot_price = total_free;
  944. }
  945. total_all += delivery_tuanz_money;
  946. } else if(tabIdx==2) {
  947. // 满免运费
  948. let is_man_shipping_fare = tdata.is_man_shipping_fare; //是否达到满xx减运费
  949. total_all += trans_free_toal;
  950. if (is_man_shipping_fare == 0) {
  951. tot_price = trans_free_toal + total_free;
  952. } else {
  953. tot_price = total_free;
  954. }
  955. }
  956. //使用积分
  957. let use_score = tdata.use_score;
  958. if (isTabSwitch && use_score) {
  959. let score_for_money = tdata.score_for_money * 1;
  960. tot_price = tot_price - score_for_money;
  961. }
  962. let disAmount = 0; //优惠金额
  963. disAmount = (total_all - tot_price*1).toFixed(2);
  964. this.setData({
  965. total_all: total_all.toFixed(2),
  966. disAmount,
  967. tot_price: tot_price.toFixed(2),
  968. total_goods_price: total_goods_price.toFixed(2)
  969. })
  970. },
  971. /**
  972. * 订单留言 20190219
  973. */
  974. bindInputMessage: function (event) {
  975. let commentArr = this.data.commentArr;
  976. let idx = event.currentTarget.dataset.idx;
  977. var val = event.detail.value;
  978. commentArr.splice(idx, 1, val);
  979. this.setData({ commentArr })
  980. },
  981. /**
  982. * 修改首页列表商品购物车数量
  983. */
  984. changeIndexList: function(){
  985. let goods = this.data.goods;
  986. if(goods.length>0){
  987. goods.forEach((item)=>{
  988. item.option.length == 0 && status.indexListCarCount(item.goods_id, 0);
  989. })
  990. }
  991. }
  992. })