index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="user-content">
  3. <view class="status_bar" :style="`background:${$config('primaryColor')}`">
  4. <!-- 这里是状态栏 -->
  5. </view>
  6. <!-- 头部 -->
  7. <view class="user-head" :style="`background:${$config('primaryColor')}`">
  8. <view class="user-photo">
  9. <u-avatar :src="userAvatarUrl" size="100" class="avatar"></u-avatar>
  10. </view>
  11. <view class="user-info">
  12. <text class="user-name">{{userData.orgName}}</text>
  13. <text class="user-phone">{{userData.username}}</text>
  14. </view>
  15. <view class="user-org" @click="show = true" v-if="orglist&&orglist.length">
  16. 切换 <u-icon name="arrow-right"></u-icon>
  17. </view>
  18. </view>
  19. <!-- 列表 -->
  20. <view class="user-list" :style="`backgroundImage:linear-gradient(180deg, ${$config('primaryColor')}, #F5F6F7 30%)`">
  21. <u-cell-group>
  22. <u-cell-item icon="volume" icon-size="36" :icon-style="{color:'#00aaff'}" index="3" @click="toPage(3)" title="消息">
  23. <u-badge :count="noReadNums" :absolute="false" slot="right-icon"></u-badge>
  24. </u-cell-item>
  25. <u-cell-item icon="edit-pen" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="toPage(1)" title="修改密码"></u-cell-item>
  26. <u-cell-item icon="man-delete" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="closeAccount" title="注销账户"></u-cell-item>
  27. <u-cell-item icon="reload" icon-size="35" :icon-style="{color:'#00aaff'}" index="1" @click="resetPrint" title="重置打印机"></u-cell-item>
  28. </u-cell-group>
  29. <u-cell-group>
  30. <!-- <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#00aaff'}" index="1" @click="toPage" title="关于我们"></u-cell-item> -->
  31. <u-cell-item icon="level" icon-size="34" :icon-style="{color:'#00aaff'}" index="2" @click="toPage(2)" :value="curVer.version" title="版本检查"></u-cell-item>
  32. <u-cell-item icon="file-text" icon-size="36" :icon-style="{color:'#00aaff'}" index="0" @click="toPage(0)" title="服务协议及隐私政策"></u-cell-item>
  33. </u-cell-group>
  34. </view>
  35. <!-- 退出 -->
  36. <view class="user-btn">
  37. <u-button type="success" :custom-style="{background:$config('primaryColor')}" hover-class="none" @click="quitOutSys" shape="circle">退出登录</u-button>
  38. </view>
  39. <u-action-sheet :list="orglist" v-model="show" @click="changeAcount" :tips="tips" :cancel-btn="true"></u-action-sheet>
  40. </view>
  41. </template>
  42. <script>
  43. import { getUserInfo, logout, login, getUnreadCount, logoff } from '@/api/user.js'
  44. import { getSysVersion } from '@/api/data.js'
  45. import { checkVersionToLoadUpdate, clzConfirm } from '@/libs/tools';
  46. import * as blesdk from '@/components/kk-printer/utils/bluetoolth';
  47. import market from "@/js_sdk/dc-market/market.js"
  48. export default {
  49. data() {
  50. return {
  51. isRemember: false,
  52. show:false,
  53. tips: {
  54. text: '切换账户',
  55. color: '#999',
  56. fontSize: 32
  57. },
  58. userInfoData: null, // 用户信息
  59. userAvatarUrl: '' ,// 用户头像
  60. curVer: null,
  61. noReadNums: 0,
  62. };
  63. },
  64. onShow() {
  65. this.getUnread()
  66. console.log(this.userData)
  67. },
  68. computed: {
  69. orglist() {
  70. // 当前连锁账户
  71. const orgs = this.$store.state.vuex_authOrgs;
  72. const user = this.$store.state.vuex_userData;
  73. if(orgs){
  74. orgs.map(item => {
  75. item.text = item.orgName
  76. })
  77. }
  78. return orgs ? orgs.filter(item => item.orgSn != user.orgSn) : []
  79. },
  80. userData () {
  81. return this.$store.state.vuex_userData;
  82. },
  83. isIos(){
  84. return uni.getSystemInfoSync().platform == "ios"
  85. }
  86. },
  87. onLoad() {
  88. uni.setNavigationBarColor({
  89. frontColor: '#ffffff',
  90. backgroundColor: this.$config('primaryColor')
  91. })
  92. this.isRemember = this.$store.state.vuex_isRemember;
  93. this.curVer = getApp().globalData.version;
  94. },
  95. methods:{
  96. // 未读消息
  97. getUnread(){
  98. getUnreadCount().then(res => {
  99. this.noReadNums = res.data.no_read_count || 0
  100. })
  101. },
  102. // 过滤权限code
  103. fiterAuthCode(data) {
  104. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  105. return data;
  106. },
  107. // 重置打印机
  108. resetPrint(){
  109. const _this = this;
  110. clzConfirm({
  111. title: '提示',
  112. content: '重置打印机后就可以重新选择其它打印机,您确定重置吗?',
  113. success: function(res) {
  114. if (res.confirm || res.index == 0) {
  115. const lastDevice = uni.getStorageSync('vuex_lastBuleDevice')
  116. blesdk.closeBLEConnection(lastDevice.deviceId)
  117. uni.setStorageSync('vuex_lastBuleDevice','')
  118. uni.showToast({
  119. title: '重置成功'
  120. })
  121. }
  122. }
  123. });
  124. },
  125. // 切换账户
  126. changeAcount(index){
  127. const _this = this
  128. const item = this.orglist[index]
  129. console.log(index,item)
  130. this.$store.state.vuex_changeOrg = item.orgSn
  131. this.$set(getApp().globalData,'changeOrg',item.orgSn)
  132. setTimeout(()=>{
  133. // 登录
  134. login({ username: '', password: '' }).then(res => {
  135. console.log(res)
  136. uni.hideLoading();
  137. if (res.status == 200) {
  138. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
  139. _this.$u.vuex('vuex_token', res.data.access_token);
  140. _this.$u.vuex('vuex_authOrgs',res.data.auth_orgs);
  141. getApp().globalData.token = res.data.access_token;
  142. uni.setStorageSync('loginTimeOut', 'NO');
  143. this.toMain()
  144. uni.$emit("refreshSalesHomeBL")
  145. uni.showToast({ icon: 'none', title: '切换成功!' });
  146. }else{
  147. uni.showToast({ icon: 'none', title: res.message });
  148. }
  149. });
  150. },100)
  151. },
  152. // 跳转到首页
  153. toMain() {
  154. uni.switchTab({
  155. url: '/pages/sales/index'
  156. });
  157. },
  158. // 打开对应的页面
  159. toPage(index){
  160. let pageUrl=[
  161. '/pages/login/userAuthYs?fromPage=usercenter',
  162. '/pages/userCenter/changePwd',
  163. 'getVersion',
  164. '/pages/xtNotice/xtNotice'
  165. ]
  166. if(index != 2){
  167. uni.navigateTo({
  168. url: pageUrl[index]
  169. })
  170. }else{
  171. this[pageUrl[index]]()
  172. }
  173. },
  174. // 注销
  175. closeAccount(){
  176. const _this = this;
  177. clzConfirm({
  178. title: '提示',
  179. content: '账户注销后将不能再使用iSCM系统,且您的所有相关数据将被删除,您确定注销吗?',
  180. success: function(res) {
  181. if (res.confirm || res.index == 0) {
  182. logoff().then(ret => {
  183. if(ret.status == 200){
  184. _this.toLogin()
  185. }
  186. })
  187. }
  188. }
  189. });
  190. },
  191. // 退出登录确认弹框
  192. quitOutSys() {
  193. const _this = this;
  194. clzConfirm({
  195. title: '提示',
  196. content: '确定退出登录?',
  197. success: function(res) {
  198. if (res.confirm || res.index == 0) {
  199. logout().then(ret => {
  200. if (ret.status == 200) {
  201. _this.toLogin()
  202. }
  203. });
  204. }
  205. }
  206. });
  207. },
  208. toLogin(){
  209. // this.$store.commit("$closeWebsocket")
  210. this.$set(getApp().globalData,'changeOrg','')
  211. uni.setStorageSync('setStatusIndexFunc', 0);
  212. this.$u.vuex('vuex_userData', '');
  213. this.$u.vuex('vuex_token', '');
  214. this.$u.vuex('vuex_authOrgs','');
  215. getApp().globalData.token = '';
  216. this.$u.vuex('vuex_tempData', '');
  217. setTimeout(function() {
  218. uni.reLaunch({
  219. url: '/pages/login/login'
  220. });
  221. }, 500);
  222. },
  223. // 获取最新版本信息
  224. getVersion() {
  225. let version = getApp().globalData.version
  226. console.log(version)
  227. getSysVersion({versionType:version.platform=='android'?'ANDROID':'IOS'}).then(ret => {
  228. console.log(JSON.stringify(ret))
  229. if(ret.status == 200){
  230. console.log(ret.data)
  231. this.$store.state.vuex_versionInfo = ret.data
  232. //进行版本型号的比对 以及下载更新请求
  233. checkVersionToLoadUpdate(ret.data, 1, market);
  234. }
  235. })
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .user-content{
  242. width: 100%;
  243. .user-head{
  244. display: flex;
  245. align-items: center;
  246. padding: 50rpx 35rpx;
  247. .user-photo{
  248. flex-shrink: 0;
  249. margin-right: 5rpx;
  250. }
  251. .user-org{
  252. color: #fff;
  253. }
  254. .user-info{
  255. flex-grow: 1;
  256. padding: 0 20rpx;
  257. color: #FFFFFF;
  258. .user-name{
  259. display: block;
  260. font-size: 36rpx;
  261. margin-bottom: 10rpx;
  262. }
  263. .user-phone{
  264. display: block;
  265. font-size: 28rpx;
  266. }
  267. }
  268. }
  269. .user-list{
  270. padding: 0 20upx;
  271. > view{
  272. margin-bottom: 20upx;
  273. border-radius: 15upx;
  274. box-shadow: 0upx 3upx 6upx #eee;
  275. overflow: hidden;
  276. }
  277. }
  278. .user-btn{
  279. padding: 85rpx 200rpx;
  280. }
  281. }
  282. </style>