password.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="main" v-if="formData.id>0">
  3. <u-form labelPosition="left" :model="formData" ref="form" :labelWidth="'178rpx'">
  4. <u-form-item :label="lang.account" prop="formData.username">
  5. <u-input v-model="formData.username" :disabled="true"></u-input>
  6. </u-form-item>
  7. <u-form-item :label="lang.password" prop="formData.password">
  8. <u-input v-model="formData.password" :placeholder="lang.input_new_password"></u-input>
  9. </u-form-item>
  10. <u-form-item :label="lang.confirm_password" prop="formData.confirm_password">
  11. <u-input v-model="formData.confirm_password" :placeholder="lang.input_confirm_password">
  12. </u-input>
  13. </u-form-item>
  14. <u-form-item :label-position="labelPosition" :label="lang.verify_code" prop="code" label-width="120">
  15. <u-input :border="border" v-model="formData.code" :placeholder="lang.verify_code" type="text"></u-input>
  16. <u-toast ref="uToast"></u-toast>
  17. <u-verification-code :keep-running="true" :seconds="seconds" @end="end" @start="start" ref="uCode"
  18. @change="codeChange" :startText="startText" :changeText="changeText" :endText="endText">
  19. </u-verification-code>
  20. <u-button slot="right" class="send-code" type="primary" size="mini" @click="sendCode()">{{tips}}
  21. </u-button>
  22. </u-form-item>
  23. </u-form>
  24. <view class="u-form-submit">
  25. <u-button class="btn" @click="submit">{{lang.confirm_modify}}</u-button>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. seconds: 60,
  34. codeTips: '',
  35. tips: '',
  36. border: false,
  37. labelPosition: 'left',
  38. startText: '获取',
  39. changeText: 'X秒获取',
  40. endText: '重新获取',
  41. formData: {
  42. id: 0,
  43. username: '',
  44. password: '',
  45. confirm_password: '',
  46. password: '',
  47. code: '',
  48. },
  49. }
  50. },
  51. onLoad(options) {
  52. this.getInfo()
  53. },
  54. methods: {
  55. start() {
  56. console.log('开始')
  57. },
  58. end() {
  59. console.log('结束')
  60. },
  61. // 获取验证码
  62. codeChange(text) {
  63. this.tips = text;
  64. },
  65. sendCode() {
  66. console.log(this.formData.username)
  67. if (this.formData.username == '') {
  68. this.$u.toast(this.lang.account_error)
  69. return false;
  70. }
  71. console.log(444)
  72. if (this.$refs.uCode.canGetCode) {
  73. // 模拟向后端请求验证码
  74. uni.showLoading({
  75. title: '正在获取验证码'
  76. })
  77. setTimeout(() => {
  78. uni.hideLoading();
  79. // 通知验证码组件内部开始倒计时
  80. this.$refs.uCode.start();
  81. this.$request.send('/api/sendmsm', {
  82. username: this.formData.username,
  83. scene: 'password'
  84. }, 'POST').then(res => {
  85. //提示是否发送成功
  86. if (res.success) {
  87. this.$u.toast(res.msg);
  88. setTimeout(function() {
  89. _this.gotoPage('/pages/login/login')
  90. }, 800)
  91. } else {
  92. this.$u.toast(res.msg);
  93. this.textChange(0)
  94. }
  95. })
  96. }, 2000);
  97. } else {
  98. this.$u.toast('请不要频繁发送');
  99. }
  100. },
  101. secondsChange(index) {
  102. this.seconds = index == 0 ? 60 : index == 1 ? 10 : 5;
  103. },
  104. textChange(index) {
  105. if (index == 0) {
  106. this.startText = '点一下获取';
  107. this.changeText = '重新获取Xs';
  108. this.endText = '再次获取'
  109. } else {
  110. this.startText = '获取';
  111. this.changeText = 'X秒获取';
  112. this.endText = '重新获取'
  113. }
  114. },
  115. // 获取收款方式详情
  116. getInfo() {
  117. let _this = this;
  118. this.$request.sendToken('/api/user/info', {}, 'POST').then(res => {
  119. this.loaded = true;
  120. if (res.success == true) {
  121. _this.formData.id = res.data.id;
  122. _this.formData.username = res.data.username;
  123. } else {
  124. this.$u.toast(res.msg);
  125. }
  126. })
  127. },
  128. // 提交
  129. submit() {
  130. let _this = this;
  131. if (this.formData.password == '') {
  132. this.$u.toast(this.lang.input_new_password)
  133. return false;
  134. }
  135. if (this.formData.confirm_password == '') {
  136. this.$u.toast(this.lang.input_confirm_password)
  137. return false;
  138. }
  139. if (this.formData.confirm_password != this.formData.password) {
  140. this.$u.toast(this.lang.confirm_password_error)
  141. return false;
  142. }
  143. if (this.formData.code == '') {
  144. this.$u.toast(this.lang.input_code)
  145. return false;
  146. }
  147. // 修改
  148. uni.showModal({
  149. title: this.lang.confirm_title,
  150. content: this.lang.cofirm_set_password,
  151. cancelText: this.lang.cancel,
  152. confirmText: this.lang.confirm,
  153. success: function(res) {
  154. if (res.confirm == true) {
  155. this.$request.sendToken('/api/user/modify', this.formData, 'POST').then(res => {
  156. this.loaded = true;
  157. if (res.success == true) {
  158. this.$u.toast(res.msg);
  159. setTimeout(function() {
  160. uni.navigateBack({
  161. delta: 1
  162. })
  163. }, 2000)
  164. } else {
  165. this.$u.toast(res.msg);
  166. }
  167. })
  168. }
  169. }
  170. });
  171. },
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .main {
  177. margin: 19rpx 28rpx 38rpx;
  178. color: #6e6c6b;
  179. .u-form {
  180. margin-top: 28rpx;
  181. background-color: #2c2b2b;
  182. border-radius: 10rpx;
  183. .u-form-item {
  184. padding: 20rpx;
  185. color: #bb955e !important;
  186. .u-form-item__body {
  187. .u-btn--primary {
  188. background-color: #bb955e;
  189. }
  190. .u-input {
  191. color: #6e6c6b !important;
  192. uni-input {
  193. color: #6e6c6b !important;
  194. }
  195. }
  196. }
  197. }
  198. .u-form-item:last-child {
  199. border: none;
  200. }
  201. .u-border-bottom:after {
  202. border-color: rgba(249, 244, 241, 0.32);
  203. }
  204. .u-border-bottom:last-child:after {
  205. border-color: transparent;
  206. }
  207. }
  208. .u-radio-group {
  209. color: #6e6c6b !important;
  210. }
  211. .u-form-submit {
  212. margin-top: 56rpx;
  213. border-radius: 10rpx;
  214. padding-bottom: 28rpx;
  215. .u-btn {
  216. border: 2rpx solid #bb955e;
  217. background-color: #2c2b2b;
  218. padding: 10rpx 22rpx;
  219. color: #bb955e;
  220. height: auto;
  221. }
  222. .u-default-hover {
  223. border: 2rpx solid #bb955e !important;
  224. background-color: #222323 !important;
  225. padding: 10rpx 22rpx;
  226. color: #bb955e !important;
  227. height: auto;
  228. }
  229. }
  230. .u-switch--on {
  231. background-color: #22a01a !important;
  232. // background-color: #bb955e !important;
  233. }
  234. }
  235. </style>