appointOrder.js 24 KB

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