account.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.text }}</view>
  5. </view>
  6. <swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
  7. <swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
  8. <view class="row b-b">
  9. <text class="tit">姓名</text>
  10. <input class="input" v-model="tabItem.orderList.name" type="text" placeholder="提款人姓名" placeholder-class="placeholder" />
  11. </view>
  12. <view class="row b-b">
  13. <text class="tit">{{ tabIndex == 0 ? '账号' : '银行卡号' }}</text>
  14. <input class="input" v-model="tabItem.orderList.code" type="text" placeholder="请输入账号" placeholder-class="placeholder" />
  15. </view>
  16. <view class="row b-b" v-if="tabIndex == 1">
  17. <text class="tit">所属银行</text>
  18. <input class="input" v-model="tabItem.orderList.bankName" type="text" placeholder="请输入所属银行" placeholder-class="placeholder" />
  19. </view>
  20. </swiper-item>
  21. </swiper>
  22. <button class="add-btn up" @click="confirm">提交申请</button>
  23. </view>
  24. </template>
  25. <script>
  26. import { aliInfo, bankInfo, setAliInfo, setBankInfo } from '@/api/wallet.js';
  27. import { edit } from '@/api/user.js';
  28. import { mapState, mapMutations } from 'vuex';
  29. import { orderData, getUserInfo,service } from '@/api/user.js';
  30. export default {
  31. data() {
  32. return {
  33. tabCurrentIndex: 0,
  34. navList: [
  35. {
  36. state: 0,
  37. text: '支付宝',
  38. loadingType: 'more',
  39. orderList: {
  40. name: '',
  41. code: '',
  42. id: ''
  43. }
  44. },
  45. {
  46. state: 1,
  47. text: '银行卡',
  48. loadingType: 'more',
  49. orderList: {
  50. name: '',
  51. code: '',
  52. bankName: '',
  53. id: ''
  54. }
  55. }
  56. ]
  57. };
  58. },
  59. computed: {
  60. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  61. },
  62. onLoad(options) {
  63. this.tabCurrentIndex = +options.state || 0;
  64. console.log(this.userInfo,'123456')
  65. if(this.userInfo.alipay_code != null){
  66. this.navList[0].orderList.code = this.userInfo.alipay_code
  67. }
  68. if(this.userInfo.alipay_name != null){
  69. this.navList[0].orderList.name = this.userInfo.alipay_name
  70. }
  71. if(this.userInfo.bank_code != null){
  72. this.navList[1].orderList.code = this.userInfo.bank_code
  73. }
  74. if(this.userInfo.bank_name != null){
  75. this.navList[1].orderList.bankName = this.userInfo.bank_name
  76. }
  77. if(this.userInfo.bank_user_name != null){
  78. this.navList[1].orderList.name = this.userInfo.bank_user_name
  79. }
  80. // this.loadAli();
  81. // this.loadBank();
  82. },
  83. methods: {
  84. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  85. //加载数据
  86. loadAli(source) {
  87. aliInfo({}).then(({ data }) => {
  88. let order = this.navList[0].orderList;
  89. this.$set(order, 'name', data.fullname);
  90. this.$set(order, 'code', data.alino);
  91. this.$set(order, 'id', data.id);
  92. });
  93. },
  94. loadBank() {
  95. bankInfo({}).then(({ data }) => {
  96. let order = this.navList[1].orderList;
  97. this.$set(order, 'name', data.fullname);
  98. this.$set(order, 'code', data.bankno);
  99. this.$set(order, 'bankName', data.bank);
  100. this.$set(order, 'id', data.id);
  101. });
  102. },
  103. //swiper 切换
  104. changeTab(e) {
  105. this.tabCurrentIndex = e.target.current;
  106. },
  107. //顶部tab点击
  108. tabClick(index) {
  109. this.tabCurrentIndex = index;
  110. },
  111. // 提交保存
  112. confirm() {
  113. let obj = this;
  114. let arr = obj.navList[obj.tabCurrentIndex].orderList;
  115. console.log(arr);
  116. let pages = getCurrentPages(); //获取所有页面栈实例列表
  117. console.log(pages);
  118. let nowPage = pages[pages.length - 1]; //当前页页面实例
  119. let prevPage = pages[pages.length - 2]; //上一页页面实例
  120. console.log(prevPage);
  121. // prevPage.$vm.sh = 100; //修改上一页data里面的sh参数值为100
  122. if (obj.tabCurrentIndex == 1) {
  123. if (!arr.name) {
  124. return this.$api.msg('请输入提款人姓名');
  125. }
  126. if (!arr.bankName) {
  127. return this.$api.msg('请输入所属银行');
  128. }
  129. if (!arr.code) {
  130. return this.$api.msg('请输入银行卡号');
  131. }
  132. let data = {
  133. bank_user_name: arr.name,
  134. bank_name: arr.bankName,
  135. bank_code: arr.code
  136. };
  137. // // #ifdef H5
  138. // prevPage.$vm.bankData = data;
  139. // // #endif
  140. // // #ifdef MP
  141. // prevPage.setData({
  142. // bankData: data
  143. // });
  144. // // #endif
  145. edit({
  146. bank_user_name: arr.name,
  147. bank_name: arr.bankName,
  148. bank_code: arr.code
  149. }).then(e => {
  150. obj.$api.msg('修改成功');
  151. obj.getUserInfo();
  152. });
  153. // obj.setBankInfo({
  154. // fullname: arr.name,
  155. // bank: arr.bankName,
  156. // bankno: arr.code,
  157. // id:arr.id
  158. // });
  159. }
  160. if (obj.tabCurrentIndex == 0) {
  161. if (!arr.name) {
  162. return this.$api.msg('请输入提款人姓名');
  163. }
  164. if (!arr.code) {
  165. return this.$api.msg('请输入支付宝账号');
  166. }
  167. let data = {
  168. alipay_name: arr.name,
  169. alipay_code: arr.code
  170. };
  171. // // #ifdef H5
  172. // prevPage.$vm.aliData = data;
  173. // // #endif
  174. // // #ifdef MP
  175. // prevPage.setData({
  176. // bankData: data
  177. // });
  178. // // #endif
  179. console.log(111);
  180. edit({
  181. alipay_name: arr.name,
  182. alipay_code: arr.code
  183. })
  184. .then(e => {
  185. console.log(e, '123456');
  186. obj.$api.msg('修改成功');
  187. obj.getUserInfo();
  188. })
  189. .catch(e => {
  190. console.log(e);
  191. });
  192. // obj.setAliInfo({
  193. // fullname: arr.name,
  194. // alino: arr.code,
  195. // id:arr.id
  196. // });
  197. }
  198. },
  199. // 更新用户信息
  200. getUserInfo() {
  201. getUserInfo({})
  202. .then(({ data }) => {
  203. console.log(data)
  204. this.setUserInfo(data);
  205. // 获取用户数据完毕后在获取订单数据防止多次跳转到登录页
  206. orderData({})
  207. .then(({ data }) => {
  208. this.setOrderInfo(data);
  209. uni.navigateBack({
  210. delta: 1
  211. });
  212. })
  213. .catch(e => {
  214. this.setOrderInfo({
  215. complete_count: 0, //完成
  216. received_count: 0, //待收货
  217. unshipped_count: 0, //待发货
  218. order_count: 0, //订单总数
  219. unpaid_count: 0 //待付款
  220. });
  221. });
  222. })
  223. .catch(e => {
  224. console.log(e);
  225. });
  226. },
  227. /* 保存银行卡详细 */
  228. // setBankInfo(obj) {
  229. // setBankInfo(obj)
  230. // .then(e => {
  231. // uni.showToast({
  232. // title: '修改成功',
  233. // duration: 2000,
  234. // position: 'top'
  235. // });
  236. // this.$api.prePage().dataUp();
  237. // setTimeout(() => {
  238. // uni.navigateBack();
  239. // }, 1500);
  240. // })
  241. // .catch(e => {
  242. // console.log(e);
  243. // });
  244. // },
  245. // // 修改支付宝信息
  246. // setAliInfo(obj) {
  247. // setAliInfo(obj)
  248. // .then(e => {
  249. // uni.showToast({
  250. // title: '修改成功',
  251. // duration: 2000,
  252. // position: 'top'
  253. // });
  254. // this.$api.prePage().dataUp();
  255. // setTimeout(() => {
  256. // uni.navigateBack();
  257. // }, 1500);
  258. // })
  259. // .catch(e => {
  260. // console.log(e);
  261. // });
  262. // }
  263. }
  264. };
  265. </script>
  266. <style lang="scss">
  267. .row {
  268. display: flex;
  269. align-items: center;
  270. position: relative;
  271. padding: 0 30rpx;
  272. height: 110rpx;
  273. background: #fff;
  274. .tit {
  275. flex-shrink: 0;
  276. width: 120rpx;
  277. font-size: 30rpx;
  278. color: $font-color-dark;
  279. }
  280. .input {
  281. flex: 1;
  282. font-size: 30rpx;
  283. color: $font-color-dark;
  284. }
  285. .iconlocation {
  286. font-size: 36rpx;
  287. color: $font-color-light;
  288. }
  289. }
  290. page,
  291. .content {
  292. background: $page-color-base;
  293. height: 100%;
  294. }
  295. .swiper-box {
  296. height: 750rpx;
  297. }
  298. .navbar {
  299. display: flex;
  300. height: 40px;
  301. padding: 0 5px;
  302. background: #fff;
  303. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  304. position: relative;
  305. z-index: 10;
  306. .nav-item {
  307. flex: 1;
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. height: 100%;
  312. font-size: 15px;
  313. color: $font-color-dark;
  314. position: relative;
  315. &.current {
  316. color: $base-color;
  317. &:after {
  318. content: '';
  319. position: absolute;
  320. left: 50%;
  321. bottom: 0;
  322. transform: translateX(-50%);
  323. width: 44px;
  324. height: 0;
  325. border-bottom: 2px solid $base-color;
  326. }
  327. }
  328. }
  329. }
  330. .add-btn {
  331. &.up {
  332. background-color: $base-color;
  333. color: #fff;
  334. }
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. width: 690rpx;
  339. height: 80rpx;
  340. margin: 0 auto;
  341. margin-top: 30rpx;
  342. font-size: $font-lg;
  343. border-radius: 10rpx;
  344. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  345. }
  346. </style>