index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const login = require('../../../../../utils/login')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. storeid: "", // 店铺id
  10. tableid: "",// 桌号
  11. list: [
  12. { value: 1, childe: false },
  13. { value: 2, childe: false },
  14. { value: 3, childe: false },
  15. { value: 4, childe: true },
  16. { value: 5, childe: false },
  17. { value: 6, childe: false },
  18. { value: 7, childe: false },
  19. { value: 8, childe: false },
  20. { value: 9, childe: false },
  21. { value: 10, childe: false },
  22. { value: 11, childe: false },
  23. { value: '更多', childe: false },
  24. ],
  25. desc: "",
  26. tableList: [],
  27. currentIndex: 0,
  28. table: null,
  29. active: 4, // 用餐人数
  30. activeColor:"#229293"
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. this.setData({
  37. activeColor:getApp().globalData.activeColor || '#229293'
  38. })
  39. let storeid = options.storeid
  40. let tableid = options.tableid
  41. this.setData({
  42. storeid: storeid,
  43. tableid: tableid
  44. })
  45. let userLogin = wx.getStorageSync("userLogin");
  46. if (userLogin == "") {
  47. login.loginNow();
  48. return;
  49. }
  50. if (!storeid) {
  51. return
  52. }
  53. this.getStore(storeid)
  54. this.getTable(tableid)
  55. this.tableList()
  56. },
  57. async getStore(id) {
  58. let ShopStore = new Parse.Query('ShopStore')
  59. let store = await ShopStore.get(id)
  60. if (store && store.id) {
  61. this.setData({
  62. store: store.toJSON()
  63. })
  64. } else {
  65. wx.showToast({
  66. title: '未找到该店铺',
  67. duration: 1600,
  68. icon: icon,
  69. })
  70. wx.navigateBack({
  71. delta: 1,
  72. })
  73. }
  74. },
  75. async getTable(id) {
  76. if (id) {
  77. let Table = new Parse.Query("TableNumber")
  78. let table = await Table.get(id)
  79. if (table && table.id) {
  80. this.setData({
  81. table: {
  82. id: table.id,
  83. name: table.get('name'),
  84. number: table.get('number')
  85. }
  86. })
  87. }
  88. }
  89. },
  90. async tableList() {
  91. let TableList = new Parse.Query('TableNumber')
  92. TableList.equalTo('store', this.data.storeid)
  93. TableList.equalTo('company', company)
  94. TableList.equalTo('status', true)
  95. TableList.select('name', "objectId", "number")
  96. let tableList = await TableList.find()
  97. console.log(tableList);
  98. if (tableList && tableList.length > 0) {
  99. let tableArr = []
  100. console.log(tableList)
  101. tableList.forEach(li => {
  102. tableArr.push({
  103. id: li.id,
  104. name: li.get('name'),
  105. number: li.get('number')
  106. })
  107. })
  108. this.setData({
  109. tableList: tableArr,
  110. table: tableArr[0]
  111. })
  112. console.log(this.data.tableList)
  113. }
  114. },
  115. onChang(e) {
  116. let list = this.data.list
  117. let value = e.currentTarget.dataset.value
  118. let show = false
  119. let active = list[value].value
  120. list.forEach((item, index) => {
  121. list[index].childe = false
  122. });
  123. if (value == 11) {
  124. show = true
  125. active = 0
  126. }
  127. list[value].childe = true
  128. this.setData({
  129. list,
  130. show,
  131. active
  132. })
  133. },
  134. bindPickerChange(e) {
  135. console.log(e)
  136. this.setData({
  137. currentIndex: Number(e.detail.value),
  138. tableid: this.data.tableList[e.detail.value].id,
  139. table: this.data.tableList[Number(e.detail.value)]
  140. })
  141. },
  142. startOrder() {
  143. console.log(this.data.storeid)
  144. console.log(this.data.table)
  145. console.log(this.data.active)
  146. if (!this.data.storeid) {
  147. wx.showToast({
  148. title: '店铺信息有误,请重新进入',
  149. duration: 1500,
  150. icon: "none"
  151. })
  152. return
  153. }
  154. if (!this.data.table) {
  155. wx.showToast({
  156. title: '请先确认桌号信息',
  157. duration: 1500,
  158. icon: "none"
  159. })
  160. return
  161. }
  162. if (!this.data.active) {
  163. wx.showToast({
  164. title: '请先确认用餐人数',
  165. duration: 1500,
  166. icon: "none"
  167. })
  168. return
  169. }
  170. let storeid = this.data.storeid
  171. let tableid = this.data.table.id
  172. let active = this.data.active
  173. let desc = this.data.desc
  174. wx.navigateTo({
  175. url: `/nova-tourism/pages/gourmet/store-package/meal-order/order-detail/index?storeid=${storeid}&tableid=${tableid}&active=${active}&desc=${desc}`
  176. })
  177. },
  178. /**
  179. * 生命周期函数--监听页面初次渲染完成
  180. */
  181. onReady: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面显示
  185. */
  186. onShow: function () {
  187. this.getStore(this.data.storeid)
  188. this.getTable(this.data.tableid)
  189. this.tableList()
  190. },
  191. /**
  192. * 生命周期函数--监听页面隐藏
  193. */
  194. onHide: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面卸载
  198. */
  199. onUnload: function () {
  200. },
  201. /**
  202. * 页面相关事件处理函数--监听用户下拉动作
  203. */
  204. onPullDownRefresh: function () {
  205. },
  206. /**
  207. * 页面上拉触底事件的处理函数
  208. */
  209. onReachBottom: function () {
  210. },
  211. /**
  212. * 用户点击右上角分享
  213. */
  214. onShareAppMessage: function () {
  215. }
  216. })