addBankcard.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view class="container flex-center flex-column">
  3. <view class="addressBack-box">
  4. <view class="consignee-box bor-line-F7F7F7">
  5. <input v-model="username" maxlength="20" class="fs28" placeholder-class="consignee" placeholder="姓名" />
  6. </view>
  7. <view class="iphoneNum-box bor-line-F7F7F7">
  8. <input v-model="phone" type="number" maxlength="11" class="fs28" placeholder-class="iphoneNum" placeholder="手机号码" />
  9. </view>
  10. <view class="consignee-box bor-line-F7F7F7">
  11. <input v-model="bankName" maxlength="20" class="fs28" placeholder-class="consignee" placeholder="银行名称" />
  12. </view>
  13. <view class="cardnum">
  14. <input v-model="cardNum" type="number" class="fs28" maxlength="20" placeholder-class="detailAddress" placeholder="卡号" />
  15. </view>
  16. </view>
  17. <view v-if="type == 2" class="deleteBankcard-box">
  18. <label class="font-color-C5AA7B" @click="delBankcard">删除银行卡</label>
  19. </view>
  20. <view class="saveAddress-box">
  21. <view v-if="type == 1" class="saveAddress" @click="saveBankcardClick">添加银行卡</view>
  22. <view v-else class="saveAddress" @click="saveBankcardClick">保存</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. const NET = require('../../utils/request')
  28. const API = require('../../config/api')
  29. export default {
  30. data() {
  31. return {
  32. show: false,
  33. type: 1, // 1.添加银行卡 2.编辑银行卡
  34. cardNum: '',
  35. bankCode: '',
  36. bankName: '',
  37. bankTagList: [],
  38. username: '',
  39. phone: '',
  40. id: '',
  41. withdraw: '',
  42. choosedValueList: [ 0 ]
  43. }
  44. },
  45. onLoad(options) {
  46. if (options.type) {
  47. this.type = options.type
  48. }
  49. if (options.withdraw) {
  50. this.withdraw = options.withdraw
  51. }
  52. this.initBankList()
  53. if (this.type == 2) {
  54. this.bankcardId = uni.getStorageSync('bankcardId')
  55. this.renderBankcard(this.bankcardId)
  56. uni.removeStorageSync('bankcardId')
  57. }
  58. },
  59. onShow() {
  60. },
  61. methods: {
  62. renderBankcard(bankcardId) {
  63. const _ = this
  64. NET.request(API.GetByIdBankcard, { bankId: bankcardId }, 'GET').then((res) => {
  65. const bankCard = res.data
  66. _.id = bankcardId
  67. _.username = bankCard.name
  68. _.phone = bankCard.phone
  69. _.bankName = bankCard.bankName
  70. _.bankCode = bankCard.bankCode
  71. _.cardNum = bankCard.bankCard
  72. _.bankTagList.forEach((item, index) => {
  73. if (_.bankCode == item.value) {
  74. _.choosedValueList = [ index ]
  75. }
  76. })
  77. })
  78. .catch((res) => {
  79. })
  80. },
  81. initBankList() {
  82. const _ = this
  83. NET.request(API.QueryBankList).then((res) => {
  84. _.bankTagList = res.data.map((item) => ({
  85. 'value': item.bankCode,
  86. 'label': item.bankName
  87. }))
  88. })
  89. .catch((res) => {
  90. })
  91. },
  92. // 新增或更新银行卡
  93. saveBankcardClick() {
  94. const _ = this
  95. this.bankTagList.forEach((item, index) => {
  96. if (item.label == _.bankName) {
  97. _.bankCode = item.value
  98. }
  99. })
  100. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  101. const method = this.type == 1 ? 'POST' : 'PUT'
  102. if (this.username == '') {
  103. uni.showToast({
  104. title: '请输入姓名!',
  105. duration: 2000,
  106. icon: 'none'
  107. })
  108. } else if (this.phone == '') {
  109. uni.showToast({
  110. title: '请输入手机号!',
  111. duration: 2000,
  112. icon: 'none'
  113. })
  114. } else if (!phoneCodeVerification.test(this.phone)) {
  115. uni.showToast({
  116. title: '请输入正确的手机号!',
  117. duration: 2000,
  118. icon: 'none'
  119. })
  120. } else if (this.bankName == '') {
  121. uni.showToast({
  122. title: '请填写银行名称!',
  123. duration: 2000,
  124. icon: 'none'
  125. })
  126. } else if (this.cardNum == '') {
  127. uni.showToast({
  128. title: '请输入卡号!',
  129. duration: 2000,
  130. icon: 'none'
  131. })
  132. } else if (this.cardNum.length != 16 && this.cardNum.length != 19) {
  133. uni.showToast({
  134. title: '请输入正确的卡号!',
  135. duration: 2000,
  136. icon: 'none'
  137. })
  138. } else if (this.type == 1) {
  139. NET.request(API.SaveBankcard, {
  140. name: this.username,
  141. phone: this.phone,
  142. bankName: this.bankName,
  143. bankCard: this.cardNum
  144. }, 'POST').then((res) => {
  145. if (res.code === '200') {
  146. uni.showToast({
  147. title: '添加成功',
  148. duration: 2000,
  149. icon: 'none'
  150. })
  151. if (this.withdraw == 1) {
  152. setTimeout(function () {
  153. uni.navigateTo({
  154. url: 'withdraw'
  155. })
  156. }, 2000)
  157. } else {
  158. setTimeout(function () {
  159. uni.navigateTo({
  160. url: 'bankcard'
  161. })
  162. }, 2000)
  163. }
  164. } else {
  165. uni.showToast({
  166. title: res.data.message,
  167. duration: 2000,
  168. icon: 'none'
  169. })
  170. }
  171. })
  172. .catch((res) => {
  173. uni.showToast({
  174. title: res.data.message,
  175. duration: 2000,
  176. icon: 'none'
  177. })
  178. })
  179. } else {
  180. NET.request(API.UpdateBankcard, {
  181. bankId: this.id,
  182. name: this.username,
  183. phone: this.phone,
  184. bankName: this.bankName,
  185. bankCard: this.cardNum
  186. }, 'POST').then((res) => {
  187. if (res.code === '200') {
  188. uni.navigateTo({
  189. url: 'bankcard'
  190. })
  191. } else {
  192. uni.showToast({
  193. title: res.msg,
  194. duration: 2000,
  195. icon: 'none'
  196. })
  197. }
  198. })
  199. .catch((res) => {
  200. uni.showToast({
  201. title: '操作失败',
  202. duration: 2000,
  203. icon: 'none'
  204. })
  205. })
  206. }
  207. },
  208. // 删除银行卡
  209. delBankcard() {
  210. uni.showModal({
  211. title: '温馨提示',
  212. content: '确认删除该银行卡?',
  213. confirmText: '确定',
  214. cancelText: '取消',
  215. success: (res) => {
  216. if (res.confirm) {
  217. this.subm()
  218. } else if (res.cancel) {
  219. }
  220. }
  221. })
  222. },
  223. subm() {
  224. NET.request(API.DelMemberBankcard, {
  225. bankId: this.bankcardId
  226. }, 'POST').then((res) => {
  227. uni.navigateTo({
  228. url: 'bankcard'
  229. })
  230. })
  231. .catch((res) => {
  232. })
  233. }
  234. }
  235. }
  236. </script>
  237. <style lang="scss">
  238. page {
  239. background-color: #F7F7F7;
  240. }
  241. .container {
  242. .addressBack-box {
  243. background-color: #FFFFFF;
  244. padding: 30upx 30upx;
  245. .consignee-box {
  246. padding-bottom: 36upx;
  247. width: 690upx;
  248. margin-top: 20upx;
  249. .consignee {
  250. color: #999999;
  251. font-size: 28upx;
  252. }
  253. }
  254. .iphoneNum-box {
  255. padding-bottom: 36upx;
  256. width: 690upx;
  257. margin-top: 36upx;
  258. .iphoneNum {
  259. color: #999999;
  260. font-size: 28upx;
  261. }
  262. }
  263. .location-box {
  264. padding-bottom: 36upx;
  265. width: 690upx;
  266. margin-top: 36upx;
  267. .location {
  268. color: #999999;
  269. font-size: 28upx;
  270. }
  271. }
  272. .bankTag-box {
  273. margin-top: 19px;
  274. padding-bottom: 19px;
  275. .addressTag {
  276. color: #999999
  277. }
  278. }
  279. .cardnum {
  280. margin-top: 19px;
  281. }
  282. .detailAddress-box {
  283. padding-bottom: 36upx;
  284. width: 690upx;
  285. margin-top: 36upx;
  286. .detailAddress {
  287. color: #999999;
  288. font-size: 28upx;
  289. }
  290. }
  291. }
  292. .addressTagBack-box {
  293. background-color: #FFFFFF;
  294. padding: 30upx 30upx;
  295. margin-top: 20upx;
  296. .addressTag-box {
  297. padding-bottom: 36upx;
  298. width: 690upx;
  299. .addressTag {
  300. color: #999999;
  301. font-size: 28upx;
  302. }
  303. }
  304. .defaultState-box {
  305. padding-bottom: 10upx;
  306. width: 690upx;
  307. margin-top: 36upx;
  308. .defaultState {
  309. color: #999999;
  310. font-size: 28upx;
  311. }
  312. }
  313. }
  314. .arrow {
  315. width: 24upx;
  316. height: 24upx;
  317. }
  318. .saveAddress-box {
  319. position: fixed;
  320. bottom: 50upx;
  321. left: 30upx;
  322. .saveAddress {
  323. width: 690upx;
  324. height: 100upx;
  325. color: #FFEBC4;
  326. text-align: center;
  327. line-height: 100upx;
  328. background: #333333;
  329. }
  330. }
  331. }
  332. .deleteBankcard-box {
  333. background-color: #FFFFFF;
  334. padding: 30upx 30upx;
  335. margin-top: 20upx;
  336. text-align: center;
  337. }
  338. .content {
  339. font-size: 35rpx;
  340. width: 500rpx;
  341. .btn {
  342. margin-bottom: 20rpx;
  343. width: 200rpx;
  344. background-image: linear-gradient(135deg, #FFA100 10%, #FF7911 100%);
  345. }
  346. }
  347. </style>