studyHouse.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. // pages/studyHouse/studyHouse.js
  2. const app = getApp();
  3. const { formatDate, formatTime2 } = require('../../utils/util.js')
  4. Page({
  5. /**
  6. * 页面的初始数据school, vipId, isAddChild, type, childName, parentName, grade
  7. */
  8. data: {
  9. pageSize: 10,
  10. pageNo: 1,
  11. maxCreateTime: formatTime2(new Date()),
  12. hiddenModel: false,
  13. value:'',
  14. isWechat:0,
  15. imgUrl:'',
  16. childName:'',
  17. sex:0,
  18. parentName:'',
  19. phone:'',
  20. grade:'',
  21. school:'',
  22. derver:'',
  23. type:1,
  24. parentRole:'',
  25. schoolModel:false,
  26. schoolIdx:0,
  27. libIdx:0,
  28. schoolList:[],
  29. // list: [
  30. // {
  31. // "id": "425ac67f-d0a5-49dc-bd8a-90768fbbd75f",
  32. // "distance": 0.87,
  33. // "leagueName": "私塾家深圳测试馆2",
  34. // "leagueAddress": "深圳市南山智园b1座4楼"
  35. // }
  36. // ],
  37. libData: {
  38. list: []
  39. },
  40. location: {},
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. console.log(options)
  47. wx.setStorageSync('schoolName', options.schoolName)
  48. this.setData(options);
  49. this.getLocation();
  50. // this.getLibrary();
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. this.setData({ pageNo: 1 })
  77. wx.stopPullDownRefresh()
  78. this.getLibrary(res => {
  79. })
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {
  85. const { isAll } = this.data
  86. if (isAll) {
  87. return
  88. }
  89. this.getLibrary()
  90. },
  91. /**
  92. * 用户点击右上角分享
  93. */
  94. onShareAppMessage: function () {
  95. },
  96. /**
  97. * 跳转
  98. */
  99. navigateCtl: app.navigateCtl,
  100. /**
  101. * 底部导航跳转
  102. */
  103. redirectCtl: app.redirectCtl,
  104. /**
  105. * 查询作业吧服务时间
  106. */
  107. chatHomeworkTime: function (id) {
  108. const { vipId } = this.data;
  109. const postData = { fn: this.chatHomeworkTime, param: { ...arguments } }
  110. app.post('/api/parents/parents/V2/service/findZybServiceList', { vipId, libId:id }, 0, postData).then(res => {
  111. const { list } = res.data;
  112. if (list.length==0){
  113. this.setData({ hiddenModel: true,isList:false })
  114. }else{
  115. this.setData({ serviceList: list, hiddenModel: true, isList: true });
  116. }
  117. })
  118. },
  119. /**
  120. * 输入馆名
  121. */
  122. inputCtl: function (e) {
  123. const { value } = e.detail
  124. this.setData({value})
  125. this.setData({ pageNo: 1 })
  126. this.getLibrary()
  127. },
  128. /**
  129. * 获取定位经纬度
  130. */
  131. getLocation: function () {
  132. app.getWxUserLocationSetting(res => {
  133. wx.showLoading({
  134. title: '定位中'
  135. })
  136. wx.getLocation({
  137. type: 'wgs84',
  138. success: res => {
  139. this.setData({
  140. location: {
  141. longitude: res.longitude, // '113.36403' ||
  142. latitude: res.latitude // '23.14203' ||
  143. }
  144. })
  145. setTimeout(() => {
  146. this.getLibrary()
  147. }, 0)
  148. },
  149. fail: res => {
  150. setTimeout(() => {
  151. wx.showToast({
  152. title: '定位失败',
  153. icon: 'none'
  154. })
  155. }, 10)
  156. setTimeout(() => {
  157. wx.navigateBack({
  158. delta: 1
  159. })
  160. }, 1000)
  161. },
  162. complete: res => {
  163. wx.hideLoading()
  164. }
  165. })
  166. })
  167. },
  168. /**
  169. * 获取图书馆定位数据
  170. */
  171. getLibrary: function () {
  172. const postData = { fn: this.getLibrary, param: { ...arguments } }
  173. let { pageNo, pageSize, value, location, maxCreateTime,list=[],vipId} = this.data
  174. const schoolName=wx.getStorageSync('schoolName')||''
  175. app.post('/api/parents/parents/V2/getLibListV1', {
  176. vipId,
  177. value,
  178. latitude: location.latitude,
  179. longitude: location.longitude,
  180. maxCreateTime,
  181. pageSize,
  182. pageNo,
  183. schoolName
  184. }, 0, postData).then(res => {
  185. const { id, leagueName, leagueAddress, schoolList, leagueAuditStatus, leagueNameAudit,schoolName}=res.data;
  186. if (pageNo == 1) {
  187. list = res.data.list
  188. } else {
  189. list = list.concat(res.data.list)
  190. }
  191. // if (pageNo == 1) {
  192. // this.setData({
  193. // libName: list[0].leagueName,
  194. // libId: list[0].id
  195. // })
  196. // }
  197. this.setData({
  198. id, leagueName, leagueAddress, leagueAuditStatus, leagueNameAudit,schoolName,
  199. list,
  200. schoolList,
  201. pageNo:list.length==pageSize * pageNo ? pageNo + 1 : pageNo,
  202. isAll: list.length < pageSize
  203. })
  204. })
  205. },
  206. /**
  207. * 解绑
  208. */
  209. unbind:function(e){
  210. const { unbindLeagueName, libId, isCut,index} = e.currentTarget.dataset.method
  211. const {list}=this.data
  212. if (isCut==1){
  213. this.setData({isCut})
  214. this.chatHomeworkTime(libId)
  215. }else{
  216. if (list[index].schoolList.length>0){
  217. this.setData({ schoolList: list[index].schoolList})
  218. }
  219. this.setData({ hiddenModel: true, unbindLeagueName, libId, isCut, libIdx: index})
  220. }
  221. },
  222. /**
  223. * 提示框隐藏
  224. */
  225. allShowModel: function () {
  226. this.setData({ hiddenModel: false, schoolModel:false })
  227. },
  228. /**
  229. *打开选择学校
  230. */
  231. selectShowModel: function () {
  232. this.setData({schoolModel: true })
  233. },
  234. /**
  235. * 选择学校
  236. */
  237. selectSchool:function(e){
  238. const { idx } = e.currentTarget.dataset
  239. const { list, libIdx, schoolList}=this.data
  240. this.setData({ schoolIdx: idx, school:schoolList[idx].schoolName})
  241. },
  242. /**
  243. * 解绑成功
  244. */
  245. unbindCtl:function(){
  246. const postData = { fn: this.unbindCtl, param: { ...arguments } };
  247. const { vipId, id, schoolList}=this.data;
  248. app.post('/api/parents/parents/V2/unbindVipLibV1', { vipId, libId:id}, 0, postData).then(res => {
  249. wx.showToast({
  250. title: '解绑成功',
  251. icon: 'none',
  252. duration: 1000
  253. });
  254. this.setData({ hiddenModel: false })
  255. this.getLibrary();
  256. })
  257. },
  258. /**
  259. * 重新选择
  260. */
  261. againChoose: function () {
  262. const postData = { fn: this.againChoose, param: { ...arguments } };
  263. const { vipId} = this.data;
  264. app.post('/api/parents/parents/V2/againChooseLib', { vipId}, 0, postData).then(res => {
  265. wx.showToast({
  266. title: '重新选择成功',
  267. icon: 'none',
  268. duration: 1000
  269. });
  270. this.setData({ hiddenModel: false })
  271. this.getLibrary();
  272. })
  273. },
  274. /**
  275. * 换学校
  276. */
  277. changeSchool: function () {
  278. const postData = { fn: this.unbindCtl, param: { ...arguments } };
  279. const { vipId, school, isCut, libId, isAddChild, type, childName, parentName, grade,unbindLeagueName, derver, sex, parentRole,schoolList } = this.data;
  280. if (isAddChild==1){
  281. this.redirectCtl({ url: 'kids_information', method: { isAddChild, school, vipId, type, childName, parentName, grade, libId, leagueName: unbindLeagueName, isMain: 1, derver, sex, parentRole, school, schoolList } }, true)
  282. }else{
  283. if (isCut == 2) {
  284. app.post('/api/parents/parents/V2/bindVipLibV2', { vipId, schoolName: school, libId }, 0, postData).then(res => {
  285. wx.showToast({
  286. title: '绑定成功',
  287. icon: 'none',
  288. duration: 1000
  289. });
  290. this.getLibrary();
  291. this.setData({ schoolModel: false })
  292. })
  293. } else {
  294. app.post('/api/parents/parents/V2/upMyChildInfo', { vipId, school }, 0, postData).then(res => {
  295. wx.showToast({
  296. title: '更换成功',
  297. icon: 'none',
  298. duration: 1000
  299. });
  300. this.setData({ schoolModel: false })
  301. })
  302. }
  303. }
  304. },
  305. /**
  306. * 绑定成功
  307. */
  308. bindVipLib:function(){
  309. const postData = { fn: this.bindVipLib, param: { ...arguments } };
  310. var that=this;
  311. const { vipId, libId, isAddChild, obj, isAddOrgam, unbindLeagueName, isWechat, isWechatschool, type, childName, parentName, grade, derver, school, sex, parentRole, schoolList} = this.data;
  312. if (schoolList.length==0){
  313. if (isAddOrgam==1){
  314. var that = this;
  315. if (isWechat==1){
  316. that.redirectCtl({ url: 'wechat_addchild', method: { isAddChild, school, vipId, type, childName, parentName, grade, libId, leagueName: unbindLeagueName, isMain: 1, derver, sex, parentRole, school, schoolList} }, true)
  317. }else{
  318. if (isAddChild==0){
  319. app.post('/api/parents/parents/V2/bindVipLibV2', { vipId, libId }, 0, postData).then(res => {
  320. wx.showToast({
  321. title: '绑定成功',
  322. icon: 'none',
  323. duration: 1000
  324. });
  325. this.setData({ hiddenModel: false })
  326. this.getLibrary();
  327. // that.redirectCtl({ url: 'kids_information', method: { isAddChild, school, vipId, type, childName, parentName, grade, libId, leagueName: unbindLeagueName, isMain: 1, derver, sex, parentRole, school } }, true)
  328. })
  329. }else{
  330. that.redirectCtl({ url: 'kids_information', method: { isAddChild, school, vipId, type, childName, parentName, grade, libId, leagueName: unbindLeagueName, isMain: 1, derver, sex, parentRole, school, schoolList} }, true)
  331. }
  332. }
  333. }else{
  334. app.post('/api/parents/parents/V2/bindVipLibV2', { vipId, libId }, 0, postData).then(res => {
  335. wx.showToast({
  336. title: '绑定成功',
  337. icon: 'none',
  338. duration: 1000
  339. });
  340. })
  341. this.setData({ hiddenModel: false })
  342. this.getLibrary();
  343. }
  344. }else{
  345. this.setData({ schoolModel: true, hiddenModel: false })
  346. }
  347. }
  348. })