layout-aside.vue 14 KB

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