index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="content">
  3. <view class="info">
  4. <view class="one">
  5. <view class="one_1">
  6. <view class="left">桌号:{{shopInfo.table}}</view>
  7. <view class="right">
  8. <view class="right_1">
  9. <text @click="toChang" :class="[is_show==true?'type':'']">店内就餐</text>
  10. <text @click="toChang" :class="[is_show==false?'type':'']">打包带走</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="one_2">
  15. <view class="left">人数</view>
  16. <view class="right">
  17. <picker @change="bindChange" :value="shopInfo.person" :range="personList">
  18. <view>
  19. {{shopInfo.person||'请选择用餐人数'}}
  20. <text v-if="shopInfo.person">人</text>
  21. </view>
  22. </picker>
  23. <uni-icons color="#C0C0C0" type="forward" size="14"></uni-icons>
  24. </view>
  25. </view>
  26. <view class="one_3">
  27. <view class="left">备注</view>
  28. <view class="right">
  29. <input v-model="shopInfo.remark" placeholder="填写备注" />
  30. <uni-icons color="#C0C0C0" type="forward" size="14"></uni-icons>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="two">
  35. <view class="two_1">消费明细</view>
  36. <view class="two_2">
  37. <scroll-view scroll-y="true" class="scroll-view">
  38. <view class="list-scroll-view">
  39. <view class="list" v-for="(item,index) in list" :key="index">
  40. <view class="img">
  41. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
  42. mode="">
  43. </image>
  44. </view>
  45. <view class="info">
  46. <view class="name textOver">
  47. <text>{{item.name}}</text>
  48. </view>
  49. <view class="spec" v-if="item.spec">
  50. <text>{{item.spec}}</text>
  51. </view>
  52. </view>
  53. <view class="money">
  54. <text>¥{{item.price}}</text>
  55. <text>×{{item.num}}</text>
  56. </view>
  57. </view>
  58. </view>
  59. </scroll-view>
  60. </view>
  61. <view class="two_3">
  62. <view class="two_3_1" v-if="shopInfo.person">
  63. <view class="left">
  64. 餐位费
  65. <text>×{{shopInfo.person}}</text>
  66. </view>
  67. <view class="right">¥{{shopInfo.perMoney}}</view>
  68. </view>
  69. <view class="two_3_2">
  70. 共{{list.length}}件商品,合计:<text>¥</text><text>{{shopInfo.goods_total}}</text>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="foot">
  76. <view class="foot_1">
  77. 需支付<text>¥</text><text>{{shopInfo.detail_total||0}}</text>
  78. </view>
  79. <view class="foot_2">
  80. <button class="button" @tap.stop="toBuy">下单</button>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. import moment from 'moment';
  87. export default {
  88. data() {
  89. return {
  90. id: "",
  91. shopInfo: {},
  92. is_show: true,
  93. personList: [
  94. '1人', '2人', '3人', '4人', '5人', '6人', '7人', '8人', '9人', '10人', '11人', '12人', '13人', '14人',
  95. '15人', '16人', '17人',
  96. '18人', '19人', '20人', '21人', '22人'
  97. ],
  98. list: [],
  99. }
  100. },
  101. onLoad: async function(e) {
  102. const that = this;
  103. that.$set(that, `id`, e.id);
  104. that.search();
  105. },
  106. onShow() {
  107. const that = this;
  108. },
  109. methods: {
  110. async search(e) {
  111. const that = this;
  112. let res;
  113. if (that.id) {
  114. res = await that.$api(`shop`, 'GET', {});
  115. if (res.errcode == '0') {
  116. let data = res.data[0]
  117. data.table = '1'
  118. that.$set(that, `shopInfo`, data);
  119. }
  120. res = await that.$api(`cart/${that.id}`, 'GET', {});
  121. if (res.errcode == '0') {
  122. that.$set(that, `list`, res.data.list)
  123. that.$set(that.shopInfo, `goods_total`, res.data.total)
  124. let table = await that.$api(`table/${res.data.table}`, `GET`)
  125. that.$set(that.shopInfo, `table`, table.data.name)
  126. that.$set(that.shopInfo, `table_id`, res.data.table)
  127. }
  128. }
  129. },
  130. // 选择堂食还是打包
  131. toChang() {
  132. const that = this;
  133. that.is_show = !that.is_show
  134. },
  135. // 选择用餐人数
  136. bindChange(e) {
  137. const that = this;
  138. that.$set(that.shopInfo, `person`, parseInt(e.detail.value) + 1)
  139. let money = that.$multiply(that.shopInfo.money, that.shopInfo.person);
  140. that.$set(that.shopInfo, `perMoney`, money)
  141. let total = that.$plus(money, that.shopInfo.goods_total)
  142. that.$set(that.shopInfo, `detail_total`, total)
  143. },
  144. // 下单
  145. async toBuy() {
  146. const that = this;
  147. if(that.shopInfo.person&&that.shopInfo.perMoney){
  148. let type = '0';
  149. if (that.is_show == true) type = '0'
  150. else type = '1'
  151. let obj = {
  152. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  153. remark: that.shopInfo.remark,
  154. table: that.shopInfo.table_id,
  155. money: that.shopInfo.detail_total,
  156. money_num: that.shopInfo.perMoney,
  157. num: that.shopInfo.person,
  158. cart:that.id,
  159. type: type,
  160. list: that.list
  161. }
  162. let res = await that.$api(`order`, 'POST', obj);
  163. if (res.errcode == '0') {
  164. uni.navigateTo({
  165. url: `/pagesHome/order/info?id=${res.data._id}`
  166. })
  167. }
  168. }else{
  169. uni.showToast({
  170. title: '下单成功',
  171. icon: 'none'
  172. })
  173. }
  174. },
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. .content {
  180. background-color: #f1f1f1;
  181. font-family: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
  182. .info {
  183. display: flex;
  184. flex-direction: column;
  185. position: relative;
  186. flex-grow: 1;
  187. padding: 2vw;
  188. .one {
  189. padding: 2vw;
  190. background-color: #ffffff;
  191. border-radius: 4vw;
  192. .one_1 {
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. padding: 2vw 0;
  197. border-bottom: 1px solid #f1f1f1;
  198. .left {
  199. font-size: 16px;
  200. font-weight: 600;
  201. }
  202. .right {
  203. font-size: 14px;
  204. .right_1 {
  205. background-color: #f1f1f1;
  206. padding: 3vw 1vw;
  207. border-radius: 5vw;
  208. text {
  209. background-color: #f1f1f1;
  210. color: #858585;
  211. padding: 2vw;
  212. }
  213. .type {
  214. padding: 2vw 3vw;
  215. border-radius: 5vw;
  216. color: #ffffff;
  217. background-color: #FF7800;
  218. }
  219. }
  220. }
  221. }
  222. .one_2 {
  223. display: flex;
  224. justify-content: space-between;
  225. align-items: center;
  226. padding: 3vw 0;
  227. border-bottom: 1px solid #f1f1f1;
  228. font-size: 14px;
  229. .right {
  230. display: flex;
  231. align-items: center;
  232. color: #858585;
  233. }
  234. }
  235. .one_3 {
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. padding: 3vw 0;
  240. font-size: 14px;
  241. .right {
  242. display: flex;
  243. align-items: flex-end;
  244. color: #858585;
  245. /deep/input {
  246. text-align: right;
  247. }
  248. }
  249. }
  250. }
  251. .two {
  252. margin: 2vw 0;
  253. padding: 2vw;
  254. background-color: #ffffff;
  255. border-radius: 4vw;
  256. .two_1 {
  257. padding: 2vw 0;
  258. font-size: 16px;
  259. font-weight: 600;
  260. }
  261. .two_2 {
  262. position: relative;
  263. display: flex;
  264. flex-direction: column;
  265. height: 32vh;
  266. .list {
  267. display: flex;
  268. width: 88vw;
  269. margin: 0 0 2vw 0;
  270. padding: 2vw;
  271. box-shadow: 0 0 5px #f1f1f1;
  272. border-radius: 5px;
  273. .img {
  274. width: 30vw;
  275. .image {
  276. width: 30vw;
  277. height: 20vw;
  278. border-radius: 5px;
  279. }
  280. }
  281. .info {
  282. width: 40vw;
  283. padding: 0 0 0 2vw;
  284. .name {
  285. font-size: 16px;
  286. }
  287. .spec {
  288. font-size: 12px;
  289. color: #858585;
  290. }
  291. }
  292. .money {
  293. display: flex;
  294. flex-direction: column;
  295. align-items: flex-end;
  296. width: 20vw;
  297. text:first-child {
  298. font-size: 14px;
  299. color: #FF8C00;
  300. }
  301. }
  302. }
  303. }
  304. .two_3 {
  305. .two_3_1 {
  306. display: flex;
  307. justify-content: space-between;
  308. align-items: center;
  309. font-size: 14px;
  310. padding: 2vw 3vw;
  311. .left {
  312. text {
  313. color: #858585;
  314. font-size: 12px;
  315. margin: 0 2vw;
  316. }
  317. }
  318. .right {
  319. color: #FF7800;
  320. }
  321. }
  322. .two_3_2 {
  323. padding: 3vw;
  324. text-align: right;
  325. font-size: 14px;
  326. color: #858585;
  327. border-top: 1px solid #f1f1f1;
  328. text:first-child {
  329. color: #FF7800;
  330. }
  331. text:last-child {
  332. color: #FF7800;
  333. font-size: 18px;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. .foot {
  340. display: flex;
  341. justify-content: space-between;
  342. align-items: center;
  343. padding: 2vw 3vw;
  344. background-color: #ffffff;
  345. border-top: 1px solid #f1f1f1;
  346. .foot_1 {
  347. font-size: 14px;
  348. color: #858585;
  349. text:first-child {
  350. color: #FF7800;
  351. }
  352. text:last-child {
  353. color: #FF7800;
  354. font-size: 18px;
  355. }
  356. }
  357. .foot_2 {
  358. .button {
  359. background-color: #FF8C00;
  360. color: #ffffff;
  361. border-radius: 5vw;
  362. font-size: 16px;
  363. }
  364. }
  365. }
  366. }
  367. .scroll-view {
  368. position: absolute;
  369. top: 0;
  370. left: 0;
  371. right: 0;
  372. bottom: 0;
  373. .list-scroll-view {
  374. display: flex;
  375. flex-direction: column;
  376. }
  377. }
  378. </style>