deposit.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. const app = getApp();
  2. const util = require('../../../utils/utils.js');
  3. let videoAd = null;
  4. Page({
  5. data: {
  6. index: 0, //0 缴纳押金 1退回押金 2退押金状态
  7. pay: 0, // 1 支付押金 0 支付/缴纳/退回
  8. popShow: true, //是否显示弹窗
  9. money: '',
  10. depoSuce: true,
  11. imgUrl: 'http://resource.bike.hanyiyun.com/xiaobanma/moneyBg.png',
  12. depShow: true, //是否选中缴纳押金 true选中 false 未选中
  13. curShow: '', //是否选中购买免押金卡 undefined 未选中 有值选中
  14. cardList: [], //免押金卡列表
  15. state: [],
  16. deposit_status: '',
  17. phone: '',
  18. is_deposit_ad: wx.getStorageSync('setting').is_return_deposit_ad_video,
  19. img: app.globalData.imgUrl,
  20. userState: wx.getStorageSync('userState'),
  21. setting: wx.getStorageSync('setting')
  22. },
  23. //获取免押金卡列表
  24. getCard() {
  25. let data = {
  26. area_id: wx.getStorageSync('home').id
  27. }
  28. if (wx.getStorageSync('home').id == undefined) {
  29. wx.showToast({
  30. title: '您附近没有运营区域',
  31. icon: 'none'
  32. })
  33. } else {
  34. app.request('/deposit_card/index', data, 'GET').then(res => {
  35. console.log(res.data);
  36. this.setData({
  37. cardList: res.data.data
  38. })
  39. wx.hideLoading({
  40. complete: (res) => {},
  41. })
  42. console.log(this.data.cardList)
  43. })
  44. }
  45. },
  46. student() {
  47. wx.navigateTo({
  48. url: '/pages/student_certification/student_certification',
  49. })
  50. },
  51. // 切换免押金卡
  52. cut(e) {
  53. let that = this;
  54. let id = e.currentTarget.dataset.id;
  55. if (that.data.state.is_deposit == 1 && that.data.state.deposit_type == 1 && id != undefined) {
  56. wx.showToast({
  57. title: '您已缴纳押金无需购买免押金卡',
  58. icon: 'none'
  59. })
  60. return;
  61. }
  62. if (id == undefined) {
  63. that.setData({
  64. depShow: true,
  65. curShow: "text_undefined",
  66. depshow: true
  67. })
  68. } else {
  69. that.setData({
  70. curShow: id,
  71. depShow: false,
  72. depshow: false
  73. })
  74. }
  75. },
  76. explain() {
  77. wx.navigateTo({
  78. url: '/pages/explain_card_free/explain_card_free',
  79. })
  80. },
  81. call_phone() {
  82. var phone = this.data.phone[0];
  83. wx.makePhoneCall({
  84. phoneNumber: phone,
  85. })
  86. },
  87. //进入页面判断是否缴纳押金
  88. getState(e) {
  89. app.request('/user/status', '', 'GET').then(res => {
  90. console.log(res, '判断');
  91. this.setData({
  92. index: res.data.is_deposit,
  93. state: res.data
  94. })
  95. })
  96. app.request('/pages/user-deposit-status', '', 'GET').then(res => {
  97. console.log(res)
  98. this.setData({
  99. deposit_status: res.data.type
  100. })
  101. })
  102. },
  103. //缴纳押金
  104. pay: util.throttle(function (e) {
  105. this.setData({
  106. pay: 1
  107. })
  108. }, 100),
  109. //显示弹窗
  110. showPop: util.throttle(function (e) {
  111. this.setData({
  112. popShow: false,
  113. })
  114. }, 1000),
  115. //取消退回押金
  116. cancle: util.throttle(function (e) {
  117. this.setData({
  118. popShow: true,
  119. })
  120. }, 1000),
  121. //确定退回押金
  122. confirm: util.throttle(function (e) {
  123. var that = this;
  124. this.setData({
  125. popShow: true,
  126. index: 1,
  127. })
  128. if (this.data.setting.deposit_delay_setting.status == true) {
  129. wx.showModal({
  130. title: '退还押金',
  131. content: '您这笔退款预计一到三天内到账是否确认退款',
  132. showCancel: true, //是否显示取消按钮
  133. cancelText: "取消", //默认是“取消”
  134. cancelColor: '#000000', //取消文字的颜色
  135. confirmText: "确认", //默认是“确定”
  136. confirmColor: '#FF0000', //确定文字的颜色
  137. success: function (res) {
  138. if (res.cancel) {
  139. //点击取消,默认隐藏弹框
  140. } else {
  141. //点击确定
  142. app.request('/deposit/refund-job', '', 'POST').then(res => {
  143. console.log(res);
  144. if (res.statusCode == 200) {
  145. wx.reLaunch({
  146. url: '/pages/refund_success/refund_success?number=' + that.data.setting.deposit_delay_setting.day,
  147. })
  148. }
  149. })
  150. }
  151. }
  152. })
  153. } else {
  154. app.request('/deposit/refund', '', 'POST').then(res => {
  155. console.log(res);
  156. if (res.statusCode == 200) {
  157. wx.showToast({
  158. title: '申请成功,1个工作日内到账!',
  159. icon: 'none'
  160. })
  161. this.getState()
  162. }
  163. })
  164. }
  165. }, 1000),
  166. //立即支付
  167. depoSuce: util.throttle(function (e) {
  168. console.log('支付')
  169. var that = this;
  170. let url = '';
  171. var data = '';
  172. if (app.globalData.req) {
  173. console.log(that.data.depShow)
  174. if (that.data.depShow) { //缴纳押金
  175. console.log(11111)
  176. url = "/deposit/pay";
  177. data = {
  178. area_id: wx.getStorageSync('home').id
  179. }
  180. } else { //购买免押金卡
  181. console.log(2222)
  182. url = "/deposit_card/pay";
  183. data = {
  184. area_id: wx.getStorageSync('home').id,
  185. id: that.data.curShow
  186. }
  187. }
  188. if (wx.getStorageSync('setting') == '') {
  189. wx.showModal({
  190. title: '提示',
  191. content: '您附近暂无运营区域~',
  192. showCancel: false,
  193. success: function (res) {
  194. if (res.confirm) {
  195. wx.navigateBack()
  196. }
  197. }
  198. })
  199. } else {
  200. app.request(url, data, 'POST', app.globalData.req).then(res => {
  201. console.log(res)
  202. if (res.statusCode == 200) {
  203. console.log(res)
  204. wx.requestPayment({
  205. timeStamp: res.data.timeStamp.toString(),
  206. nonceStr: res.data.nonceStr,
  207. package: res.data.package,
  208. signType: res.data.signType,
  209. paySign: res.data.paySign,
  210. success(res) {
  211. console.log(res)
  212. let init = '';
  213. if (that.data.depShow) {
  214. init = "购买成功"
  215. } else {
  216. init = "支付成功"
  217. }
  218. wx.showToast({
  219. title: init,
  220. icon: 'none',
  221. duration: 1000,
  222. success: function () {
  223. wx.reLaunch({
  224. url: '/pages/personal/depoSuce/depoSuce',
  225. })
  226. }
  227. })
  228. that.setData({
  229. depoSuce: true
  230. })
  231. },
  232. fail(err) {
  233. console.log(err)
  234. wx.showToast({
  235. title: '支付失败',
  236. icon: 'none'
  237. })
  238. that.setData({
  239. depoSuce: true
  240. })
  241. }
  242. })
  243. } else {
  244. console.log(res)
  245. that.setData({
  246. depoSuce: true
  247. })
  248. }
  249. })
  250. }
  251. } else {
  252. wx.showToast({
  253. title: '您的操作过于频繁,请稍后再试~',
  254. icon: 'none'
  255. })
  256. }
  257. }, 1000),
  258. onLoad: function (options) {
  259. // 是否缴纳押金
  260. console.log(this.data.depShow)
  261. var that = this;
  262. wx.showLoading({
  263. title: '加载中...',
  264. })
  265. this.getState();
  266. this.setData({
  267. money: wx.getStorageSync('setting').deposit
  268. })
  269. if (wx.getStorageSync('setting') == '') {
  270. this.setData({
  271. money: '59.00'
  272. })
  273. } else {
  274. this.setData({
  275. money: wx.getStorageSync('setting').deposit
  276. })
  277. }
  278. if (options.home) {
  279. this.setData({
  280. pay: 1
  281. })
  282. }
  283. console.log(this.data.userState, '哈哈哈')
  284. if (wx.createRewardedVideoAd) {
  285. videoAd = wx.createRewardedVideoAd({
  286. adUnitId: 'adunit-edc5c4664389a87a'
  287. })
  288. videoAd.onLoad(() => {})
  289. videoAd.onError((err) => {})
  290. videoAd.onClose((res) => {
  291. if (res && res.isEnded || res === undefined) {
  292. app.request('/deposit/refund', '', 'POST').then(res => {
  293. console.log(res);
  294. if (res.statusCode == 200) {
  295. wx.showToast({
  296. title: '加速成功,稍后到账',
  297. icon: 'none'
  298. })
  299. that.getState()
  300. }
  301. })
  302. } else {
  303. wx.showToast({
  304. title: '加速失败!',
  305. icon: 'none'
  306. })
  307. }
  308. })
  309. }
  310. this.getCard();
  311. },
  312. adShow() {
  313. if (videoAd) {
  314. videoAd.show().catch(() => {
  315. // 失败重试
  316. videoAd.load()
  317. .then(() => videoAd.show())
  318. .catch(err => {
  319. console.log('激励视频 广告显示失败')
  320. })
  321. })
  322. }
  323. },
  324. agreement: util.throttle(function (e) {
  325. //充值条约
  326. wx.navigateTo({
  327. url: '/pages/agreement/agreement',
  328. })
  329. }, 1000),
  330. onReady: function () {
  331. },
  332. onShow: function () {
  333. var phones = wx.getStorageSync('home').customer_service_phone
  334. this.setData({
  335. phone: this.data.phone.concat(phones),
  336. is_deposit_ad: wx.getStorageSync('setting').is_return_deposit_ad_video,
  337. userState: wx.getStorageSync('userState'),
  338. img: app.globalData.imgUrl,
  339. setting: wx.getStorageSync('setting')
  340. })
  341. },
  342. onHide: function () {
  343. },
  344. onUnload: function () {
  345. },
  346. onPullDownRefresh: function () {
  347. },
  348. onReachBottom: function () {
  349. },
  350. onShareAppMessage: function () {
  351. }
  352. })