|
@@ -1,20 +1,154 @@
|
|
|
-// pages/announceDemand/index.js
|
|
|
+import {
|
|
|
+ ApiModel
|
|
|
+} from "../../utils/api";
|
|
|
+const _Http = new ApiModel;
|
|
|
+import {
|
|
|
+ TestVerify
|
|
|
+} from "../../utils/verify";
|
|
|
+const _Verify = new TestVerify();
|
|
|
Page({
|
|
|
-
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ tsupplyanddemandid: 0, //ID 0为新增
|
|
|
+ newAdd: false, //是否新增 新增未保存直接退出页面会删除该供需
|
|
|
+ popups: false, //弹出层控制
|
|
|
+ ftype: "", //供需类型
|
|
|
+ ftitle: "", //供需标题
|
|
|
+ fcontent: "", //需求内容
|
|
|
+ fenddate: "", //截止日期
|
|
|
+ fissupply: "", //1供/0需,
|
|
|
+ /* 必填 */
|
|
|
+ errTips: {
|
|
|
+ ftype: false,
|
|
|
+ ftitle: false,
|
|
|
+ fcontent: false
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
-
|
|
|
+ if (options.data == undefined) {
|
|
|
+ console.log('新增')
|
|
|
+ //新增
|
|
|
+ this.addOrModify()
|
|
|
+ this.setData({
|
|
|
+ newAdd: true
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ //修改
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 表单验证 */
|
|
|
+ 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"
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /* 新增或修改 */
|
|
|
+ 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": this.data.fissupply
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(content)
|
|
|
+ /* 发送请求 */
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "customer.supplyanddemand.supplyanddemand",
|
|
|
+ "method": "insertormodify",
|
|
|
+ "content": content
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ this.setData({
|
|
|
+ tsupplyanddemandid: res.data[0].tsupplyanddemandid
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 弹出层 */
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
@@ -40,7 +174,19 @@ Page({
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
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)
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|