bindMethods.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view class="container" :class="{ show: loaded }">
  3. <view class="tabs dfsb">
  4. <view class="tab-item" :class="type == 'alipay' ? 'on' : ''" @click="setTabEvent('alipay')">支付宝</view>
  5. <!-- <view class="tab-item" :class="type == 'wechat' ? 'on' : ''" @click="setTabEvent('wechat')">微信</view> -->
  6. <view class="tab-item" :class="type == 'bank' ? 'on' : ''" @click="setTabEvent('bank')">银行卡</view>
  7. </view>
  8. <!-- 支付宝绑定 -->
  9. <view class="item" v-if="type == 'alipay'">
  10. <view class="input-item">
  11. <text class="input-item-title">实名姓名</text>
  12. <input type="text" v-model="reqData.alipay_name" placeholder="请输入收款人姓名" />
  13. </view>
  14. <view class="input-item">
  15. <text class="input-item-title">支付宝账号</text>
  16. <input type="text" v-model="reqData.alipay_num" placeholder="请输入支付宝账号" />
  17. </view>
  18. </view>
  19. <!-- <view v-if="type == 'alipay'" class="upload-box">
  20. <text class="upload-box-title">支付宝收款码</text>
  21. <view class="img-box" @click="choose_img_upload">
  22. <image :src="reqData.alipay_num.alipay_img_url || '../../static/bg/upload-icon.png'" mode="aspectFit">
  23. </image>
  24. </view>
  25. </view> -->
  26. <!-- 微信绑定 -->
  27. <!-- <view class="item" v-if="type == 'wechat'">
  28. <view class="input-item">
  29. <text class="input-item-title">收款人姓名</text>
  30. <input type="text" v-model="reqData.wechat_num.wechat_num1" placeholder="请输入收款人姓名" />
  31. </view>
  32. <view class="input-item">
  33. <text class="input-item-title">微信账号</text>
  34. <input type="text" v-model="reqData.wechat_num.wechat_num" placeholder="请输入微信账号" />
  35. </view>
  36. </view>
  37. <view v-if="type == 'wechat'" class="upload-box">
  38. <text class="upload-box-title">微信收款码</text>
  39. <view class="img-box" @click="choose_img_upload"><image :src="reqData.wechat_num.wechat_img_url || '../../static/bg/upload-icon.png'" mode="aspectFit"></image></view>
  40. </view> -->
  41. <!-- 银行卡绑定 -->
  42. <view class="item" v-if="type == 'bank'">
  43. <view class="input-item">
  44. <text class="input-item-title">姓名</text>
  45. <input type="text" v-model="reqData.bank_name" placeholder="请输入姓名" />
  46. </view>
  47. <view class="input-item">
  48. <text class="input-item-title">银行名称</text>
  49. <input type="text" v-model="reqData.bank_name" placeholder="例:中国工商银行" />
  50. </view>
  51. <view class="input-item">
  52. <text class="input-item-title">开户支行</text>
  53. <input type="text" v-model="reqData.open_bank" placeholder="请输入开户支行" />
  54. </view>
  55. <view class="input-item">
  56. <text class="input-item-title">银行卡号</text>
  57. <input type="number" v-model="reqData.bank_num" placeholder="请输入银行卡号" />
  58. </view>
  59. </view>
  60. <view class="btn-box"><u-button color="#ED742F" ref="confirmBtn" text="确认" @click="submitClickEvent"></u-button></view>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. flag:'-1',
  68. type: 'alipay',
  69. loaded: false,
  70. reqData: {}
  71. };
  72. },
  73. onLoad(options) {
  74. this.flag=options.flag||'-1';
  75. this.loadData();
  76. this.loaded = true;
  77. },
  78. methods: {
  79. /**
  80. * 请求数据只是为了代码不那么乱
  81. * 分次请求未作整合
  82. */
  83. async loadData() {
  84. // type 类型: 1=支付宝 2=银行卡
  85. const res = await this.$api.request('/user_pay/payInfo',{
  86. type: this.type=='alipay'?1:2
  87. });
  88. if (res.code == '200') {
  89. this.loaded = true;
  90. let data = res.data;
  91. this.reqData = data;
  92. } else {
  93. this.$api.toast(res.msg);
  94. }
  95. },
  96. setTabEvent(type) {
  97. this.type = type;
  98. this.loadData();
  99. },
  100. submitClickEvent() {
  101. console.log(11,this.type == 'alipay');
  102. if (this.type == 'alipay') {
  103. this.saveAli();
  104. } else if (this.type == 'wechat') {
  105. this.saveWx();
  106. } else {
  107. this.saveBank();
  108. }
  109. },
  110. saveAli() {
  111. if (!this.reqData.alipay_name) {
  112. this.$api.toast('请输入姓名');
  113. return;
  114. }
  115. if (!this.reqData.alipay_num) {
  116. this.$api.toast('请输入支付宝账号');
  117. return;
  118. }
  119. this.setColletMoneyEvent(this.reqData);
  120. },
  121. saveWx() {
  122. let _this = this;
  123. if (!_this.reqData.wechat_num.wechat_num) {
  124. _this.$api.toast('请输入微信账号');
  125. return;
  126. }
  127. _this.setColletMoneyEvent(_this.reqData.wechat_num);
  128. },
  129. saveBank() {
  130. if (!this.reqData.bank_num) {
  131. this.$api.toast('请输入银行卡号');
  132. return;
  133. } else if (!this.reqData.open_bank) {
  134. this.$api.toast('请输入开户行名称');
  135. return;
  136. } else if (!this.reqData.bank_name) {
  137. this.$api.toast('请输入姓名');
  138. // return;
  139. // }else if (!this.reqData.bank_sub) {
  140. // this.$api.toast('请输入支行名称');
  141. return;
  142. }
  143. this.setColletMoneyEvent(this.reqData);
  144. },
  145. async setColletMoneyEvent(data) {
  146. let num = this.type == 'alipay' ? 1 : 2; // 2:银行卡 1:支付宝
  147. const res = await this.$api.request('/user_pay/setPay', {
  148. type: num,
  149. ...data
  150. });
  151. if (res.code == '200') {
  152. this.$api.toast(res.msg);
  153. setTimeout(() => {
  154. uni.navigateBack();
  155. }, 800);
  156. } else {
  157. this.$api.toast(res.msg);
  158. }
  159. },
  160. }
  161. };
  162. </script>
  163. <style>
  164. page {
  165. background-color: #f5f5f5;
  166. }
  167. </style>
  168. <style lang="scss" scoped>
  169. .container {
  170. width: 100%;
  171. height: auto;
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. padding-top: 20rpx;
  176. opacity: 0;
  177. transition: opacity 0.2s;
  178. &.show {
  179. opacity: 1;
  180. }
  181. .tabs {
  182. width: 100%;
  183. height: 100rpx;
  184. background-color: #ffffff;
  185. .tab-item {
  186. flex: 1;
  187. height: 100rpx;
  188. font-size: 32rpx;
  189. color: #333;
  190. border-bottom: 1rpx solid #fff;
  191. &.on {
  192. border-bottom: 1rpx solid #ff2200;
  193. color: #ff2200;
  194. }
  195. }
  196. }
  197. .item {
  198. width: 100%;
  199. height: auto;
  200. padding: 30rpx 30rpx 0;
  201. background-color: #ffffff;
  202. .input-item {
  203. width: 100%;
  204. height: 100rpx;
  205. display: flex;
  206. align-items: center;
  207. border-bottom: 1px solid #eeeeee;
  208. &:last-child {
  209. border-bottom: none;
  210. }
  211. .input-item-title {
  212. font-size: 32rpx;
  213. color: #333;
  214. }
  215. input {
  216. text-align: right;
  217. flex: 1;
  218. font-size: 32rpx;
  219. color: #333;
  220. }
  221. }
  222. }
  223. }
  224. .upload-box {
  225. width: 750rpx;
  226. height: 414rpx;
  227. background-color: #ffffff;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. .upload-box-title {
  232. width: 100%;
  233. padding: 30rpx;
  234. font-size: 32rpx;
  235. color: #333;
  236. }
  237. .img-box {
  238. width: 430rpx;
  239. height: 270rpx;
  240. background-color: #d8d8d8;
  241. border-radius: 4rpx;
  242. margin-top: 10rpx;
  243. image {
  244. width: 100%;
  245. height: 100%;
  246. }
  247. }
  248. }
  249. .btn-box {
  250. margin-top: 60rpx;
  251. width: 100%;
  252. height: auto;
  253. padding: 0 30rpx;
  254. }
  255. </style>