index.vue 14 KB

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