serviceDetail.js 8.1 KB

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