scanAppointOrder.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. //获取应用实例
  2. var util = require('../../../utils/util.js');
  3. var api = require('../../../config/api.js');
  4. var check = require('../../../utils/check.js');
  5. var app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // serviceId:'ea11209c0e',
  12. // cusId:'931400',
  13. serviceId: '',
  14. cusId: '',
  15. gender: '2',
  16. address: {
  17. id: 0,
  18. areaCode: 0,
  19. address: '',
  20. name: '',
  21. tel: '',
  22. isDefault: 0,
  23. province: '',
  24. city: '',
  25. county: '',
  26. latitude: '',
  27. longitude: '',
  28. addressDetail: '',
  29. detail: '',
  30. addressname: '',
  31. },
  32. addressIdSave: '', //新增地址保存
  33. orderInfo: {
  34. },
  35. addressId: '',
  36. checkedAddress: {
  37. },
  38. addressList: [],
  39. addressShow: false,
  40. remark: '',
  41. remarkPopupShow: false,
  42. remarkList: [
  43. '上门前提前电话联系',
  44. '请准时到达',
  45. '请自带打扫工具',
  46. '主要打扫厨房&卫生间',
  47. '家里有宠物'
  48. ],
  49. remarkActive: '',
  50. message: '',
  51. remarkShow: false,
  52. addressId: '',
  53. addressName: '',
  54. noAppoint: '',
  55. aftersaleStatus: '',
  56. orderId: '',
  57. order: '',
  58. bookId: '',
  59. bookCount: 0,
  60. orderStatusText: '订单服务中',
  61. activeTab: 1,
  62. orderBook: {
  63. status: ''
  64. },
  65. orderChannel: 0,
  66. jzOrderBookDetails: [],
  67. unusedSerList: [],
  68. usedSerList: [],
  69. serList: [],
  70. choosePopup: false,
  71. timeList: [],
  72. // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 30),
  73. dateList: [],
  74. timeIndex: '',
  75. //选中的时间段
  76. dateIndex: 0, //选中的日期
  77. appointDate: '', //显示信息
  78. isHide: false,
  79. product: {
  80. serviceTimes: '',
  81. price: ''
  82. },
  83. noonType: 1,
  84. selectTimeValue: '',
  85. goodsTip:{
  86. remark:null
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面加载
  91. */
  92. onLoad: function (options) {
  93. console.log(options);
  94. // if (options.serviceId) {
  95. // this.setData({
  96. // serviceId: options.serviceId
  97. // });
  98. // }
  99. // if (options.orderId) {
  100. // this.setData({
  101. // orderId: options.orderId
  102. // });
  103. // }
  104. if (options.scene) {
  105. var scene = decodeURIComponent(options.scene);
  106. // scene='id,221e10b7ae;cid,931400: ""';
  107. console.log(scene);
  108. // id,46dd84a816;cid,931400 id,221e10b7ae;cid,931400: ""
  109. let sceneStr = scene.split(';');
  110. if (scene.indexOf(':') > 0) {
  111. let validStr = scene.split(':')[0];
  112. sceneStr = validStr.split(';');
  113. }
  114. if (scene.indexOf('cid') >= 0) {
  115. this.setData({
  116. serviceId: sceneStr[0].split(",")[1],
  117. cusId: sceneStr[1].split(",")[1]
  118. });
  119. this.getOrderDetail();
  120. }
  121. }else{
  122. //url解析
  123. var scene =Object.keys(options)[0];//[id,d7a4b23bad;cid,356539]
  124. console.log(Object.keys(options));
  125. // id,46dd84a816;cid,931400 id,221e10b7ae;cid,931400: ""
  126. let sceneStr = scene.split(';');
  127. if (scene.indexOf(':') > 0) {
  128. let validStr = scene.split(':')[0];
  129. sceneStr = validStr.split(';');
  130. }
  131. if (scene.indexOf('cid') >= 0) {
  132. this.setData({
  133. serviceId: sceneStr[0].split(",")[1],
  134. cusId: sceneStr[1].split(",")[1]
  135. });
  136. this.getOrderDetail();
  137. }
  138. }
  139. app.globalData.mapSelectFinish = false;
  140. // this.getOrderDetail();
  141. },
  142. getOrderDetail: function () {
  143. wx.showLoading({
  144. title: '加载中'
  145. });
  146. util.request(api.getOrderInfo, {
  147. serviceId: this.data.serviceId,
  148. cusId: this.data.cusId
  149. }).then(res => {
  150. wx.hideLoading();
  151. if (res.errno === 0) {
  152. console.log(res.data);
  153. this.setData({
  154. orderInfo: res.data,
  155. goodsTip:res.data.goodsTip,
  156. addressId: res.data.addressId,
  157. dyDetails: res.data.dyDetails,
  158. afterSale: res.data.afterSale,
  159. payOverTime: res.data.payOverTime,
  160. remainTimes: res.data.serviceTimes - res.data.servedTimes,
  161. // orderGoods: res.data.orderGoods,
  162. // handleOption: res.data.orderInfo.handleOption,
  163. // expressInfo: res.data.expressInfo
  164. });
  165. if (res.data.addressId) {
  166. this.getAddressList();
  167. }
  168. } else {
  169. util.showErrorToast(res.errmsg);
  170. }
  171. }).catch(err => {
  172. wx.hideLoading();
  173. });
  174. },
  175. getAddressList() {
  176. util.request(api.getCusAddressList, {
  177. cusId: this.data.cusId
  178. }).then(res => {
  179. if (res.errno === 0) {
  180. this.setData({
  181. addressList: res.data.list,
  182. });
  183. let current = this.data.addressList.filter(item => {
  184. return item.id == this.data.addressId
  185. });
  186. if (current.length > 0) {
  187. this.setData({
  188. checkedAddress: current[0]
  189. });
  190. }
  191. }
  192. });
  193. },
  194. onShow: function () {
  195. // this.getOrderDetail();
  196. if (app.globalData.mapSelectFinish) {
  197. let poi = app.globalData.mapSelectPoi;
  198. let location = poi.location;
  199. let address = this.data.address;
  200. address.lng = location.split(',')[0];
  201. address.lat = location.split(',')[1];
  202. address.addressname = poi.address;
  203. this.setData({
  204. address: address,
  205. // selectAddress:poi.address
  206. });
  207. console.log(this.data.address);
  208. this.getAreaCode();
  209. }
  210. },
  211. getServiceDetail: function () {
  212. let that = this;
  213. if (that.data.orderId == null || that.data.orderId === undefined) {
  214. util.showErrorToast('页面已过期,请刷新页面重新查看');
  215. return;
  216. }
  217. util.request(api.ServiceDetail, {
  218. order_id: this.data.orderId
  219. }).then(res => {
  220. if (res.errno === 0) {
  221. let jzOrderBookDetails = res.data.jzOrderBookDetails;
  222. let unusedSerList = jzOrderBookDetails.filter(item => {
  223. return item.status === 0 || item.status == 1;
  224. });
  225. let usedSerList = jzOrderBookDetails.filter(item => {
  226. return item.status == 3 || item.status == 4;
  227. });
  228. this.setData({
  229. aftersaleStatus: res.data.order ? res.data.order.aftersaleStatus : '',
  230. noAppoint: res.data.noAppoint,
  231. goods: res.data.goods,
  232. orderBook: res.data.orderBook,
  233. jzOrderBookDetails: jzOrderBookDetails,
  234. activeTab: 1,
  235. unusedSerList: unusedSerList,
  236. usedSerList: usedSerList,
  237. serList: unusedSerList,
  238. orderChannel: res.data.orderChannel,
  239. addressId: res.data.order.addressId,
  240. addressName: res.data.order.address,
  241. mobile: res.data.order.mobile,
  242. product: res.data.product
  243. });
  244. }
  245. });
  246. },
  247. showAppoint(e) {
  248. // let status = e.currentTarget.dataset.status;
  249. // if (status == 1) {
  250. // let time = e.currentTarget.dataset.time;
  251. // let str = time.substr(0, 16).replace(/-/g, '/');
  252. // let isNear = new Date(str).getTime() - new Date().getTime() - 2 * 60 * 60 * 1000;
  253. // console.log(isNear);
  254. // if (isNear < 0) {
  255. // wx.showToast({
  256. // title: '服务时间小于2小时,不能修改预约',
  257. // icon: 'none',
  258. // duration: 2000
  259. // });
  260. // return false;
  261. // }
  262. // }
  263. // if (this.data.order.aftersaleStatus == 1 || this.data.order.aftersaleStatus == 2) {
  264. // util.showErrorToast("退款中,无法预约");
  265. // return;
  266. // }
  267. // console.info(this.data.addressName)
  268. // if (this.data.addressId == 0||this.data.addressName==null||this.data.addressName=='') {
  269. // util.showErrorToast("请输入服务地址");
  270. // return;
  271. // }
  272. if (this.data.appointDate != '') {
  273. this.setData({
  274. choosePopup: true,
  275. });
  276. return false;
  277. } else {
  278. this.setData({
  279. choosePopup: true,
  280. noonType: 1,
  281. timeIndex: 0
  282. });
  283. let params = {
  284. days: 30,
  285. // orderBookId:this.data.bookId,
  286. bookId: this.data.serviceId,
  287. productId: this.data.orderInfo.productId,
  288. serviceDuration: this.data.orderInfo.serviceDuration
  289. }
  290. this.getDayTime(params);
  291. }
  292. },
  293. getTimeList() {
  294. let timeList = util.getBeginTimeList(this.data.orderInfo.serviceDuration, this.data.noonType, this.data.dateList[this.data.dateIndex].name);
  295. this.setData({
  296. timeList: timeList,
  297. selectTimeValue: timeList.length == 0 ? '' : timeList[0].value
  298. });
  299. if (this.data.timeList.length == 0) {
  300. this.setData({
  301. timeIndex: ''
  302. });
  303. }
  304. },
  305. getDayStock() {
  306. if (this.data.dateIndex < 0) {
  307. return false;
  308. }
  309. let params = {
  310. day: this.data.dateList[this.data.dateIndex].date,
  311. goodsId: this.data.orderInfo.goodsId,
  312. addressId: this.data.addressId == 0 ? this.data.addressIdSave : this.data.checkedAddress.id,
  313. productId: this.data.orderInfo.productId,
  314. orderId: this.data.orderInfo.id,
  315. serviceDuration: this.data.orderInfo.serviceDuration
  316. };
  317. wx.showLoading({
  318. title: '加载中'
  319. });
  320. util.request(api.EveryDayStock, params, "GET").then(res => {
  321. wx.hideLoading();
  322. if (res.errno == 0) {
  323. this.setData({
  324. timeList: res.data
  325. });
  326. let validList = this.data.timeList.filter(item => {
  327. return item.stock > 0;
  328. });
  329. if (validList.length > 0) {
  330. this.setData({
  331. timeIndex: validList[0].id - 1
  332. });
  333. } else {
  334. this.setData({
  335. timeIndex: ''
  336. });
  337. }
  338. } else {
  339. wx.showToast({
  340. title: res.errmsg,
  341. icon: 'none',
  342. duration: 2000
  343. });
  344. this.setData({
  345. timeList: [],
  346. timeIndex: ''
  347. });
  348. }
  349. }).catch(err => {
  350. console.log(err);
  351. wx.hideLoading();
  352. wx.showToast({
  353. title: err.errMsg,
  354. icon: 'none'
  355. });
  356. this.setData({
  357. timeList: [],
  358. timeIndex: ''
  359. });
  360. });
  361. },
  362. onClose() {
  363. this.setData({
  364. choosePopup: false
  365. });
  366. },
  367. getDayTime(params) {
  368. wx.showLoading({
  369. title: '加载中',
  370. });
  371. util.request(api.everyDayTime, params, "GET")
  372. .then(res => {
  373. wx.hideLoading();
  374. if (res.errno == 0) {
  375. this.setData({
  376. dateList: res.data,
  377. dateIndex: 0,
  378. timeIndex: -1,
  379. noonType: 1
  380. });
  381. let period = res.data[0].period;
  382. let list = period.filter(item => {
  383. return item.ofTime == '上午';
  384. });
  385. this.setData({
  386. timeList: list
  387. });
  388. } else {
  389. wx.showToast({
  390. title: res.errmsg,
  391. icon: 'none',
  392. duration: 2000
  393. });
  394. this.setData({
  395. timeList: [],
  396. timeIndex: ''
  397. });
  398. }
  399. }).catch(err => {
  400. console.log(err);
  401. wx.hideLoading();
  402. wx.showToast({
  403. title: err.errMsg,
  404. icon: 'none'
  405. });
  406. this.setData({
  407. timeList: [],
  408. timeIndex: ''
  409. });
  410. });
  411. },
  412. dateCheck(e) {
  413. let index = e.currentTarget.dataset.index;
  414. let date = e.currentTarget.dataset.date;
  415. let week = e.currentTarget.dataset.week;
  416. let isbook = e.currentTarget.dataset.isbook;
  417. this.setData({
  418. dateIndex: index
  419. });
  420. let period = this.data.dateList[this.data.dateIndex].period;
  421. let current = (this.data.noonType == 1 ? '上午' : '下午');
  422. let list = period.filter(item => {
  423. return item.ofTime == current;
  424. });
  425. this.setData({
  426. timeList: list
  427. });
  428. let isNoTime = list.every(item => {
  429. return item.timeMsg && item.timeMsg != null;
  430. });
  431. if (isNoTime) {
  432. this.setData({
  433. timeIndex: -1,
  434. selectTimeValue: ''
  435. });
  436. }
  437. // let dateName = this.data.dateList[this.data.dateIndex].name;
  438. // this.setData({
  439. // dateIndex: index
  440. // });
  441. // let curDateName = this.data.dateList[this.data.dateIndex].name;
  442. // if ((curDateName == '今天') || ((new Date()).getHours() >18&&curDateName == "明天")) {
  443. // this.setData({
  444. // noonType: 2
  445. // })
  446. // }
  447. // this.getTimeList();
  448. },
  449. timeCheck(e) {
  450. let index = e.currentTarget.dataset.index;
  451. // if (e.currentTarget.dataset.stock == 0) {
  452. // wx.showToast({
  453. // title: '所选时间无库存,请选择其他时间',
  454. // icon: 'none',
  455. // duration: 2000
  456. // });
  457. // return;
  458. // }
  459. let msg = e.currentTarget.dataset.msg;
  460. if (msg == null || msg == '') {
  461. let time = (this.data.timeList[index].begin).split(':')[0];
  462. this.setData({
  463. timeIndex: index,
  464. selectTimeValue: Number(time)
  465. });
  466. }
  467. // this.setData({
  468. // timeIndex: index,
  469. // selectTimeValue: this.data.timeList[index].value
  470. // });
  471. },
  472. submitBook() { //提交预约
  473. if (this.data.addressId == '' && this.data.addressIdSave == '') {
  474. util.showErrorToast("请输入服务地址");
  475. return;
  476. }
  477. if (this.data.timeIndex === '' || this.data.timeIndex < 0) {
  478. util.showErrorToast("请选择服务时间");
  479. return false;
  480. }
  481. // if (this.data.mobile == null || this.data.mobile.length != 11) {
  482. // util.showErrorToast("请填写手机号码");
  483. // return;
  484. // }
  485. let date = this.data.dateList[this.data.dateIndex].bookdate;
  486. let week = this.data.dateList[this.data.dateIndex].weekOfDay;
  487. let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end;
  488. console.log(date, week, time);
  489. let params = {
  490. cusId: this.data.cusId,
  491. serviceId: this.data.serviceId,
  492. date: date,
  493. startTime: time.split('-')[0],
  494. endTime: time.split('-')[1],
  495. addressId: (this.data.addressId == 0 || this.data.addressId == null) ? this.data.addressIdSave : this.data.checkedAddress.id,
  496. remark: this.data.remark + this.data.message
  497. };
  498. console.info(params);
  499. wx.showLoading({
  500. title: '加载中...'
  501. });
  502. util.request(api.customerBook, params, "POST").then(res => {
  503. if (res.errno == 0) {
  504. wx.hideLoading();
  505. this.setData({
  506. isHide: true
  507. });
  508. wx.showToast({
  509. title: '预约成功',
  510. icon: 'none',
  511. duration: 2000
  512. });
  513. // setTimeout(() => {
  514. // wx.navigateTo({
  515. // url: "/pages/ucenter/orderDetail/orderDetail?id=" + this.data.orderId
  516. // });
  517. // }, 2000);
  518. } else {
  519. wx.showToast({
  520. title: res.errmsg,
  521. icon: 'none'
  522. });
  523. // util.showErrorToast(res.errmsg);
  524. }
  525. });
  526. },
  527. confirmTime() {
  528. if (this.data.timeIndex === '' || this.data.timeIndex < 0) {
  529. util.showErrorToast('请选择服务时间');
  530. return false;
  531. }
  532. let date = this.data.dateList[this.data.dateIndex].bookdate;
  533. let week = this.data.dateList[this.data.dateIndex].weekOfDay;
  534. let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end;
  535. this.setData({
  536. choosePopup: false,
  537. appointDate: date + ' ' + week + ' ' + time
  538. });
  539. },
  540. selectAddress() {
  541. //已经输入过地址的订单 不允许再次选择地址
  542. if (this.data.order.addressId > 0) return;
  543. wx.navigateTo({
  544. url: '/pages/ucenter/address/address'
  545. });
  546. },
  547. showRemark() {
  548. this.setData({
  549. remarkShow: true
  550. });
  551. },
  552. onRemarkClose() {
  553. this.setData({
  554. remarkShow: false
  555. });
  556. },
  557. confirmRemark() {
  558. this.setData({
  559. remarkShow: false
  560. });
  561. },
  562. bindMessageInput: function (e) {
  563. this.setData({
  564. message: e.detail.value
  565. });
  566. },
  567. bindPhone(e) {
  568. this.setData({
  569. mobile: e.detail.value
  570. })
  571. },
  572. copyOrder() {
  573. wx.setClipboardData({
  574. data: this.data.orderInfo.orderSn,
  575. success: function (res) {
  576. wx.getClipboardData({
  577. success: function (res) {
  578. wx.showToast({
  579. title: '订单编号复制成功',
  580. icon: 'success',
  581. duration: 2000
  582. });
  583. }
  584. });
  585. }
  586. });
  587. },
  588. onAddressClose() {
  589. this.setData({
  590. addressShow: false
  591. })
  592. },
  593. onAddressClick() {
  594. //阻止事件冒泡,不要删
  595. },
  596. addressConfirm(e) {
  597. let address = e.currentTarget.dataset.address;
  598. this.setData({
  599. checkedAddress: address,
  600. addressShow: false
  601. });
  602. },
  603. addressSelect() {
  604. this.setData({
  605. addressShow: true
  606. });
  607. },
  608. showRemarkSelect() {
  609. this.setData({
  610. remarkPopupShow: true
  611. });
  612. },
  613. onRemarkPopupClose() {
  614. this.setData({
  615. remarkPopupShow: false
  616. })
  617. },
  618. onRemarkClick() {
  619. //阻止事件冒泡,不要删
  620. },
  621. remarkItemSelect(e) {
  622. let remark = e.currentTarget.dataset.remark;
  623. this.setData({
  624. remark: remark,
  625. remarkActive: remark,
  626. });
  627. },
  628. remarkItemConfirm() {
  629. if (this.data.remarkActive === '') {
  630. util.showErrorToast("请选择备注");
  631. return false;
  632. }
  633. this.setData({
  634. remarkPopupShow: false
  635. });
  636. },
  637. bindinputMobile(event) {
  638. let address = this.data.address;
  639. address.tel = event.detail.value;
  640. this.setData({
  641. address: address
  642. });
  643. },
  644. bindinputName(event) {
  645. let address = this.data.address;
  646. address.name = event.detail.value;
  647. this.setData({
  648. address: address
  649. });
  650. },
  651. bindinputAddress(event) {
  652. let address = this.data.address;
  653. address.detail = event.detail.value.replace(/[,,]/g, '');
  654. this.setData({
  655. address: address
  656. });
  657. // return value.replace(/[,,]/g,'');
  658. },
  659. bindAddressDetail(event) {
  660. let address = this.data.address;
  661. address.addressname = event.detail.value.replace(/[,,]/g, '');
  662. this.setData({
  663. address: address
  664. });
  665. },
  666. submitAll() {
  667. if ((this.data.addressId == '' || this.data.addressId == null) && this.data.addressIdSave == '') {
  668. this.saveAddress();
  669. } else {
  670. this.submitBook();
  671. }
  672. },
  673. async saveAddress() {
  674. console.log(this.data.address);
  675. let address = this.data.address;
  676. // if (address.addressname == 0) {
  677. // util.showErrorToast('请选择服务地址');
  678. // return false;
  679. // }
  680. if (address.addressname == '') {
  681. util.showErrorToast('请选择服务地址');
  682. return false;
  683. }
  684. if (address.name == '') {
  685. util.showErrorToast('请输入姓名');
  686. return false;
  687. }
  688. if (address.detail == '') {
  689. util.showErrorToast('请输入门牌号');
  690. return false;
  691. }
  692. if (this.data.gender == null || this.data.gender == '') {
  693. util.showErrorToast('请选择性别');
  694. return false;
  695. }
  696. if (address.tel == '') {
  697. util.showErrorToast('请输入手机号码');
  698. return false;
  699. }
  700. if (!check.isValidPhone(address.tel)) {
  701. util.showErrorToast('手机号不正确');
  702. return false;
  703. }
  704. let that = this;
  705. let addressString = address.detail == '' ? address.addressname : address.addressname + ',' + address.detail;
  706. wx.showLoading({
  707. title: '加载中...'
  708. });
  709. let res = await util.request(api.addCusAddress, {
  710. gender: this.data.gender,
  711. addressId: address.id,
  712. name: address.name,
  713. tel: address.tel,
  714. province: address.province,
  715. city: address.city,
  716. county: address.county,
  717. areaCode: address.areaCode,
  718. addressDetail: addressString,
  719. isDefault: address.isDefault,
  720. lat: Number(address.lat).toFixed(5),
  721. lng: Number(address.lng).toFixed(5),
  722. cusId: this.data.cusId
  723. }, 'POST');
  724. wx.hideLoading();
  725. if (res.errno === 0) {
  726. that.setData({
  727. addressIdSave: res.data
  728. })
  729. that.submitBook();
  730. } else {
  731. wx.showModal({
  732. title: '提醒',
  733. showCancel: false,
  734. content: res.errmsg
  735. });
  736. }
  737. },
  738. goMap() {
  739. // const key = "JA2BZ-XGOEU-UNZVD-46G64-S6MYJ-6BBF4";
  740. //使用在腾讯位置服务申请的key
  741. // const key = '6TRBZ-XXC6F-BWWJB-N75ME-BQNOF-YKFQY';
  742. // const referer = '鲸致生活LifePlus';
  743. // const category = '小区,生活服务,娱乐休闲';
  744. // wx.navigateTo({
  745. // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
  746. // });
  747. let that = this;
  748. // wx.authorize({
  749. // scope: "scope.userLocation",
  750. // success: (res) => {
  751. // console.log("authorize", res);
  752. wx.chooseLocation({
  753. success: (location) => {
  754. console.log("chooseLocation success: ", location);
  755. console.log(`经度${location.longitude},维度${location.latitude}`);
  756. console.log(location);
  757. if (location != null) {
  758. let address = that.data.address;
  759. address.lat = location.latitude;
  760. address.lng = location.longitude;
  761. address.addressname = location.address;
  762. that.setData({
  763. address: address,
  764. // selectAddress:location.address
  765. });
  766. console.log(that.data.address);
  767. that.getAreaCode();
  768. }
  769. },
  770. fail: (err) => {
  771. console.log("chooseLocation fail: " + err.errMsg);
  772. },
  773. });
  774. // },
  775. // fail: () => {
  776. // wx.openSetting({});
  777. // },
  778. // });
  779. },
  780. goMap() {
  781. console.log('gomap');
  782. app.globalData.mapSelectFinish = false;
  783. // wx.navigateTo({
  784. // url: '/pages/map/mapContent/mapContent',
  785. // });
  786. if (this.data.address.lng && this.data.address.lat) {
  787. let city = (this.data.address.city == '市辖区' ? this.data.address.province : this.data.address.city)
  788. wx.navigateTo({
  789. url: '/pages/map/mapContent/mapContent?lng=' + this.data.address.lng + '&lat=' + this.data.address.lat + '&addressname=' + this.data.address.addressname + '&city=' + city,
  790. });
  791. } else {
  792. wx.navigateTo({
  793. url: '/pages/map/mapContent/mapContent',
  794. });
  795. }
  796. },
  797. maleSelect() {
  798. this.setData({
  799. gender: 1
  800. });
  801. },
  802. femaleSelect() {
  803. this.setData({
  804. gender: 2
  805. });
  806. },
  807. getAreaCode() {
  808. let param = {
  809. location: this.data.address.lng + ',' + this.data.address.lat,
  810. extensions: 'all',
  811. key: api.gdKey,
  812. radius: 3000,
  813. };
  814. wx.request({
  815. url: api.gdUrl,
  816. data: param,
  817. method: 'GET',
  818. header: {
  819. 'Content-Type': 'application/json'
  820. },
  821. success: res => {
  822. console.log(res);
  823. if (res.data.infocode == "10000") {
  824. if (res.data.info == "OK") {
  825. // let ad_info = res.data.result.ad_info;
  826. // let areaCode = res.data.result.ad_info.adcode;
  827. let regeocode = res.data.regeocode.addressComponent;
  828. let cityName = (regeocode.city == null || regeocode.city.length == 0) ? regeocode.province : regeocode.city;
  829. let district = (regeocode.district == null || regeocode.district.length == 0) ? '' : regeocode.district;
  830. this.setData({
  831. ['address.areaCode']: regeocode.adcode,
  832. ['address.province']: regeocode.province,
  833. ['address.city']: cityName,
  834. ['address.county']: district,
  835. // ['address.addressname']:res.data.result.address
  836. });
  837. } else {
  838. wx.showToast({
  839. title: '获取地区码失败',
  840. icon: 'none',
  841. duration: 3000
  842. });
  843. }
  844. } else {
  845. wx.showToast({
  846. title: '获取地区码失败',
  847. icon: 'none',
  848. duration: 3000
  849. });
  850. }
  851. },
  852. fail: function (err) {
  853. reject(err);
  854. }
  855. });
  856. },
  857. goAddAddress() {
  858. wx.navigateTo({
  859. url: '/pages/ucenter/addressAdd/addressAdd?id=' + 0
  860. });
  861. },
  862. noonTab(e) {
  863. let noon = e.currentTarget.dataset.noon;
  864. this.setData({
  865. timeIndex: -1,
  866. noonType: noon,
  867. selectTimeValue: '',
  868. });
  869. let period = this.data.dateList[this.data.dateIndex].period;
  870. let current = (this.data.noonType == 1 ? '上午' : '下午');
  871. let list = period.filter(item => {
  872. return item.ofTime == current;
  873. });
  874. this.setData({
  875. timeList: list
  876. });
  877. }
  878. });