index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { $wuxSelect } from '../../dist/index';
  2. let app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. goodsList:[],
  9. isNeedLogistics: 1,
  10. curAddressData:false,
  11. yunPrice: 0,
  12. allGoodsAndYunPrice:0,
  13. name:'',
  14. tel:'',
  15. zw:'',
  16. remark:'',
  17. isPickerRender: false,
  18. isPickerShow: false,
  19. startTime: "2020-07-25 08:00",
  20. endTime: "2020-07-25 08:00",
  21. pickerConfig: {
  22. endDate: true,
  23. column: "second",
  24. dateLimit: true,
  25. initStartTime: "2020-07-25 08:00",
  26. initEndTime: "2022-12-01 12:00",
  27. limitStartTime: "2015-05-06 12:00",
  28. limitEndTime: "2055-05-06 12:00"
  29. }
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow: function () {
  35. this.processInfo();
  36. this.setData({
  37. name:app.globalData.name,
  38. tel:app.globalData.tel
  39. })
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. let that = this
  46. wx.getStorage({
  47. key:'shopCarInfo',
  48. success: function(res){
  49. //console.log(res.data)
  50. let goodsList = res.data.shoplist
  51. let ActiveGoods = goodsList.filter(function(item){
  52. return item.active == true
  53. })
  54. that.setData({
  55. goodsList: ActiveGoods
  56. })
  57. console.log(" 444 ");
  58. }
  59. })
  60. },
  61. createOrder(e){
  62. let uid = app.globalData.openid;
  63. if (uid == '') {
  64. wx.redirectTo({
  65. url: '../../pages/login/login'
  66. })
  67. return;
  68. }
  69. let that = this
  70. let tprice = that.data.allGoodsAndYunPrice
  71. //console.log(loginToken)
  72. let remark = e.detail.value.remark
  73. let name = e.detail.value.name
  74. let tel = e.detail.value.tel
  75. let zuowei = app.globalData.zw;
  76. if (name == "") {
  77. wx.showModal({
  78. title: '提示',
  79. content: '请填写联系人',
  80. showCancel: false
  81. })
  82. return
  83. }
  84. if (tel == "") {
  85. wx.showModal({
  86. title: '提示',
  87. content: '请填写电话',
  88. showCancel: false
  89. })
  90. return
  91. }
  92. let openid = app.globalData.openid;
  93. let pastData = {
  94. openid: openid,
  95. goodsJsonStr: that.data.goodsJsonStr,
  96. remark: remark,
  97. name:name,
  98. tel:tel,
  99. tprice: tprice
  100. }
  101. wx.request({
  102. url: app.data.resturl + '/submitorder.action',
  103. method:'post',
  104. header:{
  105. 'content-type': 'application/x-www-form-urlencoded'
  106. },
  107. data: pastData,
  108. success:function(res){
  109. //清除订单
  110. wx.getStorage({
  111. key: 'shopCarInfo',
  112. success: function(res) {
  113. let newShopCar = {}
  114. let newList = []
  115. let list = res.data.shoplist
  116. let num = 0
  117. for (let i = 0; i < list.length;i++){
  118. if (!list[i].active){
  119. newList.push(list[i])
  120. num++
  121. }
  122. }
  123. newShopCar.shoplist = newList
  124. newShopCar.shopNum = num
  125. wx.setStorage({
  126. key: 'shopCarInfo',
  127. data:newShopCar
  128. })
  129. // console.log(newShopCar)
  130. },
  131. })
  132. let code = res.data;
  133. if(code=='yes'){
  134. wx.reLaunch({
  135. url: "/pages/order-list/index"
  136. })
  137. }else{
  138. wx.showModal({
  139. title: '提示',
  140. content: '剩余不足',
  141. showCancel: false
  142. })
  143. }
  144. }
  145. })
  146. },
  147. processInfo(){
  148. let that = this
  149. var scar = wx.getStorageSync('shopCarInfo');
  150. let goodList = scar.shoplist;
  151. console.log(" ==== ");
  152. let isNeedLogistics = 0
  153. let allGoodsPrice =0
  154. let goodsJsonStr = '['
  155. for (let i = 0; i < goodList.length;i++) {
  156. let carShopBean = goodList[i]
  157. if (carShopBean.logistics){
  158. isNeedLogistics = 1
  159. }
  160. allGoodsPrice += carShopBean.price * carShopBean.number
  161. let goodsJsonStrTmp = ''
  162. if(i>0){
  163. goodsJsonStrTmp =','
  164. }
  165. goodsJsonStrTmp += `{"goodsId":${carShopBean.goodsId},"goodsQuantity":${carShopBean.number}}`
  166. goodsJsonStr += goodsJsonStrTmp
  167. }
  168. goodsJsonStr+=']'
  169. console.log(allGoodsPrice)
  170. that.setData({
  171. allGoodsAndYunPrice: allGoodsPrice,
  172. goodsJsonStr: goodsJsonStr,
  173. name:app.globalData.uinfo.name,
  174. tel: app.globalData.uinfo.tel
  175. })
  176. console.log(goodsJsonStr)
  177. },
  178. /**
  179. * 生命周期函数--监听页面初次渲染完成
  180. */
  181. onReady: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面隐藏
  185. */
  186. onHide: function () {
  187. },
  188. /**
  189. * 生命周期函数--监听页面卸载
  190. */
  191. onUnload: function () {
  192. },
  193. /**
  194. * 页面相关事件处理函数--监听用户下拉动作
  195. */
  196. onPullDownRefresh: function () {
  197. },
  198. /**
  199. * 页面上拉触底事件的处理函数
  200. */
  201. onReachBottom: function () {
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage: function () {
  207. },
  208. pickerShow: function() {
  209. this.setData({
  210. isPickerShow: true,
  211. isPickerRender: true,
  212. chartHide: true
  213. });
  214. },
  215. pickerHide: function() {
  216. this.setData({
  217. isPickerShow: false,
  218. chartHide: false
  219. });
  220. },
  221. bindPickerChange: function(e) {
  222. console.log("picker发送选择改变,携带值为", e.detail.value);
  223. console.log(this.data.sensorList);
  224. this.getData(this.data.sensorList[e.detail.value].id);
  225. // let startDate = util.formatTime(new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 7));
  226. // let endDate = util.formatTime(new Date());
  227. this.setData({
  228. index: e.detail.value,
  229. sensorId: this.data.sensorList[e.detail.value].id
  230. // startDate,
  231. // endDate
  232. });
  233. },
  234. setPickerTime: function(val) {
  235. console.log(val);
  236. let data = val.detail;
  237. let index=data.startTime.indexOf(":");
  238. let start=data.startTime.substring(index-13,index+3);
  239. let id=data.startTime.substring(index-2,index);
  240. var hh='';
  241. hh=parseInt(id);
  242. hh++;
  243. var h=hh.toString();
  244. h=h.concat(':00');
  245. this.setData({
  246. startTime: start,
  247. endTime: h
  248. });
  249. }
  250. })