index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. var util = require('../../utils/util.js');
  2. var app = getApp()
  3. Page({
  4. data: {
  5. navState: 0,
  6. is_first: 1,
  7. show_add_address: false,
  8. region: ['省', '市', '区'],
  9. address: {},
  10. theme_type: '',
  11. loadover: false,
  12. ssvoucher_list: [],
  13. addressState: false,
  14. tips: '有什么想对商家说的可以写在这里哦~',
  15. goods: {},
  16. buy_type: '',
  17. pickname: '请选择自提点',
  18. ck_yupay: 0,
  19. is_yue_open: 0,
  20. comment: '',
  21. can_sub: 1,
  22. pay_str: '立即支付',
  23. tab_index: 1,
  24. total_free: 0,
  25. is_ziti: 0,
  26. pick_up_id: 0,
  27. hide_quan: true,
  28. dispatching: 'express',
  29. pick_up_arr: 0,
  30. focus_name: false,
  31. seller_chose_id: 0,
  32. focus_mobile: false,
  33. seller_chose_store_id: 0,
  34. voucher_id_arr: [],
  35. yupay: 0,
  36. yu_money: 0,
  37. ziti_name: '',
  38. add_mo: 0,
  39. ziti_mobile: '',
  40. skustate: 0
  41. },
  42. onLoad: function (options) {
  43. var that = this;
  44. var token = wx.getStorageSync('token');
  45. this.setData({
  46. buy_type: options.type
  47. })
  48. wx.showLoading({
  49. })
  50. wx.hideLoading();
  51. wx.closeSocket();
  52. app.util.request({
  53. 'url': 'entry/wxapp/user',
  54. 'data': {
  55. controller: 'car.checkout',
  56. 'token': token,
  57. "buy_type": options.type
  58. },
  59. dataType: 'json',
  60. method: 'POST',
  61. success: function (res) {
  62. var addres = 0;
  63. if (res.data.address != null && res.data.address != false) {
  64. addres = 1;
  65. }
  66. console.log(addres);
  67. var seller_chose_id = 0;
  68. var seller_chose_store_id = 0;
  69. var seller_goods = res.data.seller_goodss;
  70. for (var i in seller_goods) {
  71. if (seller_goods[i].show_voucher == 1) {
  72. seller_chose_id = seller_goods[i].chose_vouche.id;
  73. seller_chose_store_id = seller_goods[i].chose_vouche.store_id;
  74. }
  75. for (var j in seller_goods[i].goods) {
  76. if (seller_goods[i].goods[j].header_disc > 0 && seller_goods[i].goods[j].header_disc < 100) {
  77. seller_goods[i].goods[j].header_disc = (seller_goods[i].goods[j].header_disc / 10).toFixed(1);
  78. }
  79. }
  80. }
  81. that.setData({
  82. loadover:true
  83. })
  84. if (addres == 1) {
  85. that.setData({
  86. address: {
  87. provinceName: res.data.address.province_name,
  88. cityName: res.data.address.city_name,
  89. countyName: res.data.address.country_name,
  90. detailInfo: res.data.address.address,
  91. telNumber: res.data.address.telephone,
  92. userName: res.data.address.name,
  93. },
  94. addressState: true,
  95. is_integer: res.data.is_integer,
  96. ziti_name: res.data.ziti_name,
  97. ziti_mobile: res.data.ziti_mobile,
  98. is_ziti: res.data.is_ziti,
  99. pick_up_arr: res.data.pick_up_arr,
  100. seller_goodss: res.data.seller_goodss,
  101. seller_chose_id: seller_chose_id,
  102. seller_chose_store_id: seller_chose_store_id,
  103. goods: res.data.goods,
  104. buy_type: res.data.buy_type,
  105. yupay: res.data.can_yupay,
  106. is_yue_open: res.data.is_yue_open,
  107. yu_money: res.data.yu_money,
  108. total_free: res.data.total_free
  109. })
  110. } else {
  111. that.setData({
  112. is_integer: res.data.is_integer,
  113. addressState: false,
  114. goods: res.data.goods,
  115. is_ziti: res.data.is_ziti,
  116. pick_up_arr: res.data.pick_up_arr,
  117. seller_goodss: res.data.seller_goodss,
  118. seller_chose_id: seller_chose_id,
  119. seller_chose_store_id: seller_chose_store_id,
  120. buy_type: res.data.buy_type,
  121. yupay: res.data.can_yupay,
  122. is_yue_open: res.data.is_yue_open,
  123. yu_money: res.data.yu_money,
  124. ziti_name: res.data.ziti_name,
  125. ziti_mobile: res.data.ziti_mobile,
  126. total_free: res.data.total_free
  127. })
  128. }
  129. }
  130. })
  131. },
  132. onShow: function () {
  133. var _isfirst = this.data.is_first;
  134. if (_isfirst == 0) {
  135. console.log('show_on');
  136. this.load_new_func();
  137. } else {
  138. this.setData({
  139. is_first: 0
  140. })
  141. }
  142. },
  143. chooseAddress_list: function () {
  144. var s_type = this.data.buy_type;
  145. var url = "/pages/dan/address_list?is_direct=1&buy_type=" + s_type;
  146. var pages_all = getCurrentPages();
  147. if (pages_all.length > 3) {
  148. wx.redirectTo({
  149. url: url
  150. })
  151. } else {
  152. wx.navigateTo({
  153. url: url
  154. })
  155. }
  156. },
  157. navShow: function () {
  158. this.setData({
  159. navState: 1
  160. })
  161. },
  162. goOrderfrom: function (e) {
  163. var from_id = e.detail.formId;
  164. var token = wx.getStorageSync('token');
  165. app.util.request({
  166. 'url': 'entry/wxapp/user',
  167. 'data': {
  168. controller: 'user.get_member_form_id',
  169. 'token': token,
  170. "from_id": from_id
  171. },
  172. dataType: 'json',
  173. success: function (res) {
  174. }
  175. })
  176. this.setOrder();
  177. },
  178. ck_wxpays: function () {
  179. this.setData({
  180. ck_yupay: 0
  181. })
  182. },
  183. tabchange: function (e) {
  184. var index = e.currentTarget.dataset.index;
  185. if (index == 2) {
  186. this.setData({
  187. dispatching: 'pickup',
  188. tips: '',
  189. tab_index: index
  190. })
  191. this.load_new_price();
  192. } else {
  193. this.setData({
  194. dispatching: 'express',
  195. skustate: 0,
  196. tab_index: index,
  197. tips: '有什么想对商家说的可以写在这里哦~'
  198. })
  199. this.load_new_price();
  200. }
  201. },
  202. ck_yupays: function () {
  203. var yupay = this.data.yupay;
  204. if (yupay == 0) {
  205. wx.showToast({
  206. title: '余额不足',
  207. })
  208. return false;
  209. }
  210. var ck_yupay = this.data.ck_yupay;
  211. if (ck_yupay == 1) {
  212. this.setData({
  213. ck_yupay: 0
  214. })
  215. } else {
  216. this.setData({
  217. ck_yupay: 1
  218. })
  219. }
  220. },
  221. navHide: function () {
  222. this.setData({
  223. navState: 0
  224. })
  225. },
  226. click_hide_dialog: function () {
  227. this.setData({
  228. skustate: 0
  229. })
  230. },
  231. load_new_price: function () {
  232. // dispatching:'express',
  233. var that = this;
  234. var token = wx.getStorageSync('token');
  235. var buy_type = this.data.buy_type;
  236. var dispatching = this.data.dispatching;
  237. app.util.request({
  238. 'url': 'entry/wxapp/user',
  239. 'data': {
  240. controller: 'car.checkout',
  241. 'token': token,
  242. "buy_type": buy_type,
  243. "dispatching": dispatching
  244. },
  245. dataType: 'json',
  246. method: 'POST',
  247. success: function (res) {
  248. //addressState:true,dispatching
  249. var t_addressState = false;
  250. if (res.data.address != null || dispatching == 'pickup') {
  251. t_addressState = true;
  252. }
  253. //console.log(res.data.address);
  254. //console.log(dispatching);
  255. //console.log(t_addressState);
  256. if (res.data.address != null) {
  257. that.setData({
  258. address: {
  259. provinceName: res.data.address.province_name,
  260. cityName: res.data.address.city_name,
  261. countyName: res.data.address.country_name,
  262. detailInfo: res.data.address.address,
  263. telNumber: res.data.address.telephone,
  264. userName: res.data.address.name,
  265. },
  266. addressState: t_addressState,
  267. goods: res.data.goods,
  268. buy_type: res.data.buy_type,
  269. total_free: res.data.total_free
  270. })
  271. } else {
  272. that.setData({
  273. addressState: t_addressState,
  274. goods: res.data.goods,
  275. buy_type: res.data.buy_type,
  276. total_free: res.data.total_free
  277. })
  278. }
  279. }
  280. })
  281. },
  282. show_voucher: function (event) {
  283. var that = this;
  284. var serller_id = event.currentTarget.dataset.seller_id;
  285. var voucher_list = [];
  286. var seller_chose_id = this.data.seller_chose_id;
  287. var seller_chose_store_id = this.data.seller_chose_store_id;
  288. var seller_goods = this.data.seller_goodss;
  289. for (var i in seller_goods) {
  290. var s_id = seller_goods[i].store_info.s_id;
  291. if (s_id == serller_id) {
  292. voucher_list = seller_goods[i].voucher_list;
  293. if (seller_chose_id == 0) {
  294. seller_chose_id = seller_goods[i].chose_vouche.id;
  295. seller_chose_store_id = seller_goods[i].chose_vouche.store_id;
  296. }
  297. }
  298. }
  299. that.setData({
  300. ssvoucher_list: voucher_list,
  301. voucher_serller_id: serller_id,
  302. seller_chose_id: seller_chose_id,
  303. seller_chose_store_id: seller_chose_store_id,
  304. hide_quan: false
  305. })
  306. // seller_goodss: res.data.seller_goodss,
  307. },
  308. close_voucher: function () {
  309. this.setData({
  310. hide_quan: true
  311. })
  312. },
  313. chose_voucher_id: function (event) {
  314. var voucher_id = event.currentTarget.dataset.voucher_id;
  315. var seller_id = event.currentTarget.dataset.seller_id;
  316. var that = this;
  317. var token = wx.getStorageSync('token');
  318. var buy_type = that.data.buy_type;
  319. var use_quan_str = seller_id + "_" + voucher_id;
  320. app.util.request({
  321. 'url': 'entry/wxapp/index',
  322. 'data': { controller: 'car.checkout', token: token,
  323. buy_type: buy_type, voucher_id: voucher_id, use_quan_str: use_quan_str},
  324. dataType: 'json',
  325. success: function (res) {
  326. var addres = 0;
  327. if (res.data.address != null) {
  328. addres = 1;
  329. }
  330. var seller_chose_id = 0;
  331. if (res.data.seller_goodss.show_voucher == 1) {
  332. seller_chose_id = res.data.seller_goodss.show_voucher.id
  333. }
  334. if (addres == 1) {
  335. that.setData({
  336. address: {
  337. provinceName: res.data.address.province_name,
  338. cityName: res.data.address.city_name,
  339. countyName: res.data.address.country_name,
  340. detailInfo: res.data.address.address,
  341. telNumber: res.data.address.telephone,
  342. userName: res.data.address.name,
  343. },
  344. addressState: true,
  345. seller_goodss: res.data.seller_goodss,
  346. seller_chose_id: voucher_id,
  347. seller_chose_store_id: seller_id,
  348. hide_quan: true,
  349. goods: res.data.goods,
  350. buy_type: res.data.buy_type,
  351. yupay: res.data.can_yupay,
  352. is_yue_open: res.data.is_yue_open,
  353. total_free: res.data.total_free
  354. })
  355. } else {
  356. that.setData({
  357. addressState: false,
  358. goods: res.data.goods,
  359. seller_goodss: res.data.seller_goodss,
  360. seller_chose_id: voucher_id,
  361. seller_chose_store_id: seller_id,
  362. hide_quan: true,
  363. buy_type: res.data.buy_type,
  364. yupay: res.data.can_yupay,
  365. is_yue_open: res.data.is_yue_open,
  366. total_free: res.data.total_free
  367. })
  368. }
  369. }
  370. })
  371. //voucher_id voucher_id_arr
  372. },
  373. chooseZiti: function () {
  374. this.setData({
  375. skustate: 1,
  376. tips: '',
  377. })
  378. },
  379. bindNameInput: function (e) {
  380. this.setData({
  381. ziti_name: e.detail.value
  382. })
  383. },
  384. bindAddrdetailInput: function (e) {
  385. this.setData({
  386. addr_detail: e.detail.value
  387. })
  388. },
  389. bindAddrtelInput: function (e) {
  390. this.setData({
  391. addr_tel: e.detail.value
  392. })
  393. },
  394. bindAddrnameInput: function (e) {
  395. this.setData({
  396. addr_name: e.detail.value
  397. })
  398. },
  399. bindMobileInput: function (e) {
  400. this.setData({
  401. ziti_mobile: e.detail.value
  402. })
  403. },
  404. bindRegionChange: function (e) {
  405. this.setData({
  406. region: e.detail.value
  407. })
  408. },
  409. textarea_input: function (event) {
  410. var val = event.detail.value;
  411. this.setData({
  412. comment: val
  413. })
  414. },
  415. chose_mendian: function (e) {
  416. let men_id = e.currentTarget.dataset.id;
  417. let name = e.currentTarget.dataset.name;
  418. this.load_new_price();
  419. this.setData({
  420. pick_up_id: men_id,
  421. skustate: 0,
  422. tips: '有什么想对商家说的可以写在这里哦~',
  423. dispatching: 'pickup',
  424. addressState: true,
  425. pickname: name
  426. })
  427. },
  428. load_wx_add: function () {
  429. var that = this;
  430. wx.chooseAddress({
  431. success: function (res) {
  432. var token = wx.getStorageSync('token');
  433. res.controller = 'user.add_weixinaddress';
  434. res.token = token;
  435. app.util.request({
  436. 'url': 'entry/wxapp/user',
  437. 'data': res,
  438. dataType: 'json',
  439. method: 'POST',
  440. success: function (msg) {
  441. var buy_type = that.data.buy_type;
  442. app.util.request({
  443. 'url': 'entry/wxapp/user',
  444. 'data': {
  445. controller:'car.checkout',
  446. token: token,
  447. buy_type: buy_type
  448. },
  449. dataType: 'json',
  450. method: 'POST',
  451. success: function (res) {
  452. var seller_chose_id = 0;
  453. if (res.data.seller_goodss.show_voucher == 1) {
  454. seller_chose_id = res.data.seller_goodss.show_voucher.id
  455. }
  456. that.setData({
  457. address: {
  458. provinceName: res.data.address.province_name,
  459. cityName: res.data.address.city_name,
  460. countyName: res.data.address.country_name,
  461. detailInfo: res.data.address.address,
  462. telNumber: res.data.address.telephone,
  463. userName: res.data.address.name,
  464. },
  465. seller_chose_id: seller_chose_id,
  466. seller_goodss: res.data.seller_goodss,
  467. addressState: true,
  468. goods: res.data.goods,
  469. buy_type: res.data.buy_type,
  470. yupay: res.data.can_yupay,
  471. is_yue_open: res.data.is_yue_open,
  472. total_free: res.data.total_free
  473. })
  474. }
  475. })
  476. }
  477. })
  478. }
  479. })
  480. },
  481. chooseAddress: function () {
  482. var add_mo = this.data.add_mo;
  483. var that = this;
  484. wx.getSetting({
  485. success: function (res) {
  486. var add_scope = res.authSetting;
  487. that.load_wx_add();
  488. that.setData({
  489. add_mo: 1
  490. })
  491. }
  492. })
  493. },
  494. goLink: function (event) {
  495. let link = event.currentTarget.dataset.link;
  496. wx.redirectTo({
  497. url: link
  498. })
  499. },
  500. setOrder: function () {
  501. var that = this;
  502. var token = wx.getStorageSync('token');
  503. var addressState = this.data.addressState;
  504. var voucher_id = this.data.seller_chose_id;
  505. var is_ziti = this.data.is_ziti;
  506. var seller_chose_store_id = this.data.seller_chose_store_id;
  507. var ck_yupay = this.data.ck_yupay;
  508. var dispatching = this.data.dispatching;
  509. var can_sub = this.data.can_sub;
  510. if (is_ziti == 2) {
  511. addressState = true;
  512. dispatching = 'pickup';
  513. }
  514. var comment = this.data.comment;
  515. // addressState: false,
  516. if (!addressState) {
  517. wx.showToast({
  518. title: '请选择收货地址',
  519. })
  520. return false;
  521. }
  522. var t_ziti_name = this.data.ziti_name;
  523. var t_ziti_mobile = this.data.ziti_mobile;
  524. var quan_arr = [];
  525. if (voucher_id > 0) {
  526. var t_tmp = seller_chose_store_id + '_' + voucher_id;
  527. quan_arr.push(t_tmp);
  528. }
  529. var pick_up_id = that.data.pick_up_id;
  530. if (dispatching == 'pickup') {
  531. if (t_ziti_name == '') {
  532. this.setData({
  533. focus_name: true
  534. })
  535. wx.showToast({
  536. title: '请填写联系人',
  537. })
  538. return false;
  539. }
  540. if (t_ziti_mobile == '') {
  541. this.setData({
  542. focus_mobile: true
  543. })
  544. wx.showToast({
  545. title: '请填写联系方式',
  546. })
  547. return false;
  548. }
  549. if (pick_up_id == 0) {
  550. this.setData({
  551. skustate: 1
  552. })
  553. wx.showToast({
  554. title: '请选择自提点',
  555. })
  556. return false;
  557. }
  558. }
  559. if (can_sub != 1) {
  560. return false;
  561. }
  562. this.setData({
  563. can_sub: 0
  564. })
  565. this.setData({
  566. pay_str: '支付中..'
  567. })
  568. app.util.request({
  569. 'url': 'entry/wxapp/user',
  570. 'data': {
  571. controller: 'car.sub_order',
  572. 'token': token,
  573. pay_method: 'wxpay',
  574. buy_type: that.data.buy_type,
  575. pick_up_id: that.data.pick_up_id,
  576. dispatching: that.data.dispatching,
  577. ziti_name: t_ziti_name,
  578. quan_arr: quan_arr,
  579. comment: comment,
  580. ziti_mobile: t_ziti_mobile,
  581. ck_yupay: ck_yupay
  582. },
  583. dataType: 'json',
  584. method: 'POST',
  585. success: function (res) {
  586. //has_yupay
  587. if (res.data.has_yupay == 1) {
  588. var order_id = res.data.order_id;
  589. //buytype
  590. if (that.data.buy_type == 'pin' && res.data.is_integral == 0 && res.data.is_spike == 0) {
  591. wx.redirectTo({
  592. url: '/Snailfish_shop/pages/share/index?id=' + res.data.order_id + '&is_show=1'
  593. })
  594. } else {
  595. wx.redirectTo({
  596. url: '/Snailfish_shop/pages/order/order?id=' + res.data.order_id + '&is_show=1'
  597. })
  598. }
  599. } else {
  600. var order_id = res.data.order_id;
  601. wx.requestPayment({
  602. "appId": res.data.appId,
  603. "timeStamp": res.data.timeStamp,
  604. "nonceStr": res.data.nonceStr,
  605. "package": res.data.package,
  606. "signType": res.data.signType,
  607. "paySign": res.data.paySign,
  608. 'success': function (wxres) {
  609. //buytype
  610. if (that.data.buy_type == 'pin' && res.data.is_spike == 0) {
  611. wx.redirectTo({
  612. url: '/Snailfish_shop/pages/share/index?id=' + res.data.order_id + '&is_show=1'
  613. })
  614. } else {
  615. wx.redirectTo({
  616. url: '/Snailfish_shop/pages/order/order?id=' + res.data.order_id + '&is_show=1'
  617. })
  618. }
  619. },
  620. 'fail': function (res) {
  621. //console.log(res);
  622. wx.redirectTo({
  623. url: '/pages/order/order?id=' + order_id
  624. })
  625. }
  626. })
  627. }
  628. }
  629. })
  630. },
  631. show_add_selfaddress: function () {
  632. this.setData({
  633. show_add_address: true
  634. })
  635. },
  636. close_address_dialog: function () {
  637. this.setData({
  638. show_add_address: false
  639. })
  640. },
  641. chose_location: function () {
  642. var that = this;
  643. wx.chooseLocation({
  644. success: function (e) {
  645. var path = e.address;
  646. var s_region = that.data.region;
  647. var dol_path = '';
  648. var str = path;
  649. var patt = new RegExp("(.*?省)(.*?市)(.*?区)", "g");
  650. var result = patt.exec(str);
  651. if (result == null) {
  652. patt = new RegExp("(.*?省)(.*?市)(.*?市)", "g");
  653. result = patt.exec(str);
  654. if (result == null) {
  655. patt = new RegExp("(.*?省)(.*?市)(.*县)", "g");
  656. result = patt.exec(str);
  657. if (result == null) {
  658. } else {
  659. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  660. wx.showToast({
  661. title: '省市区信息已同步修改',
  662. icon: 'none',
  663. })
  664. }
  665. s_region[0] = result[1];
  666. s_region[1] = result[2];
  667. s_region[2] = result[3];
  668. dol_path = path.replace(result[0], '');
  669. }
  670. } else {
  671. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  672. wx.showToast({
  673. title: '省市区信息已同步修改',
  674. icon: 'none',
  675. })
  676. }
  677. s_region[0] = result[1];
  678. s_region[1] = result[2];
  679. s_region[2] = result[3];
  680. dol_path = path.replace(result[0], '');
  681. }
  682. } else {
  683. if (s_region[0] != result[1] || s_region[1] != result[2] || s_region[2] != result[3]) {
  684. wx.showToast({
  685. title: '省市区信息已同步修改',
  686. icon: 'none',
  687. })
  688. }
  689. s_region[0] = result[1];
  690. s_region[1] = result[2];
  691. s_region[2] = result[3];
  692. dol_path = path.replace(result[0], '');
  693. }
  694. if (s_region[0] == '省') {
  695. wx.showToast({
  696. title: '请重新选择省市区',
  697. icon: 'none',
  698. })
  699. }
  700. var filename = dol_path + e.name;
  701. that.setData({
  702. region: s_region,
  703. addr_detail: filename
  704. })
  705. }
  706. })
  707. },
  708. sub_address_do: function () {
  709. var token = wx.getStorageSync('token');
  710. var addr_name = this.data.addr_name;
  711. var addr_tel = this.data.addr_tel;
  712. var province_name = this.data.region[0];
  713. var city_name = this.data.region[1];
  714. var area_name = this.data.region[2];
  715. var addr_detail = this.data.addr_detail;
  716. var that = this;
  717. if (addr_name == '') {
  718. wx.showToast({
  719. title: '请填写姓名',
  720. })
  721. return false;
  722. }
  723. if (addr_tel == '') {
  724. wx.showToast({
  725. title: '请填写电话',
  726. })
  727. return false;
  728. }
  729. if (province_name == '省' && city_name == '市' && area_name == '区') {
  730. wx.showToast({
  731. title: '请选择地区',
  732. })
  733. return false;
  734. }
  735. if (addr_detail == '') {
  736. wx.showToast({
  737. title: '请填写详细地址',
  738. })
  739. return false;
  740. }
  741. var res = { province_name: province_name, city_name: city_name, area_name: area_name, addr_tel: addr_tel, addr_detail: addr_detail, addr_name: addr_name };
  742. wx.request({
  743. url: util.api() + 'index.php?s=/Apicheckout/add_weixin_selftaddress/token/' + token,
  744. data: res,
  745. method: 'POST',
  746. success: function (msg) {
  747. that.close_address_dialog();
  748. var buy_type = that.data.buy_type;
  749. wx.request({
  750. url: util.api() + 'index.php?s=/Apicart/checkout/token/' + token + '/buy_type/' + buy_type,
  751. success: function (res) {
  752. var seller_chose_id = 0;
  753. if (res.data.seller_goodss.show_voucher == 1) {
  754. seller_chose_id = res.data.seller_goodss.show_voucher.id
  755. }
  756. that.setData({
  757. address: {
  758. provinceName: res.data.address.province_name,
  759. cityName: res.data.address.city_name,
  760. countyName: res.data.address.country_name,
  761. detailInfo: res.data.address.address,
  762. telNumber: res.data.address.telephone,
  763. userName: res.data.address.name,
  764. },
  765. seller_chose_id: seller_chose_id,
  766. seller_goodss: res.data.seller_goodss,
  767. addressState: true,
  768. goods: res.data.goods,
  769. buy_type: res.data.buy_type,
  770. total_free: res.data.total_free
  771. })
  772. }
  773. })
  774. }
  775. })
  776. },
  777. load_new_func: function () {
  778. var token = wx.getStorageSync('token');
  779. var that = this;
  780. var buy_type = that.data.buy_type;
  781. app.util.request({
  782. 'url': 'entry/wxapp/user',
  783. 'data': {
  784. controller: 'car.checkout',
  785. 'token': token,
  786. "buy_type": buy_type
  787. },
  788. dataType: 'json',
  789. method: 'POST',
  790. success: function (res) {
  791. var seller_chose_id = 0;
  792. if (res.data.seller_goodss.show_voucher == 1) {
  793. seller_chose_id = res.data.seller_goodss.show_voucher.id
  794. }
  795. console.log(res.data.address);
  796. if (res.data.address == null) {
  797. that.setData({
  798. addressState: false,
  799. seller_chose_id: seller_chose_id,
  800. seller_goodss: res.data.seller_goodss,
  801. goods: res.data.goods,
  802. buy_type: res.data.buy_type,
  803. total_free: res.data.total_free
  804. })
  805. } else {
  806. that.setData({
  807. address: {
  808. provinceName: res.data.address.province_name,
  809. cityName: res.data.address.city_name,
  810. countyName: res.data.address.country_name,
  811. detailInfo: res.data.address.address,
  812. telNumber: res.data.address.telephone,
  813. userName: res.data.address.name,
  814. },
  815. seller_chose_id: seller_chose_id,
  816. seller_goodss: res.data.seller_goodss,
  817. addressState: true,
  818. goods: res.data.goods,
  819. buy_type: res.data.buy_type,
  820. total_free: res.data.total_free
  821. })
  822. }
  823. }
  824. })
  825. }
  826. })