add_batch_serve.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // pages/past_record/past_record.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber, formatDate } from '../../utils/util.js'
  3. import { RenewStudentList, FindSaleServiceList,AddBatchCorrectService} 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: 3,
  17. startTime: formatDate(new Date()),
  18. isAll: false,
  19. isLoaded:false,
  20. hiddenModel:false,
  21. dateIndex:0,
  22. number:1,
  23. conflictModel:false,
  24. exchangeNum:0,
  25. list: [
  26. ]
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. options.libId = wx.getStorageSync('libId')||options.libId;
  33. this.setData(options)
  34. if(options.selectStudentList){
  35. this.setData({list:JSON.parse(options.selectStudentList),vipIdList:JSON.parse(options.vipIdList)})
  36. }else if(options.classIdList){
  37. this.setData({classIdList:JSON.parse(options.classIdList)})
  38. this.getStudentData()
  39. }
  40. this.sureSaleServiceList()
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function () {
  46. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  47. for (const i in obj) {
  48. this[i] = obj[i]
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload: function () {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {
  70. },
  71. /**
  72. * 页面上拉触底事件的处理函数
  73. */
  74. onReachBottom: function () {
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. if (app.sharePageDefaultCtl) {
  81. return app.sharePageDefaultCtl()
  82. }
  83. },
  84. /**
  85. * 底部导航跳转
  86. */
  87. redirectCtl: app.redirectCtl,
  88. /**
  89. * 路由跳转
  90. */
  91. navigateCtl: app.navigateCtl,
  92. /**
  93. * 提示框隐藏
  94. */
  95. allShowModel: function () {
  96. this.setData({ hiddenModel: false, conflictModel:false})
  97. },
  98. /**
  99. * 提示框弹出
  100. */
  101. childShowModel: function () {
  102. this.setData({ hiddenModel: true })
  103. },
  104. /**
  105. * 获取学生续费数据
  106. */
  107. getStudentData: function (cb) {
  108. const continuousFn = { fn: this.getStudentData, param: { ...arguments } }
  109. const { pageNo, pageSize, libId,classIdList}=this.data;
  110. var that=this;
  111. RenewStudentList({ data: { libId,classIdList}, continuousFn }).then(res => {
  112. const {list}=res.data
  113. var vipIdList=[]
  114. for(var i in list){
  115. vipIdList.push(list[i].vipId)
  116. }
  117. this.setData({
  118. vipIdList,
  119. list,
  120. isLoaded: true
  121. })
  122. if (isFn(cb)) cb()
  123. }).catch(res => {
  124. this.setData({ isLoaded: true })
  125. if (isFn(cb)) cb()
  126. })
  127. },
  128. /**
  129. * 查询可购买服务信息
  130. */
  131. sureSaleServiceList: function (cb) {
  132. const continuousFn = { fn: this.sureSaleServiceList, param: { ...arguments } }
  133. const { libId, dateIndex, vipId } = this.data;
  134. FindSaleServiceList({ data: { libId}, continuousFn }).then(res => {
  135. const { list } = res.data
  136. const tempList = (res => {
  137. for (let i in res) {
  138. res[i]['number'] = 1
  139. }
  140. return res
  141. })(list || [])
  142. var temp = {};
  143. temp[`priceType`] = list[dateIndex].priceType;
  144. temp[`exchangeNum`] = list[dateIndex].exchangeNum;
  145. this.setData(temp);
  146. this.setData({ payList:list,isLoaded: true })
  147. if (isFn(cb)) cb()
  148. }).catch(res => {
  149. this.setData({ isLoaded: true })
  150. if (isFn(cb)) cb()
  151. })
  152. },
  153. // 选择卡类型
  154. selectCardType: function (e) {
  155. const { payList, priceType } = this.data;
  156. const { index, type, price } = e.currentTarget.dataset;
  157. this.setData({ priceType: type, dateIndex: index })
  158. var temp = {};
  159. for (var i in payList) {
  160. temp[`payList[${i}].status`] = ''
  161. }
  162. temp[`number`] = payList[index].number;
  163. temp[`priceType`] = payList[index].priceType;
  164. temp[`exchangeNum`] = payList[index].exchangeNum;
  165. temp[`payList[${index}].status`] = 'active';
  166. this.setData(temp);
  167. },
  168. // 加月卡数量
  169. plusNum: function () {
  170. const { payList, dateIndex,list,exchangeNum} = this.data;
  171. if(list.length==0){
  172. wx.showToast({
  173. title: '此班级无学生',
  174. icon: 'none',
  175. duration:1000
  176. })
  177. return
  178. }
  179. var temp = {}
  180. let numbers = payList[dateIndex].number;
  181. if (numbers < 12) {
  182. numbers = numbers + 1;
  183. } else {
  184. numbers = numbers;
  185. }
  186. this.setData({ number: numbers })
  187. if((list.length*numbers)>exchangeNum){
  188. wx.showToast({
  189. title: '抱歉,你的塾币不足',
  190. icon: 'none',
  191. duration:1000
  192. })
  193. return
  194. }
  195. temp[`payList[${dateIndex}].number`] = numbers;
  196. this.setData(temp)
  197. },
  198. // 减月卡数量
  199. arrowNum: function () {
  200. const { payList, dateIndex,list,exchangeNum} = this.data;
  201. console.log(exchangeNum)
  202. var temp = {}
  203. let numbers = payList[dateIndex].number;
  204. if (numbers > 1) {
  205. numbers = numbers - 1;
  206. } else {
  207. numbers = 1
  208. }
  209. this.setData({ number: numbers })
  210. temp[`payList[${dateIndex}].number`] = numbers;
  211. this.setData(temp)
  212. },
  213. /**
  214. * 添加批改服务
  215. */
  216. sureAddCorrectService: function (cb) {
  217. const continuousFn = { fn: this.sureAddCorrectService, param: { ...arguments } }
  218. const {vipIdList,libId, number, priceType,list,exchangeNum} = this.data;
  219. if(list.length==0){
  220. wx.showToast({
  221. title: '此班级无学生',
  222. icon: 'none',
  223. duration:1000
  224. })
  225. return
  226. }
  227. if((list.length*number)>exchangeNum){
  228. wx.showToast({
  229. title: '抱歉,你的塾币不足',
  230. icon: 'none',
  231. duration:1000
  232. })
  233. return
  234. }
  235. AddBatchCorrectService({ data: {libId, number, priceType,vipIdList}, continuousFn }).then(res => {
  236. wx.showToast({
  237. title: '服务添加成功',
  238. icon: 'none',
  239. duration:1000
  240. })
  241. setTimeout(function(){
  242. wx.navigateBack({})
  243. },1000)
  244. if (isFn(cb)) cb()
  245. }).catch(res => {
  246. if (isFn(cb)) cb()
  247. })
  248. }
  249. })