index.wpy 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <style lang="less">
  2. page {
  3. height: 100%;
  4. overflow: hidden;
  5. background: rgba(235, 245, 250, 1);
  6. }
  7. .overflow-wrap {
  8. box-sizing: border-box;
  9. width: 100%;
  10. height: 100%;
  11. padding-left: 40rpx;
  12. padding-right: 40rpx;
  13. padding-top: 136rpx;
  14. padding-bottom: 208rpx;
  15. overflow-y: auto;
  16. .bind-item {
  17. position: relative;
  18. width: 100%;
  19. box-sizing: border-box;
  20. padding: 40rpx 48rpx;
  21. margin: 0 auto;
  22. margin-top: 24rpx;
  23. background: #ffffff;
  24. border-radius: 20px;
  25. &:nth-child(1) {
  26. margin-top: 34rpx;
  27. }
  28. .checked-icon {
  29. position: absolute;
  30. right: 0;
  31. top: 0;
  32. width: 56rpx;
  33. height: 56rpx;
  34. }
  35. .tenant-name {
  36. font-family: PingFang SC;
  37. font-size: 36rpx;
  38. font-weight: 500;
  39. line-height: 50rpx;
  40. letter-spacing: 0px;
  41. }
  42. .tenant-identity {
  43. display: flex;
  44. padding-top: 8rpx;
  45. justify-content: space-between;
  46. font-family: PingFang SC;
  47. .info {
  48. font-size: 28rpx;
  49. font-weight: 400;
  50. padding: 8rpx;
  51. //styleName: 14/常规;
  52. font-family: PingFang SC;
  53. font-weight: 400;
  54. color: #8b949e;
  55. }
  56. image {
  57. width: 112rpx;
  58. height: 40rpx;
  59. }
  60. }
  61. }
  62. .check-item {
  63. background: #3dcbcc4d;
  64. }
  65. .bind-btn-box {
  66. position: fixed;
  67. z-index: 333;
  68. bottom: 0;
  69. left: 0;
  70. height: 208rpx;
  71. width: 100%;
  72. background: linear-gradient(
  73. 180deg,
  74. rgba(235, 245, 250, 0) 0%,
  75. #ebf5fa 44.97%
  76. );
  77. button {
  78. margin-top: 20px;
  79. width: 670rpx;
  80. height: 100rpx;
  81. line-height: 100rpx;
  82. border: none;
  83. border-color: transparent;
  84. color: #fff;
  85. border-radius: 28px;
  86. background: #3dcbcc;
  87. }
  88. }
  89. }
  90. </style>
  91. <template>
  92. <div class="overflow-wrap">
  93. <page-top-bar title="公司身份选择"
  94. titleColor="#1B2129"
  95. bgColor="#EBF5FA"></page-top-bar>
  96. <div class="bind-item"
  97. @click="changeTent(item)"
  98. :class="{'check-item':selecItem.id==item.id}"
  99. :key="index+'tent'"
  100. v-for="(item,index) in tenantData">
  101. <div class="tenant-name">{{ item.name }}</div>
  102. <div class="tenant-identity">
  103. <div class="info">正式员工</div>
  104. <image class="logo-icon" v-if="item.logo" src="{{h5StaticPath+'/page-bind-tenant/logo_icon.svg'}}"/>
  105. </div>
  106. <image class="checked-icon"
  107. v-if="selecItem.id==item.id"
  108. src="{{h5StaticPath+'/page-bind-tenant/checked.svg'}}"/>
  109. </div>
  110. <div class="bind-btn-box">
  111. <button @click.stop="bindTent">确认</button>
  112. </div>
  113. </div>
  114. </template>
  115. <script>
  116. import wepy from '@wepy/core';
  117. import { mapState } from '@wepy/x';
  118. import store from '@/store';
  119. import config from '@/config';
  120. import {
  121. setUserInfoByAuth,
  122. getCompanyDataByPhone,
  123. getAvatar,
  124. wxLogin,
  125. checkLoginNew,
  126. checkTokenIsValid
  127. } from '@/service/user';
  128. import { register } from '@/api/user';
  129. wepy.page({
  130. store,
  131. config: {
  132. navigationBarTitleText: 'test'
  133. },
  134. data: {
  135. pageTopBarHeight: 48,
  136. tenantData: [
  137. {
  138. name: '科技公司1'
  139. }
  140. ],
  141. selecItem: {},
  142. h5StaticPath: config.h5StaticPath
  143. },
  144. computed: {
  145. ...mapState({
  146. userPhone: state => state.user.userPhone,
  147. token: state => state.user.token
  148. })
  149. },
  150. onLoad() {
  151. this.getPageCompanyByPhone();
  152. },
  153. onShow() {
  154. if (checkTokenIsValid() !== 3) {
  155. checkLoginNew();
  156. }
  157. },
  158. methods: {
  159. changeTent(item) {
  160. this.initTentData();
  161. item.isChecked = true;
  162. this.selecItem = item;
  163. },
  164. // 直接注册
  165. registerTent(params) {
  166. register(params)
  167. .then(res => {
  168. if (res.result == 'success') {
  169. wxLogin().then(res => {
  170. this.goHome();
  171. });
  172. } else {
  173. this.returnLogin();
  174. }
  175. })
  176. .catch(error => {
  177. this.returnLogin();
  178. });
  179. },
  180. // 注册
  181. bindTent() {
  182. let params = {
  183. phone: this.userPhone,
  184. defaultCompanyId: this.selecItem.id,
  185. headImage: getAvatar()
  186. };
  187. if (checkTokenIsValid() == 3) {
  188. // 未过期直接注册
  189. this.registerTent(params);
  190. } else {
  191. checkLoginNew();
  192. }
  193. },
  194. // 初始化租户
  195. initTentData() {
  196. this.tenantData.map(item => {
  197. item.isChecked = false;
  198. });
  199. },
  200. // 获取租户数据
  201. getPageCompanyByPhone() {
  202. getCompanyDataByPhone().then(res => {
  203. console.log(res);
  204. let data = res;
  205. if (data && data.length) {
  206. this.tenantData = data;
  207. this.initTentData();
  208. this.selecItem = this.tenantData[0];
  209. } else {
  210. wx.showToast({
  211. title: '未获得公司服务权限!',
  212. duration: 5000,
  213. icon: 'none'
  214. });
  215. this.goHome();
  216. }
  217. });
  218. },
  219. getUserPhone() {
  220. let phone = wx.getStorageSync('userPhone');
  221. console.log(`phone==${phone}`);
  222. },
  223. goHome() {
  224. wx.navigateTo({
  225. url: '/packagesEnv/pages/home/index'
  226. });
  227. },
  228. returnLogin() {
  229. wx.navigateTo({
  230. url: 'pages/index'
  231. });
  232. },
  233. goEnv() {
  234. wx.navigateTo({
  235. url:
  236. '/packagesEnv/pages/officehome/index?spaceId=Sp1101080259b3510e26e7dd4dd9bf9784f06f3feb68'
  237. });
  238. }
  239. },
  240. created() {}
  241. });
  242. </script>
  243. <config>
  244. {
  245. "navigationBarTitleText": "公司身份选择",
  246. "backgroundColor": "#EBF5FA",
  247. navigationStyle:"custom",
  248. usingComponents: {
  249. 'page-top-bar': '~@/components/common/page-top-bar',
  250. },
  251. componentPlaceholder:{
  252. 'page-top-bar': 'view'
  253. }
  254. }
  255. </config>