detail.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // 类型
  13. typeList: [
  14. { id: '0', name: '其他' },
  15. { id: '1', name: '办公生活用品' },
  16. { id: '2', name: '办公机械' },
  17. { id: '3', name: '金融用品' },
  18. { id: '4', name: '纸制品' },
  19. { id: '5', name: '书写工具' },
  20. { id: '6', name: '桌面办公文具' },
  21. ],
  22. info: { id: '1234567', name: '11', type_name: '办公室生活用品', num: '11', money: '111', brief: '无' },
  23. form: {},
  24. stock_type: '',
  25. // 图片
  26. img_url: [],
  27. // 商品类型
  28. stock_typeList: [
  29. { value: '1', label: '固定资产' },
  30. { value: '2', label: '商品' },
  31. ]
  32. },
  33. back: function () {
  34. wx.navigateBack({ url: '/pages/home/index' })
  35. },
  36. initValidate() {
  37. const rules = { stock_type: { required: true, }, code: { required: false, }, type_name: { required: true, }, name: { required: true, }, num: { required: true, }, money: { required: true, }, brief: { required: true, } }
  38. // 验证字段的提示信息,若不传则调用默认的信息
  39. const messages = { stock_type: { required: '请选择商品类型', }, code: { required: '请输入固定资产编号', }, type_name: { required: '请选择类型', }, name: { required: '请输入商品名称', }, num: { required: '请输入商品数量', }, money: { required: '请输入商品单价', }, brief: { required: '请输入商品简介', } };
  40. this.WxValidate = new WxValidate(rules, messages)
  41. },
  42. back: function () {
  43. wx.navigateBack({ url: '/pages/stock/index' })
  44. },
  45. // 类型选择
  46. stocktypeChange: function (e) {
  47. let { value } = e.detail;
  48. let data = this.data.stock_typeList[value];
  49. this.setData({ 'stock_type': data.value })
  50. this.setData({ 'form.stock_type': data.value })
  51. this.setData({ 'form.stock_type_name': data.label })
  52. },
  53. // 类型选择
  54. typeChange: function (e) {
  55. let { value } = e.detail;
  56. let data = this.data.typeList[value];
  57. this.setData({ 'form.type_id': data.id })
  58. this.setData({ 'form.type_name': data.name })
  59. },
  60. // 上传图片
  61. afterRead: function (event) {
  62. console.log(event.detail);
  63. },
  64. // 删除图片
  65. uploadDelete: function (e) {
  66. console.log(e);
  67. },
  68. // 取消保存
  69. onReset: function (e) {
  70. this.back()
  71. },
  72. // 提交保存
  73. onSubmit: function (e) {
  74. console.log(e.detail.value);
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: function (options) {
  80. if (options.id) {
  81. this.setData({ 'form': this.data.info })
  82. }
  83. //验证规则函数
  84. this.initValidate()
  85. // 计算高度
  86. this.searchHeight()
  87. },
  88. // 计算高度
  89. searchHeight: function () {
  90. let frameStyle = this.data.frameStyle;
  91. let client = app.globalData.client;
  92. let infoHeight = client.windowHeight;
  93. // 是否去掉状态栏
  94. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  95. // 是否减去底部菜单
  96. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  97. if (infoHeight) this.setData({ infoHeight: infoHeight })
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {
  133. }
  134. })