detail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: { user_name: '张小丽', user_phone: '12345678901' },
  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. // wx.getStorage({
  89. // key: 'user',
  90. // success: res => {
  91. // if (res.data) {
  92. // // 查询菜单
  93. // if (res.data) this.searchRouter(res.data);
  94. // res.data.type = type.find((i) => i.value == res.data.type).label;
  95. // if (res.data) this.setData({ userInfo: res.data });
  96. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  97. // } else {
  98. // wx.redirectTo({ url: '/pages/login/index', })
  99. // }
  100. // }
  101. // })
  102. },
  103. // 计算高度
  104. searchHeight: function () {
  105. let frameStyle = this.data.frameStyle;
  106. let client = app.globalData.client;
  107. // 减去状态栏
  108. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  109. // 是否减去底部菜单
  110. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  111. if (infoHeight) this.setData({ infoHeight: infoHeight })
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function () {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function () {
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function () {
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function () {
  147. }
  148. })