index.vue 14 KB

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