index.vue 8.6 KB

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