deposit.js 8.1 KB

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