页面绑定很多事件!

<view class="content">
<view class="user personal_func_list">
<view class="flex align-c personal_func_item">
<view class="name">
<text>品牌</text>
</view>
<view class="input flex_1">
<picker bindchange="brandPickerChange" value="{{brand_index}}" range-key="name" range="{{brand_array}}">
<view class="picker">
{{brand_array[brand_index].name}}
</view>
</picker>
</view> </view>
<view class="flex align-c personal_func_item">
<view class="name">
<text>型号</text>
</view>
<view class="input flex_1">
<picker bindchange="modelPickerChange" value="{{model_index}}" range-key="name" range="{{model_array}}">
<view class="picker">
{{model_array[model_index].name}}
</view>
</picker>
</view> </view> <view class="flex align-c personal_func_item">
<view class="name">
<text>姓名</text>
</view>
<view class="input flex_1">
<input placeholder="请输入真实姓名" bindinput="keyName" />
</view>
</view>
<view class="flex align-c personal_func_item">
<view class="name">
<text>电话</text>
</view>
<view class="input flex_1">
<input placeholder="请输入手机号码" bindinput="keyPhone" />
</view>
</view> <view class="flex align-c personal_func_item">
<view class="name">
<text>地址</text>
</view>
<view class="input flex_1">
<input placeholder="请输入地址" bindinput="keyAddress" />
</view>
</view> <view class="flex align-c personal_func_item">
<view class="name">
<text>故障原因</text>
</view>
<view class="input flex_1">
<input placeholder="请输入故障原因" bindinput="keyReason" />
</view>
</view> </view>
<button class="sub_btn background_color_beauty" bindtap="applyAfterSale">提交</button>
</view>

JS处理很多数据获取与提交!

// pages/mine/index.js
const Api = require("../../config/method.js");
const Session = require('../../common/auth/session')
const tips = require('../../common/tips.js');
const app = getApp();
const session = Session.get();
Page({
data: {
brand_array: [],
brand_index: 0,
model_array:[],
model_index: 0,
brand_id : 0,
model_id : 0,
realname:'',
tel:'',
address:'',
reason:''
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.init();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
this.init();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
init: function () {
let self = this;
let session = Session.get();
if (session && session.uid) {
// 获取品牌数据
Api.GetBrandList({}).then(res=>{
self.setData({
brand_array:res.data,
brand_id : res.data[0]['brand_id']
}) // 获取型号数据
Api.GetModelList({'brand_id':self.data.brand_id}).then(res=>{
self.setData({
model_array : res.data,
model_id: res.data[0]['model_id']
})
})
}) } else {
tips.showAction('系统提示','您还没有登录, 请先登录?',()=>{
let url = '/pages/mine/index'
wx.switchTab({ url })
});
}
},
brandPickerChange: function(e) {
let self = this;
let brand_index = e.detail.value;
let brand_id = self.data.brand_array[brand_index]['brand_id'];
this.setData({
brand_index: brand_index,
brand_id:brand_id
})
// 获取型号数据
Api.GetModelList({'brand_id':brand_id}).then(res=>{
self.setData({
model_array : res.data,
model_id: res.data[0]['model_id'],
model_index : 0
})
})
},
modelPickerChange: function(e) {
let self = this;
let model_index = e.detail.value;
let model_id = self.data.model_array[model_index]['model_id'];
this.setData({
model_index: model_index,
model_id:model_id
})
},
keyName :function(e) {
let { value } = e.detail;
this.setData({
realname:value
})
},
keyPhone :function(e) {
let { value } = e.detail;
this.setData({
tel:value
})
},
keyAddress :function(e) {
let { value } = e.detail;
this.setData({
address:value
})
},
keyReason :function(e) {
let { value } = e.detail;
this.setData({
reason:value
})
},
applyAfterSale : function() {
// 判断参数是否传递
var self = this;
const session = Session.get();
let uid = session.uid;
let {brand_id,model_id,realname,tel,address,reason} = this.data;
if(!brand_id||!model_id||!realname||!tel||!address||!reason){
tips.showModel('系统提示','请完善信息');
return;
}
Api.ApplyAfterSale({ uid, realname,tel,brand_id,model_id,address,reason }).then(res=>{
console.log(JSON.stringify(res));
if (res.errno == 0) {
tips.showSuccess('申请成功!');
setTimeout(function () {
wx.switchTab({
url: '/pages/mine/index'
})
}, 1000) } else {
tips.showModel('系统提示',res.errdesc);
}
})
},
onShareAppMessage: function () {
// 设置了,页面才可以分享
return {
title: '屹族',
desc: '屹族小程序商铺',
path: '/pages/index/index'
}
}
})

微信小程序之表单提交的更多相关文章

  1. 2017-01-11小程序form表单提交

    小程序form表单提交 1.小程序相对于之前的WEB+PHP建站来说,个人理解为只是将web放到了微信端,用小程序固定的格式前前端进行布局.事件触发和数据的输送和读取,服务器端可以用任何后端语言写,但 ...

  2. 微信小程序-form表单-获取用户输入文本框的值

    微信小程序-form表单-获取用户输入文本框的值 <input name='formnickname' class="textarea" placeholder=" ...

  3. 微信小程序之表单验证

    表单验证 何为表单验证呢? 百度百科给出的回答是这样的: 表单验证是javascript中的高级选项之一.JavaScript 可用来在数据被送往服务器前对 HTML 表单中的这些输入数据进行验证 [ ...

  4. 微信小程序_(表单组件)checkbox与label

    微信小程序组件checkbox官方文档 传送门 微信小程序组件label官方文档 传送门 Learn 一.checkbox组件 二.label组件与checkbox组件共用 一.checkbox组件 ...

  5. 微信小程序_(表单组件)button组件的使用

    微信小程序表单组件button官方文档 传送门 Learn 一.button组件的使用 一.button组件的使用 size:按钮的大小[默认值default] type:按钮的样式类型[默认值def ...

  6. 微信小程序常用表单校验方法(手机号校验、身份证号(严格和非严格校验、验证码六位数字校验))

    util.js function isPhone(value) { if (!/^1(3|4|5|7|8)\d{9}$/.test(value)) { return false } else { re ...

  7. 「小程序JAVA实战」小程序的表单组件(25)

    转自:https://idig8.com/2018/08/18/xiaochengxujavashizhanxiaochengxudebiaodanzujian25/ 来说下 ,小程序的基础组件.源码 ...

  8. 原创:经验分享:微信小程序外包接单常见问题及流程

    从九月底内测到现在已经三个半月.凌晨一点睡觉已经习以为常,也正是这样,才让无前端经验的我做微信小程序开发并不感到费劲.最近才开始接微信小程序的外包项目,目前已经签下了五份合同,成品出了两个.加上转给朋 ...

  9. [转]经验分享:微信小程序外包接单常见问题及流程

    本文转自:https://www.cnblogs.com/wxapp-union/p/6245301.html 从九月底内测到现在已经三个半月.凌晨一点睡觉已经习以为常,也正是这样,才让无前端经验的我 ...

随机推荐

  1. yii2:frontend/frontactoin curl生成

    yii2:frontend/frontactoin curl生成 想要覆写已存在文件,选中 “overwrite” 下的复选框然后点击 “Generator”.如果是新文件,只点击 “Generato ...

  2. Django中ORM模板常用属性讲解

    学习了ORM模板中常用的字段以及使用方法,具体如下: from django.db import models # Create your models here. # 如果要将一个普通的类映射到数据 ...

  3. Spring AOP(面向切面示例)

    什么是AOP?基本概念切面(aspect):横切关注点被模块化的特殊对象.通知(advice):切面必须要完成的工作.切面中的每个方向称之为通知.通知是在切面对象中的.目标(target):被通知的对 ...

  4. TCP与UDP(实时通讯)

    1.TCP使用 导入AsyncSocket资源文件夹,此文件是arc混编,加入库文件,如下图: #import "ViewController.h" #import "A ...

  5. 偶然遇到的samba服务器权限问题

    也许有一些参考价值. CentOS 6.4使用命令service smb start启动samba服务器,在配置文件都正确,而且对应的共享目录权限也正确,使用smbpasswd添加了用户,这之后,使用 ...

  6. TF随笔-3

    >>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...

  7. Electron 使用 Webpack2 打包多入口应用程序

    Electron 使用 Webpack2 打包多入口应用程序 接前面一篇文章,前一篇文章中只有一个页面,并且只有一个js文件,所以打包的时候会把那个js打包成一个bundle.js文件.但是假如我们有 ...

  8. Kotlin For Gank.io (干货集中营Kotlin实现)

    介绍 Kotlin,现在如火如荼,所以花了一点时间把之前的项目用Kotlin重构一下 原项目地址:https://github.com/onlyloveyd/GankIOClient 对应Kotlin ...

  9. Leetcode 890. Find and Replace Pattern

    把pattern映射到数字,也就是把pattern标准化. 比如abb和cdd如果都能标准化为011,那么就是同构的. class Solution: def findAndReplacePatter ...

  10. 测试中认识 sqlite

    1.SQLite,是一款轻型的数据库:简单, 轻松的API 单词速记中单词离线包也用到sqlite 百度了一下,基本的使用语句: .help .quit sqlite3 testDB.db 在当前目录 ...