index.vue 8.6 KB

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