detail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import WxValidate from '../../utils/wxValidate'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '需求信息添加', leftArrow: true, useBar: false },
  9. // 主体高度
  10. infoHeight: '',
  11. form: {},
  12. // 商品列表
  13. order: [],
  14. user_id: '12333',
  15. // 弹框
  16. dialog: { title: '添加商品', show: false, type: '1' },
  17. },
  18. initValidate() {
  19. const rules = { user_name: { required: true, }, user_phone: { required: true, tel: true } }
  20. // 验证字段的提示信息,若不传则调用默认的信息
  21. const messages = { user_name: { required: '请输入姓名', }, user_phone: { required: '请输入电话', } };
  22. this.WxValidate = new WxValidate(rules, messages)
  23. },
  24. back: function () {
  25. wx.navigateBack({ url: '/pages/apply/index' })
  26. },
  27. // 添加商品
  28. addOrder: function () {
  29. this.setData({ dialog: { title: '添加商品', show: true, type: '1' } })
  30. },
  31. // 商品保存
  32. orderSubmit: function (e) {
  33. const params = e.detail.value;
  34. if (!params.name) wx.showToast({ title: `商品名称`, icon: 'error', duration: 2000 });
  35. else if (!params.num) wx.showToast({ title: `商品数量`, icon: 'error', duration: 2000 });
  36. if (params.name && params.num) {
  37. this.setData({ order: [...this.data.order, params] });
  38. this.setData({ orderForm: {} });
  39. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } });
  40. }
  41. },
  42. // 商品取消保存
  43. orderReset: function (e) {
  44. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } })
  45. },
  46. // 取消保存
  47. onReset: function (e) {
  48. this.back()
  49. },
  50. // 提交保存
  51. onSubmit: function (e) {
  52. const params = e.detail.value;
  53. if (!this.WxValidate.checkForm(params)) {
  54. const error = this.WxValidate.errorList[0];
  55. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  56. return false
  57. } else {
  58. params.order = this.data.order;
  59. if (params.order.length > 0) {
  60. wx.showModal({
  61. title: '提示',
  62. content: '是否确认提交',
  63. success(res) {
  64. if (res.confirm) {
  65. wx.showToast({ title: '提交成功', icon: 'success', duration: 2000 })
  66. } else if (res.cancel) {
  67. console.log('用户点击取消')
  68. }
  69. }
  70. })
  71. } else {
  72. wx.showToast({ title: `缺少商品`, icon: 'error', duration: 2000 })
  73. }
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: function (options) {
  80. //验证规则函数
  81. this.initValidate()
  82. this.watchLogin();
  83. // 计算高度
  84. this.searchHeight();
  85. },
  86. // 监听用户是否登录
  87. watchLogin: function () {
  88. let info = { user_name: '张小丽', user_phone: '12345678901' };
  89. this.setData({ form: info });
  90. // wx.getStorage({
  91. // key: 'user',
  92. // success: res => {
  93. // if (res.data) {
  94. // // 查询菜单
  95. // if (res.data) this.searchRouter(res.data);
  96. // res.data.type = type.find((i) => i.value == res.data.type).label;
  97. // if (res.data) this.setData({ userInfo: res.data });
  98. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  99. // } else {
  100. // wx.redirectTo({ url: '/pages/login/index', })
  101. // }
  102. // }
  103. // })
  104. },
  105. // 计算高度
  106. searchHeight: function () {
  107. let frameStyle = this.data.frameStyle;
  108. let client = app.globalData.client;
  109. // 减去状态栏
  110. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  111. // 是否减去底部菜单
  112. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  113. if (infoHeight) this.setData({ infoHeight: infoHeight })
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. },
  145. /**
  146. * 用户点击右上角分享
  147. */
  148. onShareAppMessage: function () {
  149. }
  150. })