index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. const app = getApp();
  2. var WxParse = require('../../wxParse/wxParse.js');
  3. Page({
  4. data: {
  5. arr: [],
  6. arrIndex: 0,
  7. tabSwiper: [],
  8. content: [],
  9. show: false,
  10. num: 1,
  11. info: '',
  12. yuName: '',
  13. color: '#ccc',
  14. jiaColor: 'blue',
  15. maxnum: '',
  16. coupon_id:'',
  17. coupon:''
  18. },
  19. onLoad: function () {
  20. },
  21. tabbar: function (e) {
  22. this.setData({
  23. arrIndex: e.currentTarget.dataset.index,
  24. num: 1,
  25. color: '#ccc',
  26. jiaColor: 'blue',
  27. })
  28. },
  29. swiper: function (e) {
  30. console.log(e)
  31. this.setData({
  32. arrIndex: e.detail.current
  33. })
  34. },
  35. onShow:function(){
  36. var that = this;
  37. wx.request({
  38. url: 'https://yutang.web.ximengnaikang.com/api/company',
  39. method: 'GET',
  40. header:{
  41. 'Authorization':wx.getStorageSync('token')
  42. },
  43. success: function (res) {
  44. console.log(res)
  45. var article = res.data.data.company.body;
  46. WxParse.wxParse('article', 'html', article, that, 5);
  47. that.setData({
  48. arr: res.data.data.company.tabs,
  49. tabSwiper: res.data.data.seats,
  50. content: res.data.data.company
  51. })
  52. wx.setStorageSync('items', res.data.data.seats)
  53. }
  54. })
  55. wx.request({
  56. url: 'https://yutang.web.ximengnaikang.com/api/user/coupons',
  57. method: 'GET',
  58. header: {
  59. 'content-type': 'application/x-www-form-urlencoded',
  60. 'Authorization':wx.getStorageSync('token')
  61. },
  62. success: function (res) {
  63. console.log(res.data.data.length)
  64. if (res.statusCode == 200 && res.data.data.length>=1) {
  65. that.setData({coupon:res.data.data[0],coupon_id:res.data.data[0].id})
  66. }
  67. }
  68. })
  69. },
  70. yuyue: function (e) {
  71. console.log(e)
  72. var item = e.currentTarget.dataset.item;
  73. var yuName = e.currentTarget.dataset.yuname;
  74. var maxnum = e.currentTarget.dataset.num;
  75. var userInfo = wx.getStorageSync('userInfo');
  76. console.log(userInfo)
  77. if (userInfo == undefined || userInfo == '' || userInfo.nickname==null) {
  78. wx.showModal({
  79. title: '用户授权',
  80. content: '此功能需要获取您的昵称等公开信息,请到小程序的设置中打开用户权限!',
  81. cancelText: '下次再说',
  82. confirmText: '去授权',
  83. success: function (res) {
  84. if (res.confirm) {
  85. wx.navigateTo({
  86. url: '../login/login',
  87. })
  88. }
  89. }
  90. })
  91. return;
  92. }else if(userInfo.mobile==null){
  93. wx.showModal({
  94. title: '手机号授权',
  95. content: '此功能需要获取您的手机号,请到小程序的设置中打开用户权限!',
  96. cancelText: '下次再说',
  97. confirmText: '去授权',
  98. success: function (res) {
  99. if (res.confirm) {
  100. wx.navigateTo({
  101. url: '../login/login?mobile=true',
  102. })
  103. }
  104. }
  105. })
  106. return;
  107. } else {
  108. console.log(yuName)
  109. this.setData({
  110. show: true,
  111. info: item,
  112. yuName,
  113. maxnum
  114. })
  115. }
  116. },
  117. quxiao: function () {
  118. this.setData({
  119. show: false,
  120. num: 1,
  121. color: '#ccc',
  122. jiaColor: 'blue',
  123. })
  124. },
  125. queren: function () {
  126. var that = this;
  127. var data = {
  128. 'number': this.data.num,
  129. 'day': this.data.info.date,
  130. 'seat_id': this.data.info.site_id,
  131. 'coupon_id':this.data.coupon_id
  132. }
  133. wx.request({
  134. url: 'https://yutang.web.ximengnaikang.com/api/storeOrder',
  135. method: 'POST',
  136. data: data,
  137. header: {
  138. 'content-type': 'application/x-www-form-urlencoded',
  139. 'Authorization': wx.getStorageSync('token')
  140. },
  141. success: function (res) {
  142. console.log(res)
  143. if (res.statusCode == 200) {
  144. that.setData({
  145. show: false,
  146. num: 1,
  147. color: '#ccc',
  148. jiaColor: 'blue',
  149. })
  150. wx.requestPayment({ //调用微信支付
  151. timeStamp: res.data.data.timeStamp.toString(),
  152. nonceStr: res.data.data.nonceStr,
  153. package: res.data.data.package,
  154. signType: res.data.data.signType,
  155. paySign: res.data.data.paySign,
  156. success(resp) {
  157. console.log(resp)
  158. wx.showToast({
  159. title: '预约成功',
  160. icon: 'none'
  161. })
  162. wx.request({
  163. url: 'https://yutang.web.ximengnaikang.com/api/company',
  164. method: 'GET',
  165. header:{
  166. 'Authorization':wx.getStorageSync('token')
  167. },
  168. success: function (res) {
  169. console.log(res)
  170. that.setData({
  171. tabSwiper: res.data.data.seats,
  172. })
  173. }
  174. })
  175. },
  176. fail(err) {
  177. console.log(err)
  178. wx.showToast({
  179. title: '支付失败',
  180. icon: 'none'
  181. })
  182. }
  183. })
  184. }
  185. }
  186. })
  187. },
  188. jian: function () {
  189. this.setData({
  190. num: this.data.num - 1
  191. })
  192. if (this.data.num <= 1) {
  193. this.setData({
  194. color: '#ccc',
  195. num: 1
  196. })
  197. return;
  198. } else {
  199. this.setData({
  200. color: 'blue',
  201. jiaColor: 'blue'
  202. })
  203. }
  204. },
  205. jia: function () {
  206. this.setData({
  207. num: this.data.num + 1
  208. })
  209. if (this.data.num == this.data.maxnum) {
  210. this.setData({
  211. jiaColor: '#ccc',
  212. num: this.data.maxnum
  213. })
  214. return;
  215. } else {
  216. this.setData({
  217. jiaColor: 'blue',
  218. color: 'blue'
  219. })
  220. }
  221. },
  222. onPullDownRefresh: function () {
  223. wx.showNavigationBarLoading();
  224. var that = this;
  225. wx.request({
  226. url: 'https://yutang.web.ximengnaikang.com/api/user/coupons',
  227. method: 'GET',
  228. header: {
  229. 'content-type': 'application/x-www-form-urlencoded',
  230. 'Authorization':wx.getStorageSync('token')
  231. },
  232. success: function (res) {
  233. console.log(res.data.data.length)
  234. if (res.statusCode == 200 && res.data.data.length>=1) {
  235. that.setData({coupon:res.data.data[0],coupon_id:res.data.data[0].id})
  236. }
  237. }
  238. })
  239. wx.request({
  240. url: 'https://yutang.web.ximengnaikang.com/api/company',
  241. method: 'GET',
  242. header:{
  243. 'Authorization':wx.getStorageSync('token')
  244. },
  245. success: function (res) {
  246. console.log(res)
  247. that.setData({
  248. tabSwiper: res.data.data.seats,
  249. })
  250. wx.showToast({
  251. title: '刷新成功',
  252. icon:'none'
  253. })
  254. wx.hideNavigationBarLoading();
  255. wx.stopPullDownRefresh();
  256. }
  257. })
  258. },
  259. })