add_student_serve.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // pages/past_record/past_record.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber, formatDate,throttle } from '../../utils/util.js'
  3. import { HomeworkList, FindOwnServiceList, FindSaleServiceList, CalculateValidInterval, FindConflictServiceList, AddCorrectService, DelLibChild } from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app=getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. baseImgUrl,
  14. thumbnail,
  15. pageNo: 1,
  16. pageSize: 5,
  17. startTime: formatDate(new Date()),
  18. isAll: false,
  19. isLoaded:false,
  20. hiddenModel:false,
  21. dateIndex:0,
  22. number:1,
  23. conflictModel:false,
  24. childInfo: {
  25. // "childName": "zhsfsf",
  26. // "imgUrl": "",
  27. // "school": "华景小学",
  28. // "grade": "三年级",
  29. // "serviceBeginTime": "2019-09-03",
  30. // "serviceEndTime": "2019-09=12",
  31. // derver:'5421562',
  32. // derverType:0
  33. },
  34. list: [
  35. // {
  36. // "date": "2019-09-03",
  37. // "suggestion": "sfsfsfsf",
  38. // "homeworkpictures": [
  39. // { "fileKey": "/2019/09/03/1.png" },
  40. // ]
  41. // },
  42. // {
  43. // "date": "2019-09-03",
  44. // "suggestion": "sfsfsfsf",
  45. // "homeworkpictures": [
  46. // { "fileKey": "/2019/09/03/1.png" },
  47. // ]
  48. // },
  49. // {
  50. // "date": "2019-09-03",
  51. // "suggestion": "sfsfsfsf",
  52. // "homeworkpictures": [
  53. // { "fileKey": "/2019/09/03/1.png" },
  54. // ]
  55. // },
  56. ]
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. options.libId = wx.getStorageSync('libId')||options.libId;
  63. this.setData(options)
  64. console.log(options)
  65. this.getData()
  66. this.sureSaleServiceList()
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {
  72. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  73. for (const i in obj) {
  74. this[i] = obj[i]
  75. }
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. this.setData({ pageNo: 1 })
  97. this.getData(res => {
  98. wx.stopPullDownRefresh()
  99. })
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. const { isAll } = this.data
  106. if (isAll) {
  107. return
  108. }
  109. this.getData()
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. if (app.sharePageDefaultCtl) {
  116. return app.sharePageDefaultCtl()
  117. }
  118. },
  119. /**
  120. * 底部导航跳转
  121. */
  122. redirectCtl: app.redirectCtl,
  123. /**
  124. * 路由跳转
  125. */
  126. navigateCtl: app.navigateCtl,
  127. /**
  128. * 提示框隐藏
  129. */
  130. allShowModel: function () {
  131. this.setData({ hiddenModel: false, conflictModel:false})
  132. },
  133. /**
  134. * 提示框弹出
  135. */
  136. childShowModel:throttle( function () {
  137. this.setData({ hiddenModel: true })
  138. },1000),
  139. /**
  140. * 选择时间
  141. */
  142. bindDateChange: function (e) {
  143. console.log(e)
  144. const { value } = e.detail
  145. const beginDate = value.split("-").join(".")
  146. this.setData({ beginDate })
  147. this.sureValidInterval()
  148. },
  149. /**
  150. * 查询已拥有服务
  151. */
  152. sureOwnServiceList: function (cb) {
  153. const continuousFn = { fn: this.sureOwnServiceList, param: { ...arguments } }
  154. const { vipId } = this.data;
  155. FindOwnServiceList({ data: { vipId }, continuousFn }).then(res => {
  156. const { list}=res.data
  157. this.setData({ serveList: list})
  158. if (isFn(cb)) cb()
  159. }).catch(res => {
  160. if (isFn(cb)) cb()
  161. })
  162. },
  163. /**
  164. * 查询可购买服务信息
  165. */
  166. sureSaleServiceList: function (cb) {
  167. const continuousFn = { fn: this.sureSaleServiceList, param: { ...arguments } }
  168. const { libId, dateIndex, vipId } = this.data;
  169. FindSaleServiceList({ data: { libId, vipId}, continuousFn }).then(res => {
  170. const { list } = res.data
  171. const tempList = (res => {
  172. for (let i in res) {
  173. res[i]['number'] = 1
  174. }
  175. return res
  176. })(list || [])
  177. var temp = {};
  178. temp[`priceType`] = list[dateIndex].priceType;
  179. temp[`beginDate`] = list[dateIndex].beginDate;
  180. temp[`endDate`] = list[dateIndex].endDate;
  181. this.setData(temp);
  182. this.setData({ payList:list })
  183. if (isFn(cb)) cb()
  184. }).catch(res => {
  185. if (isFn(cb)) cb()
  186. })
  187. },
  188. // 选择卡类型
  189. selectCardType: function (e) {
  190. const { payList, priceType } = this.data;
  191. const { index, type, price } = e.currentTarget.dataset;
  192. this.setData({ priceType: type, dateIndex: index })
  193. var temp = {};
  194. for (var i in payList) {
  195. temp[`payList[${i}].status`] = ''
  196. }
  197. temp[`number`] = payList[index].number;
  198. temp[`beginDate`] = payList[index].beginDate;
  199. temp[`endDate`] = payList[index].endDate;
  200. temp[`payList[${index}].status`] = 'active';
  201. this.setData(temp);
  202. },
  203. // 加月卡数量
  204. plusNum:throttle( function () {
  205. const { payList, number, dateIndex } = this.data;
  206. var temp = {}
  207. let numbers = payList[dateIndex].number;
  208. if (numbers < 12) {
  209. numbers = numbers + 1;
  210. } else {
  211. numbers = numbers;
  212. }
  213. this.setData({ number: numbers })
  214. temp[`payList[${dateIndex}].number`] = numbers;
  215. this.setData(temp)
  216. this.sureValidInterval()
  217. },500),
  218. // 减月卡数量
  219. arrowNum:throttle( function () {
  220. const { payList, number, dateIndex } = this.data;
  221. var temp = {}
  222. let numbers = payList[dateIndex].number;
  223. if (numbers > 1) {
  224. numbers = numbers - 1;
  225. } else {
  226. numbers = 1
  227. }
  228. this.setData({ number: numbers })
  229. temp[`payList[${dateIndex}].number`] = numbers;
  230. this.setData(temp)
  231. this.sureValidInterval()
  232. },500),
  233. /**
  234. * 计算服务有效时间
  235. */
  236. sureValidInterval:throttle( function (cb) {
  237. const continuousFn = { fn: this.sureValidInterval, param: { ...arguments } }
  238. const { number, priceType, beginDate, payList, dateIndex, vipId } = this.data;
  239. CalculateValidInterval({ data: { num: number, priceType, beginDate, vipId }, continuousFn }).then(res => {
  240. const { beginDate, endDate } = res.data
  241. console.log(beginDate, endDate)
  242. var temp = {}
  243. temp[`payList[${dateIndex}].beginDate`] = beginDate;
  244. temp[`payList[${dateIndex}].endDate`] = endDate;
  245. this.setData(temp)
  246. this.setData({ beginDate, endDate })
  247. if (isFn(cb)) cb()
  248. }).catch(res => {
  249. if (isFn(cb)) cb()
  250. })
  251. },1000),
  252. /**
  253. * 查询有冲突的服务
  254. */
  255. sureServiceList: function (cb) {
  256. const continuousFn = { fn: this.sureServiceList, param: { ...arguments } }
  257. const { vipId, beginDate, endDate } = this.data;
  258. FindConflictServiceList({ data: { vipId, beginDate, endDate }, continuousFn }).then(res => {
  259. const { list } = res.data
  260. if (list.length > 0) {
  261. this.setData({ conflictModel: true, conflictList: list })
  262. } else {
  263. this.setData({ hiddenModel: false })
  264. this.sureAddCorrectService()
  265. }
  266. if (isFn(cb)) cb()
  267. }).catch(res => {
  268. if (isFn(cb)) cb()
  269. })
  270. },
  271. /**
  272. * 添加批改服务
  273. */
  274. sureAddCorrectService: function (cb) {
  275. const continuousFn = { fn: this.sureAddCorrectService, param: { ...arguments } }
  276. const { vipId, libId, number, priceType, beginDate, endDate } = this.data;
  277. console.log(vipId, libId, number, priceType, beginDate, endDate)
  278. AddCorrectService({ data: { vipId, libId, number, priceType, beginDate, endDate }, continuousFn }).then(res => {
  279. wx.showToast({
  280. title: '服务添加成功',
  281. icon: 'none',
  282. duration:1500
  283. })
  284. setTimeout(function(){
  285. wx.navigateBack({})
  286. },1500)
  287. if (isFn(cb)) cb()
  288. }).catch(res => {
  289. if (isFn(cb)) cb()
  290. })
  291. },
  292. /**
  293. * 从校区移除小孩
  294. */
  295. sureDelLibChild: function (cb) {
  296. const continuousFn = { fn: this.sureDelLibChild, param: { ...arguments } }
  297. const { vipId, libId } = this.data;
  298. DelLibChild({ data: { vipId, libId }, continuousFn }).then(res => {
  299. wx.showToast({
  300. title: '操作成功',
  301. icon: 'none'
  302. })
  303. this.allShowModel()
  304. wx.navigateBack({})
  305. if (isFn(cb)) cb()
  306. }).catch(res => {
  307. if (isFn(cb)) cb()
  308. })
  309. },
  310. /**
  311. * 获取数据
  312. */
  313. getData: function (cb) {
  314. const continuousFn = { fn: this.getData, param: { ...arguments } }
  315. const { vipId, pageNo, pageSize, list} = this.data
  316. // console.log(new Date())
  317. HomeworkList({ data: { vipId, pageNo, pageSize}, continuousFn }).then(res => {
  318. // const {list} = res.data;
  319. const { derver } = res.data;
  320. const listTemp = (res => {
  321. for (let i in res) {
  322. res[i].times = res[i].date.slice(0,10)
  323. }
  324. return res
  325. })(res.data.list)
  326. let arr = []
  327. if (pageNo == 1) {
  328. arr = [...listTemp]
  329. } else {
  330. arr = [...list, ...listTemp]
  331. }
  332. this.setData({
  333. derver,
  334. list: arr,
  335. pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
  336. isAll: listTemp.length < pageSize,
  337. isLoaded: true
  338. })
  339. if (isFn(cb)) cb()
  340. }).catch(res => {
  341. this.setData({ isLoaded: true })
  342. if (isFn(cb)) cb()
  343. })
  344. },
  345. })