Commit 91b55198 by 施宇

表单校验

parent 9c9dc943
...@@ -18,23 +18,38 @@ Page({ ...@@ -18,23 +18,38 @@ Page({
}, },
formSubmit: function (e) { formSubmit: function (e) {
let obj = e.detail.value; let obj = e.detail.value;
if (!obj.goods_name) { if (!obj.goods_name.trim().length) {
tips('请填写型号'); tips('请填写型号');
return return
} else if (!obj.brand_name) { } else if (obj.goods_name.trim().length < 3) {
tips('型号不能小于3个字符');
return
} else if (!obj.brand_name.trim().length) {
tips('请填写品牌'); tips('请填写品牌');
return return
} else if (!obj.number) { } else if (obj.brand_name.trim().length < 2) {
tips('品牌不能小于2个字符');
return
} else if (!obj.number.trim().length) {
tips('请填写数量'); tips('请填写数量');
return return
} else if (!obj.price) { } else if (isNaN(Number(obj.number.trim()))) {
tips('数量必须为数字');
return
} else if (!obj.price.trim().length) {
tips('请填写价格'); tips('请填写价格');
return return
} else { } else {
if (obj.hq == 2) {//期货 if (obj.hq == 2) {//期货
if (!obj.day) { if (!obj.day.trim().length) {
tips('请填写货期'); tips('请填写货期');
return return
} else if (isNaN(Number(obj.day.trim()))) {
tips('货期必须为数字');
return
} else if (obj.day.trim().length > 3) {
tips('货期不能大于3个字符');
return
} }
} }
} }
......
...@@ -19,7 +19,7 @@ Page({ ...@@ -19,7 +19,7 @@ Page({
price: "", price: "",
day: "", day: "",
goodId: "", goodId: "",
hq:"1", hq: "1",
isShowTip: true isShowTip: true
}, },
...@@ -40,7 +40,7 @@ Page({ ...@@ -40,7 +40,7 @@ Page({
title: '新增商品' title: '新增商品'
}) })
} }
}, },
getGoodData: function () { getGoodData: function () {
let me = this; let me = this;
...@@ -65,44 +65,59 @@ Page({ ...@@ -65,44 +65,59 @@ Page({
}, },
renderForm: function (infoObj) { renderForm: function (infoObj) {
this.setData({ this.setData({
goodsName:infoObj.goods_name, goodsName: infoObj.goods_name,
brandName: infoObj.brand_name, brandName: infoObj.brand_name,
encap: infoObj.encap, encap: infoObj.encap,
stock: infoObj.stock, stock: infoObj.stock,
price: infoObj.price, price: infoObj.price,
currency: infoObj.currency, currency: infoObj.currency,
imgUrl:infoObj.goods_images imgUrl: infoObj.goods_images
}); });
if(infoObj.delivery_time !== '现货'){ if (infoObj.delivery_time !== '现货') {
let day = infoObj.delivery_time.replace('天',''); let day = infoObj.delivery_time.replace('天', '');
console.log(day) console.log(day)
this.setData({ this.setData({
isShowTime:2, isShowTime: 2,
hq:2, hq: 2,
day:day day: day
}); });
} }
}, },
formSubmit: function (e) { formSubmit: function (e) {
let obj = e.detail.value; let obj = e.detail.value;
if (!obj.goods_name) { if (!obj.goods_name.trim().length) {
tips('请填写型号'); tips('请填写型号');
return return
} else if (!obj.brand_name) { } else if (obj.goods_name.trim().length < 3) {
tips('型号不能小于3个字符');
return
} else if (!obj.brand_name.trim().length) {
tips('请填写品牌'); tips('请填写品牌');
return return
} else if (!obj.stock) { } else if (obj.brand_name.trim().length < 2) {
tips('品牌不能小于2个字符');
return
} else if (!obj.stock.trim().length) {
tips('请填写库存'); tips('请填写库存');
return return
} else if (!obj.price) { } else if (isNaN(Number(obj.stock.trim()))) {
tips('库存必须为数字');
return
} else if (!obj.price.trim().length) {
tips('请填写价格'); tips('请填写价格');
return return
} else { } else {
if (obj.hq == 2) {//期货 if (obj.hq == 2) {//期货
if (!obj.day) { if (!obj.day.trim().length) {
tips('请填写货期'); tips('请填写货期');
return return
} else if (isNaN(Number(obj.day.trim()))) {
tips('货期必须为数字');
return
} else if (obj.day.trim().length > 3) {
tips('货期不能大于3个字符');
return
} }
} }
} }
...@@ -152,7 +167,7 @@ Page({ ...@@ -152,7 +167,7 @@ Page({
let val = e.detail.value; let val = e.detail.value;
this.setData({ this.setData({
isShowTime: val == 1 ? false : true, isShowTime: val == 1 ? false : true,
hq:val hq: val
}) })
}, },
...@@ -170,7 +185,7 @@ Page({ ...@@ -170,7 +185,7 @@ Page({
imgUrl: null imgUrl: null
}) })
}, },
deleteGood:function(){ deleteGood: function () {
}, },
/** /**
......
// pages/form/xj/index.js // pages/form/xj/index.js
import { getData, chooseImg, tips } from '../../../utils/util.js'; import {
import { apis } from '../../../utils/api.js'; getData,
chooseImg,
tips
} from '../../../utils/util.js';
import {
apis
} from '../../../utils/api.js';
Page({ Page({
/** /**
...@@ -14,31 +20,46 @@ Page({ ...@@ -14,31 +20,46 @@ Page({
isClick: true, isClick: true,
isShowTip: true isShowTip: true
}, },
formSubmit: function (e) { formSubmit: function(e) {
let obj = e.detail.value; let obj = e.detail.value;
if (!obj.goods_name) { if (!obj.goods_name.trim().length) {
tips('请填写型号'); tips('请填写型号');
return return
} else if (!obj.brand_name) { } else if (obj.goods_name.trim().length < 3) {
tips('型号不能小于3个字符');
return
} else if (!obj.brand_name.trim().length) {
tips('请填写品牌'); tips('请填写品牌');
return return
} else if (!obj.number) { } else if (obj.brand_name.trim().length < 2) {
tips('品牌不能小于2个字符');
return
} else if (!obj.number.trim().length) {
tips('请填写数量'); tips('请填写数量');
return return
} else if (!obj.price) { } else if (isNaN(Number(obj.number.trim()))) {
tips('数量必须为数字');
return
} else if (!obj.price.trim().length) {
tips('请填写价格'); tips('请填写价格');
return return
} else { } else {
if (obj.hq == 2) {//期货 if (obj.hq == 2) { //期货
if (!obj.day) { if (!obj.day.trim().length) {
tips('请填写货期'); tips('请填写货期');
return return
} else if (isNaN(Number(obj.day.trim()))) {
tips('货期必须为数字');
return
} else if (obj.day.trim().length > 3) {
tips('货期不能大于3个字符');
return
} }
} }
} }
this.postData(obj); this.postData(obj);
}, },
postData: function (obj) { postData: function(obj) {
let me = this; let me = this;
let token = wx.getStorageSync('access_token'); let token = wx.getStorageSync('access_token');
obj.hq == 1 ? obj.delivery_time = '现货' : obj.delivery_time = obj.day + '天'; obj.hq == 1 ? obj.delivery_time = '现货' : obj.delivery_time = obj.day + '天';
...@@ -51,7 +72,7 @@ Page({ ...@@ -51,7 +72,7 @@ Page({
me.setData({ me.setData({
isClick: false isClick: false
}) })
getData(apis.inquiryadd, 'get', obj, function (res) { getData(apis.inquiryadd, 'get', obj, function(res) {
if (res.errcode == 0) { if (res.errcode == 0) {
tips('发布成功') tips('发布成功')
me.setData({ me.setData({
...@@ -75,16 +96,16 @@ Page({ ...@@ -75,16 +96,16 @@ Page({
}) })
}, },
uploadImg: function () { uploadImg: function() {
let me = this; let me = this;
chooseImg(apis.ossupload, 1, function (url) { chooseImg(apis.ossupload, 1, function(url) {
me.setData({ me.setData({
imgUrl: url imgUrl: url
}) })
}) })
}, },
deleteImg: function () { deleteImg: function() {
this.setData({ this.setData({
imgUrl: null imgUrl: null
}) })
...@@ -92,71 +113,71 @@ Page({ ...@@ -92,71 +113,71 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function(options) {
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function () { onReady: function() {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function() {
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function() {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function () { onUnload: function() {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function () { onPullDownRefresh: function() {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom: function () { onReachBottom: function() {
}, },
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage: function () { onShareAppMessage: function() {
}, },
changePrice: function (e) { changePrice: function(e) {
let type = e.target.dataset.pricetype; let type = e.target.dataset.pricetype;
this.setData({ this.setData({
currency: type, currency: type,
isShowSwitch: false isShowSwitch: false
}) })
}, },
switchPrice: function () { switchPrice: function() {
this.setData({ this.setData({
isShowSwitch: !this.data.isShowSwitch isShowSwitch: !this.data.isShowSwitch
}) })
}, },
closeTip: function () { closeTip: function() {
this.setData({ this.setData({
isShowTip: false isShowTip: false
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment