detail.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. userInfo: {},
  13. form: {},
  14. // 弹框
  15. dialog: { title: '添加商品', show: false, type: '1' },
  16. // 入库商品
  17. order: [],
  18. // 库存已存
  19. oneorderForm: {},
  20. // 查询库存
  21. shoppinginput: '',
  22. stockList: [],
  23. },
  24. initValidate() {
  25. const rules = { register_name: { required: true, }, register_phone: { required: true, }, register_date: { required: true, }, reason: { required: true, } }
  26. // 验证字段的提示信息,若不传则调用默认的信息
  27. const messages = { register_name: { required: '请输入登记人', }, register_phone: { required: '请输入电话', }, register_date: { required: '请选择登记时间', }, reason: { required: '请输入入库原因', } };
  28. this.WxValidate = new WxValidate(rules, messages)
  29. },
  30. back: function () {
  31. wx.navigateBack({ url: '/pages/indepot/index' })
  32. },
  33. // 选择登记时间
  34. registerdateChange: function (e) {
  35. let { value } = e.detail;
  36. this.setData({ 'form.register_date': value })
  37. },
  38. // 添加商品
  39. addOrder: function () {
  40. this.setData({ dialog: { title: '添加商品', show: true, type: '1' } })
  41. },
  42. // 已有库存
  43. // 取消保存
  44. oneorderReset: function () {
  45. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } })
  46. },
  47. // 查询
  48. shoppinginput: function (e) {
  49. this.setData({ shoopingtext: e.detail.value })
  50. },
  51. // 查询库存
  52. searchStock: function () {
  53. let shoopingtext = this.data.shoopingtext;
  54. if (shoopingtext) {
  55. wx.request({
  56. url: app.globalData.publicUrl + `/api/hc/stock`,
  57. method: "get",
  58. data: { name: shoopingtext },
  59. header: {},
  60. success: (res) => {
  61. if (res.data.errcode == '0') {
  62. if (res.data.total > 0) {
  63. this.setData({ stockList: res.data.data })
  64. } else {
  65. wx.showToast({ title: `暂无产品`, icon: 'sucess', duration: 2000 })
  66. }
  67. } else {
  68. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  69. }
  70. },
  71. })
  72. } else {
  73. wx.showToast({ title: `请输入商品名称`, icon: 'error', duration: 2000 })
  74. }
  75. },
  76. // 确认选择商品
  77. stockChange: function (e) {
  78. const { item } = e.currentTarget.dataset;
  79. this.setData({ 'oneorderForm.stock_market_id': item.id })
  80. this.setData({ 'oneorderForm.name': item.name })
  81. this.setData({ 'oneorderForm.stockNum': item.num })
  82. },
  83. // 提交保存
  84. oneorderSubmit: function (e) {
  85. const params = e.detail.value;
  86. if (!params.name) wx.showToast({ title: `商品名称`, icon: 'error', duration: 2000 });
  87. else if (!params.num) wx.showToast({ title: `商品数量`, icon: 'error', duration: 2000 });
  88. if (params.name && params.num) {
  89. this.setData({ order: [...this.data.order, params] });
  90. this.setData({ oneorderForm: {} });
  91. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } });
  92. }
  93. },
  94. // 取消保存
  95. onReset: function (e) {
  96. this.back()
  97. },
  98. // 提交保存
  99. onSubmit: function (e) {
  100. const params = e.detail.value;
  101. if (!this.WxValidate.checkForm(params)) {
  102. const error = this.WxValidate.errorList[0];
  103. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  104. return false
  105. } else {
  106. params.order = this.data.order;
  107. wx.request({
  108. url: app.globalData.publicUrl + `/api/hc/marketOut`,
  109. method: "post",
  110. data: { ...params },
  111. header: {},
  112. success: (res) => {
  113. if (res.data.errcode == '0') {
  114. wx.showToast({ title: `出库添加完成`, icon: 'success', duration: 2000 })
  115. this.back()
  116. } else {
  117. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  118. }
  119. },
  120. })
  121. }
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad: function (options) {
  127. // 查询用户是否登录
  128. wx.getStorage({
  129. key: 'user',
  130. success: res => {
  131. if (res.data) {
  132. if (res.data) this.setData({ userInfo: res.data });
  133. this.setData({ form: { operate_id: res.data.id, operate_name: res.data.name } })
  134. } else {
  135. wx.redirectTo({ url: '/pages/login/index', })
  136. }
  137. }
  138. })
  139. //验证规则函数
  140. this.initValidate()
  141. // 计算高度
  142. this.searchHeight()
  143. },
  144. // 计算高度
  145. searchHeight: function () {
  146. let frameStyle = this.data.frameStyle;
  147. let client = app.globalData.client;
  148. // 减去状态栏
  149. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  150. // 是否减去底部菜单
  151. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  152. if (infoHeight) this.setData({ infoHeight: infoHeight })
  153. },
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面显示
  161. */
  162. onShow: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function () {
  173. },
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {
  178. },
  179. /**
  180. * 页面上拉触底事件的处理函数
  181. */
  182. onReachBottom: function () {
  183. },
  184. /**
  185. * 用户点击右上角分享
  186. */
  187. onShareAppMessage: function () {
  188. }
  189. })