index.vue 15 KB

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