layout-aside.vue 14 KB

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