|
@@ -1,5 +1,6 @@
|
|
|
// pages/login/login.js
|
|
|
import WxValidate from '../../utils/wxValidate'
|
|
|
+const { stock_type } = require('../../utils/dict');
|
|
|
const app = getApp()
|
|
|
Page({
|
|
|
|
|
@@ -11,25 +12,14 @@ Page({
|
|
|
// 主体高度
|
|
|
infoHeight: '',
|
|
|
// 类型
|
|
|
- typeList: [
|
|
|
- { id: '0', name: '其他' },
|
|
|
- { id: '1', name: '办公生活用品' },
|
|
|
- { id: '2', name: '办公机械' },
|
|
|
- { id: '3', name: '金融用品' },
|
|
|
- { id: '4', name: '纸制品' },
|
|
|
- { id: '5', name: '书写工具' },
|
|
|
- { id: '6', name: '桌面办公文具' },
|
|
|
- ],
|
|
|
- info: { id: '1234567', name: '11', type_name: '办公室生活用品', num: '11', money: '111', brief: '无' },
|
|
|
+ typeList: [],
|
|
|
+ id: '',
|
|
|
form: {},
|
|
|
stock_type: '',
|
|
|
// 图片
|
|
|
img_url: [],
|
|
|
// 商品类型
|
|
|
- stock_typeList: [
|
|
|
- { value: '1', label: '固定资产' },
|
|
|
- { value: '2', label: '商品' },
|
|
|
- ]
|
|
|
+ stock_typeList: stock_type
|
|
|
},
|
|
|
back: function () {
|
|
|
wx.navigateBack({ url: '/pages/home/index' })
|
|
@@ -59,12 +49,18 @@ Page({
|
|
|
this.setData({ 'form.type_name': data.name })
|
|
|
},
|
|
|
// 上传图片
|
|
|
- afterRead: function (event) {
|
|
|
- console.log(event.detail);
|
|
|
+ imgUpl: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.img_url;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ img_url: data })
|
|
|
},
|
|
|
// 删除图片
|
|
|
- uploadDelete: function (e) {
|
|
|
- console.log(e);
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.img_url;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ img_url: arr })
|
|
|
},
|
|
|
// 取消保存
|
|
|
onReset: function (e) {
|
|
@@ -72,20 +68,56 @@ Page({
|
|
|
},
|
|
|
// 提交保存
|
|
|
onSubmit: function (e) {
|
|
|
- console.log(e.detail.value);
|
|
|
+ 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 {
|
|
|
+ console.log(params);
|
|
|
+ }
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
- if (options.id) {
|
|
|
- this.setData({ 'form': this.data.info })
|
|
|
- }
|
|
|
+ // 查询其他数据
|
|
|
+ this.searchOther()
|
|
|
//验证规则函数
|
|
|
this.initValidate()
|
|
|
+ if (options.id) this.setData({ id: options.id })
|
|
|
+ // 监听用户是否登录
|
|
|
+ this.watchLogin();
|
|
|
// 计算高度
|
|
|
this.searchHeight()
|
|
|
},
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: function () {
|
|
|
+ const that = this;
|
|
|
+ let id = that.data.id;
|
|
|
+ if (id) {
|
|
|
+ // 如果有ID查询数据详情,赋值给form
|
|
|
+ }
|
|
|
+ // wx.getStorage({
|
|
|
+ // key: 'user',
|
|
|
+ // success: res => {
|
|
|
+ // if (res.data) {
|
|
|
+ // // 查询菜单
|
|
|
+ // if (res.data) this.searchRouter(res.data);
|
|
|
+ // res.data.type = type.find((i) => i.value == res.data.type).label;
|
|
|
+ // if (res.data) this.setData({ userInfo: res.data });
|
|
|
+ // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
|
|
|
+ // } else {
|
|
|
+ // wx.redirectTo({ url: '/pages/login/index', })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ searchOther: function () {
|
|
|
+ //查询类型
|
|
|
+ console.log('查询类型');
|
|
|
+ },
|
|
|
// 计算高度
|
|
|
searchHeight: function () {
|
|
|
let frameStyle = this.data.frameStyle;
|