detail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/market/detail.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. typeList: [
  16. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "办公用品" },
  17. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "金融用品" },
  18. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "书写工具" },
  19. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "办公机械" },
  20. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "文件用品" },
  21. { code: "8", id: "61dd3480bf70154c7fa35ac5", name: "其他用品" },
  22. ],
  23. // 图片
  24. img_url: [],
  25. },
  26. initValidate() {
  27. const rules = { type_name: { required: true }, name: { required: true, }, brief: { required: true, }, money: { required: true, }, }
  28. // 验证字段的提示信息,若不传则调用默认的信息
  29. const messages = { type_name: { required: '请选择商品类型', }, name: { required: '请输入商品名称', }, brief: { required: '请输入商品简介', }, money: { required: '请输入商品价格', }, };
  30. this.WxValidate = new WxValidate(rules, messages)
  31. },
  32. back: function () {
  33. wx.navigateBack({ url: '/pages/market/index' })
  34. },
  35. // 类型选择
  36. typeChange: function (e) {
  37. let { value } = e.detail;
  38. let data = this.data.typeList[value];
  39. this.setData({ 'form.type_id': data.id })
  40. this.setData({ 'form.type_name': data.name })
  41. },
  42. // 上传图片
  43. imgUpl: function (e) {
  44. const that = this;
  45. let data = that.data.img_url;
  46. data.push(e.detail)
  47. that.setData({ img_url: data })
  48. },
  49. // 删除图片
  50. imgDel: function (e) {
  51. const that = this;
  52. let list = that.data.img_url;
  53. let arr = list.filter((i, index) => index != e.detail.index)
  54. that.setData({ img_url: arr })
  55. },
  56. // 取消保存
  57. onReset: function (e) {
  58. this.back()
  59. },
  60. // 提交保存
  61. onSubmit: function (e) {
  62. const params = e.detail.value;
  63. params.img_url = this.data.img_url;
  64. if (!this.WxValidate.checkForm(params)) {
  65. const error = this.WxValidate.errorList[0];
  66. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  67. return false
  68. } else {
  69. wx.showModal({
  70. title: '是否确认提交商品',
  71. success(res) {
  72. if (res.confirm) {
  73. wx.showToast({ title: `提交商品成功`, icon: 'success', duration: 2000 });
  74. } else if (res.cancel) {
  75. }
  76. }
  77. })
  78. }
  79. },
  80. /**
  81. * 生命周期函数--监听页面加载
  82. */
  83. onLoad: function (options) {
  84. this.watchLogin();
  85. //验证规则函数
  86. this.initValidate()
  87. // 计算高度
  88. this.searchHeight()
  89. },
  90. // 监听用户是否登录
  91. watchLogin: function () {
  92. let info = { id: '00010102883', name: '供货单位' };
  93. this.setData({ userInfo: info });
  94. this.setData({ 'form.mech_name': info.name, 'form.mech_id': info.id, })
  95. // wx.getStorage({
  96. // key: 'user',
  97. // success: res => {
  98. // if (res.data) {
  99. // // 查询菜单
  100. // if (res.data) this.searchRouter(res.data);
  101. // res.data.type = type.find((i) => i.value == res.data.type).label;
  102. // if (res.data) this.setData({ userInfo: res.data });
  103. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  104. // } else {
  105. // wx.redirectTo({ url: '/pages/login/index', })
  106. // }
  107. // }
  108. // })
  109. },
  110. // 计算高度
  111. searchHeight: function () {
  112. let frameStyle = this.data.frameStyle;
  113. let client = app.globalData.client;
  114. // 减去状态栏
  115. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  116. // 是否减去底部菜单
  117. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  118. if (infoHeight) this.setData({ infoHeight: infoHeight })
  119. },
  120. /**
  121. * 生命周期函数--监听页面初次渲染完成
  122. */
  123. onReady: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面显示
  127. */
  128. onShow: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面隐藏
  132. */
  133. onHide: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面卸载
  137. */
  138. onUnload: function () {
  139. },
  140. /**
  141. * 页面相关事件处理函数--监听用户下拉动作
  142. */
  143. onPullDownRefresh: function () {
  144. },
  145. /**
  146. * 页面上拉触底事件的处理函数
  147. */
  148. onReachBottom: function () {
  149. },
  150. /**
  151. * 用户点击右上角分享
  152. */
  153. onShareAppMessage: function () {
  154. }
  155. })