bindCompanyUser.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="content">
  3. <image v-if="isBind" src="https://cos.his.cdwjyyh.com/fs/20250414/3da41caccf8346b188809fac656ba834.jpg" mode="widthFix"></image>
  4. <view v-if="!isBind" class="bindbox">{{msg}}</view>
  5. <!-- <view class="bindbox">
  6. <image :src="baseUrl + '/images/bindComUser.png'" mode="aspectFill"></image>
  7. <view>立即绑定,享受更多权益</view>
  8. </view>
  9. <button class="bind-btn" :loading="btnLodaing" :disabled="btnLodaing" @click="handleBind">立即绑定</button> -->
  10. </view>
  11. </template>
  12. <script>
  13. import {getUserInfo} from '@/api/user.js'
  14. import { bindCompanyFsUser } from '@/api/companyUser.js'
  15. export default {
  16. data() {
  17. return {
  18. isBind: false,
  19. msg: '绑定中...',
  20. baseUrl:uni.getStorageSync('requestPath'),
  21. btnLodaing: false,
  22. companyUserId: '',
  23. }
  24. },
  25. onLoad(option) {
  26. let obj = {}
  27. if(option.q) {
  28. let url = decodeURIComponent(option.q) // 获取到二维码原始链接内容
  29. // // 对url中携带的参数提取处理
  30. obj = this.$urlToObj(url)
  31. }
  32. this.companyUserId = obj.companyUserId || option.companyUserId
  33. },
  34. onShow() {
  35. if(!this.isBind) {
  36. const historyApp = uni.getStorageSync('historyApp') || '';
  37. if(historyApp) {
  38. this.handleBind()
  39. } else {
  40. this.getUser()
  41. }
  42. } else {
  43. this.msg = '已绑定或已经存在绑定关系'
  44. }
  45. },
  46. methods: {
  47. getUser() {
  48. uni.showLoading({
  49. title: '绑定中...'
  50. })
  51. getUserInfo().then(
  52. res => {
  53. if(res.code==200){
  54. if(res.user!=null){
  55. if(res.user.historyApp) {
  56. uni.setStorageSync('historyApp',res.user.historyApp)
  57. this.handleBind()
  58. } else {
  59. uni.hideLoading()
  60. uni.redirectTo({
  61. url: '/pages_user/downApp'
  62. })
  63. }
  64. }
  65. else{
  66. uni.hideLoading()
  67. this.utils.loginOut();
  68. }
  69. }else{
  70. uni.hideLoading()
  71. uni.showToast({
  72. icon:'none',
  73. title: "请求失败",
  74. });
  75. }
  76. },
  77. rej => {}
  78. ).catch(()=>{
  79. uni.hideLoading()
  80. });
  81. },
  82. handleBind() {
  83. uni.showLoading({
  84. title: '绑定中...'
  85. })
  86. this.msg = '绑定中...'
  87. this.$isLogin().then(
  88. res => {
  89. if(res){
  90. this.submit();
  91. }
  92. else{
  93. uni.hideLoading()
  94. uni.navigateTo({
  95. url:'/pages/auth/login'
  96. })
  97. }
  98. }
  99. ).catch(()=>{
  100. this.msg = '绑定失败'
  101. uni.hideLoading()
  102. });
  103. },
  104. submit() {
  105. this.btnLodaing = true
  106. uni.showLoading({
  107. title: '绑定中...'
  108. })
  109. bindCompanyFsUser(this.companyUserId).then(res=>{
  110. this.btnLodaing = false
  111. uni.hideLoading()
  112. if(res.code == 200) {
  113. this.isBind = true
  114. this.msg = '绑定成功'
  115. uni.showToast({
  116. title: res.msg,
  117. icon: 'none'
  118. })
  119. }else {
  120. if(res.msg=="已存在绑定关系") {
  121. this.isBind = true
  122. this.msg = '绑定成功'
  123. uni.showToast({
  124. title: '绑定成功',
  125. icon: 'none'
  126. })
  127. } else {
  128. this.msg = res.msg
  129. this.isBind = false
  130. uni.showToast({
  131. title: res.msg,
  132. icon: 'none'
  133. })
  134. }
  135. }
  136. }).catch(()=>{
  137. this.msg = '绑定失败'
  138. this.isBind = false
  139. this.btnLodaing = false
  140. uni.hideLoading()
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .bindbox {
  148. display: flex;
  149. flex-direction: column;
  150. align-items: center;
  151. justify-content: center;
  152. padding-top: 20vh;
  153. font-family: PingFang SC, PingFang SC;
  154. font-weight: 400;
  155. font-size: 32rpx;
  156. color: #757575;
  157. image {
  158. height: 150rpx;
  159. width: 150rpx;
  160. margin-bottom: 50rpx;
  161. }
  162. }
  163. .content {
  164. width: 100%;
  165. display: flex;
  166. flex-direction: column;
  167. align-items: center;
  168. }
  169. .bind-btn {
  170. margin: 20vh auto 20px auto;
  171. width: 300px;
  172. height: 44px;
  173. line-height: 44px;
  174. text-align: center;
  175. background: #FF5C03 !important;
  176. color: #fff !important;
  177. font-size: 16px;
  178. font-weight: 500;
  179. border-radius: 22px;
  180. display: block;
  181. &:after {
  182. border: none;
  183. }
  184. }
  185. </style>