index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate';
  3. import moment from "../../utils/moment.min";
  4. const { apply_status } = require('../../utils/dict');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. frameStyle: { useTop: true, name: '采购需求信息', leftArrow: true, useBar: false },
  12. // 主体高度
  13. infoHeight: '',
  14. userInfo: {},
  15. // 查询
  16. shoopingtext: '',
  17. // 采购申请
  18. list: [],
  19. // 弹框
  20. dialog: { title: '详细信息', show: false, type: '1' },
  21. // 详细信息
  22. info: {},
  23. // 审核
  24. checkForm: {},
  25. // 比对结果
  26. resultList: []
  27. },
  28. initValidate() {
  29. const rules = { status: { required: true, } }
  30. // 验证字段的提示信息,若不传则调用默认的信息
  31. const messages = { status: { required: '请选择审核状态', } };
  32. this.WxValidate = new WxValidate(rules, messages)
  33. },
  34. back: function () {
  35. wx.navigateBack({ url: '/pages/home/index' })
  36. },
  37. // 详细信息
  38. toView: function (e) {
  39. const { id } = e.currentTarget.dataset;
  40. wx.request({
  41. url: app.globalData.publicUrl + `/api/hc/apply/${id}`,
  42. method: "get",
  43. data: {},
  44. header: {},
  45. success: (res) => {
  46. if (res.data.errcode == '0') {
  47. this.setData({ info: res.data.data })
  48. this.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  49. } else {
  50. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  51. }
  52. },
  53. })
  54. },
  55. // 自动对比库存
  56. toContrast: function (e) {
  57. const { id, order } = e.currentTarget.dataset;
  58. wx.request({
  59. url: app.globalData.publicUrl + `/api/hc/apply/compare`,
  60. method: "post",
  61. data: { id, order },
  62. header: {},
  63. success: (res) => {
  64. if (res.data.errcode == '0') {
  65. this.setData({ resultList: res.data.data })
  66. this.setData({ dialog: { title: '比对结果', show: true, type: '3' } })
  67. } else {
  68. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  69. }
  70. },
  71. })
  72. },
  73. // 审核信息是否是采买,还是领取
  74. toCheck: function (e) {
  75. const { id } = e.currentTarget.dataset;
  76. this.setData({ checkForm: { id: id } });
  77. this.setData({ dialog: { title: '审核信息', show: true, type: '2' } })
  78. },
  79. // 提交审核
  80. checkSubmit: function (e) {
  81. const params = e.detail.value;
  82. if (!this.WxValidate.checkForm(params)) {
  83. const error = this.WxValidate.errorList[0];
  84. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  85. return false
  86. } else {
  87. // 审核时间
  88. params.examine_date = moment().format('YYYY-MM-DD');
  89. wx.request({
  90. url: app.globalData.publicUrl + `/api/hc/apply/update/${params.id}`,
  91. method: "post",
  92. data: { ...params },
  93. header: {},
  94. success: (res) => {
  95. if (res.data.errcode == '0') {
  96. wx.showToast({ title: `审核信息成功`, icon: 'success', duration: 2000 });
  97. this.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  98. this.search();
  99. } else {
  100. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  101. }
  102. },
  103. })
  104. }
  105. },
  106. // 查询
  107. shoppinginput: function (e) {
  108. this.setData({ shoopingtext: e.detail.value })
  109. },
  110. /**
  111. * 生命周期函数--监听页面加载
  112. */
  113. onLoad: function (options) {
  114. // 查询用户是否登录
  115. wx.getStorage({
  116. key: 'user',
  117. success: res => {
  118. if (res.data) {
  119. if (res.data) this.setData({ userInfo: res.data });
  120. this.search();
  121. } else {
  122. wx.redirectTo({ url: '/pages/login/index', })
  123. }
  124. }
  125. })
  126. //验证规则函数
  127. this.initValidate();
  128. // 计算高度
  129. this.searchHeight();
  130. },
  131. // 查询采购列表
  132. search: function () {
  133. const info = {};
  134. let shoopingtext = this.data.shoopingtext;
  135. if (shoopingtext) info.user_name = shoopingtext;
  136. wx.request({
  137. url: app.globalData.publicUrl + `/api/hc/apply`,
  138. method: "get",
  139. data: { ...info },
  140. header: {},
  141. success: (res) => {
  142. if (res.data.errcode == '0') {
  143. for (const val of res.data.data) {
  144. val.status_name = apply_status.find((i) => i.value == val.status).label;
  145. }
  146. this.setData({ list: res.data.data })
  147. } else {
  148. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  149. }
  150. },
  151. })
  152. },
  153. // 计算高度
  154. searchHeight: function () {
  155. let frameStyle = this.data.frameStyle;
  156. let client = app.globalData.client;
  157. // 减去状态栏
  158. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  159. // 是否减去底部菜单
  160. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  161. if (infoHeight) this.setData({ infoHeight: infoHeight })
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面显示
  170. */
  171. onShow: function () {
  172. this.onLoad()
  173. },
  174. /**
  175. * 生命周期函数--监听页面隐藏
  176. */
  177. onHide: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面卸载
  181. */
  182. onUnload: function () {
  183. },
  184. /**
  185. * 页面相关事件处理函数--监听用户下拉动作
  186. */
  187. onPullDownRefresh: function () {
  188. },
  189. /**
  190. * 页面上拉触底事件的处理函数
  191. */
  192. onReachBottom: function () {
  193. },
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage: function () {
  198. }
  199. })