placeOrder.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // pages/order/placeOrder/placeOrder.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. activeKey: 0,
  8. navList: [
  9. {
  10. tit: "活动"
  11. },
  12. {
  13. tit: "套餐"
  14. },
  15. {
  16. tit: "洗衣"
  17. },
  18. {
  19. tit: "洗鞋"
  20. },
  21. {
  22. tit: "其他"
  23. },
  24. {
  25. tit: "其他"
  26. },
  27. {
  28. tit: "其他"
  29. },
  30. {
  31. tit: "其他"
  32. },
  33. {
  34. tit: "其他"
  35. },
  36. ],
  37. height: '',
  38. show: false,
  39. detailsShow: false,
  40. carList: [
  41. ],
  42. carNum: 0,
  43. carPrice: '',
  44. shoppingList: [
  45. {
  46. num: 0,
  47. id: 0,
  48. price: 20
  49. },
  50. {
  51. num: 0,
  52. id: 1,
  53. price: 39
  54. }
  55. ]
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.getHeight()
  62. this.getCarAll()
  63. },
  64. shoppingMinus(e) {
  65. let items = e.currentTarget.dataset.item, list = this.data.shoppingList;
  66. list.map(item => {
  67. if (items.id == item.id) {
  68. item.num--
  69. console.log(item);
  70. this.changeCarList(item)
  71. }
  72. })
  73. this.setData({
  74. shoppingList: list
  75. })
  76. this.getCarAll()
  77. },
  78. shoppingPlus(e) {
  79. let items = e.currentTarget.dataset.item, list = this.data.shoppingList;
  80. list.map(item => {
  81. if (items.id == item.id) {
  82. item.num++
  83. this.changeCarList(item)
  84. }
  85. })
  86. this.setData({
  87. shoppingList: list
  88. })
  89. this.getCarAll()
  90. },
  91. changeCarList(item) {
  92. let carList = this.data.carList
  93. if (carList.length == 0) {
  94. carList.push(item)
  95. this.setData({
  96. carList
  97. })
  98. return
  99. }
  100. console.log(item);
  101. var type = false;
  102. carList.map((i, index) => {
  103. if (i.id === item.id) {
  104. i.num = item.num
  105. if (item.num == 0) {
  106. carList.splice(index, 1)
  107. }
  108. this.setData({
  109. carList
  110. })
  111. type = false
  112. } else {
  113. type = true
  114. }
  115. })
  116. if (type) {
  117. carList.push(item)
  118. }
  119. console.log(carList);
  120. this.setData({
  121. carList
  122. })
  123. },
  124. changeShoppingList(item) {
  125. console.log(item);
  126. let shoppingList = this.data.shoppingList;
  127. shoppingList.map(i => {
  128. if (item.id == i.id) {
  129. i.num = item.num
  130. }
  131. })
  132. this.setData({
  133. shoppingList
  134. })
  135. },
  136. getCarAll() {
  137. this.setData({
  138. carNum: 0,
  139. carPrice: 0
  140. })
  141. let carList = this.data.carList
  142. carList.map(item => {
  143. wx.nextTick(() => {
  144. this.setData({
  145. carNum: this.data.carNum + item.num,
  146. carPrice: this.data.carPrice + item.price * item.num
  147. })
  148. })
  149. })
  150. },
  151. getOrder() {
  152. wx.navigateTo({
  153. url: '/pages/order/confirmOreder/confirmOreder',
  154. })
  155. },
  156. carPlus(e) {
  157. let items = e.currentTarget.dataset.item, list = this.data.carList
  158. console.log(items);
  159. list.map((item, index) => {
  160. if (items.id == item.id) {
  161. item.num++
  162. this.changeShoppingList(item)
  163. }
  164. })
  165. this.setData({
  166. carList: list
  167. })
  168. this.getCarAll()
  169. },
  170. carMinus(e) {
  171. let items = e.currentTarget.dataset.item, list = this.data.carList
  172. list.map((item, index) => {
  173. if (items.id == item.id) {
  174. item.num--
  175. this.changeShoppingList(item)
  176. if (items.num - 1 <= 0) {
  177. list.splice(index, 1)
  178. }
  179. }
  180. })
  181. this.setData({
  182. carList: list
  183. })
  184. this.getCarAll()
  185. },
  186. clearCarAll() {
  187. this.setData({
  188. carList: []
  189. })
  190. let shoppingList = this.data.shoppingList
  191. shoppingList.map(item => {
  192. item.num = 0
  193. })
  194. this.setData({
  195. shoppingList
  196. })
  197. this.getCarAll()
  198. this.btnShow()
  199. this.getHeight()
  200. },
  201. closeNews() {
  202. console.log(this.data.height);
  203. this.setData({
  204. height: this.data.height + 40
  205. })
  206. },
  207. changeActive(e) {
  208. let { activekey } = e.currentTarget.dataset
  209. this.setData({
  210. activeKey: activekey
  211. })
  212. },
  213. addressDetail() {
  214. this.setData({
  215. detailsShow: !this.data.detailsShow
  216. })
  217. },
  218. getHeight() {
  219. var clientHeight;
  220. wx.getSystemInfo({
  221. success: (res) => {
  222. clientHeight = res.windowHeight;
  223. }
  224. });
  225. var query1 = wx.createSelectorQuery()
  226. var query2 = wx.createSelectorQuery()
  227. var query3 = wx.createSelectorQuery()
  228. query1.select('#footerBar').boundingClientRect()
  229. query2.select('#topBox').boundingClientRect()
  230. query3.select('#scrollBox').boundingClientRect()
  231. query2.exec(result => {
  232. query3.exec(r => {
  233. query1.exec(res => {
  234. if (res && res[0] != null) {
  235. this.setData({
  236. height: clientHeight - res[0].height - result[0].height - r[0].height - 40
  237. })
  238. } else {
  239. this.setData({
  240. height: clientHeight - result[0].height - r[0].height - 40
  241. })
  242. }
  243. console.log(clientHeight, result[0].height, r[0].height);
  244. })
  245. })
  246. })
  247. },
  248. btnShow() {
  249. this.setData({
  250. show: !this.data.show
  251. })
  252. },
  253. })