edit-bank.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. var sysT = require('../../../tool/sys-tool.js')
  2. var verify = require('../../../tool/verify.js')
  3. var businessT = require('../../../tool/business-tool.js')
  4. var publicData = require('../../../constant/data.js')
  5. var url = require('../../../constant/url.js')
  6. import Net from '../../../tool/net.js'
  7. var net = new Net()
  8. var app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. adapter: {
  15. isIos: false,
  16. bgHeight: '',
  17. suffix: ''
  18. },
  19. customer: {},//自动同步(引用)
  20. data: {},
  21. inputValue: '',
  22. textareaValue: '',
  23. textareaPlaceholderHide: false,
  24. bankIcon: '',
  25. refreshBank: false,
  26. isInput: false
  27. },
  28. getBankIcon: function (bank) {
  29. var icon = publicData.bankDic[bank]
  30. if (icon) {
  31. icon = '../../../icon/bank/' + icon + '.png'
  32. } else {
  33. icon = ''
  34. }
  35. return icon
  36. },
  37. chooseBank: businessT.action(function () {
  38. if (this.data.isInput) {
  39. this.data.isInput = false
  40. this.getBankWithInChooseBank(true)
  41. return
  42. }
  43. this.intoChooseBank()
  44. }),
  45. inputAction: function (sender) {
  46. businessT.debugLog(sender)
  47. this.data.inputValue = sender.detail.value
  48. this.setData({
  49. inputValue: this.data.inputValue
  50. })
  51. },
  52. inputFocus: function (sender) {
  53. businessT.debugLog('inputfocus')
  54. this.data.isInput = true
  55. },
  56. inputBlur: function (sender) {
  57. businessT.debugLog('inputblur')
  58. if (this.data.isInput) {
  59. this.data.isInput = false
  60. this.getBankWithInChooseBank(false)
  61. }
  62. },
  63. getBankWithInChooseBank: function (flag) {
  64. var that = this
  65. net.connect({
  66. url: url.alipayGetBank + this.data.inputValue,
  67. data: {},
  68. method: 'GET',
  69. success: (err, res) => {},
  70. fail: (err, res) => {
  71. businessT.debugLog(res)
  72. if (res && res['bank']) {
  73. var dic = publicData.alipayBankDic
  74. if (dic[res['bank']]) {
  75. that.data.data.bank = dic[res['bank']]
  76. that.data.bankIcon = that.getBankIcon(that.data.data.bank)
  77. that.setData({
  78. data: that.data.data,
  79. bankIcon: that.data.bankIcon
  80. })
  81. return
  82. }
  83. }
  84. if (flag) {
  85. businessT.debugLog('flag')
  86. that.intoChooseBank()
  87. }
  88. }
  89. }, false)
  90. },
  91. intoChooseBank: function () {
  92. wx.navigateTo({
  93. url: '../choose-bank/choose-bank',
  94. })
  95. },
  96. textareaInput: function (sender) {
  97. businessT.debugLog(sender)
  98. this.data.textareaValue = sender.detail.value
  99. this.setData({
  100. textareaValue: this.data.textareaValue
  101. })
  102. },
  103. textareaFocus: function (sender) {
  104. if (!this.data.textareaPlaceholderHide) {
  105. this.data.textareaPlaceholderHide = true;
  106. this.setData({
  107. textareaPlaceholderHide: this.data.textareaPlaceholderHide
  108. })
  109. }
  110. },
  111. textareaBlur: function (sender) {
  112. if (this.data.textareaValue.length == 0 && this.data.textareaPlaceholderHide) {
  113. this.data.textareaPlaceholderHide = false;
  114. this.setData({
  115. textareaPlaceholderHide: this.data.textareaPlaceholderHide
  116. })
  117. }
  118. },
  119. saveAction: businessT.action(function (sender) {
  120. businessT.debugLog(this.data.inputValue)
  121. if (!verify.isNumber(this.data.inputValue) || this.data.inputValue.length < publicData.minBankCodeLength) {
  122. wx.showToast({
  123. title: '请输入正确的银行卡号',
  124. icon: 'none'
  125. })
  126. return
  127. }
  128. if (this.data.data.bank.length < publicData.minBankNameLength) {
  129. wx.showToast({
  130. title: '请输入正确的银行名称',
  131. icon: 'none'
  132. })
  133. return
  134. }
  135. wx.showLoading({
  136. title: '正在保存',
  137. mask: true
  138. })
  139. net.connectNeedLogin({
  140. url: url.app_host + url.modifyBank,
  141. data: {
  142. sbu_id: this.data.customer.id,
  143. bank: this.data.data.bank,
  144. bank_branch: this.data.textareaValue,
  145. bank_code: this.data.inputValue
  146. },
  147. success: (err, res) => {
  148. this.data.customer.bank = this.data.data.bank
  149. this.data.customer.bank_branch = this.data.textareaValue
  150. this.data.customer.bank_code = this.data.inputValue
  151. wx.hideLoading()
  152. wx.showToast({
  153. title: '保存成功',
  154. icon: 'none'
  155. })
  156. wx.navigateBack({})
  157. },
  158. fail: (err, res) => {
  159. businessT.showFailTips(err, '保存失败')
  160. }
  161. })
  162. }),
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function (options) {
  167. sysT.adaptor()
  168. businessT.debugLog(sysT.usableHeight(112))
  169. this.data.customer = app.globalData.customerList[options.i]
  170. businessT.debugLog(this.data.customer)
  171. this.data.data = {
  172. bank_code: this.data.customer.bank_code,
  173. bank_branch: this.data.customer.bank_branch,
  174. bank: this.data.customer.bank,
  175. user_name: this.data.customer.user_name
  176. }
  177. var isIos = sysT.sysInfo().system.indexOf("iOS") == 0
  178. this.data.adapter = {
  179. isIos: isIos,
  180. bgHeight: sysT.usableHeight(112),
  181. suffix: sysT.suffixOfClass(),
  182. }
  183. this.data.textareaPlaceholderHide = this.data.data.bank_branch.length > 0
  184. this.data.bankIcon = this.getBankIcon(this.data.data.bank)
  185. this.setData({
  186. textareaValue: this.data.data.bank_branch,
  187. textareaPlaceholderHide: this.data.textareaPlaceholderHide,
  188. inputValue: this.data.data.bank_code,
  189. adapter: this.data.adapter,
  190. data: this.data.data,
  191. bankIcon: this.data.bankIcon
  192. })
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow: function () {
  203. if (this.data.refreshBank) {
  204. this.data.refreshBank = false
  205. this.data.bankIcon = this.getBankIcon(this.data.data.bank)
  206. this.setData({
  207. data: this.data.data,
  208. bankIcon: this.data.bankIcon
  209. })
  210. }
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. },
  217. /**
  218. * 生命周期函数--监听页面卸载
  219. */
  220. onUnload: function () {
  221. },
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh: function () {
  226. },
  227. /**
  228. * 页面上拉触底事件的处理函数
  229. */
  230. onReachBottom: function () {
  231. },
  232. /**
  233. * 用户点击右上角分享
  234. */
  235. onShareAppMessage: function () {
  236. }
  237. })