detail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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: { id: '00010102883', name: '供货单位' },
  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.setData({ 'form.mech_name': this.data.userInfo.name, 'form.mech_id': this.data.userInfo.id, })
  85. this.watchLogin();
  86. //验证规则函数
  87. this.initValidate()
  88. // 计算高度
  89. this.searchHeight()
  90. },
  91. // 监听用户是否登录
  92. watchLogin: function () {
  93. // wx.getStorage({
  94. // key: 'user',
  95. // success: res => {
  96. // if (res.data) {
  97. // // 查询菜单
  98. // if (res.data) this.searchRouter(res.data);
  99. // res.data.type = type.find((i) => i.value == res.data.type).label;
  100. // if (res.data) this.setData({ userInfo: res.data });
  101. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  102. // } else {
  103. // wx.redirectTo({ url: '/pages/login/index', })
  104. // }
  105. // }
  106. // })
  107. },
  108. // 计算高度
  109. searchHeight: function () {
  110. let frameStyle = this.data.frameStyle;
  111. let client = app.globalData.client;
  112. // 减去状态栏
  113. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  114. // 是否减去底部菜单
  115. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  116. if (infoHeight) this.setData({ infoHeight: infoHeight })
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. }
  153. })