index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="bindingCard">
  3. <capsule :showBorder="true" bgColor="#FFFFFF">
  4. <template v-slot:top>
  5. <view class="detail-top">
  6. <view class="back-icon" @click="backClick">
  7. <tui-icon name="arrowleft" :size="32" color="#000"></tui-icon>
  8. </view>
  9. <view class="shop-name">{{ title }}</view>
  10. </view>
  11. </template>
  12. </capsule>
  13. <view class="seize"></view>
  14. <view class="binding-box">
  15. <view class="binding-title">绑定账户</view>
  16. <view class="binding-container">
  17. <view class="change-box">
  18. <view class="change-title">银行卡卡号</view>
  19. <view class="change-ipt">
  20. <tui-input
  21. placeholder="请输入"
  22. padding="0 16rpx 0 0 "
  23. :size="28"
  24. :inputBorder="false"
  25. :borderBottom="false"
  26. v-model="bankInfo.cardNumber"
  27. >
  28. </tui-input>
  29. </view>
  30. </view>
  31. <view class="change-box">
  32. <view class="change-title">持卡人姓名</view>
  33. <view class="change-ipt">
  34. <tui-input
  35. placeholder="请输入"
  36. padding="0 16rpx 0 0 "
  37. :size="28"
  38. :inputBorder="false"
  39. :borderBottom="false"
  40. v-model="bankInfo.cardName"
  41. @blur="changeCardName"
  42. >
  43. </tui-input>
  44. </view>
  45. </view>
  46. <view class="change-box">
  47. <view class="change-title">银行</view>
  48. <view class="change-ipt">
  49. <tui-input
  50. placeholder="请输入"
  51. padding="0 16rpx 0 0 "
  52. :size="28"
  53. :inputBorder="false"
  54. :borderBottom="false"
  55. :disabled="true"
  56. :value="dictName"
  57. >
  58. <template #right>
  59. <view class="right-text" @click="showChange">选择</view>
  60. </template>
  61. </tui-input>
  62. </view>
  63. </view>
  64. <view class="change-box">
  65. <view class="change-title">注册手机号</view>
  66. <view class="change-ipt">
  67. <tui-input
  68. placeholder="请输入手机号码"
  69. padding="0 16rpx 0 0 "
  70. :size="28"
  71. :inputBorder="false"
  72. :borderBottom="false"
  73. v-model="bankInfo.phone"
  74. >
  75. <template #left>
  76. <view class="ipt-left">+86</view>
  77. </template>
  78. </tui-input>
  79. </view>
  80. </view>
  81. <view class="change-box">
  82. <view class="change-title">短信验证码</view>
  83. <view class="change-ipt">
  84. <tui-input
  85. placeholder="请输入"
  86. padding="0 16rpx 0 0 "
  87. :size="28"
  88. :inputBorder="false"
  89. :borderBottom="false"
  90. v-model="code"
  91. >
  92. <template #right>
  93. <tui-countdown-verify
  94. text="获取验证码"
  95. sendText="发送中..."
  96. borderColor="#E7E7E7"
  97. color="rgba(0, 0, 0, 0.6)"
  98. :size="28"
  99. :seconds="60"
  100. :successVal="successVal"
  101. :resetVal="resetVal"
  102. @send="getVerify"
  103. ></tui-countdown-verify>
  104. <!-- <view class="ipt-right">获取验证码</view> -->
  105. </template>
  106. </tui-input>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. <view class="btn-list">
  112. <view class="btn" @click="backClick">取消</view>
  113. <view class="btn" @click="btnClick">{{ btnTitle }}</view>
  114. </view>
  115. <tui-picker
  116. :show="showPicker"
  117. :layer="1"
  118. :pickerData="bankList"
  119. textField="dictName"
  120. valueField="dictId"
  121. cancelColor="rgba(0, 0, 0, 0.6)"
  122. confirmColor="#EA5C1E"
  123. :value="value"
  124. @change="nameChange"
  125. @hide="showChange"
  126. ></tui-picker>
  127. </view>
  128. </template>
  129. <script>
  130. import {
  131. getSelect,
  132. getCode,
  133. updateReceiving,
  134. saveReceiving,
  135. } from "@/config/index.js";
  136. // {
  137. // "id": "",
  138. // "cardName": "徐枝浪",
  139. // "cardNumber": "1234567893333",
  140. // "bank": 2001,
  141. // "phone": "13539102414",
  142. // "code": "1",
  143. // "bankType": 2,
  144. // "province": "",
  145. // "city": "",
  146. // "bankName": "",
  147. // "unionBank": "",
  148. // "bankCode": ""
  149. // }
  150. export default {
  151. created() {
  152. // 获取所有银行列表
  153. this.getBankAll();
  154. },
  155. onLoad(option) {
  156. // type == 1 表示已经有银行卡了
  157. if (option.type == 1) {
  158. this.title = "修改银行卡";
  159. this.btnTitle = "修改";
  160. // 本地获取数据
  161. this.bankInfo = uni.getStorageSync("bankInfo");
  162. this.dictName = this.bankInfo.dictName;
  163. // 给 value 赋值
  164. this.value = [this.bankInfo.dictName];
  165. }
  166. },
  167. data() {
  168. return {
  169. title: "绑定银行卡",
  170. btnTitle: "确认",
  171. // 银行卡名称
  172. dictName: "",
  173. bankInfo: {
  174. // cardNumber: "",
  175. // cardName: "",
  176. // bank: "",
  177. // phone: "",
  178. // code: "",
  179. id: "",
  180. cardName: "",
  181. cardNumber: "",
  182. bank: "",
  183. phone: "",
  184. bankType: "",
  185. province: "",
  186. city: "",
  187. bankName: "",
  188. unionBank: "",
  189. bankCode: "",
  190. },
  191. // 控制 选择银行显示
  192. showPicker: false,
  193. bankList: [],
  194. value: [],
  195. // 控制获取验证码成功
  196. successVal: 0,
  197. // 控制获取验证码失败
  198. resetVal: 0,
  199. // 二维码
  200. code: "",
  201. };
  202. },
  203. methods: {
  204. // 姓名特殊字符判断
  205. changeCardName() {
  206. let rule = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、' ']/g;
  207. if (rule.test(this.bankInfo.cardName)) {
  208. this.$showToast("姓名不能包含特殊字符!");
  209. this.bankInfo.cardName = this.bankInfo.cardName.replace(rule, "");
  210. }
  211. },
  212. // 获取所有银行
  213. async getBankAll() {
  214. let { data } = await getSelect({ dictName: "所属银行" });
  215. this.bankList = data;
  216. },
  217. // 获取验证码
  218. async getVerify() {
  219. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  220. if (!phoneCodeVerification.test(this.bankInfo.phone)) {
  221. this.$showToast("请输入正确的手机号!");
  222. this.resetVal++;
  223. return;
  224. }
  225. let res = await getCode({ phone: this.bankInfo.phone });
  226. if (res.message == "") {
  227. this.successVal++;
  228. } else {
  229. this.$showToast(res.message);
  230. this.resetVal++;
  231. }
  232. },
  233. // 保存 / 修改点击事件
  234. btnClick() {
  235. // 进去先对数据进行正则判断
  236. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  237. const cardRule = /^([1-9]{1})(\d{15}|\d{18})$/;
  238. if (!phoneCodeVerification.test(this.bankInfo.phone)) {
  239. this.$showToast("请输入正确的手机号!");
  240. return;
  241. }
  242. if (!cardRule.test(this.bankInfo.cardNumber)) {
  243. this.$showToast("卡号需为16~19位的数字");
  244. return;
  245. }
  246. if (this.code == "") {
  247. this.$showToast("验证码不能为空");
  248. return;
  249. }
  250. this.bankInfo.code = this.code;
  251. if (this.btnTitle == "修改") {
  252. this.updateAccount();
  253. } else {
  254. this.saveAccount();
  255. }
  256. },
  257. // 修改账户信息
  258. async updateAccount() {
  259. // 对数据进行处理
  260. let obj = { ...this.bankInfo };
  261. // 删除自己添加的数据
  262. delete obj.dictName;
  263. let res = await updateReceiving(obj);
  264. if (res.code == "") {
  265. this.$showToast("修改成功");
  266. // 跳转回我的账户页面
  267. setTimeout(() => {
  268. this.backClick();
  269. }, 1500);
  270. }
  271. },
  272. // 保存账户信息
  273. async saveAccount() {
  274. let res = await saveReceiving(this.bankInfo);
  275. if (res.code == "") {
  276. this.$showToast("保存成功");
  277. // 跳转回我的账户页面
  278. setTimeout(() => {
  279. this.backClick();
  280. }, 1500);
  281. }
  282. },
  283. // 控制选择显示
  284. showChange() {
  285. this.showPicker = !this.showPicker;
  286. },
  287. // 选择银行确认
  288. nameChange(key) {
  289. this.bankInfo.bank = key.dictId;
  290. this.dictName = key.dictName;
  291. },
  292. backClick() {
  293. uni.navigateBack({
  294. fail: () => {
  295. uni.redirectTo({
  296. url: "/pages_module/receiving/index",
  297. });
  298. },
  299. });
  300. },
  301. },
  302. // 页面卸载清除缓存
  303. onUnload() {
  304. uni.removeStorageSync("bankInfo");
  305. },
  306. };
  307. </script>
  308. <style lang="scss" scoped>
  309. @import "./index.scss";
  310. </style>