detail.js 4.6 KB

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