scanAppointOrder.js 23 KB

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