chooseEnterp.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="enterp">
  3. <view class="head_text">{{enterPriseList.length <= 0 ? '请绑定企业以登录' : '请选择企业以登录'}}</view>
  4. <view class="line"></view>
  5. <view class="enter_list">
  6. <view class="enterp-box" v-for="(item,index) in enterPriseList" @click="toLogin(item)">
  7. <text class="iconfont icon-qiye" style="font-size: 40rpx; color: #2979FF;vertical-align: middle;"></text>
  8. <text style="vertical-align: middle; display: inline-block; margin-left: 10rpx;">{{item.enterpriseName}}</text>
  9. </view>
  10. </view>
  11. <view class="btn-view">
  12. <u-button type="primary" :custom-style="customStyle" @click="bindEnterprises">绑定企业</u-button>
  13. </view>
  14. <u-modal negative-top="200" :async-close="true" :show-title="false" :show-cancel-button="true" :mask-close-able="false" ref="uModal" :show="showModal" @confirm="confirm" @cancel="cancel">
  15. <view class="slot-content ">
  16. <u-form label-width="140" :model="form">
  17. <u-form-item label="企业编号:" required>
  18. <u-input placeholder="请输入企业编号" :clearable="false" v-model="form.enterpriseCode"></u-input>
  19. </u-form-item>
  20. <u-form-item label="账 号 :" required>
  21. <u-input placeholder="请输入账号" :clearable="false" v-model="form.username"></u-input>
  22. </u-form-item>
  23. <u-form-item label="密 码 :" required>
  24. <u-input placeholder="请输入密码" type="password" :password-icon="false" :clearable="false" v-model="form.password"></u-input>
  25. </u-form-item>
  26. </u-form>
  27. </view>
  28. </u-modal>
  29. </view>
  30. </template>
  31. <script>
  32. import encryption from '../../utils/util'
  33. import crypto from '../../utils/crypto.js'
  34. export default {
  35. data() {
  36. return {
  37. customStyle: {
  38. height: '100rpx',
  39. marginBottom: '20rpx',
  40. fontWeight: '700'
  41. },
  42. showModal: false,
  43. enterPriseList: [],
  44. user_info: {},
  45. enterpriseInfo: '',
  46. form: {
  47. enterpriseCode: '',
  48. username: '',
  49. password: '',
  50. phone: ''
  51. },
  52. wxUserInfo: ''
  53. };
  54. },
  55. onLoad(option) {
  56. console.log("有没又进来")
  57. this.user_info = uni.getStorageSync('userInfo')
  58. this.form.phone = this.user_info.username
  59. this.getEnterprise()
  60. },
  61. methods: {
  62. async getEnterprise () {
  63. const { data: res } = await this.$request({
  64. url: '/admin/enterprise/getSysEnterprisePage/' + this.user_info.phone,
  65. method: 'GET',
  66. data: {}
  67. })
  68. console.log(res)
  69. if (res.code == 0) {
  70. this.enterPriseList = res.data || []
  71. }
  72. },
  73. async toLogin (val) {
  74. const that = this
  75. uni.showLoading({
  76. title: '正在登录中'
  77. });
  78. console.log(val)
  79. console.log(that.user_info.phone)
  80. that.enterpriseInfo = val
  81. setTimeout(async function () {
  82. const { data: res } = await that.$request({
  83. url: '/admin/enterprise/login',
  84. method: 'POST',
  85. data: {
  86. enterpriseCode: that.enterpriseInfo.enterpriseCode,
  87. phone: that.user_info.phone
  88. }
  89. })
  90. console.log(res, 'resrsers')
  91. if (res.code == 0) {
  92. uni.setStorageSync('phone', that.user_info.phone)
  93. uni.setStorageSync('oldtoken', uni.getStorageSync('token'))
  94. uni.setStorageSync('token', res.data.access_token)
  95. uni.setStorageSync('enterpriseInfo', JSON.stringify(that.enterpriseInfo))
  96. getApp().globalData.tabIndex = 'approval'
  97. uni.switchTab({
  98. url: "/pages/approval/approvallist"
  99. })
  100. uni.showToast({
  101. title: '登录成功',
  102. icon: "none"
  103. })
  104. } else if (res.code == 1) {
  105. uni.showToast({
  106. title: '认证失败,请重新认证',
  107. icon: 'none',
  108. success: function (res) {
  109. setTimeout((function () {
  110. // const url = "/pages/login/accountLogin/index?enterpriseCode=" + that.enterpriseInfo.enterpriseCode
  111. // uni.navigateTo({
  112. // url: url
  113. // })
  114. that.form.enterpriseCode = val.enterpriseCode
  115. that.showModal = true
  116. }), 1000)
  117. }
  118. })
  119. } else {
  120. uni.showToast({
  121. title: res.data.msg,
  122. icon: "none"
  123. })
  124. }
  125. uni.hideLoading()
  126. }, 1500);
  127. },
  128. bindEnterprises () {
  129. console.log('绑定')
  130. this.showModal = true
  131. },
  132. confirm () {
  133. const that = this
  134. that.$refs.uModal.clearLoading();
  135. console.log(that.form)
  136. if (that.form.enterpriseCode == '') {
  137. uni.showToast({
  138. title: '请输入企业编号',
  139. icon: 'none'
  140. })
  141. } else if (that.form.username == '') {
  142. uni.showToast({
  143. title: '请输入账号',
  144. icon: 'none'
  145. })
  146. } else if (that.form.password == '') {
  147. uni.showToast({
  148. title: '请输入密码',
  149. icon: 'none'
  150. })
  151. } else {
  152. uni.showLoading({
  153. title: '正在绑定中'
  154. });
  155. setTimeout(async function () {
  156. const user =crypto.encryption({
  157. data: that.form,
  158. key: 'pigxpigxpigxpigx',
  159. param: ['password'],
  160. source: 'mini'
  161. })
  162. const { data: res } = await that.$request({
  163. url: '/admin/enterprise/bindEnterpriseUserInfo',
  164. method: 'POST',
  165. data: user,
  166. header: {
  167. 'Content-Type': 'application/json;charset=utf-8',
  168. 'Authorization': uni.getStorageSync('token'),
  169. 'TENANT-ID': uni.getStorageSync('tenantId')
  170. }
  171. })
  172. console.log('--------',res)
  173. if (res.code == 0) {
  174. uni.setStorageSync('tenantId', res.data.enterpriseInfo.tenantId)
  175. uni.setStorageSync('oldtoken', uni.getStorageSync('token'))
  176. uni.setStorageSync('token', res.data.access_token)
  177. uni.setStorageSync('enterpriseInfo', JSON.stringify(res.data.enterpriseInfo))
  178. getApp().globalData.tabIndex = 'approval'
  179. uni.switchTab({
  180. url: "/pages/approval/approvallist"
  181. })
  182. uni.showToast({
  183. title: '绑定登录成功',
  184. icon: "none",
  185. duration: 2500,
  186. })
  187. } else {
  188. uni.showToast({
  189. title: res.msg == null ? '企业绑定失败' : res.msg,
  190. icon: "none",
  191. })
  192. }
  193. // uni.hideLoading();
  194. }, 1000);
  195. }
  196. },
  197. cancel () {
  198. Object.keys(this.form).forEach(key => (this.form[key] = ""));
  199. this.showModal=false;
  200. },
  201. // 生成随机数字
  202. randomLenNum (len, date) {
  203. let random = ''
  204. random = Math.ceil(Math.random() * 100000000000000).toString().substr(0, len || 4)
  205. if (date) random = random + Date.now()
  206. return random
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. .enterp {
  213. text-align: center;
  214. }
  215. .head_text {
  216. font-size: 40rpx;
  217. margin: 100rpx 0 60rpx;
  218. }
  219. .line {
  220. width: 30%;
  221. height: 2rpx;
  222. margin: auto;
  223. background-color: #e6e6e6;
  224. margin-bottom: 50rpx;
  225. }
  226. .enter_list {
  227. width: 80%;
  228. margin: 40rpx auto;
  229. }
  230. .enterp-box {
  231. text-align: left;
  232. height: 120rpx;
  233. background-color: #FFFFFF;
  234. line-height: 120rpx;
  235. padding: 0 40rpx;
  236. margin-bottom: 30rpx;
  237. }
  238. .btn-view {
  239. width: 80%;
  240. margin: 0 auto;
  241. }
  242. .slot-content {
  243. padding: 40rpx;
  244. }
  245. .u-form-item {
  246. padding: 10rpx 0 !important;
  247. }
  248. </style>