detail.js 6.3 KB

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