// pages/login/login.js import WxValidate from '../../utils/wxValidate'; import moment from "../../utils/moment.min"; const { apply_status } = require('../../utils/dict'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '采购需求信息', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', userInfo: {}, // 查询 shoopingtext: '', // 采购申请 list: [], // 弹框 dialog: { title: '详细信息', show: false, type: '1' }, // 详细信息 info: {}, // 审核 checkForm: {}, // 比对结果 resultList: [] }, initValidate() { const rules = { status: { required: true, } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { status: { required: '请选择审核状态', } }; this.WxValidate = new WxValidate(rules, messages) }, back: function () { wx.navigateBack({ url: '/pages/home/index' }) }, // 详细信息 toView: function (e) { const { id } = e.currentTarget.dataset; wx.request({ url: app.globalData.publicUrl + `/api/hc/apply/${id}`, method: "get", data: {}, header: {}, success: (res) => { if (res.data.errcode == '0') { this.setData({ info: res.data.data }) this.setData({ dialog: { title: '详细信息', show: true, type: '1' } }) } else { wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 }) } }, }) }, // 自动对比库存 toContrast: function (e) { const { id, order } = e.currentTarget.dataset; wx.request({ url: app.globalData.publicUrl + `/api/hc/apply/compare`, method: "post", data: { id, order }, header: {}, success: (res) => { if (res.data.errcode == '0') { this.setData({ resultList: res.data.data }) this.setData({ dialog: { title: '比对结果', show: true, type: '3' } }) } else { wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 }) } }, }) }, // 审核信息是否是采买,还是领取 toCheck: function (e) { const { id } = e.currentTarget.dataset; this.setData({ checkForm: { id: id } }); this.setData({ dialog: { title: '审核信息', show: true, type: '2' } }) }, // 提交审核 checkSubmit: function (e) { const params = e.detail.value; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 }) return false } else { // 审核时间 params.examine_date = moment().format('YYYY-MM-DD'); wx.request({ url: app.globalData.publicUrl + `/api/hc/apply/update/${params.id}`, method: "post", data: { ...params }, header: {}, success: (res) => { if (res.data.errcode == '0') { wx.showToast({ title: `审核信息成功`, icon: 'success', duration: 2000 }); this.setData({ dialog: { title: '详细信息', show: false, type: '1' } }) this.search(); } else { wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 }) } }, }) } }, // 查询 shoppinginput: function (e) { this.setData({ shoopingtext: e.detail.value }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 查询用户是否登录 wx.getStorage({ key: 'user', success: res => { if (res.data) { if (res.data) this.setData({ userInfo: res.data }); this.search(); } else { wx.redirectTo({ url: '/pages/login/index', }) } } }) //验证规则函数 this.initValidate(); // 计算高度 this.searchHeight(); }, // 查询采购列表 search: function () { const info = {}; let shoopingtext = this.data.shoopingtext; if (shoopingtext) info.user_name = shoopingtext; wx.request({ url: app.globalData.publicUrl + `/api/hc/apply`, method: "get", data: { ...info }, header: {}, success: (res) => { if (res.data.errcode == '0') { for (const val of res.data.data) { val.status_name = apply_status.find((i) => i.value == val.status).label; } this.setData({ list: res.data.data }) } else { wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 }) } }, }) }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; // 减去状态栏 let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2); // 是否减去底部菜单 if (frameStyle.useBar) infoHeight = infoHeight - 50; if (infoHeight) this.setData({ infoHeight: infoHeight }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.onLoad() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })