serviceDetail.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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), 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: unusedSerList,
  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() - 24 * 60 * 60 * 1000;
  131. console.log(isNear);
  132. if (isNear < 0) {
  133. wx.showToast({
  134. title: '服务时间小于24小时,不能修改预约',
  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. }
  158. wx.showLoading({
  159. title: '加载中',
  160. });
  161. util.request(api.EveryDayStock, params, "GET")
  162. .then(res => {
  163. wx.hideLoading();
  164. if (res.errno == 0) {
  165. this.setData({
  166. timeList: res.data,
  167. timeIndex: 0
  168. });
  169. // let validList = this.data.timeList.filter(item => {
  170. // return item.stock > 0
  171. // });
  172. // if (validList.length > 0) {
  173. // this.setData({
  174. // timeIndex: validList[0].id - 1
  175. // });
  176. // } else {
  177. // this.setData({
  178. // timeIndex: ''
  179. // });
  180. // }
  181. } else {
  182. wx.showToast({
  183. title: res.errmsg,
  184. icon: 'none',
  185. duration: 2000
  186. });
  187. this.setData({
  188. timeList: [],
  189. timeIndex: ''
  190. });
  191. }
  192. }).catch(function (err) {
  193. console.log(err);
  194. wx.hideLoading();
  195. wx.showToast({
  196. title: err.errMsg,
  197. icon: 'none'
  198. });
  199. this.setData({
  200. timeList: [],
  201. timeIndex: ''
  202. });
  203. });
  204. },
  205. onClose() {
  206. this.setData({
  207. choosePopup: false
  208. });
  209. },
  210. dateCheck(e) {
  211. let index = e.currentTarget.dataset.index;
  212. let date = e.currentTarget.dataset.date;
  213. let week = e.currentTarget.dataset.week;
  214. let isbook = e.currentTarget.dataset.isbook;
  215. // if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) {
  216. // this.setData({
  217. // dateIndex: index
  218. // });
  219. // }
  220. if (isbook) {
  221. this.setData({
  222. dateIndex: index
  223. });
  224. // this.getDayStock();
  225. }
  226. },
  227. timeCheck(e) {
  228. let index = e.currentTarget.dataset.index;
  229. // if (e.currentTarget.dataset.stock == 0) {
  230. // wx.showToast({
  231. // title: '所选时间无库存,请选择其他时间',
  232. // icon: 'none',
  233. // duration: 2000
  234. // });
  235. // return;
  236. // }
  237. this.setData({
  238. timeIndex: index
  239. });
  240. },
  241. confirmTime() {
  242. if (this.data.timeIndex === '') {
  243. wx.showToast({
  244. title: '请选择服务时间',
  245. icon: 'none',
  246. duration: 2000
  247. });
  248. return false;
  249. }
  250. let date = this.data.dateList[this.data.dateIndex].date;
  251. let week = this.data.dateList[this.data.dateIndex].week;
  252. let time = this.data.timeList[this.data.timeIndex].time;
  253. console.log(date, week, time);
  254. let params = {
  255. detail_id: this.data.serviceId,
  256. date: date,
  257. startTime: time.split('-')[0],
  258. endTime: time.split('-')[1],
  259. addressId: this.data.checkedAddress.addressId ? this.data.checkedAddress.addressId : 0
  260. };
  261. util.request(api.ServiceOrderBook, params, "GET")
  262. .then(res => {
  263. console.log(res);
  264. if (res.errno == 0) {
  265. wx.showToast({
  266. title: '预约成功',
  267. icon: 'none',
  268. duration: 2000
  269. });
  270. this.setData({
  271. // oneTimeAppoint:date+' '+week+' '+time,
  272. choosePopup: false,
  273. });
  274. this.getServiceDetail();
  275. } else {
  276. util.showErrorToast(res.errmsg);
  277. }
  278. });
  279. },
  280. /**
  281. * 生命周期函数--监听页面初次渲染完成
  282. */
  283. onReady: function () {
  284. },
  285. /**
  286. * 生命周期函数--监听页面显示
  287. */
  288. onShow: function (options) {
  289. let that = this;
  290. var addressInfo = wx.getStorageSync('addressInfo');
  291. if (addressInfo === "") {
  292. addressInfo = {};
  293. }
  294. that.setData({
  295. checkedAddress: addressInfo
  296. })
  297. console.info(this.data.checkedAddress)
  298. },
  299. /**
  300. * 生命周期函数--监听页面隐藏
  301. */
  302. onHide: function () {
  303. },
  304. /**
  305. * 生命周期函数--监听页面卸载
  306. */
  307. onUnload: function () {
  308. },
  309. /**
  310. * 页面相关事件处理函数--监听用户下拉动作
  311. */
  312. onPullDownRefresh: function () {
  313. },
  314. /**
  315. * 页面上拉触底事件的处理函数
  316. */
  317. onReachBottom: function () {
  318. },
  319. /**
  320. * 用户点击右上角分享
  321. */
  322. onShareAppMessage: function () {
  323. }
  324. })