initBind.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="repairEntrance">
  3. <view class="info page_padding">
  4. <view class="info_text">
  5. <view class="text_left text_justify">您还没有绑定工号,请填写您的工号进行绑定。</view>
  6. </view>
  7. <view class="info_form">
  8. <view class="info_form_item">
  9. <label for="account" class="label"><text class="required newicon newicon-bitian"></text>工号:</label>
  10. <uni-easyinput class="flex1" v-model="postData.account" placeholder="请输入工号" focus
  11. :styles="{borderColor: !postData.account.trim() && isSubmit ? '#f00' : ''}" :primaryColor="primaryColor" />
  12. </view>
  13. </view>
  14. </view>
  15. <view class="foot_common_btns">
  16. <button @click="bind" type="default" class="primaryButton btn">绑定</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup>
  21. import { onLoad } from '@dcloudio/uni-app'
  22. import { api_bindAccount } from "@/http/api.js"
  23. import { defaultColor } from '@/static/js/theme.js'
  24. import { reactive, ref } from 'vue'
  25. import { useWechatAuth } from '@/share/useWechatAuth.js'
  26. import { useSetTitle } from '@/share/useSetTitle.js'
  27. useSetTitle()
  28. const { wechatAuth } = useWechatAuth()
  29. // 数据
  30. const postData = reactive({
  31. account: '',
  32. })
  33. // 传参
  34. const options = reactive({
  35. wechat: '',
  36. })
  37. // easyinput颜色
  38. const primaryColor = ref(defaultColor)
  39. // 是否提交
  40. const isSubmit = ref(false)
  41. /**
  42. * 绑定
  43. */
  44. function bind() {
  45. isSubmit.value = true;
  46. if(!postData.account.trim()){
  47. uni.showToast({
  48. icon: 'none',
  49. title: '请填写工号'
  50. });
  51. return;
  52. }
  53. bindFn();
  54. }
  55. /**
  56. * 绑定工号
  57. */
  58. function bindFn(type) {
  59. uni.showLoading({
  60. title: "加载中",
  61. mask: true,
  62. });
  63. api_bindAccount({
  64. account: postData.account,
  65. wechat: options.wechat,
  66. type: type || undefined,
  67. }).then(res => {
  68. uni.hideLoading();
  69. if (res.status == 200) {
  70. if(type === undefined){
  71. // 查询
  72. uni.showModal({
  73. title: '提示',
  74. content: `您输入的工号为“${postData.account}”对应姓名“${res.data ? res.data.name : ''}”,您确认绑定吗?`,
  75. confirmColor: defaultColor,
  76. confirmText: '确认',
  77. success: function(res) {
  78. if (res.confirm) {
  79. bindFn('bind');
  80. }
  81. }
  82. });
  83. }else{
  84. // 绑定
  85. wechatAuth();
  86. }
  87. } else if (res.status == 403) {
  88. //未查询到
  89. uni.showModal({
  90. title: '提示',
  91. content: `您填写的工号“${postData.account}”,未查询到!请确认工号是否正确,如有问题请联系管理员。`,
  92. showCancel: false,
  93. confirmColor: defaultColor,
  94. confirmText: '取消',
  95. });
  96. } else if (res.status == 401) {
  97. //已被绑定
  98. uni.showModal({
  99. title: '提示',
  100. content: `您填写工号为“${postData.account}”对应姓名为“${res.data ? res.data.name : ''}”已经被绑定,如有误请联系管理员处理。`,
  101. showCancel: false,
  102. confirmColor: defaultColor,
  103. confirmText: '取消',
  104. });
  105. } else {
  106. uni.showToast({
  107. icon: 'none',
  108. title: res.msg || '请求数据失败!'
  109. });
  110. }
  111. })
  112. }
  113. onLoad((option) => {
  114. console.log(option);
  115. options.wechat = option.wechat;
  116. })
  117. </script>
  118. <style lang="scss" scoped>
  119. .repairEntrance {
  120. height: 100%;
  121. display: flex;
  122. flex-direction: column;
  123. justify-content: space-between;
  124. align-items: center;
  125. .info {
  126. .info_text {
  127. line-height: 56rpx;
  128. font-size: 34rpx;
  129. padding: 90rpx 0 58rpx;
  130. display: flex;
  131. justify-content: center;
  132. align-items: center;
  133. }
  134. .info_form {
  135. .info_form_item {
  136. height: 86rpx;
  137. display: flex;
  138. align-items: center;
  139. }
  140. }
  141. }
  142. }
  143. </style>