index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view :style="colorStyle">
  3. <view :style="{ backgroundPositionY: `${statusBarHeight + navBarHeight}px` }" class="confirm-order">
  4. <view class="nav-bar fixed">
  5. <view :style="{ height: `${statusBarHeight}px` }"></view>
  6. <view :style="{ height: `${navBarHeight}px` }" class="inner">
  7. <navigator class="btn" open-type="navigateBack" hover-class="none">
  8. <text class="iconfont icon-fanhui2"></text>
  9. </navigator>
  10. <view>提交订单</view>
  11. </view>
  12. </view>
  13. <view class="header">
  14. <view class="top">
  15. <view class="name">{{ codeData.storeName.storeName }}</view>
  16. <view class="number"><text class="light">{{ codeData.category.name }}{{ codeData.table_number }}</text>号桌</view>
  17. </view>
  18. <view>{{ codeData.serial_number }}</view>
  19. </view>
  20. <view class="dining">
  21. <view class="total">共点{{ goodsNumber }}份</view>
  22. <view>{{ tablePartake.length }}人就餐</view>
  23. </view>
  24. <view v-for="item in tablePartake" :key="item.userInfo.uid" class="dinner">
  25. <view class="head">
  26. <image class="image" :src="item.userInfo.avatar || '/static/images/f.png'" mode="aspectFill"></image>
  27. <view class="name">{{ item.userInfo.nickname }}</view>
  28. <!-- <view class="name">已点7份</view> -->
  29. <view>{{ item.order_time }}下单</view>
  30. </view>
  31. <view class="body">
  32. <view v-for="goods in item.goods" :key="goods.id" :class="{ gray: !goods.is_true_stock }" class="item">
  33. <image class="image" :src="goods.productInfo.image" mode="aspectFill"></image>
  34. <view class="text">
  35. <view class="name">{{ goods.productInfo.store_name }}</view>
  36. <view class="attr">{{ goods.productInfo.attrInfo.suk }}</view>
  37. <view class="money">¥{{ goods.truePrice }}</view>
  38. </view>
  39. <view class="number">x {{ goods.cart_num }}</view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="footer">
  44. <view class="inner"></view>
  45. </view>
  46. <view class="footer fixed">
  47. <view class="inner">
  48. <view class="total">合计:<text class="money">¥{{ total }}</text></view>
  49. <button class="btn" hover-class="none" @tap="getTableCode(onAdd)">加购</button>
  50. <button class="btn fill" hover-class="none" @tap="getTableCode(onSettle)">去结账</button>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import colors from '@/mixins/color.js';
  58. import {
  59. getCodeData,
  60. getTableCode,
  61. getTablePartake,
  62. settleTable,
  63. } from '@/api/store.js';
  64. export default {
  65. mixins: [colors],
  66. data() {
  67. return {
  68. statusBarHeight: 0,
  69. navBarHeight: 0,
  70. tablePartake: [],
  71. codeData: {},
  72. }
  73. },
  74. computed: {
  75. goodsNumber() {
  76. let goodsNumber = 0;
  77. this.tablePartake.forEach(item => {
  78. goodsNumber = item.goods.reduce((total, cell) => {
  79. return total + cell.cart_num;
  80. }, goodsNumber);
  81. })
  82. return goodsNumber;
  83. },
  84. total() {
  85. let total = 0;
  86. this.tablePartake.forEach(item => {
  87. total = item.goods.reduce((total, cell) => {
  88. return this.$util.$h.Add(total, this.$util.$h.Mul(cell.truePrice, cell.cart_num));
  89. }, total);
  90. });
  91. return total;
  92. }
  93. },
  94. onLoad(option) {
  95. const {
  96. tableId,
  97. } = option;
  98. let {
  99. height,
  100. top
  101. } = uni.getMenuButtonBoundingClientRect();
  102. uni.getSystemInfo({
  103. success: ({
  104. statusBarHeight
  105. }) => {
  106. this.statusBarHeight = statusBarHeight;
  107. this.navBarHeight = 2 * (top - statusBarHeight) + height;
  108. }
  109. });
  110. this.tableId = tableId;
  111. this.getCodeData();
  112. this.getTablePartake();
  113. },
  114. onPullDownRefresh() {
  115. this.getTablePartake();
  116. },
  117. methods: {
  118. // 获取桌码信息
  119. getCodeData() {
  120. getCodeData({
  121. tableId: this.tableId
  122. }).then(res => {
  123. this.codeData = res.data;
  124. });
  125. },
  126. getTablePartake(callback) {
  127. getTablePartake({
  128. tableId: this.tableId
  129. }).then(({
  130. data
  131. }) => {
  132. let tablePartake = [];
  133. Object.keys(data).forEach(key => {
  134. tablePartake.push(data[key]);
  135. });
  136. this.tablePartake = tablePartake;
  137. uni.stopPullDownRefresh();
  138. if (callback) {
  139. let is_true_stock = true;
  140. for (let partakeItem of this.tablePartake) {
  141. if (!is_true_stock) {
  142. break;
  143. }
  144. for (let goodsItem of partakeItem.goods) {
  145. is_true_stock = goodsItem.is_true_stock;
  146. if (!is_true_stock) {
  147. break;
  148. }
  149. }
  150. }
  151. if (!is_true_stock) {
  152. return this.$util.Tips({
  153. title: '存在库存不足的商品,请检查'
  154. });
  155. }
  156. callback();
  157. }
  158. }).catch(err => {
  159. this.$util.Tips({
  160. title: err
  161. });
  162. });
  163. },
  164. settleTable() {
  165. settleTable({
  166. tableId: this.tableId
  167. }).then(res => {
  168. uni.navigateTo({
  169. url: `/pages/goods/order_confirm/index?new=1&delivery_type=2&cartId=${res.data.cartIds}&store_id=${this.codeData.store_id}&tableId=${this.tableId}`
  170. });
  171. }).catch(err => {
  172. this.$util.Tips({
  173. title: err
  174. });
  175. });
  176. },
  177. // 去结账
  178. onSettle() {
  179. uni.showModal({
  180. title: '是否结账',
  181. content: '您是否确认结算当前账单',
  182. success: ({
  183. confirm
  184. }) => {
  185. if (confirm) {
  186. this.getTablePartake(this.settleTable);
  187. }
  188. }
  189. });
  190. },
  191. // 加购
  192. onAdd() {
  193. uni.navigateTo({
  194. url: `/pages/store/table_code/index?store_id=${this.codeData.store_id}&qrcode_id=${this.codeData.id}`
  195. });
  196. },
  197. getTableCode(callback) {
  198. getTableCode({ tableId: this.tableId }).then(res => {
  199. const status = res.data.table.status;
  200. switch (status){
  201. case -1:
  202. case 2:
  203. case 3:
  204. this.$util.Tips({
  205. title: status == -1 ? '本单已取消' : '本单已结账'
  206. });
  207. break;
  208. default:
  209. callback();
  210. break;
  211. }
  212. }).catch(err => {
  213. this.$util.Tips({
  214. title: err
  215. });
  216. });
  217. }
  218. },
  219. }
  220. </script>
  221. <style>
  222. page {
  223. background-color: #F5F5F5;
  224. }
  225. </style>
  226. <style lang="scss" scoped>
  227. .confirm-order {
  228. background: linear-gradient(180deg, var(--view-theme) 0%, #F5F5F5 100%);
  229. background-size: 100% 292rpx;
  230. background-repeat: no-repeat;
  231. }
  232. .nav-bar {
  233. background-color: var(--view-theme);
  234. &.fixed {
  235. position: sticky;
  236. top: 0;
  237. right: 0;
  238. left: 0;
  239. z-index: 9;
  240. }
  241. .inner {
  242. position: relative;
  243. display: flex;
  244. justify-content: center;
  245. align-items: center;
  246. font-size: 30rpx;
  247. color: #FFFFFF;
  248. }
  249. .btn {
  250. position: absolute;
  251. top: 0;
  252. bottom: 0;
  253. left: 0;
  254. display: flex;
  255. align-items: center;
  256. padding: 0 30rpx;
  257. font-size: 24rpx;
  258. color: #FFFFFF;
  259. }
  260. }
  261. .header {
  262. padding: 52rpx 24rpx 46rpx;
  263. border-radius: 14rpx;
  264. margin: 16rpx 30rpx 20rpx;
  265. background-color: #FFFFFF;
  266. font-size: 24rpx;
  267. color: #999999;
  268. .top {
  269. display: flex;
  270. margin-bottom: 18rpx;
  271. }
  272. .name {
  273. flex: 1;
  274. min-width: 0;
  275. font-weight: 600;
  276. font-size: 34rpx;
  277. color: #333333;
  278. }
  279. .number {
  280. color: #333333;
  281. }
  282. .light {
  283. margin-right: 6rpx;
  284. font-weight: 600;
  285. font-size: 34rpx;
  286. color: var(--view-theme);
  287. }
  288. }
  289. .dining {
  290. display: flex;
  291. align-items: center;
  292. height: 85rpx;
  293. padding: 0 24rpx;
  294. border-radius: 14rpx;
  295. margin: 20rpx 30rpx;
  296. background-color: #FFFFFF;
  297. font-size: 24rpx;
  298. color: #333333;
  299. .total {
  300. flex: 1;
  301. min-width: 0;
  302. }
  303. }
  304. .dinner {
  305. border-radius: 14rpx;
  306. margin: 20rpx 30rpx;
  307. background-color: #FFFFFF;
  308. .head {
  309. display: flex;
  310. align-items: center;
  311. height: 86rpx;
  312. padding: 0 25rpx;
  313. border-bottom: 1rpx solid #F0F0F0;
  314. font-size: 26rpx;
  315. color: #333333;
  316. .image {
  317. display: block;
  318. width: 40rpx;
  319. height: 40rpx;
  320. border-radius: 50%;
  321. }
  322. .name {
  323. flex: 1;
  324. min-width: 0;
  325. margin: 0 20rpx;
  326. }
  327. }
  328. .item {
  329. position: relative;
  330. display: flex;
  331. padding: 25rpx;
  332. &.gray {
  333. background-color: #EEEEEE;
  334. }
  335. +.item {
  336. &::before {
  337. content: "";
  338. position: absolute;
  339. top: 0;
  340. right: 0;
  341. left: 25rpx;
  342. border-top: 1rpx solid #EEEEEE;
  343. }
  344. }
  345. .image {
  346. display: block;
  347. width: 130rpx;
  348. height: 130rpx;
  349. border-radius: 6rpx;
  350. }
  351. .text {
  352. flex: 1;
  353. min-width: 0;
  354. margin: 0 20rpx;
  355. }
  356. .name {
  357. overflow: hidden;
  358. white-space: nowrap;
  359. text-overflow: ellipsis;
  360. font-size: 28rpx;
  361. line-height: 40rpx;
  362. color: #333333;
  363. }
  364. .attr {
  365. margin-top: 8rpx;
  366. font-size: 20rpx;
  367. color: #999999;
  368. }
  369. .money {
  370. margin-top: 14rpx;
  371. font-size: 26rpx;
  372. line-height: 36rpx;
  373. color: var(--view-theme);
  374. }
  375. .number {
  376. font-size: 26rpx;
  377. line-height: 40rpx;
  378. color: #999999;
  379. }
  380. }
  381. }
  382. .footer {
  383. padding-bottom: constant(safe-area-inset-bottom);
  384. padding-bottom: env(safe-area-inset-bottom);
  385. &.fixed {
  386. position: fixed;
  387. right: 0;
  388. bottom: 0;
  389. left: 0;
  390. z-index: 9;
  391. background-color: #FFFFFF;
  392. }
  393. .inner {
  394. display: flex;
  395. align-items: center;
  396. height: 100rpx;
  397. padding-right: 20rpx;
  398. }
  399. .total {
  400. flex: 1;
  401. min-width: 0;
  402. padding: 0 26rpx;
  403. font-size: 28rpx;
  404. color: #333333;
  405. }
  406. .money {
  407. color: var(--view-theme);
  408. }
  409. .btn {
  410. transform: rotateZ(360deg);
  411. padding: 18rpx 62rpx;
  412. border: 1rpx solid var(--view-theme);
  413. border-radius: 38rpx;
  414. font-size: 28rpx;
  415. line-height: 40rpx;
  416. color: var(--view-theme);
  417. +.btn {
  418. margin-left: 20rpx;
  419. }
  420. &.fill {
  421. background-color: var(--view-theme);
  422. color: #FFFFFF;
  423. }
  424. }
  425. }
  426. </style>