detail.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // 计算高度
  83. this.searchHeight();
  84. },
  85. // 计算高度
  86. searchHeight: function () {
  87. let frameStyle = this.data.frameStyle;
  88. let client = app.globalData.client;
  89. // 减去状态栏
  90. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  91. // 是否减去底部菜单
  92. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  93. if (infoHeight) this.setData({ infoHeight: infoHeight })
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面隐藏
  107. */
  108. onHide: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面卸载
  112. */
  113. onUnload: function () {
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh: function () {
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage: function () {
  129. }
  130. })