index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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_name}}</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') that.$set(that, `shopInfo`, res.data[0]);
  116. res = await that.$api(`cart/${that.id}`, 'GET', {});
  117. if (res.errcode == '0') {
  118. that.$set(that, `list`, res.data.list)
  119. that.$set(that.shopInfo, `goods_total`, res.data.total)
  120. let table = await that.$api(`table/${res.data.table}`, `GET`)
  121. that.$set(that.shopInfo, `table_name`, table.data.name)
  122. that.$set(that.shopInfo, `table_id`, res.data.table)
  123. }
  124. }
  125. },
  126. // 选择堂食还是打包
  127. toChang() {
  128. const that = this;
  129. that.is_show = !that.is_show
  130. },
  131. // 选择用餐人数
  132. bindChange(e) {
  133. const that = this;
  134. that.$set(that.shopInfo, `person`, parseInt(e.detail.value) + 1)
  135. let money = that.$multiply(that.shopInfo.money, that.shopInfo.person);
  136. that.$set(that.shopInfo, `perMoney`, money)
  137. let total = that.$plus(money, that.shopInfo.goods_total)
  138. that.$set(that.shopInfo, `detail_total`, total)
  139. },
  140. // 下单
  141. async toBuy() {
  142. const that = this;
  143. if(that.shopInfo.person&&that.shopInfo.perMoney){
  144. let type = '0';
  145. if (that.is_show == true) type = '0'
  146. else type = '1'
  147. let obj = {
  148. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  149. remark: that.shopInfo.remark,
  150. table: that.shopInfo.table_id,
  151. money: that.shopInfo.detail_total,
  152. money_num: that.shopInfo.perMoney,
  153. num: that.shopInfo.person,
  154. cart:that.id,
  155. type: type,
  156. list: that.list
  157. }
  158. let res = await that.$api(`order`, 'POST', obj);
  159. if (res.errcode == '0') {
  160. uni.navigateTo({
  161. url: `/pagesHome/order/info?id=${res.data._id}`
  162. })
  163. }
  164. }else{
  165. uni.showToast({
  166. title: '请选择用餐人数',
  167. icon: 'none'
  168. })
  169. }
  170. },
  171. }
  172. }
  173. </script>
  174. <style lang="scss">
  175. .content {
  176. background-color: #f1f1f1;
  177. font-family: 12px/1 Tahoma, Helvetica, Arial, "\5b8b\4f53", sans-serif;
  178. .info {
  179. display: flex;
  180. flex-direction: column;
  181. position: relative;
  182. flex-grow: 1;
  183. padding: 2vw;
  184. .one {
  185. padding: 2vw;
  186. background-color: #ffffff;
  187. border-radius: 4vw;
  188. .one_1 {
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. padding: 2vw 0;
  193. border-bottom: 1px solid #f1f1f1;
  194. .left {
  195. font-size: 16px;
  196. font-weight: 600;
  197. }
  198. .right {
  199. font-size: 14px;
  200. .right_1 {
  201. background-color: #f1f1f1;
  202. padding: 3vw 1vw;
  203. border-radius: 5vw;
  204. text {
  205. background-color: #f1f1f1;
  206. color: #858585;
  207. padding: 2vw;
  208. }
  209. .type {
  210. padding: 2vw 3vw;
  211. border-radius: 5vw;
  212. color: #ffffff;
  213. background-color: #FF7800;
  214. }
  215. }
  216. }
  217. }
  218. .one_2 {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. padding: 3vw 0;
  223. border-bottom: 1px solid #f1f1f1;
  224. font-size: 14px;
  225. .right {
  226. display: flex;
  227. align-items: center;
  228. color: #858585;
  229. }
  230. }
  231. .one_3 {
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. padding: 3vw 0;
  236. font-size: 14px;
  237. .right {
  238. display: flex;
  239. align-items: flex-end;
  240. color: #858585;
  241. /deep/input {
  242. text-align: right;
  243. }
  244. }
  245. }
  246. }
  247. .two {
  248. margin: 2vw 0;
  249. padding: 2vw;
  250. background-color: #ffffff;
  251. border-radius: 4vw;
  252. .two_1 {
  253. padding: 2vw 0;
  254. font-size: 16px;
  255. font-weight: 600;
  256. }
  257. .two_2 {
  258. position: relative;
  259. display: flex;
  260. flex-direction: column;
  261. height: 32vh;
  262. .list {
  263. display: flex;
  264. width: 88vw;
  265. margin: 0 0 2vw 0;
  266. padding: 2vw;
  267. box-shadow: 0 0 5px #f1f1f1;
  268. border-radius: 5px;
  269. .img {
  270. width: 30vw;
  271. .image {
  272. width: 30vw;
  273. height: 20vw;
  274. border-radius: 5px;
  275. }
  276. }
  277. .info {
  278. width: 40vw;
  279. padding: 0 0 0 2vw;
  280. .name {
  281. font-size: 16px;
  282. }
  283. .spec {
  284. font-size: 12px;
  285. color: #858585;
  286. }
  287. }
  288. .money {
  289. display: flex;
  290. flex-direction: column;
  291. align-items: flex-end;
  292. width: 20vw;
  293. text:first-child {
  294. font-size: 14px;
  295. color: #FF8C00;
  296. }
  297. }
  298. }
  299. }
  300. .two_3 {
  301. .two_3_1 {
  302. display: flex;
  303. justify-content: space-between;
  304. align-items: center;
  305. font-size: 14px;
  306. padding: 2vw 3vw;
  307. .left {
  308. text {
  309. color: #858585;
  310. font-size: 12px;
  311. margin: 0 2vw;
  312. }
  313. }
  314. .right {
  315. color: #FF7800;
  316. }
  317. }
  318. .two_3_2 {
  319. padding: 3vw;
  320. text-align: right;
  321. font-size: 14px;
  322. color: #858585;
  323. border-top: 1px solid #f1f1f1;
  324. text:first-child {
  325. color: #FF7800;
  326. }
  327. text:last-child {
  328. color: #FF7800;
  329. font-size: 18px;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. .foot {
  336. display: flex;
  337. justify-content: space-between;
  338. align-items: center;
  339. padding: 2vw 3vw;
  340. background-color: #ffffff;
  341. border-top: 1px solid #f1f1f1;
  342. .foot_1 {
  343. font-size: 14px;
  344. color: #858585;
  345. text:first-child {
  346. color: #FF7800;
  347. }
  348. text:last-child {
  349. color: #FF7800;
  350. font-size: 18px;
  351. }
  352. }
  353. .foot_2 {
  354. .button {
  355. background-color: #FF8C00;
  356. color: #ffffff;
  357. border-radius: 5vw;
  358. font-size: 16px;
  359. }
  360. }
  361. }
  362. }
  363. .scroll-view {
  364. position: absolute;
  365. top: 0;
  366. left: 0;
  367. right: 0;
  368. bottom: 0;
  369. .list-scroll-view {
  370. display: flex;
  371. flex-direction: column;
  372. }
  373. }
  374. </style>