index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <template>
  2. <view class="order-container">
  3. <erp-nav-bar title="ERP 下单" :show-back="false" />
  4. <!-- 1. 未登录状态 -->
  5. <view class="auth-waiting-full" v-if="!isLoggedIn">
  6. <view class="auth-card">
  7. <image class="auth-icon" src="https://img.icons8.com/color/192/hourglass-sand-top.png" mode="aspectFit">
  8. </image>
  9. <text class="auth-title">未登录</text>
  10. <text class="auth-desc">您还未登录账号,请先登录以后在进行下单操作</text>
  11. <button class="contact-btn" @click="goToLogin">前往登录</button>
  12. </view>
  13. </view>
  14. <!-- 2. 已登录但未分配授权客户 -->
  15. <view class="auth-waiting-full" v-else-if="authorizedClients.length === 0">
  16. <view class="auth-card">
  17. <image class="auth-icon" src="https://img.icons8.com/color/192/hourglass-sand-top.png" mode="aspectFit">
  18. </image>
  19. <text class="auth-title">待管理员授权</text>
  20. <text class="auth-desc">您的账户尚未获得下单权限,请联系管理员核准授权后即可进行下单操作。</text>
  21. <button class="contact-btn" @click="contactAdmin">联系管理员</button>
  22. </view>
  23. </view>
  24. <!-- 3. 已登录且已分配授权客户:显示下单页面 -->
  25. <template v-else>
  26. <scroll-view scroll-y class="order-scroll-list" :show-scrollbar="false" :enhanced="true">
  27. <view class="list-wrapper">
  28. <!-- 列表头部:仅在有数据时显示 -->
  29. <view class="list-header" v-if="selectedModels.length > 0">
  30. <text class="header-text">已选型号列表:</text>
  31. </view>
  32. <!-- 1. 列表渲染 (精品化设计) -->
  33. <view class="model-item-card" v-for="(item, index) in selectedModels" :key="index"
  34. v-if="selectedModels.length > 0" @click="editItem(index, item)">
  35. <view class="remove-icon" @click.stop="removeItem(index)">
  36. <text class="x-icon">×</text>
  37. </view>
  38. <view class="card-line">
  39. <text class="model-value">{{ item.type }}</text>
  40. <view class="count-tag">
  41. 支数<text class="count-num">{{ item.count }}</text>
  42. </view>
  43. </view>
  44. <view class="card-line secondary">
  45. <text class="surface-label">表面名称:</text>
  46. <text class="surface-text">{{ item.surfaceName }}</text>
  47. </view>
  48. </view>
  49. <!-- 2. 全屏缺省状态:美化后的引导页 -->
  50. <view class="empty-state-full" v-else>
  51. <view class="empty-visual">
  52. <image class="empty-img" src="https://img.icons8.com/clouds/200/shopping-cart.png"
  53. mode="aspectFit"></image>
  54. <view class="empty-bg-glow"></view>
  55. </view>
  56. <text class="empty-title">暂无已选型号</text>
  57. <button class="empty-action-btn" @click="goToAddModel">选型下单</button>
  58. </view>
  59. <view class="bottom-safe-space"></view>
  60. </view>
  61. </scroll-view>
  62. <!-- 悬浮添加按钮 (仅在有数据时显示) -->
  63. <view class="floating-add-btn" @click="goToAddModel" v-if="selectedModels.length > 0">
  64. <view class="plus-icon"></view>
  65. </view>
  66. <!-- 底部支付/下单汇总栏 (仅在有数据时显示) -->
  67. <view class="footer-summary-bar" v-if="selectedModels.length > 0">
  68. <view class="summary-info">
  69. <text class="count-label">共计:</text>
  70. <text class="num-highlight">{{ selectedModels.length }}</text>
  71. <text class="unit">条</text>
  72. <view class="split-line"></view>
  73. <text class="num-highlight green">{{ totalCount }}</text>
  74. <text class="unit">支</text>
  75. </view>
  76. <button class="submit-order-btn" :disabled="selectedModels.length === 0"
  77. @click="submitFinalOrder">立即下单</button>
  78. </view>
  79. </template>
  80. <!-- 底部菜单栏 -->
  81. <erp-tab-bar active="order"></erp-tab-bar>
  82. </view>
  83. </template>
  84. <script>
  85. import ErpTabBar from '@/components/erp-tab-bar.vue';
  86. import ErpNavBar from '@/components/erp-nav-bar.vue';
  87. import { getMyInfo } from '@/api/system/customer.js';
  88. export default {
  89. components: { ErpNavBar, ErpTabBar },
  90. data() {
  91. return {
  92. isLoggedIn: false,
  93. authorizedClients: [],
  94. selectedModels: []
  95. }
  96. },
  97. computed: {
  98. totalCount() {
  99. return this.selectedModels.reduce((sum, item) => sum + parseInt(item.count || 0), 0);
  100. }
  101. },
  102. onLoad() {
  103. // 监听添加型号的事件
  104. uni.$on('add_order_item', (data) => {
  105. this.selectedModels.push(data);
  106. uni.showToast({ title: '添加成功', icon: 'success' });
  107. });
  108. // 监听修改型号的事件
  109. uni.$on('update_order_item', (res) => {
  110. if (res.index > -1) {
  111. this.$set(this.selectedModels, res.index, res.data);
  112. uni.showToast({ title: '修改成功', icon: 'success' });
  113. }
  114. });
  115. },
  116. onShow() {
  117. this.checkLoginStatus();
  118. },
  119. onUnload() {
  120. uni.$off('add_order_item');
  121. uni.$off('update_order_item');
  122. },
  123. methods: {
  124. async checkLoginStatus() {
  125. const token = uni.getStorageSync('token');
  126. if (!token) {
  127. this.isLoggedIn = false;
  128. this.authorizedClients = [];
  129. return;
  130. }
  131. try {
  132. await getMyInfo();
  133. this.isLoggedIn = true;
  134. this.loadAuthorizedClients();
  135. } catch (e) {
  136. uni.removeStorageSync('token');
  137. uni.removeStorageSync('isLogin');
  138. this.isLoggedIn = false;
  139. this.authorizedClients = [];
  140. }
  141. },
  142. loadAuthorizedClients() {
  143. const clients = uni.getStorageSync('authorizedClients');
  144. this.authorizedClients = clients || [];
  145. },
  146. goToLogin() {
  147. uni.reLaunch({ url: '/pages/login/index' });
  148. },
  149. contactAdmin() { uni.showModal({ title: '联系管理员', content: '管理员电话:138-0000-0000', showCancel: false, confirmColor: '#C1001C' }); },
  150. goToAddModel() {
  151. uni.navigateTo({
  152. url: '/pages/order/add-model/index'
  153. });
  154. },
  155. editItem(index, item) {
  156. uni.navigateTo({
  157. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  158. });
  159. },
  160. removeItem(index) {
  161. const self = this;
  162. uni.showModal({
  163. title: '提示',
  164. content: '确定移除该型号吗?',
  165. success: (res) => {
  166. if (res.confirm) {
  167. self.selectedModels.splice(index, 1);
  168. }
  169. }
  170. });
  171. },
  172. submitFinalOrder() {
  173. if (this.selectedModels.length === 0) return;
  174. uni.showLoading({ title: '正在提交结果', mask: true });
  175. setTimeout(() => {
  176. uni.hideLoading();
  177. uni.navigateTo({
  178. url: '/pages/order/success/index'
  179. });
  180. // 注意:此处不再手动清空 selectedModels,防止跳转前页面出现“暂无数据”的闪现
  181. // 并在 success 页面点击“再来一单”时通过 reLaunch 自动重置页面状态
  182. }, 1500);
  183. }
  184. }
  185. }
  186. </script>
  187. <style scoped>
  188. /deep/ ::-webkit-scrollbar {
  189. display: none !important;
  190. width: 0 !important;
  191. height: 0 !important;
  192. }
  193. .order-container {
  194. width: 100%;
  195. height: 100vh;
  196. background: #f8fafc;
  197. display: flex;
  198. flex-direction: column;
  199. overflow: hidden;
  200. }
  201. /* 授权等待样式保持一致 */
  202. .auth-waiting-full {
  203. flex: 1;
  204. display: flex;
  205. flex-direction: column;
  206. align-items: center;
  207. justify-content: flex-start;
  208. padding: 200rpx 40rpx 40rpx;
  209. background: linear-gradient(180deg, rgba(0, 122, 255, 0.08) 0%, rgba(247, 248, 250, 1) 100%);
  210. }
  211. .auth-card {
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. text-align: center;
  216. }
  217. .auth-icon {
  218. width: 200rpx;
  219. height: 200rpx;
  220. margin-bottom: 50rpx;
  221. }
  222. .auth-title {
  223. font-size: 44rpx;
  224. font-weight: bold;
  225. color: #1a1a1a;
  226. margin-bottom: 24rpx;
  227. }
  228. .auth-desc {
  229. font-size: 28rpx;
  230. color: #666;
  231. line-height: 1.8;
  232. margin-bottom: 80rpx;
  233. padding: 0 20rpx;
  234. }
  235. .contact-btn {
  236. width: 360rpx;
  237. height: 96rpx;
  238. background: linear-gradient(135deg, #C1001C 0%, #FF4D4F 100%);
  239. color: #fff;
  240. border-radius: 48rpx;
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. font-size: 32rpx;
  245. font-weight: bold;
  246. border: none;
  247. box-shadow: 0 12rpx 30rpx rgba(193, 0, 28, 0.2);
  248. }
  249. .authorized-btn {
  250. width: 360rpx;
  251. height: 96rpx;
  252. background: #fff;
  253. color: #C1001C;
  254. border-radius: 48rpx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: center;
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. border: 2rpx solid #C1001C;
  261. margin-top: 30rpx;
  262. }
  263. /* 已授权列表页样式 */
  264. .order-container {
  265. width: 100%;
  266. height: 100vh;
  267. background: #f7f8fa;
  268. display: flex;
  269. flex-direction: column;
  270. overflow: hidden;
  271. }
  272. .order-scroll-list {
  273. flex: 1;
  274. height: 0;
  275. }
  276. .list-wrapper {
  277. padding: 30rpx;
  278. /* 确保最后一条数据不被底部双层固定栏遮挡:汇总栏130 + 菜单栏110 + 安全区 + 缓冲余量 */
  279. padding-bottom: calc(280rpx + env(safe-area-inset-bottom));
  280. }
  281. .list-header {
  282. padding: 10rpx 0 20rpx;
  283. }
  284. .header-text {
  285. font-size: 34rpx;
  286. font-weight: bold;
  287. color: #1a1a1a;
  288. position: relative;
  289. padding-left: 24rpx;
  290. }
  291. .header-text::before {
  292. content: '';
  293. position: absolute;
  294. left: 0;
  295. top: 10%;
  296. height: 80%;
  297. width: 8rpx;
  298. background: #C1001C;
  299. border-radius: 4rpx;
  300. }
  301. /* 型号卡片:大幅升级美化 */
  302. .model-item-card {
  303. background: #fff;
  304. border-radius: 24rpx;
  305. padding: 36rpx;
  306. margin-bottom: 30rpx;
  307. position: relative;
  308. box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.04);
  309. border: 1rpx solid rgba(0, 0, 0, 0.02);
  310. }
  311. .remove-icon {
  312. position: absolute;
  313. right: 0;
  314. top: 0;
  315. width: 50rpx;
  316. height: 50rpx;
  317. background: rgba(255, 77, 79, 0.1);
  318. border-radius: 0 24rpx 0 24rpx;
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. z-index: 5;
  323. }
  324. .x-icon {
  325. font-size: 32rpx;
  326. color: #ff4d4f;
  327. font-weight: bold;
  328. }
  329. .card-line {
  330. display: flex;
  331. align-items: center;
  332. margin-bottom: 20rpx;
  333. }
  334. .card-line.secondary {
  335. margin-bottom: 0;
  336. padding-top: 20rpx;
  337. border-top: 1rpx dashed #f0f0f0;
  338. }
  339. .model-label {
  340. font-size: 26rpx;
  341. color: #999;
  342. }
  343. .model-value {
  344. font-size: 34rpx;
  345. font-weight: bold;
  346. color: #333;
  347. flex: 1;
  348. }
  349. .count-tag {
  350. background: #FFF1F2;
  351. color: #C1001C;
  352. padding: 4rpx 16rpx;
  353. border-radius: 8rpx;
  354. font-size: 24rpx;
  355. font-weight: bold;
  356. }
  357. .count-num {
  358. font-size: 30rpx;
  359. margin-left: 8rpx;
  360. }
  361. .surface-label {
  362. font-size: 26rpx;
  363. color: #999;
  364. }
  365. .surface-text {
  366. font-size: 28rpx;
  367. color: #666;
  368. }
  369. /* 悬浮添加按钮:位置上移避免拥挤 */
  370. .floating-add-btn {
  371. position: fixed;
  372. right: 40rpx;
  373. bottom: calc(260rpx + env(safe-area-inset-bottom) + 40rpx);
  374. width: 110rpx;
  375. height: 110rpx;
  376. background: #C1001C;
  377. border-radius: 50%;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. box-shadow: 0 12rpx 40rpx rgba(193, 0, 28, 0.4);
  382. z-index: 100;
  383. transition: transform 0.2s;
  384. }
  385. .floating-add-btn:active {
  386. transform: scale(0.9);
  387. }
  388. .plus-icon {
  389. width: 40rpx;
  390. height: 4rpx;
  391. background: #fff;
  392. border-radius: 2rpx;
  393. position: relative;
  394. }
  395. .plus-icon::after {
  396. content: '';
  397. position: absolute;
  398. top: 0;
  399. left: 0;
  400. width: 100%;
  401. height: 100%;
  402. background: #fff;
  403. transform: rotate(90deg);
  404. border-radius: 2rpx;
  405. }
  406. /* 底部汇总栏:微调间距与样式 */
  407. .footer-summary-bar {
  408. position: fixed;
  409. bottom: calc(110rpx + env(safe-area-inset-bottom));
  410. left: 0;
  411. width: 100%;
  412. height: 130rpx;
  413. background: #fff;
  414. border-top: 1rpx solid #f0f0f0;
  415. display: flex;
  416. align-items: center;
  417. justify-content: space-between;
  418. padding: 0 40rpx;
  419. box-sizing: border-box;
  420. z-index: 99;
  421. box-shadow: 0 -10rpx 40rpx rgba(0, 0, 0, 0.05);
  422. }
  423. .summary-info {
  424. display: flex;
  425. align-items: center;
  426. }
  427. .count-label {
  428. font-size: 26rpx;
  429. color: #999;
  430. }
  431. .num-highlight {
  432. font-size: 36rpx;
  433. font-weight: bold;
  434. color: #1a1a1a;
  435. margin: 0 4rpx;
  436. }
  437. .num-highlight.green {
  438. color: #C1001C;
  439. }
  440. .unit {
  441. font-size: 24rpx;
  442. color: #999;
  443. margin-left: 2rpx;
  444. }
  445. .split-line {
  446. width: 1rpx;
  447. height: 30rpx;
  448. background: #eee;
  449. margin: 0 20rpx;
  450. }
  451. .submit-order-btn {
  452. width: 220rpx;
  453. height: 80rpx;
  454. background: #e0e0e0;
  455. color: #666;
  456. font-size: 28rpx;
  457. border-radius: 40rpx;
  458. display: flex;
  459. align-items: center;
  460. justify-content: center;
  461. border: none;
  462. margin: 0;
  463. transition: all 0.3s;
  464. }
  465. .submit-order-btn:not([disabled]) {
  466. background: #C1001C;
  467. color: #fff;
  468. font-weight: bold;
  469. }
  470. /* 全屏缺省页样式 */
  471. .empty-state-full {
  472. display: flex;
  473. flex-direction: column;
  474. align-items: center;
  475. justify-content: center;
  476. padding-top: 120rpx;
  477. }
  478. .empty-visual {
  479. position: relative;
  480. margin-bottom: 40rpx;
  481. width: 400rpx;
  482. height: 400rpx;
  483. display: flex;
  484. align-items: center;
  485. justify-content: center;
  486. }
  487. .empty-img {
  488. width: 320rpx;
  489. height: 320rpx;
  490. z-index: 2;
  491. }
  492. .empty-bg-glow {
  493. position: absolute;
  494. width: 240rpx;
  495. height: 240rpx;
  496. background: radial-gradient(circle, rgba(193, 0, 28, 0.15) 0%, rgba(248, 250, 252, 0) 70%);
  497. z-index: 1;
  498. border-radius: 50%;
  499. }
  500. .empty-title {
  501. font-size: 36rpx;
  502. font-weight: bold;
  503. color: #1a1a1a;
  504. margin-bottom: 80rpx;
  505. }
  506. .empty-desc {
  507. font-size: 26rpx;
  508. color: #999;
  509. margin-bottom: 60rpx;
  510. text-align: center;
  511. padding: 0 80rpx;
  512. line-height: 1.6;
  513. }
  514. .empty-action-btn {
  515. width: 320rpx;
  516. height: 90rpx;
  517. background: #C1001C;
  518. color: #fff;
  519. border-radius: 45rpx;
  520. font-size: 30rpx;
  521. font-weight: bold;
  522. display: flex;
  523. align-items: center;
  524. justify-content: center;
  525. box-shadow: 0 10rpx 30rpx rgba(193, 0, 28, 0.2);
  526. border: none;
  527. }
  528. .empty-action-btn:active {
  529. opacity: 0.8;
  530. transform: scale(0.96);
  531. }
  532. .bottom-safe-space {
  533. height: 100rpx;
  534. }
  535. </style>