| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 | import {    ApiModel} from "../../utils/api";const _Http = new ApiModel;import {    TestVerify} from "../../utils/verify";const _Verify = new TestVerify();Page({    /**     * 页面的初始数据     */    data: {        maxDate: Number,        minDate: Number,        showCalendar: false, //日历显示        tsupplyanddemandid: 0, //ID 0为新增        newAdd: false, //是否新增 新增未保存直接退出页面会删除该供需        popups: false, //弹出层控制        ftype: "", //供需类型        ftitle: "", //供需标题        fcontent: "", //需求内容	        fenddate: "", //截止日期        /* 必填 */        errTips: {            ftype: false,            ftitle: false,            fcontent: false        }    },    /**     * 生命周期函数--监听页面加载     */    onLoad: function (options) {        this.setTime()        if (options.data == undefined) {            console.log('新增')            //新增            this.addOrModify()            this.setData({                newAdd: true            })        } else {            //修改        }    },    setTime() {        this.setData({            maxDate: Date.parse(new Date()) + 1000 * 60 * 60 * 24 * 31,            minDate: Date.parse(new Date())        })    },    /* 打开时间选择器 */    setDate() {        this.selectComponent("#SetDate").dateOnClose()    },    /* 设置下架 */    setSoldOut(date) {        this.setData({            fenddate: date.detail        })    },    /* 表单验证 */    formVerify() {        let errTips = this.data.errTips,            verify = true;        /* 验证分类 */        if (!_Verify.required(this.data.ftype)) {            errTips.ftype = true;            verify = false;        }        /* 验证标题  */        if (!_Verify.required(this.data.ftitle)) {            errTips.ftitle = true;            verify = false;        }        /* 验证内容  */        if (!_Verify.required(this.data.fcontent)) {            errTips.fcontent = true;            verify = false;        }        this.setData({            errTips        })        return verify;    },    /* 提交 */    submit() {        if (!this.formVerify()) return wx.showToast({            title: '请检查表单内容',            icon: "error"        });        this.setData({            newAdd: false        })        this.addOrModify()    },    /* 新增或修改 */    addOrModify() {        let content = {};        if (this.data.tsupplyanddemandid == 0) {            //新增产品            content = {                "tsupplyanddemandid": 0,                "fissupply": 0            }        } else {            //修改需求            content = {                "tsupplyanddemandid": this.data.tsupplyanddemandid,                "ftype": this.data.ftype,                "ftitle": this.data.ftitle,                "fcontent": this.data.fcontent,                "fenddate": this.data.fenddate,                "fissupply": 0            }        }        /* 发送请求 */        _Http.basic({            "accesstoken": wx.getStorageSync('userData').token,            "classname": "customer.supplyanddemand.supplyanddemand",            "method": "insertormodify",            "content": content        }).then(res => {            console.log(res)            if (this.data.newAdd) {                this.setData({                    tsupplyanddemandid: res.data[0].tsupplyanddemandid                })            }else{                wx.showToast({                  title: '保存成功',                })                setTimeout(()=>{                    wx.navigateBack({                        delta: 1,                      })                },500)            }        })    },    /* 弹出层 */    showPop() {        this.setData({            popups: !this.data.popups        })    },    /* 单选改变 */    radioChange(value) {        this.setData({            ftype: value.detail,            popups: false,            "errTips.ftype": false        })    },    /* 获取焦点 */    inputFocus(e) {        const {            name        } = e.currentTarget.dataset;        let errTips = this.data.errTips;        errTips[name] = false;        this.setData({            errTips        })    },    /* 失去焦点 */    inputBlur(e) {        const {            name        } = e.currentTarget.dataset;        const {            value        } = e.detail;        if (value.trim() == "") {            let errTips = this.data.errTips;            errTips[name] = true;            this.setData({                errTips            })        }    },    /**     * 生命周期函数--监听页面初次渲染完成     */    onReady: function () {    },    /**     * 生命周期函数--监听页面显示     */    onShow: function () {    },    /**     * 生命周期函数--监听页面隐藏     */    onHide: function () {    },    /**     * 生命周期函数--监听页面卸载     */    onUnload: function () {        //新增未保存,退出页面删除新增        if (this.data.newAdd) {            _Http.basic({                "accesstoken": wx.getStorageSync('userData').token,                "classname": "customer.supplyanddemand.supplyanddemand",                "method": "deletesupplyanddemand",                "content": {                    "tsupplyanddemandid": this.data.tsupplyanddemandid                }            }).then(res => {                console.log(res)            })        }    },    /**     * 页面相关事件处理函数--监听用户下拉动作     */    onPullDownRefresh: function () {    },    /**     * 页面上拉触底事件的处理函数     */    onReachBottom: function () {    },    /**     * 用户点击右上角分享     */    onShareAppMessage: function () {    }})
 |