order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="order-container">
  3. <!-- 1. 未登录状态拦截 -->
  4. <view class="not-logged-in-full" v-if="!isLogin">
  5. <view class="auth-card">
  6. <image class="auth-icon" src="https://img.icons8.com/clouds/200/lock.png" mode="aspectFit"></image>
  7. <text class="auth-title">您还未登录</text>
  8. <text class="auth-desc">请先登录账号,授权后即可查看下单权限并进行下单操作。</text>
  9. <button class="contact-btn" @click="goToLogin">去登录</button>
  10. </view>
  11. </view>
  12. <!-- 2. 待管理员授权状态 (已登录但无权限) -->
  13. <view class="auth-waiting-full" v-else-if="!isAuthorized">
  14. <view class="auth-card">
  15. <image class="auth-icon" src="https://img.icons8.com/color/192/hourglass-sand-top.png" mode="aspectFit"></image>
  16. <text class="auth-title">待管理员授权</text>
  17. <text class="auth-desc">您的账户尚未获得下单权限,请联系管理员核准授权后即可进行下单操作。</text>
  18. <button class="contact-btn" @click="contactAdmin">联系管理员</button>
  19. <button class="authorized-btn" @click="isAuthorized = true">我已授权</button>
  20. </view>
  21. </view>
  22. <!-- 3. 已授权状态:已选型号列表 (参考草图2) -->
  23. <template v-else>
  24. <scroll-view
  25. scroll-y
  26. class="order-scroll-list"
  27. :show-scrollbar="false"
  28. :enhanced="true">
  29. <view class="list-wrapper">
  30. <!-- 列表头部:仅在有数据时显示 -->
  31. <view class="list-header" v-if="selectedModels.length > 0">
  32. <text class="header-text">已选型号列表:</text>
  33. </view>
  34. <!-- 1. 列表渲染 (精品化设计) -->
  35. <view class="model-item-card" v-for="(item, index) in selectedModels" :key="index" v-if="selectedModels.length > 0" @click="editItem(index, item)">
  36. <view class="remove-icon" @click.stop="removeItem(index)">
  37. <text class="x-icon">×</text>
  38. </view>
  39. <view class="card-line">
  40. <text class="model-value">{{item.type}}</text>
  41. <view class="count-tag">
  42. 支数<text class="count-num">{{item.count}}</text>
  43. </view>
  44. </view>
  45. <view class="card-line secondary">
  46. <text class="surface-label">表面名称:</text>
  47. <text class="surface-text">{{item.surfaceName}}</text>
  48. </view>
  49. </view>
  50. <!-- 2. 全屏缺省状态:美化后的引导页 -->
  51. <view class="empty-state-full" v-else>
  52. <view class="empty-visual">
  53. <image class="empty-img" src="https://img.icons8.com/clouds/200/shopping-cart.png" mode="aspectFit"></image>
  54. <view class="empty-bg-glow"></view>
  55. </view>
  56. <text class="empty-title">暂无已选型号</text>
  57. <button class="empty-action-btn" @click="goToAddModel">选型下单</button>
  58. </view>
  59. <view class="bottom-safe-space"></view>
  60. </view>
  61. </scroll-view>
  62. <!-- 悬浮添加按钮 (仅在有数据时显示) -->
  63. <view class="floating-add-btn" @click="goToAddModel" v-if="selectedModels.length > 0">
  64. <view class="plus-icon"></view>
  65. </view>
  66. <!-- 底部支付/下单汇总栏 (仅在有数据时显示) -->
  67. <view class="footer-summary-bar" v-if="selectedModels.length > 0">
  68. <view class="summary-info">
  69. <text class="count-label">共计:</text>
  70. <text class="num-highlight">{{selectedModels.length}}</text>
  71. <text class="unit">条</text>
  72. <view class="split-line"></view>
  73. <text class="num-highlight green">{{totalCount}}</text>
  74. <text class="unit">支</text>
  75. </view>
  76. <button class="submit-order-btn" :disabled="selectedModels.length === 0" @click="submitFinalOrder">立即下单</button>
  77. </view>
  78. </template>
  79. <!-- 底部菜单栏 -->
  80. <erp-tab-bar active="order"></erp-tab-bar>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. return {
  87. isLogin: false,
  88. isAuthorized: false,
  89. selectedModels: []
  90. }
  91. },
  92. computed: {
  93. totalCount() {
  94. return this.selectedModels.reduce((sum, item) => sum + parseInt(item.count || 0), 0);
  95. }
  96. },
  97. onLoad() {
  98. // 监听添加型号的事件
  99. uni.$on('add_order_item', (data) => {
  100. this.selectedModels.push(data);
  101. uni.showToast({ title: '添加成功', icon: 'success' });
  102. });
  103. // 监听修改型号的事件
  104. uni.$on('update_order_item', (res) => {
  105. if (res.index > -1) {
  106. this.$set(this.selectedModels, res.index, res.data);
  107. uni.showToast({ title: '修改成功', icon: 'success' });
  108. }
  109. });
  110. },
  111. onShow() {
  112. // 每次进入页面刷新登录状态
  113. this.isLogin = !!uni.getStorageSync('isLogin');
  114. // 如果已登录,模拟获取授权状态(实际开发中应请求接口)
  115. if (this.isLogin) {
  116. // 假设只要登录了就默认展示已授权,或者维持原有逻辑
  117. // 这里为了演示“待授权”状态,我们手动控制它,或者根据登录状态设置
  118. // this.isAuthorized = true;
  119. }
  120. },
  121. onUnload() {
  122. uni.$off('add_order_item');
  123. uni.$off('update_order_item');
  124. },
  125. methods: {
  126. goToLogin() {
  127. uni.navigateTo({
  128. url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/order/order')
  129. });
  130. },
  131. contactAdmin() { uni.showModal({ title: '联系管理员', content: '管理员电话:138-0000-0000', showCancel: false, confirmColor: '#C1001C' }); },
  132. goToAddModel() {
  133. uni.navigateTo({
  134. url: '/pages/order/add_model'
  135. });
  136. },
  137. editItem(index, item) {
  138. uni.navigateTo({
  139. url: `/pages/order/edit_model?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
  140. });
  141. },
  142. removeItem(index) {
  143. const self = this;
  144. uni.showModal({
  145. title: '提示',
  146. content: '确定移除该型号吗?',
  147. success: (res) => {
  148. if (res.confirm) {
  149. self.selectedModels.splice(index, 1);
  150. }
  151. }
  152. });
  153. },
  154. submitFinalOrder() {
  155. if (this.selectedModels.length === 0) return;
  156. uni.showLoading({ title: '正在提交结果', mask: true });
  157. setTimeout(() => {
  158. uni.hideLoading();
  159. uni.navigateTo({
  160. url: '/pages/order/success'
  161. });
  162. // 注意:此处不再手动清空 selectedModels,防止跳转前页面出现“暂无数据”的闪现
  163. // 并在 success 页面点击“再来一单”时通过 reLaunch 自动重置页面状态
  164. }, 1500);
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped>
  170. /deep/ ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
  171. .order-container { width: 100%; height: 100vh; background: #f8fafc; display: flex; flex-direction: column; overflow: hidden; }
  172. /* 授权等待/未登录样式保持一致 */
  173. .auth-waiting-full, .not-logged-in-full { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 200rpx 40rpx 40rpx; background: linear-gradient(180deg, rgba(0, 122, 255, 0.08) 0%, rgba(247, 248, 250, 1) 100%); }
  174. .auth-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
  175. .auth-icon { width: 200rpx; height: 200rpx; margin-bottom: 50rpx; }
  176. .auth-title { font-size: 44rpx; font-weight: bold; color: #1a1a1a; margin-bottom: 24rpx; }
  177. .auth-desc { font-size: 28rpx; color: #666; line-height: 1.8; margin-bottom: 80rpx; padding: 0 20rpx; }
  178. .contact-btn { width: 360rpx; height: 96rpx; background: linear-gradient(135deg, #C1001C 0%, #FF4D4F 100%); color: #fff; border-radius: 48rpx; display: flex; align-items: center; justify-content: center; font-size: 32rpx; font-weight: bold; border: none; box-shadow: 0 12rpx 30rpx rgba(193, 0, 28, 0.2); }
  179. .authorized-btn { width: 360rpx; height: 96rpx; background: #fff; color: #C1001C; border-radius: 48rpx; display: flex; align-items: center; justify-content: center; font-size: 32rpx; font-weight: bold; border: 2rpx solid #C1001C; margin-top: 30rpx; }
  180. /* 已授权列表页样式 */
  181. .order-container { width: 100%; height: 100vh; background: #f7f8fa; display: flex; flex-direction: column; overflow: hidden; }
  182. .order-scroll-list { flex: 1; height: 0; }
  183. .list-wrapper {
  184. padding: 30rpx;
  185. /* 确保最后一条数据不被底部双层固定栏遮挡:汇总栏130 + 菜单栏110 + 安全区 + 缓冲余量 */
  186. padding-bottom: calc(280rpx + env(safe-area-inset-bottom));
  187. }
  188. .list-header { padding: 10rpx 0 20rpx; }
  189. .header-text { font-size: 34rpx; font-weight: bold; color: #1a1a1a; position: relative; padding-left: 24rpx; }
  190. .header-text::before { content: ''; position: absolute; left: 0; top: 10%; height: 80%; width: 8rpx; background: #C1001C; border-radius: 4rpx; }
  191. /* 型号卡片:大幅升级美化 */
  192. .model-item-card {
  193. background: #fff;
  194. border-radius: 24rpx;
  195. padding: 36rpx;
  196. margin-bottom: 30rpx;
  197. position: relative;
  198. box-shadow: 0 8rpx 30rpx rgba(0,0,0,0.04);
  199. border: 1rpx solid rgba(0,0,0,0.02);
  200. }
  201. .remove-icon {
  202. position: absolute;
  203. right: 0;
  204. top: 0;
  205. width: 50rpx;
  206. height: 50rpx;
  207. background: rgba(255, 77, 79, 0.1);
  208. border-radius: 0 24rpx 0 24rpx;
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. z-index: 5;
  213. }
  214. .x-icon { font-size: 32rpx; color: #ff4d4f; font-weight: bold; }
  215. .card-line { display: flex; align-items: center; margin-bottom: 20rpx; }
  216. .card-line.secondary { margin-bottom: 0; padding-top: 20rpx; border-top: 1rpx dashed #f0f0f0; }
  217. .model-label { font-size: 26rpx; color: #999; }
  218. .model-value { font-size: 34rpx; font-weight: bold; color: #333; flex: 1; }
  219. .count-tag { background: #FFF1F2; color: #C1001C; padding: 4rpx 16rpx; border-radius: 8rpx; font-size: 24rpx; font-weight: bold; }
  220. .count-num { font-size: 30rpx; margin-left: 8rpx; }
  221. .surface-label { font-size: 26rpx; color: #999; }
  222. .surface-text { font-size: 28rpx; color: #666; }
  223. /* 悬浮添加按钮:位置上移避免拥挤 */
  224. .floating-add-btn {
  225. position: fixed;
  226. right: 40rpx;
  227. bottom: calc(260rpx + env(safe-area-inset-bottom) + 40rpx);
  228. width: 110rpx;
  229. height: 110rpx;
  230. background: #C1001C;
  231. border-radius: 50%;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. box-shadow: 0 12rpx 40rpx rgba(193, 0, 28, 0.4);
  236. z-index: 100;
  237. transition: transform 0.2s;
  238. }
  239. .floating-add-btn:active { transform: scale(0.9); }
  240. .plus-icon { width: 40rpx; height: 4rpx; background: #fff; border-radius: 2rpx; position: relative; }
  241. .plus-icon::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #fff; transform: rotate(90deg); border-radius: 2rpx; }
  242. /* 底部汇总栏:微调间距与样式 */
  243. .footer-summary-bar {
  244. position: fixed;
  245. bottom: calc(110rpx + env(safe-area-inset-bottom));
  246. left: 0;
  247. width: 100%;
  248. height: 130rpx;
  249. background: #fff;
  250. border-top: 1rpx solid #f0f0f0;
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. padding: 0 40rpx;
  255. box-sizing: border-box;
  256. z-index: 99;
  257. box-shadow: 0 -10rpx 40rpx rgba(0,0,0,0.05);
  258. }
  259. .summary-info { display: flex; align-items: center; }
  260. .count-label { font-size: 26rpx; color: #999; }
  261. .num-highlight { font-size: 36rpx; font-weight: bold; color: #1a1a1a; margin: 0 4rpx; }
  262. .num-highlight.green { color: #C1001C; }
  263. .unit { font-size: 24rpx; color: #999; margin-left: 2rpx; }
  264. .split-line { width: 1rpx; height: 30rpx; background: #eee; margin: 0 20rpx; }
  265. .submit-order-btn {
  266. width: 220rpx; height: 80rpx; background: #e0e0e0; color: #666; font-size: 28rpx;
  267. border-radius: 40rpx; display: flex; align-items: center; justify-content: center;
  268. border: none; margin: 0; transition: all 0.3s;
  269. }
  270. .submit-order-btn:not([disabled]) {
  271. background: #C1001C; color: #fff; font-weight: bold;
  272. }
  273. /* 全屏缺省页样式 */
  274. .empty-state-full {
  275. display: flex;
  276. flex-direction: column;
  277. align-items: center;
  278. justify-content: center;
  279. padding-top: 120rpx;
  280. }
  281. .empty-visual { position: relative; margin-bottom: 40rpx; width: 400rpx; height: 400rpx; display: flex; align-items: center; justify-content: center; }
  282. .empty-img { width: 320rpx; height: 320rpx; z-index: 2; }
  283. .empty-bg-glow {
  284. position: absolute; width: 240rpx; height: 240rpx;
  285. background: radial-gradient(circle, rgba(193, 0, 28, 0.15) 0%, rgba(248, 250, 252, 0) 70%);
  286. z-index: 1; border-radius: 50%;
  287. }
  288. .empty-title { font-size: 36rpx; font-weight: bold; color: #1a1a1a; margin-bottom: 80rpx; }
  289. .empty-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; text-align: center; padding: 0 80rpx; line-height: 1.6; }
  290. .empty-action-btn {
  291. width: 320rpx; height: 90rpx; background: #C1001C; color: #fff;
  292. border-radius: 45rpx; font-size: 30rpx; font-weight: bold;
  293. display: flex; align-items: center; justify-content: center;
  294. box-shadow: 0 10rpx 30rpx rgba(193, 0, 28, 0.2);
  295. border: none;
  296. }
  297. .empty-action-btn:active { opacity: 0.8; transform: scale(0.96); }
  298. .bottom-safe-space { height: 100rpx; }
  299. </style>