index.vue 16 KB

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