detail.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. imgUpl: function (e) {
  93. const that = this;
  94. let data = that.data.img_url;
  95. data.push(e.detail)
  96. that.setData({ img_url: data })
  97. },
  98. // 删除图片
  99. imgDel: function (e) {
  100. const that = this;
  101. let list = that.data.img_url;
  102. let arr = list.filter((i, index) => index != e.detail.index)
  103. that.setData({ img_url: arr })
  104. },
  105. twoorderSubmit: function (e) {
  106. console.log(e.detail);
  107. },
  108. // 取消保存
  109. onReset: function (e) {
  110. this.back()
  111. },
  112. // 提交保存
  113. onSubmit: function (e) {
  114. const params = e.detail.value;
  115. if (!this.WxValidate.checkForm(params)) {
  116. const error = this.WxValidate.errorList[0];
  117. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  118. return false
  119. } else {
  120. console.log(params);
  121. }
  122. },
  123. /**
  124. * 生命周期函数--监听页面加载
  125. */
  126. onLoad: function (options) {
  127. // 查询其他信息
  128. this.searchOther();
  129. //验证规则函数
  130. this.initValidate()
  131. if (options.id) this.setData({ id: options.id })
  132. // 监听用户是否登录
  133. this.watchLogin();
  134. // 计算高度
  135. this.searchHeight()
  136. },
  137. // 监听用户是否登录
  138. watchLogin: function () {
  139. const that = this;
  140. let id = that.data.id;
  141. if (id) {
  142. // 如果有ID查询数据详情,赋值给form
  143. }
  144. // wx.getStorage({
  145. // key: 'user',
  146. // success: res => {
  147. // if (res.data) {
  148. // // 查询菜单
  149. // if (res.data) this.searchRouter(res.data);
  150. // res.data.type = type.find((i) => i.value == res.data.type).label;
  151. // if (res.data) this.setData({ userInfo: res.data });
  152. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  153. // } else {
  154. // wx.redirectTo({ url: '/pages/login/index', })
  155. // }
  156. // }
  157. // })
  158. },
  159. // 查询其他信息
  160. searchOther: function () {
  161. },
  162. // 计算高度
  163. searchHeight: function () {
  164. let frameStyle = this.data.frameStyle;
  165. let client = app.globalData.client;
  166. // 减去状态栏
  167. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  168. // 是否减去底部菜单
  169. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  170. if (infoHeight) this.setData({ infoHeight: infoHeight })
  171. },
  172. /**
  173. * 生命周期函数--监听页面初次渲染完成
  174. */
  175. onReady: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面显示
  179. */
  180. onShow: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面隐藏
  184. */
  185. onHide: function () {
  186. },
  187. /**
  188. * 生命周期函数--监听页面卸载
  189. */
  190. onUnload: function () {
  191. },
  192. /**
  193. * 页面相关事件处理函数--监听用户下拉动作
  194. */
  195. onPullDownRefresh: function () {
  196. },
  197. /**
  198. * 页面上拉触底事件的处理函数
  199. */
  200. onReachBottom: function () {
  201. },
  202. /**
  203. * 用户点击右上角分享
  204. */
  205. onShareAppMessage: function () {
  206. }
  207. })