serviceDetail.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. timeIndex: '', //选中的时间段
  30. dateIndex: 0, //
  31. checkedAddress: {
  32. addressId: 0
  33. }, //选中的地址信息
  34. isHaveAddress: false
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. this.setData({
  41. orderId: options.orderId
  42. });
  43. // this.getServiceDetail();
  44. },
  45. getServiceDetail: function () {
  46. // wx.showLoading({
  47. // title: '加载中',
  48. // });
  49. // setTimeout(function() {
  50. // wx.hideLoading();
  51. // }, 2000);
  52. util.request(api.ServiceDetail, {
  53. order_id: this.data.orderId
  54. // order_id: '1342922'
  55. }).then(res => {
  56. // wx.hideLoading();
  57. if (res.errno === 0) {
  58. let jzOrderBookDetails = res.data.jzOrderBookDetails;
  59. let unusedSerList = jzOrderBookDetails.filter(item => {
  60. return item.status === 0 || item.status == 1|| item.status == 7
  61. });
  62. let usedSerList = jzOrderBookDetails.filter(item => {
  63. return item.status == 3 || item.status == 4
  64. });
  65. // let timeList = check.getTimeList(res.data.goods.serviceDuration);
  66. this.setData({
  67. aftersaleStatus: res.data.order.aftersaleStatus,
  68. goods: res.data.goods,
  69. noAppoint: res.data.noAppoint,
  70. orderBook: res.data.orderBook,
  71. jzOrderBookDetails: jzOrderBookDetails,
  72. // activeTab: 1,
  73. unusedSerList: unusedSerList,
  74. usedSerList: usedSerList,
  75. serList: (this.data.activeTab==1?unusedSerList:usedSerList),
  76. // timeList: timeList,
  77. orderChannel: res.data.orderChannel,
  78. isHaveAddress: res.data.order.addressId != null && res.data.order.addressId > 0 && res.data.order.address ? true : false
  79. });
  80. if (res.data.order.addressId) {
  81. console.info("set address")
  82. this.setData({
  83. checkedAddress: {
  84. addressId: res.data.order.addressId,
  85. address: res.data.order.address,
  86. tel: res.data.order.mobile,
  87. name: res.data.order.consignee
  88. }
  89. })
  90. console.info(this.data.checkedAddress)
  91. }
  92. }
  93. });
  94. },
  95. selectAddress() {
  96. wx.navigateTo({
  97. url: '/pages/ucenter/address/address',
  98. })
  99. },
  100. onTabChange(e) {
  101. this.setData({
  102. activeTab: e.detail.name,
  103. });
  104. if (this.data.activeTab == 1) {
  105. this.setData({
  106. serList: this.data.unusedSerList
  107. });
  108. } else {
  109. this.setData({
  110. serList: this.data.usedSerList
  111. })
  112. }
  113. },
  114. showAppoint(e) {
  115. //是否有地址 如果没有地址 必须先选择地址
  116. console.info(this.data.checkedAddress)
  117. if (this.data.checkedAddress.address == null ||
  118. this.data.checkedAddress.address == '') {
  119. wx.showToast({
  120. title: '请先选择服务地址',
  121. icon: 'none',
  122. duration: 2000
  123. });
  124. return false;
  125. }
  126. let status = e.currentTarget.dataset.status;
  127. if (status == 1) {
  128. let time = e.currentTarget.dataset.time;
  129. let str = time.substr(0, 16).replace(/-/g, '/');
  130. let isNear = (new Date(str)).getTime() - (new Date()).getTime() - 2 * 60 * 60 * 1000;
  131. console.log(isNear);
  132. if (isNear < 0) {
  133. wx.showToast({
  134. title: '服务时间小于2小时,不能修改预约',
  135. icon: 'none',
  136. duration: 2000
  137. });
  138. return false;
  139. }
  140. }
  141. this.setData({
  142. choosePopup: true,
  143. serviceId: e.currentTarget.dataset.id
  144. });
  145. this.getDayStock();
  146. },
  147. getDayStock() {
  148. if (this.data.dateIndex < 0) {
  149. return false;
  150. }
  151. let params = {
  152. day: this.data.dateList[this.data.dateIndex].date,
  153. goodsId: this.data.orderBook.goodsId,
  154. lng: this.data.orderBook.lng,
  155. lat: this.data.orderBook.lat,
  156. addressId: this.data.checkedAddress.addressId,
  157. productId:this.data.orderBook.productId,
  158. serviceDuration:this.data.orderBook.serviceDuration
  159. }
  160. wx.showLoading({
  161. title: '加载中',
  162. });
  163. util.request(api.EveryDayStock, params, "GET")
  164. .then(res => {
  165. wx.hideLoading();
  166. if (res.errno == 0) {
  167. this.setData({
  168. timeList: res.data,
  169. timeIndex: 0
  170. });
  171. // let validList = this.data.timeList.filter(item => {
  172. // return item.stock > 0
  173. // });
  174. // if (validList.length > 0) {
  175. // this.setData({
  176. // timeIndex: validList[0].id - 1
  177. // });
  178. // } else {
  179. // this.setData({
  180. // timeIndex: ''
  181. // });
  182. // }
  183. } else {
  184. wx.showToast({
  185. title: res.errmsg,
  186. icon: 'none',
  187. duration: 2000
  188. });
  189. this.setData({
  190. timeList: [],
  191. timeIndex: ''
  192. });
  193. }
  194. }).catch(function (err) {
  195. console.log(err);
  196. wx.hideLoading();
  197. wx.showToast({
  198. title: err.errMsg,
  199. icon: 'none'
  200. });
  201. this.setData({
  202. timeList: [],
  203. timeIndex: ''
  204. });
  205. });
  206. },
  207. onClose() {
  208. this.setData({
  209. choosePopup: false
  210. });
  211. },
  212. dateCheck(e) {
  213. let index = e.currentTarget.dataset.index;
  214. let date = e.currentTarget.dataset.date;
  215. let week = e.currentTarget.dataset.week;
  216. let isbook = e.currentTarget.dataset.isbook;
  217. // if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) {
  218. // this.setData({
  219. // dateIndex: index
  220. // });
  221. // }
  222. if (isbook) {
  223. this.setData({
  224. dateIndex: index
  225. });
  226. this.getDayStock();
  227. }
  228. },
  229. timeCheck(e) {
  230. let index = e.currentTarget.dataset.index;
  231. // if (e.currentTarget.dataset.stock == 0) {
  232. // wx.showToast({
  233. // title: '所选时间无库存,请选择其他时间',
  234. // icon: 'none',
  235. // duration: 2000
  236. // });
  237. // return;
  238. // }
  239. this.setData({
  240. timeIndex: index
  241. });
  242. },
  243. confirmTime() {
  244. if (this.data.timeIndex === '') {
  245. wx.showToast({
  246. title: '请选择服务时间',
  247. icon: 'none',
  248. duration: 2000
  249. });
  250. return false;
  251. }
  252. let date = this.data.dateList[this.data.dateIndex].date;
  253. let week = this.data.dateList[this.data.dateIndex].week;
  254. let time = this.data.timeList[this.data.timeIndex].time;
  255. console.log(date, week, time);
  256. let params = {
  257. detail_id: this.data.serviceId,
  258. date: date,
  259. startTime: time.split('-')[0],
  260. endTime: time.split('-')[1],
  261. addressId: this.data.checkedAddress.addressId ? this.data.checkedAddress.addressId : 0
  262. };
  263. util.request(api.ServiceOrderBook, params, "GET")
  264. .then(res => {
  265. console.log(res);
  266. if (res.errno == 0) {
  267. wx.showToast({
  268. title: '预约成功',
  269. icon: 'none',
  270. duration: 2000
  271. });
  272. // this.setData({
  273. // // oneTimeAppoint:date+' '+week+' '+time,
  274. // choosePopup: false,
  275. // });
  276. // this.getServiceDetail();
  277. wx.navigateTo({
  278. url: '/pages/checkout/appointResult/appointResult?id='+this.data.orderId,
  279. });
  280. } else {
  281. util.showErrorToast(res.errmsg);
  282. }
  283. });
  284. },
  285. /**
  286. * 生命周期函数--监听页面初次渲染完成
  287. */
  288. onReady: function () {
  289. },
  290. /**
  291. * 生命周期函数--监听页面显示
  292. */
  293. onShow: function (options) {
  294. let that = this;
  295. var addressInfo = wx.getStorageSync('addressInfo');
  296. if (addressInfo === "") {
  297. addressInfo = {};
  298. }
  299. that.setData({
  300. checkedAddress: addressInfo
  301. })
  302. console.info(this.data.checkedAddress)
  303. if(this.data.orderId){
  304. this.getServiceDetail();
  305. }
  306. },
  307. goReVisit(e){
  308. let id=e.currentTarget.dataset.id;
  309. wx.navigateTo({
  310. url:'/pages/extra/newRevisit/newRevisit?id='+id,
  311. success: (res) => {
  312. },
  313. fail: (res) => {
  314. },
  315. });
  316. },
  317. /**
  318. * 生命周期函数--监听页面隐藏
  319. */
  320. onHide: function () {
  321. },
  322. /**
  323. * 生命周期函数--监听页面卸载
  324. */
  325. onUnload: function () {
  326. },
  327. /**
  328. * 页面相关事件处理函数--监听用户下拉动作
  329. */
  330. onPullDownRefresh: function () {
  331. },
  332. /**
  333. * 页面上拉触底事件的处理函数
  334. */
  335. onReachBottom: function () {
  336. },
  337. /**
  338. * 用户点击右上角分享
  339. */
  340. onShareAppMessage: function () {
  341. }
  342. })