layout-top.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view v-if="menu.length">
  3. <view class="top-container">
  4. <view class="top-left">{{menuName}}</view>
  5. <view class="top-right">
  6. <text class="curr-store">{{storeInfo ? storeInfo.store_name : ''}}</text>
  7. <text class="cut-store" @click="switchStore()">切换门店</text>
  8. <uni-dropdown>
  9. <view slot="dropdown-link" class="head-box">
  10. <view class="login-wrap">
  11. <text>{{userInfo ? userInfo.username : ''}}</text>
  12. <text class="iconfont iconsanjiao_xia"></text>
  13. </view>
  14. </view>
  15. <view slot="dropdown">
  16. <view class="dropdown-menu">
  17. <view class="menu-item" v-if="userInfo" @click="changePassword">
  18. 修改密码
  19. <text class="iconfont iconqianhou2"></text>
  20. </view>
  21. <view class="menu-item logout" @click="$refs.logout.open()">
  22. 退出登录
  23. <text class="iconfont icontuichu"></text>
  24. </view>
  25. <view class="arrow"></view>
  26. </view>
  27. </view>
  28. </uni-dropdown>
  29. </view>
  30. </view>
  31. <uni-popup ref="passwordPopup">
  32. <view class="password-popup">
  33. <view class="head">修改密码</view>
  34. <view class="common-form body">
  35. <view class="common-form-item">
  36. <view class="form-label">
  37. <text class="required">*</text>
  38. 原密码
  39. </view>
  40. <view class="form-input-inline"><input type="text" :password="true" v-model="codeData.old_pass" class="form-input" placeholder="请输入原密码" /></view>
  41. </view>
  42. <view class="common-form-item">
  43. <view class="form-label">
  44. <text class="required">*</text>
  45. 新密码
  46. </view>
  47. <view class="form-input-inline"><input type="text" :password="true" v-model="codeData.new_pass" class="form-input" placeholder="请输入新密码" /></view>
  48. </view>
  49. <view class="common-form-item">
  50. <view class="form-label">
  51. <text class="required">*</text>
  52. 确认新密码
  53. </view>
  54. <view class="form-input-inline">
  55. <input type="text" :password="true" v-model="codeData.confirm_new_pass" class="form-input" placeholder="请输入新密码" />
  56. </view>
  57. </view>
  58. <view class="common-btn-wrap">
  59. <button type="default" class="primary-btn screen-btn" @click="modifyPasswordFn">确定</button>
  60. <button type="default" class="default-btn" @click="$refs.passwordPopup.close()">取消</button>
  61. </view>
  62. </view>
  63. </view>
  64. </uni-popup>
  65. <uni-popup ref="storePop">
  66. <view class="pop-box store-select">
  67. <view class="pop-header">
  68. <view class="pop-header-text">选择门店</view>
  69. <view class="pop-header-close" @click="$refs.storePop.close()"><i class="iconguanbi1 iconfont"></i></view>
  70. </view>
  71. <scroll-view scroll-y="true" class="common-scrollbar pop-content">
  72. <view class="content-lists">
  73. <view
  74. class="content-items"
  75. v-for="(item, index) in storeList"
  76. @click="selectStore(item)"
  77. :key="index"
  78. :class="{ active: storeInfo && storeInfo.store_id == item.store_id }"
  79. >
  80. <view class="item-img">
  81. <image v-if="item.store_image" :src="$util.img(item.store_image)" @error="$util.img(defaultImg.store)" mode="aspectFit"></image>
  82. <image v-else :src="$util.img(defaultImg.store)" mode="aspectFit"></image>
  83. </view>
  84. <view class="item-info">
  85. <view class="item-name">{{ item.store_name }}</view>
  86. <view class="item-phone">
  87. <i class="iconfont iconshijian"></i>
  88. {{ item.open_date ? item.open_date : '营业时间请联系管理员' }}
  89. </view>
  90. <view class="item-addr">
  91. <i class="iconfont icondizhi"></i>
  92. {{ item.full_address }}
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </scroll-view>
  98. <view class="pop-bottom"><button class="primary-btn" @click="$refs.storePop.close()">确定</button></view>
  99. </view>
  100. </uni-popup>
  101. <uni-popup ref="logout" type="center">
  102. <view class="logout-popup">
  103. <view class="title">确定退出系统?系统将自动交班</view>
  104. <view class="btn">
  105. <button type="primary" class="default-btn btn save" @click="$refs.logout.close()">取消</button>
  106. <button type="primary" class="primary-btn btn" @click="logout">确定</button>
  107. </view>
  108. </view>
  109. </uni-popup>
  110. </view>
  111. </template>
  112. <script>
  113. import { mapState } from 'vuex';
  114. export default {
  115. name: 'LayoutTop',
  116. props: {},
  117. created() {
  118. this.getStoreList();
  119. },
  120. data() {
  121. return {
  122. moreIndex: 0,
  123. logoError: false,
  124. storeList: [],
  125. codeData: {
  126. old_pass: '',
  127. new_pass: '',
  128. confirm_new_pass: ''
  129. }
  130. };
  131. },
  132. computed: {
  133. ...mapState(['first', 'second', 'third', 'currRoute', 'addon', 'userInfo', 'menu']),
  134. menuName: function(){
  135. let pages = getCurrentPages();
  136. let page = pages[pages.length - 1];
  137. let title = page && page.$holder ? page.$holder.navigationBarTitleText : '';
  138. return title;
  139. }
  140. },
  141. watch: {
  142. storeInfo: function() {
  143. this.$store.dispatch('getUserGroup');
  144. },
  145. menu: function() {
  146. this.checkPageAuth();
  147. }
  148. },
  149. methods: {
  150. logout() {
  151. this.$api.sendRequest({
  152. url: '/cashier/storeapi/cashier/changeshifts',
  153. success: res => {
  154. if (res.code == 0 && res.data) {
  155. this.$refs.logout.close();
  156. uni.removeStorage({
  157. key: 'cashier_token',
  158. success: () => {
  159. this.$store.commit('setStoreInfo', null);
  160. this.$store.commit('setMemberInfo', null);
  161. this.$store.commit('setUserInfo', null);
  162. this.$store.commit('setMenu', []);
  163. this.$util.redirectTo('/pages/login/login', {}, 'reLaunch');
  164. }
  165. });
  166. } else {
  167. this.isSub = false;
  168. this.$util.showToast({
  169. title: res.message
  170. });
  171. }
  172. }
  173. });
  174. },
  175. switchStore() {
  176. this.$refs.storePop.open('center');
  177. },
  178. changePassword() {
  179. this.$refs.passwordPopup.open('center');
  180. },
  181. modifyPasswordFn() {
  182. if (this.codeData.new_pass != this.codeData.confirm_new_pass) {
  183. this.$util.showToast({
  184. title: '两次密码输入不一致,请重新输入'
  185. });
  186. return false;
  187. }
  188. this.$api.sendRequest({
  189. url: '/cashier/storeapi/user/modifypassword',
  190. data: this.codeData,
  191. success: res => {
  192. this.$util.showToast({
  193. title: res.message
  194. });
  195. if (res.code >= 0) {
  196. this.codeData.old_pass = '';
  197. this.codeData.new_pass = '';
  198. this.codeData.confirm_new_pass = '';
  199. uni.removeStorageSync('cashier_token');
  200. this.$refs.passwordPopup.close();
  201. setTimeout(() => {
  202. this.$util.redirectTo('/pages/login/login');
  203. }, 500);
  204. }
  205. }
  206. });
  207. },
  208. selectStore(data) {
  209. uni.setStorageSync('store_id', data.store_id);
  210. this.$store.dispatch('getStoreInfo');
  211. this.$refs.storePop.close();
  212. this.$forceUpdate();
  213. },
  214. getStoreList() {
  215. this.$api.sendRequest({
  216. url: '/cashier/storeapi/store/lists',
  217. success: res => {
  218. if (res.code == 0 && res.data) this.storeList = res.data;
  219. }
  220. });
  221. },
  222. /**
  223. * 检测页面是否有权限
  224. */
  225. checkPageAuth() {
  226. this.$api.sendRequest({
  227. url: '/cashier/storeapi/store/checkpageauth',
  228. data: {
  229. page: this.currRoute
  230. },
  231. success: res => {
  232. if (res.code && res.code == -10012) {
  233. this.$util.redirectTo('/pages/index/no_permission', {}, 'redirectTo');
  234. }
  235. }
  236. });
  237. }
  238. }
  239. };
  240. </script>
  241. <style lang="scss">
  242. .top-container{
  243. position: relative;
  244. margin-left: -.06rem;
  245. margin-bottom: .06rem;
  246. padding: 0 .2rem;
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. flex-direction: row-reverse;
  251. height: .45rem;
  252. background-color: #fff;
  253. .top-left{
  254. position: absolute;
  255. left: 50%;
  256. transform: translateX(-50%);
  257. font-size: 18px;
  258. }
  259. .top-right{
  260. display: flex;
  261. align-items: center;
  262. .curr-store{
  263. margin-right: .08rem;
  264. border: .01rem solid $uni-color-primary;
  265. border-radius: .02rem;
  266. font-size: $uni-font-size-sm;
  267. color: $uni-color-primary;
  268. line-height: 1;
  269. padding: .04rem .06rem;
  270. }
  271. .cut-store{
  272. margin-right: 10px;
  273. font-size: $uni-font-size-sm;
  274. color: $uni-color-primary;
  275. }
  276. }
  277. }
  278. .dropdown-menu {
  279. padding: 0rem 0;
  280. margin-top: 0.15rem;
  281. background-color: #fff;
  282. border: 0.01rem solid #ebeef5;
  283. border-radius: 0.04rem;
  284. box-shadow: 0 0.01rem 0.12rem 0 rgba(0, 0, 0, 0.1);
  285. position: relative;
  286. width: 3rem;
  287. .arrow {
  288. position: absolute;
  289. top: -0.1rem;
  290. right: 0.08rem;
  291. width: 0;
  292. height: 0;
  293. border-left: 0.1rem solid transparent;
  294. border-right: 0.1rem solid transparent;
  295. border-bottom: 0.1rem solid #fff;
  296. }
  297. .menu-item {
  298. width: calc(100% - 0.2rem);
  299. height: 0.57rem;
  300. display: flex;
  301. align-items: center;
  302. justify-content: space-between;
  303. margin: 0 0.1rem;
  304. padding: 0.05rem 0.05rem;
  305. text-align: center;
  306. cursor: pointer;
  307. color: #303133;
  308. box-sizing: border-box;
  309. border-bottom: 0.01rem solid #e6e6e6;
  310. &:hover {
  311. color: $primary-color;
  312. }
  313. .iconfont {
  314. color: #999;
  315. }
  316. &:nth-child(3) {
  317. border: 0;
  318. }
  319. &.logout {
  320. margin: 0;
  321. background-color: #eff0f4;
  322. padding: 0.05rem 0.15rem;
  323. width: 100%;
  324. }
  325. }
  326. }
  327. .pop-box {
  328. background: #ffffff;
  329. width: 6rem;
  330. height: 4rem;
  331. .pop-header {
  332. padding: 0 0.15rem 0 0.2rem;
  333. height: 0.5rem;
  334. line-height: 0.5rem;
  335. border-bottom: 0.01rem solid #f0f0f0;
  336. font-size: 0.14rem;
  337. color: #333;
  338. overflow: hidden;
  339. border-radius: 0.02rem 0.2rem 0 0;
  340. box-sizing: border-box;
  341. display: flex;
  342. justify-content: space-between;
  343. .pop-header-text {
  344. }
  345. .pop-header-close {
  346. cursor: pointer;
  347. i {
  348. font-size: 0.18rem;
  349. }
  350. }
  351. }
  352. .pop-content {
  353. height: calc(100% - 1.05rem);
  354. overflow-y: scroll;
  355. padding: 0.2rem;
  356. box-sizing: border-box;
  357. }
  358. .pop-bottom {
  359. padding: 0.1rem;
  360. height: 0.65rem;
  361. border-top: 0.01rem solid #eee;
  362. button {
  363. width: 1rem;
  364. }
  365. }
  366. }
  367. // 选择门店
  368. .store-select {
  369. .content-lists {
  370. width: calc(100% - 0.2rem);
  371. padding-bottom: 0.2rem;
  372. .content-items {
  373. cursor: pointer;
  374. border-width: 0.01rem;
  375. border-color: #cccccc;
  376. border-style: solid;
  377. padding: 0.15rem;
  378. border-radius: 0.03rem;
  379. margin-bottom: 0.1rem;
  380. display: flex;
  381. .item-info {
  382. margin-left: 0.1rem;
  383. .item-name {
  384. font-size: 0.16rem;
  385. font-weight: 600;
  386. }
  387. .item-phone {
  388. margin-top: 0.08rem;
  389. color: #999;
  390. i {
  391. margin-right: 0.05rem;
  392. font-size: 0.14rem;
  393. }
  394. }
  395. .item-addr {
  396. margin-top: 0.03rem;
  397. color: #999;
  398. i {
  399. font-size: 0.14rem;
  400. margin-right: 0.05rem;
  401. }
  402. }
  403. }
  404. .item-img {
  405. width: 0.7rem;
  406. height: 0.7rem;
  407. image {
  408. width: 100%;
  409. height: 100%;
  410. }
  411. }
  412. &.active {
  413. border-color: $primary-color;
  414. }
  415. }
  416. }
  417. }
  418. .password-popup {
  419. background-color: #fff;
  420. width: 4.5rem;
  421. .head {
  422. padding: 0 0.2rem;
  423. height: 0.5rem;
  424. line-height: 0.5rem;
  425. margin-bottom: 0.1rem;
  426. }
  427. .body {
  428. padding: 0 0.1rem 0.2rem 0.3rem;
  429. }
  430. }
  431. .logout-popup {
  432. width: 3rem;
  433. min-height: 1.5rem;
  434. border-radius: 0.06rem;
  435. background: #ffffff;
  436. padding: 0.4rem 0.15rem 0;
  437. box-sizing: border-box;
  438. .title {
  439. font-size: 0.16rem;
  440. text-align: center;
  441. }
  442. .btn {
  443. width: 100%;
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. margin-top: 0.3rem;
  448. .btn {
  449. width: 36%;
  450. height: auto;
  451. padding: 0 0.15rem;
  452. margin: 0;
  453. height: 0.35rem;
  454. }
  455. .btn:last-child {
  456. margin-left: 0.25rem;
  457. }
  458. }
  459. }
  460. </style>