index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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="!myInfo.authClientFRowID">
  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. <!-- 全屏加载过渡 -->
  27. <view class="loading-state-full" v-if="isLoading">
  28. <view class="loading-anim-box">
  29. <view class="dot-spinner">
  30. <view class="dot"></view>
  31. <view class="dot"></view>
  32. <view class="dot"></view>
  33. </view>
  34. <text class="loading-text">正在同步 ERP 数据...</text>
  35. </view>
  36. </view>
  37. <scroll-view scroll-y class="order-scroll-list" :show-scrollbar="false" :enhanced="true" v-else>
  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({ fOrderId: '' });
  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. }
  170. },
  171. goToLogin() {
  172. uni.reLaunch({ url: '/pages/login/index' });
  173. },
  174. contactAdmin() { uni.showModal({ title: '联系管理员', content: '管理员电话:138-0000-0000', showCancel: false, confirmColor: '#C1001C' }); },
  175. goToAddModel() {
  176. uni.navigateTo({
  177. url: '/pages/order/add-model/index'
  178. });
  179. },
  180. editItem(index, item) {
  181. uni.navigateTo({
  182. url: `/pages/order/edit-model/index?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  183. });
  184. },
  185. removeItem(index) {
  186. const self = this;
  187. uni.showModal({
  188. title: '提示',
  189. content: '确定移除该型号吗?',
  190. success: (res) => {
  191. if (res.confirm) {
  192. self.selectedModels.splice(index, 1);
  193. }
  194. }
  195. });
  196. },
  197. async submitFinalOrder() {
  198. if (this.selectedModels.length === 0) return;
  199. uni.showLoading({ title: '正在提交订单', mask: true });
  200. try {
  201. const detailIds = this.selectedModels.map(item => item.frowId);
  202. await addOrder({ detailIds });
  203. uni.hideLoading();
  204. uni.showToast({ title: '下单成功', icon: 'success' });
  205. setTimeout(() => {
  206. uni.navigateTo({
  207. url: '/pages/order/success/index'
  208. });
  209. }, 1500);
  210. } catch (e) {
  211. uni.hideLoading();
  212. // request.js 会统一处理并提示异常信息
  213. }
  214. }
  215. }
  216. }
  217. </script>
  218. <style scoped>
  219. /deep/ ::-webkit-scrollbar {
  220. display: none !important;
  221. width: 0 !important;
  222. height: 0 !important;
  223. }
  224. .order-container {
  225. width: 100%;
  226. height: 100vh;
  227. background: #f8fafc;
  228. display: flex;
  229. flex-direction: column;
  230. overflow: hidden;
  231. }
  232. /* 授权等待样式保持一致 */
  233. .auth-waiting-full {
  234. flex: 1;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. justify-content: flex-start;
  239. padding: 200rpx 40rpx 40rpx;
  240. background: linear-gradient(180deg, rgba(0, 122, 255, 0.08) 0%, rgba(247, 248, 250, 1) 100%);
  241. }
  242. .auth-card {
  243. display: flex;
  244. flex-direction: column;
  245. align-items: center;
  246. text-align: center;
  247. }
  248. .auth-icon {
  249. width: 200rpx;
  250. height: 200rpx;
  251. margin-bottom: 50rpx;
  252. }
  253. .auth-title {
  254. font-size: 44rpx;
  255. font-weight: bold;
  256. color: #1a1a1a;
  257. margin-bottom: 24rpx;
  258. }
  259. .auth-desc {
  260. font-size: 28rpx;
  261. color: #666;
  262. line-height: 1.8;
  263. margin-bottom: 80rpx;
  264. padding: 0 20rpx;
  265. }
  266. .contact-btn {
  267. width: 360rpx;
  268. height: 96rpx;
  269. background: linear-gradient(135deg, #C1001C 0%, #FF4D4F 100%);
  270. color: #fff;
  271. border-radius: 48rpx;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. font-size: 32rpx;
  276. font-weight: bold;
  277. border: none;
  278. box-shadow: 0 12rpx 30rpx rgba(193, 0, 28, 0.2);
  279. }
  280. .authorized-btn {
  281. width: 360rpx;
  282. height: 96rpx;
  283. background: #fff;
  284. color: #C1001C;
  285. border-radius: 48rpx;
  286. display: flex;
  287. align-items: center;
  288. justify-content: center;
  289. font-size: 32rpx;
  290. font-weight: bold;
  291. border: 2rpx solid #C1001C;
  292. margin-top: 30rpx;
  293. }
  294. /* 已授权列表页样式 */
  295. .order-container {
  296. width: 100%;
  297. height: 100vh;
  298. background: #f7f8fa;
  299. display: flex;
  300. flex-direction: column;
  301. overflow: hidden;
  302. }
  303. .order-scroll-list {
  304. flex: 1;
  305. height: 0;
  306. }
  307. .list-wrapper {
  308. padding: 30rpx;
  309. /* 确保最后一条数据不被底部双层固定栏遮挡:汇总栏130 + 菜单栏110 + 安全区 + 缓冲余量 */
  310. padding-bottom: calc(280rpx + env(safe-area-inset-bottom));
  311. }
  312. .list-header {
  313. padding: 10rpx 0 20rpx;
  314. }
  315. .header-text {
  316. font-size: 34rpx;
  317. font-weight: bold;
  318. color: #1a1a1a;
  319. position: relative;
  320. padding-left: 24rpx;
  321. }
  322. .header-text::before {
  323. content: '';
  324. position: absolute;
  325. left: 0;
  326. top: 10%;
  327. height: 80%;
  328. width: 8rpx;
  329. background: #C1001C;
  330. border-radius: 4rpx;
  331. }
  332. /* 型号卡片:大幅升级美化 */
  333. .model-item-card {
  334. background: #fff;
  335. border-radius: 24rpx;
  336. padding: 36rpx;
  337. margin-bottom: 30rpx;
  338. position: relative;
  339. box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.04);
  340. border: 1rpx solid rgba(0, 0, 0, 0.02);
  341. }
  342. .remove-icon {
  343. position: absolute;
  344. right: 0;
  345. top: 0;
  346. width: 50rpx;
  347. height: 50rpx;
  348. background: rgba(255, 77, 79, 0.1);
  349. border-radius: 0 24rpx 0 24rpx;
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. z-index: 5;
  354. }
  355. .x-icon {
  356. font-size: 32rpx;
  357. color: #ff4d4f;
  358. font-weight: bold;
  359. }
  360. .card-line {
  361. display: flex;
  362. align-items: center;
  363. margin-bottom: 20rpx;
  364. }
  365. .card-line.secondary {
  366. margin-bottom: 0;
  367. padding-top: 20rpx;
  368. border-top: 1rpx dashed #f0f0f0;
  369. }
  370. .model-value {
  371. font-size: 34rpx;
  372. font-weight: bold;
  373. color: #333;
  374. flex: 1;
  375. }
  376. .count-tag {
  377. background: #FFF1F2;
  378. color: #C1001C;
  379. padding: 4rpx 16rpx;
  380. border-radius: 8rpx;
  381. font-size: 24rpx;
  382. font-weight: bold;
  383. }
  384. .count-num {
  385. font-size: 30rpx;
  386. margin-left: 8rpx;
  387. }
  388. .surface-label {
  389. font-size: 26rpx;
  390. color: #999;
  391. }
  392. .surface-text {
  393. font-size: 28rpx;
  394. color: #666;
  395. }
  396. /* 悬浮添加按钮:位置上移避免拥挤 */
  397. .floating-add-btn {
  398. position: fixed;
  399. right: 40rpx;
  400. bottom: calc(260rpx + env(safe-area-inset-bottom) + 40rpx);
  401. width: 110rpx;
  402. height: 110rpx;
  403. background: #C1001C;
  404. border-radius: 50%;
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. box-shadow: 0 12rpx 40rpx rgba(193, 0, 28, 0.4);
  409. z-index: 100;
  410. transition: transform 0.2s;
  411. }
  412. .floating-add-btn:active {
  413. transform: scale(0.9);
  414. }
  415. .plus-icon {
  416. width: 40rpx;
  417. height: 4rpx;
  418. background: #fff;
  419. border-radius: 2rpx;
  420. position: relative;
  421. }
  422. .plus-icon::after {
  423. content: '';
  424. position: absolute;
  425. top: 0;
  426. left: 0;
  427. width: 100%;
  428. height: 100%;
  429. background: #fff;
  430. transform: rotate(90deg);
  431. border-radius: 2rpx;
  432. }
  433. /* 底部汇总栏:微调间距与样式 */
  434. .footer-summary-bar {
  435. position: fixed;
  436. bottom: calc(110rpx + env(safe-area-inset-bottom));
  437. left: 0;
  438. width: 100%;
  439. height: 130rpx;
  440. background: #fff;
  441. border-top: 1rpx solid #f0f0f0;
  442. display: flex;
  443. align-items: center;
  444. justify-content: space-between;
  445. padding: 0 40rpx;
  446. box-sizing: border-box;
  447. z-index: 99;
  448. box-shadow: 0 -10rpx 40rpx rgba(0, 0, 0, 0.05);
  449. }
  450. .summary-info {
  451. display: flex;
  452. align-items: center;
  453. }
  454. .count-label {
  455. font-size: 26rpx;
  456. color: #999;
  457. }
  458. .num-highlight {
  459. font-size: 36rpx;
  460. font-weight: bold;
  461. color: #1a1a1a;
  462. margin: 0 4rpx;
  463. }
  464. .num-highlight.green {
  465. color: #C1001C;
  466. }
  467. .unit {
  468. font-size: 24rpx;
  469. color: #999;
  470. margin-left: 2rpx;
  471. }
  472. .split-line {
  473. width: 1rpx;
  474. height: 30rpx;
  475. background: #eee;
  476. margin: 0 20rpx;
  477. }
  478. .submit-order-btn {
  479. width: 220rpx;
  480. height: 80rpx;
  481. background: #e0e0e0;
  482. color: #666;
  483. font-size: 28rpx;
  484. border-radius: 40rpx;
  485. display: flex;
  486. align-items: center;
  487. justify-content: center;
  488. border: none;
  489. margin: 0;
  490. transition: all 0.3s;
  491. }
  492. .submit-order-btn:not([disabled]) {
  493. background: #C1001C;
  494. color: #fff;
  495. font-weight: bold;
  496. }
  497. /* 全屏缺省页样式 */
  498. .empty-state-full {
  499. display: flex;
  500. flex-direction: column;
  501. align-items: center;
  502. justify-content: center;
  503. padding-top: 120rpx;
  504. }
  505. .empty-visual {
  506. position: relative;
  507. margin-bottom: 40rpx;
  508. width: 400rpx;
  509. height: 400rpx;
  510. display: flex;
  511. align-items: center;
  512. justify-content: center;
  513. }
  514. .empty-img {
  515. width: 320rpx;
  516. height: 320rpx;
  517. z-index: 2;
  518. }
  519. .empty-bg-glow {
  520. position: absolute;
  521. width: 240rpx;
  522. height: 240rpx;
  523. background: radial-gradient(circle, rgba(193, 0, 28, 0.15) 0%, rgba(248, 250, 252, 0) 70%);
  524. z-index: 1;
  525. border-radius: 50%;
  526. }
  527. .empty-title {
  528. font-size: 36rpx;
  529. font-weight: bold;
  530. color: #1a1a1a;
  531. margin-bottom: 80rpx;
  532. }
  533. .empty-desc {
  534. font-size: 26rpx;
  535. color: #999;
  536. margin-bottom: 60rpx;
  537. text-align: center;
  538. padding: 0 80rpx;
  539. line-height: 1.6;
  540. }
  541. .empty-action-btn {
  542. width: 320rpx;
  543. height: 90rpx;
  544. background: #C1001C;
  545. color: #fff;
  546. border-radius: 45rpx;
  547. font-size: 30rpx;
  548. font-weight: bold;
  549. display: flex;
  550. align-items: center;
  551. justify-content: center;
  552. box-shadow: 0 10rpx 30rpx rgba(193, 0, 28, 0.2);
  553. border: none;
  554. }
  555. .empty-action-btn:active {
  556. opacity: 0.8;
  557. transform: scale(0.96);
  558. }
  559. .bottom-safe-space {
  560. height: 100rpx;
  561. }
  562. /* 加载动画样式 */
  563. .loading-state-full {
  564. flex: 1;
  565. display: flex;
  566. align-items: center;
  567. justify-content: center;
  568. padding-bottom: 200rpx;
  569. }
  570. .loading-anim-box {
  571. display: flex;
  572. flex-direction: column;
  573. align-items: center;
  574. }
  575. .dot-spinner {
  576. display: flex;
  577. justify-content: center;
  578. align-items: center;
  579. margin-bottom: 30rpx;
  580. }
  581. .dot {
  582. width: 16rpx;
  583. height: 16rpx;
  584. background-color: #C1001C;
  585. border-radius: 50%;
  586. margin: 0 8rpx;
  587. animation: dot-pulse 1.4s infinite ease-in-out both;
  588. }
  589. .dot:nth-child(1) { animation-delay: -0.32s; }
  590. .dot:nth-child(2) { animation-delay: -0.16s; }
  591. @keyframes dot-pulse {
  592. 0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  593. 40% { transform: scale(1); opacity: 1; }
  594. }
  595. .loading-text {
  596. font-size: 26rpx;
  597. color: #999;
  598. letter-spacing: 2rpx;
  599. }
  600. </style>