index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <view class="person_wrap">
  3. <template v-if="userInfo.userId">
  4. <view class="navbar-wrap">
  5. <view class="column" :class="{ fixed: isFixedTop }" :style="{ background: background }" id="navbar">
  6. <view class="left"></view>
  7. <view style="font-size:36rpx" class="center">我的</view>
  8. <view class="right" @click="handleSetting">
  9. <u-icon name="setting" color="#333"></u-icon>
  10. </view>
  11. </view>
  12. <!-- <view class="column" v-if="isFixedTop"></view> -->
  13. </view>
  14. <view class="header_wrap">
  15. <view class="header_top_wrap">
  16. <view class="header_info_left">
  17. <u-avatar @click="handleAvatarClick" :src="$avatar(userInfo.avatar)" size="100rpx"></u-avatar>
  18. <view class="info_wrap">
  19. <view class="info_top">
  20. <text class="follow_name">{{ userInfo.userName }}</text>
  21. <u-switch v-model="onlineStatus" active-value='0' inactive-value='1'
  22. :loading="onlineLoading" @change="changeOnlineStatus"></u-switch>
  23. <text class="identity">{{ onlineStatus === '0' ? '上线' : '下线' }}</text>
  24. <!-- 只有当showRoleSwitch为true时才显示切换权限按钮 -->
  25. <view class="identity" v-if="$store.state.user.showRoleSwitch" @click="handleSwitchRole">切换权限</view>
  26. </view>
  27. <view class="info_bottom">
  28. <text>{{ userInfo.phonenumber }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="header_info_right" @click="toPersonal">
  33. <u-icon name="arrow-right" color="#aaa"></u-icon>
  34. </view>
  35. </view>
  36. <view class="parson_menu_wrap" v-if="isCrmRole">
  37. <view class="parson_menu_list">
  38. <navigator url="/pages/publicClue/index" open-type="switchTab" class="menu_item"
  39. hover-class="none">
  40. <image src="@/static/parson/icon-wf.png" mode=""></image>
  41. <text>销售公海</text>
  42. </navigator>
  43. <navigator url='/pages/message/index' open-type="navigate" class="menu_item" hover-class="none">
  44. <image src="@/static/parson/icon-myMessage.png" mode=""></image>
  45. <text>我的消息</text>
  46. </navigator>
  47. <!-- <navigator url='/pages/order/index' open-type="navigate"
  48. class="menu_item" hover-class="none">
  49. <image src="@/static/parson/icon-mycase.png" mode=""></image>
  50. <text>接单中心</text>
  51. </navigator> -->
  52. <navigator url='/pages/privateClue/index' open-type="switchTab" class="menu_item"
  53. hover-class="none">
  54. <image src="@/static/parson/clue.png" mode=""></image>
  55. <text>销售线索</text>
  56. </navigator>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="cards_wrap">
  61. <cards></cards>
  62. </view>
  63. </template>
  64. <u-loading-page :loading="true" v-else></u-loading-page>
  65. <u-picker :show="showSwitchRole" :columns="columns" keyName="label" :defaultIndex="defaultIndex" @confirm="confirmSwitchRole" @cancel="showSwitchRole = false"></u-picker>
  66. </view>
  67. </template>
  68. <script>
  69. import cards from "./cards/index.vue"
  70. // import optionList from "./option/index.vue"
  71. import permision from "@/js_sdk/wa-permission/permission.js";
  72. import { getRoles } from '@/utils/util.js'
  73. export default {
  74. components: {
  75. // optionList,
  76. cards
  77. },
  78. data() {
  79. return {
  80. onlineLoading: false,
  81. switchSystemShow: false,
  82. navbarInitTop: 0, //导航栏初始化距顶部的距离
  83. isFixedTop: true, //是否固定顶部
  84. background: "", // 为了实现渐变背景颜色
  85. showSwitchRole: false,
  86. columns: [],
  87. defaultIndex: [this.$store.state.user.currentRoleIndex],
  88. isHaveCRM: false,
  89. isHaveSalesman: false,
  90. isHaveWarehouse: false,
  91. };
  92. },
  93. computed: {
  94. isCrmRole(){
  95. return getRoles().some(v => v.includes('CRM'))
  96. },
  97. userInfo() {
  98. return this.$store.state.user.userInfo;
  99. },
  100. onlineStatus: {
  101. get() {
  102. const val = this.$store.state.user.userInfo.onlineStatus;
  103. // u-switch 要求 v-model 的值必须等于 activeValue 或 inactiveValue
  104. // 这里统一返回字符串 '0' 或 '1',避免初始为 null/undefined 时的告警
  105. if (val === '0' || val === 0) return '0';
  106. if (val === '1' || val === 1) return '1';
  107. return '1';
  108. },
  109. set(val) {
  110. this.$store.commit("user/SET_USER_ONLINE_STATUS", val);
  111. },
  112. },
  113. nickName() {
  114. return this.userInfo.nickName;
  115. },
  116. userName() {
  117. return this.userInfo.userName;
  118. },
  119. deptName() {
  120. return this.userInfo.newOrgName;
  121. },
  122. time() {
  123. return this.$dayjs().format("YYYY-MM-DD HH:mm:ss")
  124. },
  125. systemList() {
  126. return this.$store.state.user.systemList;
  127. },
  128. filterSystemList() {
  129. return this.systemList.filter(v => this.userInfo.subsystemList.some(u => v.value === u.systemCode));
  130. },
  131. currentSystem: {
  132. get() {
  133. return this.$store.getters.system.value
  134. },
  135. set(val) {
  136. const system = this.systemList.find(v => v.value === val);
  137. // 如果有没保存的催记直接清掉
  138. this.$store.commit("follow/SET_FORM", {});
  139. this.$store.commit("follow/SET_PARAMS", {});
  140. this.$store.commit("user/SET_SYSTEM", system);
  141. this.$store.commit("user/SET_BELONGSYSTEM", {
  142. code: val,
  143. callback: (flag) => {
  144. if (flag) {
  145. setTimeout(() => {
  146. // 定时器可加可不加
  147. uni.reLaunch({
  148. url: "/pages/person/index",
  149. success: () => {
  150. uni.$u.toast("切换成功,当前为" + system.text);
  151. }
  152. })
  153. }, 300)
  154. } else {
  155. this.$store.commit("user/SET_TOKEN", "");
  156. this.$store.commit("user/SET_USERINFO", {});
  157. uni.reLaunch({
  158. url: "/pages/login/index",
  159. success() {
  160. uni.$u.toast("请检查您是否有该系统权限");
  161. }
  162. })
  163. }
  164. }
  165. })
  166. },
  167. },
  168. },
  169. methods: {
  170. handleSwitchRole(){
  171. this.columns = [];
  172. let roles = this.$store.state.user.availableRoles;
  173. let roleOptions = [];
  174. const hasAdminRole = roles.some(role => role.includes('admin'));
  175. const hasCrmRole = roles.some(role => role.includes('CRM'));
  176. const hasWAREandSALE = roles.some(role => role.includes('WAREandSALE'));
  177. if(hasAdminRole || (hasCrmRole && hasWAREandSALE) ){//管理员、crm+仓库、crm+销售、仓库+销售
  178. roleOptions.push(
  179. { label: 'CRM权限', value: 'CRM' },
  180. { label: '仓库和销售权限', value: 'WAREandSALE' },
  181. );
  182. }else if(hasCrmRole){//只有crm
  183. roleOptions.push(
  184. { label: 'CRM权限', value: 'CRM' },
  185. );
  186. }else if(hasWAREandSALE){//只有仓库或销售
  187. roleOptions.push(
  188. { label: '仓库和销售权限', value: 'WAREandSALE' },
  189. );
  190. }
  191. this.columns = [roleOptions];
  192. this.showSwitchRole = true;
  193. },
  194. confirmSwitchRole(e) {
  195. this.showSwitchRole = false;
  196. this.$store.commit('user/SET_CURRENT_ROLE_INDEX', e.indexs[0]);
  197. setTimeout(()=>{
  198. this.$store.commit('user/SWITCH_ROLE', e.value[0]);
  199. },50)
  200. },
  201. changeOnlineStatus(val) {
  202. this.onlineLoading = true;
  203. uni.$u.api.changeOnlineStatus({ userId: this.$store.state.user.userInfo.userId, onlineStatus: val });
  204. this.onlineLoading = false;
  205. },
  206. handleTest() {
  207. uni.navigateTo({
  208. url: "/pages/demo/demo"
  209. })
  210. },
  211. // 确认选择系统事件
  212. handleSystemConfirm() {
  213. },
  214. // 取消选择系统事件
  215. handleSystemCancel() {
  216. },
  217. // 点击打开选择系统
  218. handleSwitchSystem() {
  219. this.$refs.switch.showModal();
  220. },
  221. onPullDownRefresh() {
  222. uni.stopPullDownRefresh();
  223. this.$store.dispatch("user/getUserInfo");
  224. },
  225. toPersonal() {
  226. uni.navigateTo({
  227. url: "/pages/profile/index"
  228. })
  229. },
  230. handleSetting() {
  231. uni.navigateTo({
  232. url: "/pages/setting/index"
  233. })
  234. },
  235. registerFun() {
  236. if (!this.$store.state.app.callSystem) {
  237. this.$store.dispatch("app/getExtensionByUserId", {
  238. userId: this.$store.state.user.userInfo.userId
  239. }).then((res) => {
  240. Promise.all([permision.requestAndroidPermission("android.permission.RECORD_AUDIO"), permision.requestAndroidPermission('android.permission.MODIFY_AUDIO_SETTINGS')]).then(result => {
  241. const flag = result.every(v => v == 1);
  242. if (flag) {
  243. this.$store.dispatch("app/createWv");
  244. }
  245. })
  246. });
  247. }
  248. },
  249. handleAvatarClick() {
  250. //跳转个人资料
  251. uni.navigateTo({
  252. url: "/pages/profile/index"
  253. })
  254. }
  255. },
  256. mounted() {
  257. if (this.navbarInitTop == 0) {
  258. const query = uni.createSelectorQuery().in(this);
  259. //获取节点距离顶部的距离
  260. query.select("#navbar").boundingClientRect(function (rect) {
  261. if (rect && rect.top > 0) {
  262. var navbarInitTop = parseInt(rect.top);
  263. this.navbarInitTop = navbarInitTop;
  264. }
  265. }).exec();
  266. }
  267. if (this.$store.state.user.token) {
  268. this.$store.dispatch("user/getUserInfo");
  269. } else {
  270. uni.navigateTo({
  271. url: "/pages/login/index"
  272. })
  273. }
  274. },
  275. /**
  276. * 监听页面滑动事件
  277. */
  278. onPageScroll: function (e) {
  279. var scrollTop = parseInt(e.scrollTop); //滚动条距离顶部高度
  280. this.background = `rgba(255, 255, 255,${scrollTop / (scrollTop + 60)})`;
  281. //判断'滚动条'滚动的距离 和 '元素在初始时'距顶部的距离进行判断
  282. var isSatisfy = scrollTop >= this.navbarInitTop ? true : false;
  283. //为了防止不停的setData, 这儿做了一个等式判断。 只有处于吸顶的临界值才会不相等
  284. if (this.isFixedTop === isSatisfy) {
  285. return false;
  286. }
  287. this.isFixedTop = isSatisfy;
  288. }
  289. };
  290. </script>
  291. <style>
  292. .watermarkCans {
  293. width: 250rpx;
  294. height: 250rpx;
  295. position: absolute;
  296. z-index: -1;
  297. }
  298. </style>
  299. <style lang="scss" scoped>
  300. .switchSysytemSelect {
  301. height: 0rpx;
  302. overflow: hidden;
  303. }
  304. .switchSysytemBtn {
  305. width: 630rpx;
  306. margin: auto;
  307. margin-top: 60rpx;
  308. ::v-deep .u-button {
  309. border-radius: 100rpx;
  310. }
  311. }
  312. .person_wrap {
  313. background-size: cover;
  314. background-repeat: no-repeat;
  315. // padding: 0 30rpx;
  316. position: relative;
  317. height: 100vh;
  318. .header_wrap {
  319. box-sizing: border-box;
  320. background: url("@/static/parson/parson_background.png");
  321. background-size: cover;
  322. width: 750rpx;
  323. // position: absolute;
  324. // top: 0;
  325. // left: 0;
  326. padding: 170rpx 30rpx 0 30rpx;
  327. .header_top_wrap {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. .header_info_left {
  332. display: flex;
  333. align-items: center;
  334. // image {
  335. // width: 100rpx;
  336. // height: 100rpx;
  337. // margin-right: 30rpx;
  338. // border-radius: 50%;
  339. // }
  340. .info_wrap {
  341. margin-left: 20rpx;
  342. .info_top {
  343. margin-bottom: 20rpx;
  344. display: flex;
  345. align-items: center;
  346. .follow_name {
  347. font-size: 32rpx;
  348. color: #202020;
  349. font-weight: bold;
  350. margin-right: 20rpx;
  351. }
  352. .identity {
  353. display: inline-block;
  354. width: 100rpx;
  355. line-height: 36rpx;
  356. background: #ffffff;
  357. border-radius: 18px;
  358. text-align: center;
  359. font-size: 22rpx;
  360. color: #666666;
  361. margin-left: 10px;
  362. }
  363. }
  364. .info_bottom {
  365. text {
  366. font-size: 28rpx;
  367. color: #666666;
  368. }
  369. }
  370. }
  371. }
  372. .header_info_right {
  373. ::v-deep .u-icon__icon {
  374. font-size: 30rpx !important;
  375. }
  376. }
  377. }
  378. .cards_wrap {
  379. padding: 0 30rpx 0 30rpx;
  380. }
  381. .box {
  382. height: 200vh;
  383. }
  384. .parson_menu_wrap {
  385. background: #ffffff;
  386. border-radius: 20px;
  387. box-shadow: 0px 4px 20px 0px rgba(16, 140, 255, 0.10);
  388. margin-top: 58rpx;
  389. .parson_menu_list {
  390. display: flex;
  391. padding: 40rpx 0;
  392. .menu_item {
  393. width: 33%;
  394. display: flex;
  395. flex-direction: column;
  396. align-items: center;
  397. image {
  398. width: 48rpx;
  399. height: 48rpx;
  400. margin-bottom: 24rpx;
  401. }
  402. text {
  403. font-size: 28rpx;
  404. color: #202020;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. .secondHalf {
  411. padding: 0 30rpx;
  412. }
  413. .box {
  414. height: 200vh;
  415. }
  416. }
  417. .navbar-wrap {
  418. width: 750rpx;
  419. .left {
  420. width: 70rpx;
  421. }
  422. .right {
  423. margin-right: 30rpx;
  424. ::v-deep .u-icon__icon {
  425. font-size: 40rpx !important;
  426. }
  427. }
  428. }
  429. .navbar-wrap .column {
  430. box-sizing: border-box;
  431. padding-top: 60rpx;
  432. width: 750rpx;
  433. height: 170rpx;
  434. display: flex;
  435. justify-content: space-between;
  436. align-items: center;
  437. background: transparent;
  438. top: 0;
  439. left: 0;
  440. z-index: 100;
  441. }
  442. .navbar-wrap .column.fixed {
  443. width: 750rpx;
  444. position: fixed;
  445. }
  446. .navbar-wrap .column .center {
  447. text-align: center;
  448. font-size: 36rpx;
  449. color: #333333;
  450. letter-spacing: 1px;
  451. position: relative;
  452. }
  453. </style>