serviceDetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var check = require('../../../utils/check.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. orderId: '',
  11. serviceId: '',
  12. bookCount: 0,
  13. orderStatusText: '订单服务中',
  14. activeTab: 1,
  15. noAppoint: '',
  16. aftersaleStatus: '',
  17. orderBook: {
  18. status: '',
  19. },
  20. orderChannel: 0,
  21. jzOrderBookDetails: [],
  22. unusedSerList: [],
  23. usedSerList: [],
  24. serList: [],
  25. choosePopup: false,
  26. // timeList: check.getTimeList(1),
  27. timeList: [],
  28. // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 21),
  29. dateList:[],
  30. timeIndex: '', //选中的时间段
  31. dateIndex: 0, //
  32. checkedAddress: {
  33. addressId: 0
  34. }, //选中的地址信息
  35. isHaveAddress: false,
  36. noonType: 1,
  37. selectTimeValue: '',
  38. bookId:'',
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. this.setData({
  45. orderId: options.orderId
  46. });
  47. // this.getServiceDetail();
  48. },
  49. getServiceDetail: function () {
  50. // wx.showLoading({
  51. // title: '加载中',
  52. // });
  53. // setTimeout(function() {
  54. // wx.hideLoading();
  55. // }, 2000);
  56. util.request(api.ServiceDetail, {
  57. order_id: this.data.orderId
  58. // order_id: '1342922'
  59. }).then(res => {
  60. // wx.hideLoading();
  61. if (res.errno === 0) {
  62. let jzOrderBookDetails = res.data.jzOrderBookDetails;
  63. let unusedSerList = jzOrderBookDetails.filter(item => {
  64. return item.status === 0 || item.status == 1 || item.status == 7
  65. });
  66. let usedSerList = jzOrderBookDetails.filter(item => {
  67. return item.status == 3 || item.status == 4
  68. });
  69. // let timeList = check.getTimeList(res.data.goods.serviceDuration);
  70. this.setData({
  71. aftersaleStatus: res.data.order.aftersaleStatus,
  72. goods: res.data.goods,
  73. noAppoint: res.data.noAppoint,
  74. orderBook: res.data.orderBook,
  75. jzOrderBookDetails: jzOrderBookDetails,
  76. // activeTab: 1,
  77. unusedSerList: unusedSerList,
  78. usedSerList: usedSerList,
  79. serList: (this.data.activeTab == 1 ? unusedSerList : usedSerList),
  80. // timeList: timeList,
  81. orderChannel: res.data.orderChannel,
  82. isHaveAddress: res.data.order.addressId != null && res.data.order.addressId > 0 && res.data.order.address ? true : false
  83. });
  84. console.log(res.data.order.addressId);
  85. if (res.data.order.addressId) {
  86. console.info("set address")
  87. this.setData({
  88. checkedAddress: {
  89. addressId: res.data.order.addressId,
  90. address: res.data.order.address,
  91. tel: res.data.order.mobile,
  92. name: res.data.order.consignee
  93. }
  94. })
  95. console.info(this.data.checkedAddress)
  96. }
  97. }
  98. });
  99. },
  100. selectAddress() {
  101. wx.navigateTo({
  102. url: '/pages/ucenter/address/address',
  103. })
  104. },
  105. onTabChange(e) {
  106. this.setData({
  107. activeTab: e.detail.name,
  108. });
  109. if (this.data.activeTab == 1) {
  110. this.setData({
  111. serList: this.data.unusedSerList
  112. });
  113. } else {
  114. this.setData({
  115. serList: this.data.usedSerList
  116. })
  117. }
  118. },
  119. showAppoint(e) {
  120. //是否有地址 如果没有地址 必须先选择地址
  121. console.info(this.data.checkedAddress)
  122. if (this.data.checkedAddress.addressId == null
  123. ||this.data.checkedAddress.addressId =='') {
  124. wx.showToast({
  125. title: '请先选择服务地址',
  126. icon: 'none',
  127. duration: 2000
  128. });
  129. return false;
  130. }
  131. let status = e.currentTarget.dataset.status;
  132. if (status == 1) {
  133. let time = e.currentTarget.dataset.time;
  134. let str = time.substr(0, 16).replace(/-/g, '/');
  135. let isNear = (new Date(str)).getTime() - (new Date()).getTime() - 2 * 60 * 60 * 1000;
  136. console.log(isNear);
  137. if (isNear < 0) {
  138. wx.showToast({
  139. title: '服务时间小于2小时,不能修改预约',
  140. icon: 'none',
  141. duration: 2000
  142. });
  143. return false;
  144. }
  145. }
  146. this.setData({
  147. choosePopup: true,
  148. serviceId: e.currentTarget.dataset.id,
  149. bookId:e.currentTarget.dataset.bookid
  150. });
  151. // this.getDayStock();
  152. this.getDayTime();
  153. },
  154. getDayStock() {
  155. if (this.data.dateIndex < 0) {
  156. return false;
  157. }
  158. if( this.data.checkedAddress.addressId==null|| this.data.checkedAddress.addressId==0){
  159. wx.showToast({
  160. title: '请选择地址',
  161. icon:'none'
  162. })
  163. return false
  164. }
  165. let params = {
  166. day: this.data.dateList[this.data.dateIndex].date,
  167. goodsId: this.data.orderBook.goodsId,
  168. lng: this.data.orderBook.lng,
  169. lat: this.data.orderBook.lat,
  170. addressId: this.data.checkedAddress.addressId,
  171. productId: this.data.orderBook.productId,
  172. serviceDuration: this.data.orderBook.serviceDuration
  173. }
  174. wx.showLoading({
  175. title: '加载中',
  176. });
  177. util.request(api.EveryDayStock, params, "GET")
  178. .then(res => {
  179. wx.hideLoading();
  180. if (res.errno == 0) {
  181. this.setData({
  182. timeList: res.data,
  183. timeIndex: 0
  184. });
  185. // let validList = this.data.timeList.filter(item => {
  186. // return item.stock > 0
  187. // });
  188. // if (validList.length > 0) {
  189. // this.setData({
  190. // timeIndex: validList[0].id - 1
  191. // });
  192. // } else {
  193. // this.setData({
  194. // timeIndex: ''
  195. // });
  196. // }
  197. } else {
  198. wx.showToast({
  199. title: res.errmsg,
  200. icon: 'none',
  201. duration: 2000
  202. });
  203. this.setData({
  204. timeList: [],
  205. timeIndex: ''
  206. });
  207. }
  208. }).catch(function (err) {
  209. console.log(err);
  210. wx.hideLoading();
  211. wx.showToast({
  212. title: err.errMsg,
  213. icon: 'none'
  214. });
  215. this.setData({
  216. timeList: [],
  217. timeIndex: ''
  218. });
  219. });
  220. },
  221. onClose() {
  222. this.setData({
  223. choosePopup: false
  224. });
  225. },
  226. getDayTime() {
  227. let params = {
  228. days:30,
  229. orderBookId:this.data.bookId,
  230. bookId:this.data.serviceId
  231. }
  232. wx.showLoading({
  233. title: '加载中',
  234. });
  235. util.request(api.everyDayTime, params, "GET")
  236. .then(res => {
  237. wx.hideLoading();
  238. if (res.errno == 0) {
  239. this.setData({
  240. dateList: res.data,
  241. dateIndex:0,
  242. timeIndex: -1,
  243. noonType:1
  244. });
  245. let period=res.data[0].period;
  246. let list=period.filter(item=>{
  247. return item.ofTime=='上午';
  248. });
  249. this.setData({
  250. timeList:list
  251. });
  252. } else {
  253. wx.showToast({
  254. title: res.errmsg,
  255. icon: 'none',
  256. duration: 2000
  257. });
  258. this.setData({
  259. timeList: [],
  260. timeIndex: ''
  261. });
  262. }
  263. }).catch(function (err) {
  264. console.log(err);
  265. wx.hideLoading();
  266. wx.showToast({
  267. title: err.errMsg,
  268. icon: 'none'
  269. });
  270. this.setData({
  271. timeList: [],
  272. timeIndex: ''
  273. });
  274. });
  275. },
  276. dateCheck(e) {
  277. let index = e.currentTarget.dataset.index;
  278. let date = e.currentTarget.dataset.date;
  279. let week = e.currentTarget.dataset.week;
  280. let isbook = e.currentTarget.dataset.isbook;
  281. // if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) {
  282. // this.setData({
  283. // dateIndex: index
  284. // });
  285. // }
  286. this.setData({
  287. dateIndex: index
  288. });
  289. let period=this.data.dateList[this.data.dateIndex].period;
  290. let current=(this.data.noonType==1?'上午':'下午');
  291. let list=period.filter(item=>{
  292. return item.ofTime==current;
  293. });
  294. this.setData({
  295. timeList:list
  296. });
  297. let isNoTime=list.every(item=>{
  298. return item.timeMsg&&item.timeMsg!=null;
  299. });
  300. if(isNoTime){
  301. this.setData({
  302. timeIndex:-1,
  303. selectTimeValue:''
  304. });
  305. }
  306. },
  307. timeCheck(e) {
  308. let index = e.currentTarget.dataset.index;
  309. // if (e.currentTarget.dataset.stock == 0) {
  310. // wx.showToast({
  311. // title: '所选时间无库存,请选择其他时间',
  312. // icon: 'none',
  313. // duration: 2000
  314. // });
  315. // return;
  316. // }
  317. let msg=e.currentTarget.dataset.msg;
  318. if (msg==null||msg=='') {
  319. let time= (this.data.timeList[index].begin).split(':')[0];
  320. this.setData({
  321. timeIndex: index,
  322. selectTimeValue: Number(time)
  323. });
  324. }
  325. },
  326. noonTab(e) {
  327. let noon = e.currentTarget.dataset.noon;
  328. this.setData({
  329. timeIndex: -1,
  330. noonType: noon,
  331. selectTimeValue:'',
  332. });
  333. let period=this.data.dateList[this.data.dateIndex].period;
  334. let current=(this.data.noonType==1?'上午':'下午');
  335. let list=period.filter(item=>{
  336. return item.ofTime==current;
  337. });
  338. this.setData({
  339. timeList:list
  340. });
  341. },
  342. confirmTime() {
  343. if (this.data.timeIndex === ''||this.data.timeIndex<0) {
  344. wx.showToast({
  345. title: '请选择服务时间',
  346. icon: 'none',
  347. duration: 2000
  348. });
  349. return false;
  350. }
  351. let date = this.data.dateList[this.data.dateIndex].bookdate;
  352. let week = this.data.dateList[this.data.dateIndex].weekOfDay;
  353. let time = this.data.timeList[this.data.timeIndex].begin+'-'+this.data.timeList[this.data.timeIndex].end;
  354. console.log(date, week, time);
  355. let params = {
  356. detail_id: this.data.serviceId,
  357. date: date,
  358. startTime: time.split('-')[0],
  359. endTime: time.split('-')[1],
  360. addressId: this.data.checkedAddress.addressId ? this.data.checkedAddress.addressId : 0
  361. };
  362. util.request(api.ServiceOrderBook, params, "GET")
  363. .then(res => {
  364. console.log(res);
  365. if (res.errno == 0) {
  366. wx.showToast({
  367. title: '预约成功',
  368. icon: 'none',
  369. duration: 2000
  370. });
  371. // this.setData({
  372. // // oneTimeAppoint:date+' '+week+' '+time,
  373. // choosePopup: false,
  374. // });
  375. // this.getServiceDetail();
  376. wx.navigateTo({
  377. url: '/pages/checkout/appointResult/appointResult?id=' + this.data.orderId,
  378. });
  379. } else {
  380. //util.showErrorToast(res.errmsg);
  381. wx.showToast({
  382. title: res.errmsg,
  383. icon: 'none',
  384. duration: 2000
  385. });
  386. }
  387. });
  388. },
  389. /**
  390. * 生命周期函数--监听页面初次渲染完成
  391. */
  392. onReady: function () {
  393. },
  394. /**
  395. * 生命周期函数--监听页面显示
  396. */
  397. onShow: function (options) {
  398. let that = this;
  399. var addressInfo = wx.getStorageSync('addressInfo');
  400. if (addressInfo === "") {
  401. addressInfo = {};
  402. }
  403. that.setData({
  404. checkedAddress: addressInfo
  405. })
  406. console.info(this.data.checkedAddress)
  407. if (this.data.orderId) {
  408. this.getServiceDetail();
  409. }
  410. },
  411. goReVisit(e) {
  412. let id = e.currentTarget.dataset.id;
  413. wx.navigateTo({
  414. url: '/pages/extra/newRevisit/newRevisit?id=' + id,
  415. success: (res) => {
  416. },
  417. fail: (res) => {
  418. },
  419. });
  420. },
  421. /**
  422. * 生命周期函数--监听页面隐藏
  423. */
  424. onHide: function () {
  425. },
  426. /**
  427. * 生命周期函数--监听页面卸载
  428. */
  429. onUnload: function () {
  430. },
  431. /**
  432. * 页面相关事件处理函数--监听用户下拉动作
  433. */
  434. onPullDownRefresh: function () {
  435. },
  436. /**
  437. * 页面上拉触底事件的处理函数
  438. */
  439. onReachBottom: function () {
  440. },
  441. /**
  442. * 用户点击右上角分享
  443. */
  444. onShareAppMessage: function () {
  445. }
  446. })