AccountSet.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false"><view class="div member-account-set" v-if="user">
  3. <view class="div common-header-wrap">
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="common-header-holder"></view>
  6. <view class="common-header-fixed">
  7. <title-header />
  8. <uni-nav-bar title="账号设置" class="common-header" left-icon="back" @clickLeft="goBack()">
  9. </uni-nav-bar>
  10. </view>
  11. </view>
  12. <view class="div main-content">
  13. <view class="div menu-list">
  14. <view class="div" v-show="(user.member_mobilebind && user.member_mobile) || (user.member_emailbind && user.member_email)" @click='popupVisible("password")'>
  15. <flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">修改登录密码</text></flex-line>
  16. </view>
  17. <view class="div" v-show="(user.member_mobilebind && user.member_mobile) || (user.member_emailbind && user.member_email)" @click='popupVisible("paypwd")'>
  18. <flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">修改支付密码</text></flex-line>
  19. </view>
  20. <view class="div" @click='popupVisible("mobile")'>
  21. <flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">{{(user.member_mobilebind?'修改':'绑定')+'手机'}}</text><text class="span" slot="right">{{user.member_mobile}}</text></flex-line>
  22. </view>
  23. <view class="div" @click='popupVisible("email")'>
  24. <flex-line class="menu-item" :is-link="true" :show-border="true"><text class="span line-name">{{(user.member_emailbind?'修改':'绑定')+'邮箱'}}</text><text class="span" slot="right">{{user.member_email}}</text></flex-line>
  25. </view>
  26. </view>
  27. <view class="div pt-10 pb-10">
  28. <view class="div common-btn ds-button-large" @click="_logout">退出登录</view>
  29. </view>
  30. </view>
  31. <!--修改手机-->
  32. <uni-popup background-color="#fff" ref="editMobileVisible" type="right" >
  33. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  34. <view class="div common-header-wrap">
  35. <view :style="'height:'+navHeight+'px'"></view>
  36. <view class="common-header-holder"></view>
  37. <view class="common-header-fixed">
  38. <title-header />
  39. <uni-nav-bar :title="(user.member_mobilebind?'修改':'绑定')+'手机'" class="common-header" left-icon="back" @clickLeft="hidePopup('editMobileVisible')">
  40. </uni-nav-bar>
  41. </view>
  42. </view>
  43. <view class="div common-popup-content">
  44. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">手机</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="mobile" type="number" :attr="{ oninput: 'if(value.length>11)value=value.slice(0,11)' }" /></view></flex-line>
  45. <flex-line class="field-line" :show-border="true"><text class="span field-name">验证码</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="verifyCodeMobile" type="number" :attr="{ oninput: 'if(value.length>6)value=value.slice(0,6)' }" /><view @click="sendVerifyCodeMobile" class="div common-btn send-btn">{{sendStateTextMobile}}</view></view></flex-line>
  46. <view class="div common-btn ds-button-large mt-10" @click='updateMobile' >提交</view>
  47. </view>
  48. </view>
  49. </uni-popup>
  50. <!--修改邮箱-->
  51. <uni-popup background-color="#fff" ref="editEmailVisible" type="right" >
  52. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  53. <view class="div common-header-wrap">
  54. <view :style="'height:'+navHeight+'px'"></view>
  55. <view class="common-header-holder"></view>
  56. <view class="common-header-fixed">
  57. <title-header />
  58. <uni-nav-bar :title="(user.member_emailbind?'修改':'绑定')+'邮箱'" class="common-header" left-icon="back" @clickLeft="hidePopup('editEmailVisible')">
  59. </uni-nav-bar>
  60. </view>
  61. </view>
  62. <view class="div common-popup-content">
  63. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  64. <view class="main-content">
  65. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">邮箱</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="email" /></view></flex-line>
  66. <view class="div common-btn ds-button-large mt-10" @click="sendVerifyCodeEmail">提交</view>
  67. </view>
  68. </scroll-view>
  69. </view>
  70. </view>
  71. </uni-popup>
  72. <!--修改登录密码-->
  73. <uni-popup background-color="#fff" ref="editPasswordVisible" type="right" >
  74. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  75. <view class="div common-header-wrap">
  76. <view :style="'height:'+navHeight+'px'"></view>
  77. <view class="common-header-holder"></view>
  78. <view class="common-header-fixed">
  79. <title-header />
  80. <uni-nav-bar title="修改登录密码" class="common-header" left-icon="back" @clickLeft="hidePopup('editPasswordVisible')">
  81. </uni-nav-bar>
  82. </view>
  83. </view>
  84. <view class="div common-popup-content">
  85. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  86. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">新密码</text><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="password1" /></view></flex-line>
  87. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">确认密码</text><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="password2" /></view></flex-line>
  88. <view class="div common-btn ds-button-large mt-10" @click='updatePassword' >提交</view>
  89. </scroll-view>
  90. </view>
  91. </view>
  92. </uni-popup>
  93. <!--修改支付密码-->
  94. <uni-popup background-color="#fff" ref="editPaypwdVisible" type="right" >
  95. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  96. <view class="div common-header-wrap">
  97. <view :style="'height:'+navHeight+'px'"></view>
  98. <view class="common-header-holder"></view>
  99. <view class="common-header-fixed">
  100. <title-header />
  101. <uni-nav-bar title="修改支付密码" class="common-header" left-icon="back" @clickLeft="hidePopup('editPaypwdVisible')">
  102. </uni-nav-bar>
  103. </view>
  104. </view>
  105. <view class="div common-popup-content">
  106. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  107. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">新密码</text><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="paypwd1" /></view></flex-line>
  108. <flex-line class="field-line menu-item" :show-border="true"><text class="span field-name">确认密码</text><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="paypwd2" /></view></flex-line>
  109. <view class="div common-btn ds-button-large mt-10" @click="updatePaypwd">提交</view>
  110. </scroll-view>
  111. </view>
  112. </view>
  113. </uni-popup>
  114. <uni-popup background-color="#fff" ref="sendAuthCode" type="right" >
  115. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  116. <view class="div common-header-wrap">
  117. <view :style="'height:'+navHeight+'px'"></view>
  118. <view class="common-header-holder"></view>
  119. <view class="common-header-fixed">
  120. <title-header />
  121. <uni-nav-bar title="身份验证" class="common-header" left-icon="back" @clickLeft="hidePopup('sendAuthCode')">
  122. </uni-nav-bar>
  123. </view>
  124. </view>
  125. <view class="div common-popup-content">
  126. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  127. <common-send-code @checkSuccess="checkSuccess" />
  128. </scroll-view>
  129. </view>
  130. </view>
  131. </uni-popup>
  132. </view></member-base>
  133. </template>
  134. <script>
  135. import {getFontSize} from '@/util/common'
  136. import TitleHeader from '../../TitleHeader'
  137. import MemberBase from '../MemberBase'
  138. import { mapState, mapMutations } from 'vuex'
  139. import { logout, getMemberInfo } from '../../../api/member'
  140. import CommonSendCode from '../common/CommonSendCode'
  141. import { updateUserMobile, updateUserPassword, updateUserPaypwd, bindUserMobile, bindUserEmail } from '../../../api/memberSetting'
  142. import flexLine from '../../flexLine'
  143. export default {
  144. components:{
  145. TitleHeader,
  146. MemberBase,
  147. flexLine,
  148. CommonSendCode
  149. },
  150. name:'MemberSetting',
  151. data(){
  152. return {
  153. navHeight: 0,
  154. screenWidth:0,
  155. authType: 'mobile',
  156. paypwd1: '',
  157. paypwd2: '',
  158. mobile: '',
  159. email: '',
  160. password1: '',
  161. password2: '',
  162. verifyCodeMobile: '',
  163. canSendMobile: true,
  164. timeIntervalMobile: false,
  165. sendStateTextMobile: '发送',
  166. canSendEmail: true,
  167. timeIntervalEmail: false,
  168. sendStateTextEmail: '发送'
  169. }
  170. },
  171. beforeDestroy: function () {
  172. clearInterval(this.timeIntervalMobile)
  173. clearInterval(this.timeIntervalEmail)
  174. },
  175. created: function () {
  176. this.getMemberInfo()
  177. },
  178. computed:{
  179. fontSize(){
  180. return getFontSize()
  181. },
  182. ...mapState({
  183. user: state => state.member.info
  184. })
  185. },
  186. mounted(){
  187. // #ifdef MP-WEIXIN
  188. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  189. // #endif
  190. this.screenWidth=uni.getSystemInfoSync().screenWidth
  191. },
  192. methods:{
  193. getMemberInfo(){
  194. getMemberInfo().then(res => {
  195. this.memberUpdate({info:res.result.member_info})
  196. if (!res.result.member_info.member_emailbind) { // 如果没有绑定邮箱则输入项自动填写上次的邮箱
  197. this.email = res.result.member_info.member_email
  198. }
  199. if (!res.result.member_info.member_mobilebind) { // 如果没有绑定手机则输入项自动填写上次的手机
  200. this.mobile = res.result.member_info.member_mobile
  201. }
  202. }, error => {}
  203. )
  204. },
  205. showPopup(id){
  206. this.$refs[id].open()
  207. },
  208. hidePopup(id){
  209. this.$refs[id].close()
  210. },
  211. goBack(){uni.navigateBack({delta:1})},
  212. ...mapMutations({
  213. memberUpdate: 'memberUpdate',
  214. memberEdit: 'memberEdit',
  215. memberLogout: 'memberLogout'
  216. }),
  217. _logout () {
  218. console.log("退出登录")
  219. logout(this.user.member_name).then(res => {
  220. console.log(res)
  221. this.memberLogout()
  222. uni.navigateTo({url:'/pages/home/memberlogin/Login'})
  223. },error=> {
  224. console.log(error)
  225. uni.showToast({icon:'none',title: error.message})
  226. })
  227. },
  228. popupVisible (authType) {
  229. this.authType = authType
  230. switch (authType) {
  231. case 'mobile':
  232. if (this.user.member_mobilebind && this.user.member_mobile) { // 已绑定手机则需要验证
  233. this.showPopup('sendAuthCode')
  234. } else {
  235. this.showPopup('editMobileVisible')
  236. }
  237. break
  238. case 'email':
  239. if (this.user.member_emailbind && this.user.member_email) { // 已绑定邮箱则需要验证
  240. this.showPopup('sendAuthCode')
  241. } else {
  242. this.showPopup('editEmailVisible')
  243. }
  244. break
  245. case 'password':
  246. this.showPopup('sendAuthCode')
  247. break
  248. case 'paypwd':
  249. this.showPopup('sendAuthCode')
  250. break
  251. }
  252. },
  253. checkSuccess () {
  254. this.hidePopup('sendAuthCode')
  255. switch (this.authType) {
  256. case 'mobile':
  257. this.showPopup('editMobileVisible')
  258. break
  259. case 'email':
  260. this.showPopup('editEmailVisible')
  261. break
  262. case 'password':
  263. this.showPopup('editPasswordVisible')
  264. break
  265. case 'paypwd':
  266. this.showPopup('editPaypwdVisible')
  267. break
  268. }
  269. },
  270. // 更改绑定手机号
  271. updateMobile () {
  272. updateUserMobile(this.verifyCodeMobile).then(res => {
  273. this.memberEdit({ member_mobile: this.mobile, member_mobilebind: 1 })
  274. uni.showToast({icon:'none',title: res.message})
  275. this.getMemberInfo()
  276. this.hidePopup('editMobileVisible')
  277. }).catch(function (error) {
  278. uni.showToast({icon:'none',title: error.message})
  279. })
  280. },
  281. // 更改登录密码
  282. updatePassword () {
  283. updateUserPassword(this.password1, this.password2).then(res => {
  284. uni.showToast({icon:'none',title: res.message})
  285. this.getMemberInfo()
  286. this.hidePopup('editPasswordVisible')
  287. }).catch(function (error) {
  288. uni.showToast({icon:'none',title: error.message})
  289. })
  290. },
  291. // 更改支付密码
  292. updatePaypwd () {
  293. updateUserPaypwd(this.paypwd1, this.paypwd2).then(res => {
  294. uni.showToast({icon:'none',title: res.message})
  295. this.getMemberInfo()
  296. this.hidePopup('editPaypwdVisible')
  297. }).catch(function (error) {
  298. uni.showToast({icon:'none',title: error.message})
  299. })
  300. },
  301. // 发送手机验证码
  302. sendVerifyCodeMobile () {
  303. if (!this.canSendMobile) {
  304. return
  305. }
  306. bindUserMobile(this.mobile).then(res => {
  307. this.memberEdit({ member_mobile: this.mobile, member_mobilebind: 0 })
  308. this.canSendMobile = false
  309. let second = 60
  310. uni.showToast({icon:'none',title: res.message})
  311. let _this = this
  312. this.timeIntervalMobile = setInterval(function () {
  313. if (second <= 0) {
  314. _this.canSendMobile = true
  315. _this.sendStateTextMobile = '发送'
  316. clearInterval(_this.timeIntervalMobile)
  317. }else{
  318. _this.sendStateTextMobile = second + 's'
  319. }
  320. second--
  321. }, 1000)
  322. }).catch(function (error) {
  323. uni.showToast({icon:'none',title: error.message})
  324. })
  325. },
  326. // 发送邮箱验证码
  327. sendVerifyCodeEmail () {
  328. if (!this.canSendEmail) {
  329. return
  330. }
  331. bindUserEmail(this.email).then(res => {
  332. this.memberEdit({ member_email: this.email, member_emailbind: 0 })
  333. this.canSendEmail = false
  334. let second = 60
  335. uni.showToast({icon:'none',title: res.message})
  336. let _this = this
  337. this.timeIntervalEmail = setInterval(function () {
  338. if (second <= 0) {
  339. _this.canSendEmail = true
  340. _this.sendStateTextEmail = '发送'
  341. clearInterval(_this.timeIntervalEmail)
  342. }else{
  343. _this.sendStateTextEmail = second + 's'
  344. }
  345. second--
  346. }, 1000)
  347. }).catch(function (error) {
  348. uni.showToast({icon:'none',title: error.message})
  349. })
  350. }
  351. }
  352. }
  353. </script>
  354. <style lang="scss" scoped>
  355. .main-content{background: #fff;padding:0 $pageSpace}
  356. .common-popup-content{padding:0 $pageSpace;box-sizing: border-box}
  357. .send-btn{border:1px solid $primaryColor;color:$primaryColor;min-width: 2rem}
  358. .member-account-set {position:relative;z-index:100;
  359. .menu-list{
  360. .menu-item {
  361. .right-arrow{transform: rotate(-90deg);color:#ddd;font-size:$fontSize;}
  362. }
  363. }
  364. }
  365. </style>