bank.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="page">
  3. <headerline shownav=true isback="true" @tapnav="tapnav" :navstyle="navstyle" :navitem="navitem"
  4. :navselect="navselect" :statusbarheight='statusBarHeight'></headerline>
  5. <view v-if="navselect==0">
  6. <ul class="cardManage clearFix" id="_bankList" style="clear: both;margin-top: 10px;">
  7. <li class="bank_item" v-for="(value,index) in bank" :key='index'>
  8. <dl>
  9. <dd><span> {{value['bankname']}}</span><span>持卡人:{{value['realname']}}</span></dd>
  10. <dd><span>卡号:{{value['number']}}</span></dd>
  11. </dl>
  12. <p class="bank_bottom">绑定时间:{{$action.timestampToTime(value['time'])}}<span></span></p>
  13. <span class="bank_default" v-if="value.default==1">
  14. <image src="../../static/img/bank_img.png" style="height:60px;width:60px;">
  15. </span>
  16. </li>
  17. </ul>
  18. <div class="nodata" style="color: #666;clear: both;margin-top: 10px;text-align: center">
  19. 最多可以绑定<span style="color: #ff0000">{{system['bank_num']}}</span>张银行卡
  20. </div>
  21. </view>
  22. <view v-else>
  23. <ul class="profile">
  24. <li>姓  名:</li>
  25. <li>
  26. <block v-if="banklen>0">
  27. {{realname}}
  28. </block>
  29. <input v-else v-model="realname" class="input1" />
  30. </li>
  31. </ul>
  32. <ul class="profile">
  33. <li>卡  号:</li>
  34. <li><input name="banknum" id="banknum" type="digit" v-model="banknum" class="input1">
  35. </li>
  36. </ul>
  37. <ul class="profile">
  38. <li>选择银行:</li>
  39. <li>
  40. <picker @change="bindbankChange" :value="bankid" :range="banklist">
  41. <view class="uni-input">{{bankname}}</view>
  42. </picker>
  43. </li>
  44. </ul>
  45. <ul class="profile">
  46. <li>所在地区:</li>
  47. <li>
  48. <picker mode="multiSelector" @cancel="oncancel()" @columnchange="bindMultiPickerColumnChange"
  49. :value="multiIndex" :range="area">
  50. <view class="uni-input" @tap="tapaddress();">{{item.province}},{{item.city}}</view>
  51. </picker>
  52. </li>
  53. </ul>
  54. <ul class="profile">
  55. <li>支行名称:</li>
  56. <li>
  57. <input type="text" name="mark" v-model="mark" class="input1" id="mark">
  58. </li>
  59. </ul>
  60. <ul class="profile">
  61. <li>首 选 卡:</li>
  62. <li>
  63. <picker @change="binddefaultChange" :value="isdefault" :range="default_arr">
  64. <view class="uni-input">{{default_arr[isdefault]}}</view>
  65. </picker>
  66. </li>
  67. </ul>
  68. <ul class="profile">
  69. <li>资金密码:</li>
  70. <li>
  71. <input type="password" name='pwd' id='pwd' v-model='pwd' class="input1" maxlength="6">
  72. </li>
  73. </ul>
  74. <view style="margin:15px auto;display:block;width: 80%;">
  75. <button class="button1" @tap="click_bind()">
  76. 确认并提交
  77. </button>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import api from "../../library/index.js"
  84. import headerline from '../../components/header.vue'
  85. import http from "../../library/http.js"
  86. import uniIcons from '../../components/uni-icons/uni-icons.vue'
  87. import address from '../../library/address.js'
  88. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  89. export default {
  90. components: {
  91. uniIcons,
  92. headerline,
  93. },
  94. data() {
  95. return {
  96. statusBarHeight: statusBarHeight + 'px',
  97. navitem: ['我的银行卡', '新增银行卡'],
  98. navselect: 0,
  99. navstyle: "width:60%;left:20%",
  100. user: uni.getStorageSync('userInfo'),
  101. system: uni.getStorageSync('system'),
  102. bank: uni.getStorageSync('bank'),
  103. banklen: 0,
  104. banklist: uni.getStorageSync('banklist'),
  105. realname: '',
  106. default_arr: ['否', '是'],
  107. isdefault: 1,
  108. province: [],
  109. city: [],
  110. multiIndex: [0, 0],
  111. area: [
  112. ['省份'],
  113. ['城市']
  114. ],
  115. showarea: 0,
  116. provice1: '',
  117. city1: '',
  118. provice2: '',
  119. city2: '',
  120. c1: 0,
  121. c2: 0,
  122. item: {
  123. 'province': '省份',
  124. 'city': '城市'
  125. },
  126. bankname: '工商银行',
  127. banknum: '',
  128. pwd: '',
  129. mark: '',
  130. bankid: 0,
  131. }
  132. },
  133. methods: {
  134. tapnav(num) {
  135. if (num == 0 && this.banklen == 0) {
  136. uni.showToast({
  137. title: '您还没有绑定任何银行卡',
  138. icon: 'none'
  139. })
  140. } else {
  141. if (this.banklen >= this.system['bank_num']) {
  142. uni.showToast({
  143. title: '每个用户最多只能绑定' + this.system['bank_num'] + '张银行卡',
  144. icon: 'none'
  145. })
  146. } else
  147. this.navselect = num;
  148. }
  149. },
  150. binddefaultChange(e) {
  151. this.isdefault = e.target.value
  152. },
  153. bindbankChange(e) {
  154. var num = e.target.value;
  155. this.bankname = this.banklist[num]
  156. this.bankid = num;
  157. },
  158. setbanknum(num) {
  159. },
  160. tapaddress() {
  161. // console.log( this.sex);
  162. // console.log( this.area[0]);
  163. // console.log( this.area[1]);
  164. this.provice2 = this.item.province;
  165. this.city2 = this.item.city;
  166. },
  167. bindMultiPickerColumnChange(e) {
  168. var detail = e.detail;
  169. detail.value = parseInt(detail.value);
  170. if (detail.column == 0) {
  171. // console.log(this.city[detail.value].city);
  172. this.c1 = detail.value;
  173. this.area[1] = this.city[detail.value].city;
  174. this.multiIndex[0] = detail.value;
  175. this.provice1 = this.city[detail.value].province;
  176. this.city1 = this.area[1][this.c2];
  177. } else {
  178. this.c2 = detail.value;
  179. this.multiIndex[1] = detail.value;
  180. this.city1 = this.area[1][detail.value];
  181. }
  182. this.item.province = this.provice1
  183. this.item.city = this.city1
  184. },
  185. oncancel() {
  186. this.item.province = this.provice2
  187. this.item.city = this.city2
  188. },
  189. getAddress() {
  190. if (!this.item.province || this.item.province == null) this.item.province = '省份';
  191. if (!this.item.city || this.item.city == null) this.item.city = '城市';
  192. var c1 = 0;
  193. address.forEach(item => {
  194. this.province.push(item.provinceName);
  195. // console.log(this.item.province,item.provinceName);
  196. if (this.item.province == item.provinceName) this.multiIndex[0] = parseInt(c1);
  197. c1++;
  198. var arr = {};
  199. arr.province = item.provinceName;
  200. var city1 = [];
  201. var c2 = 0;
  202. item.city.forEach(c => {
  203. if (c.cityName != '')
  204. city1.push(c.cityName)
  205. if (this.item.province == item.provinceName && this.item.city == c.cityName)
  206. this.multiIndex[1] = parseInt(c2);
  207. c2++;
  208. })
  209. arr.city = city1;
  210. this.city.push(arr)
  211. })
  212. // console.log(this.province);
  213. // this.area=[];
  214. this.area[0] = this.province;
  215. this.area[1] = this.city[this.multiIndex[0]].city;
  216. this.showarea = 1;
  217. },
  218. getuserinfo() {
  219. var postdata = {
  220. id: uni.getStorageSync('access_token')
  221. };
  222. http.setWait(false).post('user.php?act=userinfo', postdata).then(res => {
  223. this.user = res.data;
  224. uni.setStorageSync('userInfo', this.user)
  225. })
  226. },
  227. getbank() {
  228. var postdata = {
  229. userid: uni.getStorageSync('access_token')
  230. };
  231. http.setWait(false).post('user.php?act=mybank', postdata).then(res => {
  232. this.bank = res.data;
  233. uni.setStorageSync('bank', this.bank)
  234. if (res.num < 1) this.tapnav(1);
  235. else {
  236. this.realname = res.data[0].realname;
  237. this.isdefault = 0;
  238. }
  239. this.banklen = res.num;
  240. var banklist = [];
  241. for (var ii in res.banklist) {
  242. banklist.push(res.banklist[ii])
  243. }
  244. this.banklist = banklist;
  245. uni.setStorageSync('banklist', banklist);
  246. this.getuserinfo();
  247. })
  248. },
  249. click_bind() {
  250. if (this.realname == '') {
  251. uni.showToast({
  252. title: '请输入开户姓名',
  253. icon: 'none'
  254. })
  255. return false;
  256. }
  257. // if (this.realname.length < 2 || this.realname.length > 4) {
  258. // uni.showToast({
  259. // title: '开户姓名最多四个字',
  260. // icon: 'none'
  261. // })
  262. // return false;
  263. // }
  264. var reglx = /^[\u0391-\uFFE5]+$/;
  265. if (!reglx.test(this.realname)) {
  266. uni.showToast({
  267. title: '开户姓名只能包含中文',
  268. icon: 'none'
  269. })
  270. return false;
  271. }
  272. if (this.banknum == "") {
  273. uni.showToast({
  274. title: '请输入银行卡号',
  275. icon: 'none'
  276. })
  277. return false;
  278. }
  279. if (this.banknum.length < 15 || this.banknum.length > 19) {
  280. uni.showToast({
  281. title: '银行卡号长度必须在15到19之间',
  282. icon: 'none'
  283. })
  284. return false;
  285. }
  286. var num = /^\d*$/;
  287. //全数字
  288. if (!num.exec(this.banknum)) {
  289. uni.showToast({
  290. title: '银行卡号必须全为数字',
  291. icon: 'none'
  292. })
  293. return false;
  294. }
  295. // var regExp = /^([1-9]{1})(\d{14}|\d{15}|\d{16}|\d{17}|\d{18}|\d{19})$/;
  296. // if(!regExp.test(this.banknum)){
  297. // uni.showToast({
  298. // title:'银行卡号格式不正确',
  299. // icon:'none'
  300. // })
  301. // return false;
  302. // }
  303. if (this.item.city == '城市') {
  304. uni.showToast({
  305. title: '请输选择开户行所在地区',
  306. icon: 'none'
  307. })
  308. return false;
  309. }
  310. if (this.mark == "") {
  311. uni.showToast({
  312. title: '请输入支行名称',
  313. icon: 'none'
  314. })
  315. return false;
  316. }
  317. if (this.pwd == "") {
  318. uni.showToast({
  319. title: '请输入资金密码',
  320. icon: 'none'
  321. })
  322. return false;
  323. }
  324. if (parseInt(this.pwd) > 0 && parseInt(this.pwd) < 1000000 && this.pwd.length == 6) {
  325. } else {
  326. uni.showToast({
  327. title: '资金密码必须为6位数字',
  328. icon: 'none'
  329. })
  330. return false;
  331. }
  332. if (this.$action.check_userlock() == false) return false;
  333. http.setWait(true).post('user.php?act=bank_add', {
  334. userid: this.user.id,
  335. bankname: this.bankname,
  336. realname: this.realname,
  337. banknum: this.banknum,
  338. province: this.item.province,
  339. city: this.item.city,
  340. mark: this.mark,
  341. default: this.isdefault,
  342. pwd: this.pwd
  343. }).then(res => {
  344. this.getbank();
  345. this.navselect = 0
  346. uni.showToast({
  347. icon: 'none',
  348. title: '银行卡绑定成功',
  349. duration: 1000
  350. })
  351. })
  352. }
  353. },
  354. onLoad(opts) {
  355. this.getbank();
  356. this.getAddress();
  357. }
  358. }
  359. </script>
  360. <style lang="scss" scoped>
  361. @import "@/static/css/user.css";
  362. .page {
  363. background-color: #fafafa;
  364. }
  365. .profile,
  366. .login-lines1 {
  367. background-color: #fff;
  368. margin: 10px auto;
  369. width: 100%;
  370. vertical-align: middle;
  371. }
  372. .profile li {
  373. vertical-align: middle;
  374. }
  375. .profile li:first-child {
  376. width: 100px
  377. }
  378. .profile li:last-child {
  379. width: calc(100% - 130px)
  380. }
  381. </style>