list.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <view>
  3. <view class="view">
  4. <u-list @scrolltolower="scrolltolower">
  5. <view class="hand">
  6. <u-row>
  7. <u-col span="8">
  8. <view class="orgTop">
  9. <u--text text="所属机构" size="22" bold color="#619f8a"></u--text>
  10. </view>
  11. <view>
  12. <u--text :text="data.organizationName" size="20" bold color="#757575"></u--text>
  13. </view>
  14. </u-col>
  15. <!--<u-col span="4">
  16. <view>
  17. <u-button class="sxButton" size="normal" loadingMode="circle" color="#65c1aa">统计查看
  18. </u-button>
  19. </view>
  20. </u-col> -->
  21. </u-row>
  22. <view class="uni-list" style="margin-top: 5px;">
  23. <view class="uni-list-cell">
  24. <view class="uni-list-cell-left">
  25. 就餐地:
  26. </view>
  27. <view class="uni-list-cell-db">
  28. <u--text :text="jcd" size="22" bold color="#757575"></u--text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view v-if="!shopDataNow">
  34. <image style="margin: 0 auto; width: 100%;" src="../../static/img/page/empty_view.png"></image>
  35. </view>
  36. <u-list-item v-for="(item, index) in shopDataNow" :key="index">
  37. <view v-if="item.amount !== 0 && item.amount" class="listItemStyle">
  38. <u-row>
  39. <u-col span="3">
  40. <u--image :showLoading="true" shape="circle" :src="baseURL+item.cuisinePicture"
  41. width="70px" height="70px" style="margin: 10px;"></u--image>
  42. </u-col>
  43. <u-col span="6" class="">
  44. <view>
  45. {{item.cuisineName}}
  46. </view>
  47. <view style="margin-top: 3px;">
  48. {{"¥ "+item.price}}
  49. </view>
  50. </u-col>
  51. <u-col span="3" class="numberStyler">
  52. <u-number-box v-model="item.amount" step="1" :min="0" :max="item.maximum"
  53. :showMinus="item.amount > 0">
  54. <view @click="addToCart(0,item)" slot="minus" class="minus">
  55. <u-icon name="minus" size="12"></u-icon>
  56. </view>
  57. <text slot="input" style="width: 50px;text-align: center;"
  58. class="input">{{item.amount}}</text>
  59. <view @click="addToCart(1,item)" slot="plus" class="plus">
  60. <u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
  61. </view>
  62. </u-number-box>
  63. </u-col>
  64. </u-row>
  65. </view>
  66. </u-list-item>
  67. <br>
  68. <br>
  69. <br>
  70. <br>
  71. </u-list>
  72. </view>
  73. <view class="bottim_view">
  74. <view>
  75. <u-row>
  76. <u-col span="6">
  77. <view class="sum_price_view">
  78. <span>合计:</span>
  79. <u-row>
  80. <u-col span="6">
  81. <u-icon name="rmb" color="#aa0000" size="20"></u-icon>
  82. </u-col>
  83. <u-col span="6">
  84. <u--text size="35" color="#aa0000" :text="priceSum"></u--text>
  85. </u-col>
  86. </u-row>
  87. </view>
  88. </u-col>
  89. <u-col span="6">
  90. <u-button class="btnDoPay" shape="circle" @click="toOKPage" :disabled="isDisabled"
  91. color="linear-gradient(to bottom right, #79a7a4, #88d8a1)" text="确认支付"></u-button>
  92. </u-col>
  93. </u-row>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. baseURL: this.$BASE_URL,
  103. priceSum: 0.0,
  104. dateShow: false,
  105. isDisabled: false,
  106. data: {
  107. organizationName: "",
  108. },
  109. jcd: uni.getStorageSync("jcd"),
  110. from: {
  111. userNumber: '',
  112. jgid: '',
  113. paytime: this.result(Number(new Date()), 'datetime'),
  114. periodId: 0,
  115. menuNumber: "",
  116. patternId: 0,
  117. orderTotal: 0,
  118. details: []
  119. },
  120. shopData: [],
  121. shopDataNow: []
  122. }
  123. },
  124. onShow() {
  125. this.shopDataNow = []
  126. this.data.organizationName = uni.getStorageSync("orgInfo").organizationName
  127. //清空价格总数
  128. this.priceSum = 0;
  129. //获取瀑布流中所有菜品数据
  130. const data = uni.getStorageSync('shopData')
  131. for (var i = 0; i < data.length; i++) {
  132. if (data[i].amount) {
  133. //计算单个菜品的总价格
  134. const total = data[i].amount * data[i].price
  135. data[i].total = total
  136. //传入 购物数据当前集合
  137. this.shopDataNow.push(data[i])
  138. //计算页面显示的总价格
  139. this.priceSum = parseFloat(this.priceSum) + (data[i].amount * parseFloat(data[i].price))
  140. }
  141. }
  142. //获取菜品查询数据
  143. const cuisinesData = uni.getStorageSync("cuisinesData")
  144. //获取用户信息
  145. const user = uni.getStorageSync('userInfo');
  146. this.from = {
  147. periodId: cuisinesData.periodId,
  148. menuNumber: cuisinesData.menuNumber,
  149. patternId: cuisinesData.patternId,
  150. details: this.shopDataNow,
  151. userNumber: user.userName,
  152. jgid: user.organizationCode,
  153. paytime: Number(new Date()),
  154. orderTotal: this.priceSum,
  155. placeNumber: uni.getStorageSync("placeNumber"),
  156. placeName: uni.getStorageSync("jcd")
  157. }
  158. console.log(this.from)
  159. },
  160. methods: {
  161. addToCart(type, food) {
  162. if (food.maximum <= food.amount && type === 1) {
  163. this.showToast({
  164. duration: 1500,
  165. message: "已达最大下单限制"
  166. });
  167. return;
  168. } else {
  169. if (type === 0) {
  170. food.amount -= 1
  171. this.priceSum = parseFloat(this.priceSum) - parseFloat(food.price)
  172. } else if (type === 1) {
  173. uni.showToast({
  174. duration: 500,
  175. icon: 'checkmark',
  176. title: "[ " + food.cuisineName + " ]加入购物车"
  177. });
  178. this.priceSum = parseFloat(this.priceSum) + parseFloat(food.price)
  179. }
  180. }
  181. let copy = []
  182. for (var i = 0; i < this.shopDataNow.length; i++) {
  183. if (0 != this.shopDataNow[i].amount) {
  184. copy.push(this.shopDataNow[i])
  185. }
  186. }
  187. this.from.orderTotal = this.priceSum
  188. this.from.details = copy
  189. },
  190. toOKPage() {
  191. this.isDisabled = true
  192. let that = this
  193. uni.requestSubscribeMessage({
  194. tmplIds: ['88SU4FmQU0cwuJTwoddwyu6kr9Kq-PdfB6dT9-SlXaA'],
  195. success(res) {
  196. that.submitOrder()
  197. },
  198. fail() {
  199. that.submitOrder()
  200. }
  201. })
  202. },
  203. async submitOrder() {
  204. if (this.priceSum === 0) {
  205. uni.showToast({
  206. duration: 1500,
  207. icon: 'none',
  208. title: "没有选择菜品"
  209. });
  210. return
  211. }
  212. uni.showLoading({
  213. title: '加载中',
  214. mask: true
  215. })
  216. // 发送请求
  217. const {
  218. data: res
  219. } = await this.$httpRequest({
  220. url: '/app/order',
  221. method: 'post',
  222. data: this.from
  223. });
  224. if (res.code === 200) {
  225. this.priceSum = 0.0;
  226. setTimeout(() => {
  227. uni.hideLoading()
  228. this.isDisabled = false
  229. uni.navigateTo({
  230. url: 'ok'
  231. })
  232. }, 1000)
  233. } else {
  234. this.isDisabled = false
  235. uni.hideLoading()
  236. uni.showToast({
  237. duration: 1500,
  238. title: res.msg,
  239. icon: 'none'
  240. });
  241. }
  242. },
  243. submitDate() {},
  244. scrolltolower() {
  245. //this.getRechargeHistoryList()
  246. },
  247. loadmore(data) {
  248. for (var i = 0; i < data.length; i++) {
  249. this.indexList.push(data[i])
  250. }
  251. },
  252. result(time, mode) {
  253. const timeFormat = uni.$u.timeFormat
  254. switch (mode) {
  255. case 'datetime':
  256. return timeFormat(time, 'yyyy-mm-dd hh:MM')
  257. case 'date':
  258. return timeFormat(time, 'yyyy-mm-dd')
  259. case 'year-month':
  260. return timeFormat(time, 'yyyy-mm')
  261. case 'time':
  262. return time
  263. default:
  264. return ''
  265. }
  266. }
  267. }
  268. }
  269. </script>
  270. <style>
  271. .view {
  272. background-color: #ebebeb;
  273. padding-top: 10px;
  274. }
  275. .hand {
  276. padding: 5%;
  277. margin: 0 5px 5px 5px;
  278. border-radius: 15px;
  279. background: linear-gradient(to bottom right, #97dad8, #f1fef9);
  280. }
  281. .orgTop {
  282. margin-bottom: 5px;
  283. }
  284. .sxButton {
  285. width: 100px;
  286. display: flex;
  287. flex-direction: column;
  288. align-items: center;
  289. }
  290. .listTermDate {
  291. padding: 10px 0;
  292. }
  293. .listItemStyle {
  294. margin: 5px 12px;
  295. padding: 5px;
  296. border-radius: 15px;
  297. background-color: #fafafa;
  298. }
  299. .minus {
  300. width: 22px;
  301. height: 22px;
  302. background-color: #efefef;
  303. border-width: 1px;
  304. border-color: #c6c6c6;
  305. border-radius: 100px;
  306. display: flex;
  307. justify-content: center;
  308. align-items: center;
  309. }
  310. .input {
  311. padding: 0;
  312. }
  313. .plus {
  314. width: 22px;
  315. height: 22px;
  316. background-color: #FF0000;
  317. border-radius: 50%;
  318. /* #ifndef APP-NVUE */
  319. display: flex;
  320. /* #endif */
  321. justify-content: center;
  322. align-items: center;
  323. }
  324. .numberStyler {
  325. position: relative;
  326. left: -10px;
  327. }
  328. .bottim_view {
  329. padding: 5px 20px 30px;
  330. position: fixed;
  331. left: 0px;
  332. bottom: 0px;
  333. width: 100%;
  334. height: 80px;
  335. background-color: #ffffff;
  336. z-index: 9999;
  337. }
  338. .sum_price_num_style {
  339. font-size: 30px;
  340. color: #d83024;
  341. }
  342. .sum_price_view {
  343. margin-left: 10px;
  344. display: flex;
  345. justify-content: unset;
  346. align-items: baseline;
  347. }
  348. .btnDoPay {
  349. width: 100%;
  350. }
  351. </style>