index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. show: false,
  9. cardList:[],
  10. name:'',
  11. cardId:'',
  12. bankName:'',
  13. objectId:'',
  14. activeColor: getApp().globalData.activeColor,
  15. titleColor: getApp().globalData.titleColor
  16. },
  17. onClickShow() {
  18. this.setData({ show: true });
  19. },
  20. onClickHide() {
  21. this.setData({ show: false });
  22. },
  23. delete(e){
  24. let cardList = this.data.cardList
  25. cardList.splice(e.currentTarget.dataset.index,1)
  26. let Account = Parse.Object.extend("Account")
  27. let account = new Account()
  28. account.id = this.data.objectId
  29. if((cardList && cardList.length == 0) || !cardList) {
  30. account.set("bank",null)
  31. }else {
  32. account.set("bank",cardList)
  33. }
  34. account.save().then(res=>{
  35. wx.showToast({
  36. title: '删除银行卡成功',
  37. icon: 'succee',
  38. duration: 2000
  39. })
  40. this.getCardList()
  41. })
  42. },
  43. submit(){
  44. const _this = this
  45. let reg = /[\u4e00-\u9fa5]/
  46. let name = this.data.name
  47. let bankName = this.data.bankName
  48. let cardId = this.data.cardId
  49. if(!this.data.name || !this.data.cardId || !this.data.bankName){
  50. wx.showToast({
  51. title: '请填写完整信息',
  52. icon: 'none',
  53. duration: 2000
  54. })
  55. return
  56. }
  57. if(!reg.test(name)){
  58. wx.showToast({
  59. title: '请输入您的真实姓名',
  60. icon: 'none',
  61. duration: 2000
  62. })
  63. return
  64. }
  65. let regExp = /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/;
  66. if(!regExp.test(cardId)){
  67. wx.showToast({
  68. title: '请输入正确的银行卡号',
  69. icon: 'none',
  70. duration: 2000
  71. })
  72. return
  73. }
  74. if(!reg.test(bankName)){
  75. wx.showToast({
  76. title: '请输入正确的开卡行',
  77. icon: 'none',
  78. duration: 2000
  79. })
  80. return
  81. }
  82. let Account = Parse.Object.extend("Account")
  83. let account = new Account()
  84. account.id = this.data.objectId
  85. account.addUnique("bank",{
  86. name,
  87. cardId,
  88. bankName
  89. })
  90. account.save().then(res=>{
  91. console.log(res)
  92. wx.showToast({
  93. title: '添加银行卡成功',
  94. icon: 'succee',
  95. duration: 2000
  96. })
  97. this.onClickHide()
  98. this.getCardList()
  99. this.setData({
  100. name:null,
  101. cardId: null,
  102. bankName:null
  103. })
  104. })
  105. },
  106. getCardList(){
  107. let Account = new Parse.Query("Account")
  108. Account.equalTo("user",Parse.User.current().id)
  109. Account.equalTo("company",company)
  110. Account.first().then(res=>{
  111. let account = res.toJSON()
  112. this.setData({
  113. cardList:account.bank ? account.bank : [] ,
  114. objectId:account.objectId
  115. })
  116. })
  117. },
  118. bindKeyInput(e){
  119. this.setData({
  120. [e.currentTarget.dataset.prop]: e.detail.value
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad: function (options) {
  127. this.getCardList()
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })