//index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: ‘Hello World’,
userInfo: {},
userid:’-1’,
username:‘本人’,
hasUserInfo: false,
items: [ /数组中的元素是对象/
{ name: ‘早稻’, value: ‘早稻’},
{ name: ‘中稻’, value: ‘中稻’ },
{ name: ‘晚稻’, value: ‘晚稻’ },
],
lzflag:0,
passtype: [
{ value: 0, name: ‘否’ },
{ value: 1, name: ‘是’ }
],
orderno:’’,
idcard: ‘’,
mobile: ‘’,
realname: ‘’,
area_address: ‘’,
bank_name: ‘’,
bank_cardno: ‘’,
crop_name: ‘111’,
insured_areasize: 0,
direct_areasize: ‘’,
insured_amount:0,
rate_value: ‘’,
premium: ‘’,
is_landcircle: ‘否’,
premium_sum: 0,
self_premium: 0,
allowance_amount: 0,
imageurl: [],
imgData: [],
dao1: 0,
dao2: ‘’,
dao3: 0,
dao4: ‘’,
dao5: 0,
dao6: ‘’,
isShow1:false,
isShow2:false,
isShow3:false
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: ‘…/logs/logs’
})
},
onLoad: function (options) {
var parameter = JSON.parse(options.parameter);
this.setData({
orderno: parameter.orderno,
idcard: parameter.cardNo,
mobile: parameter.telephone,
realname: parameter.userName,
area_address: parameter.plantAddress,
bank_name: parameter.openingBank,
bank_cardno:parameter.bankNo,
rate_value: parameter.rate_value,
dao2: parameter.unit_premium,
dao4: parameter.unit_premium,
dao6: parameter.unit_premium,
insured_amount: parameter.insured_amount,
allowance_amount: parameter.allowance_amount
})
// this.ctx = wx.createCameraContext();
// var userid = wx.getStorageSync('userInfo').userid;
// if (userid) {
// this.setData({
// username: wx.getStorageSync('userInfo').username,
// userid: wx.getStorageSync('userInfo').userid
// })
// } else {
// wx.navigateTo({
// url: '/pages/logn/index',
// })
// }
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
watchUsername: function (event) {
this.setData({
idcard: event.detail.value
})
},
bindPickerChange: function (e) {
console.log(e);
console.log(‘picker发送选择改变,携带值为’, e.detail.value)
if (e.detail.value==0){
// 0 否 1 是
this.setData({
is_landcircle:‘否’,
index: e.detail.value,
lzflag:0,
imgData:’’
})
} else if (e.detail.value == 1){
this.setData({
is_landcircle:‘是’,
index: e.detail.value,
lzflag: 1
})
}
},
/**
上传照片//选择图片时限制9张,如需超过9张,同理亦可参照此方法上传多张照片
/
uploadImg: function () {
var that = this;
wx.chooseImage({
count: 9,
sizeType: [‘original’, ‘compressed’],
sourceType: [‘album’, ‘camera’],
success: function (res) {
var successUp = 0; //成功
var failUp = 0; //失败
var length = res.tempFilePaths.length; //总数
var count = 0; //第几张
that.setData({
imageurl: res.tempFilePaths
})
that.uploadOneByOne(res.tempFilePaths, successUp, failUp, count, length);
},
});
},
/*
console.log(‘img:’, imgarr[index])
// imgarr.splice(index, 1);
// that.setData({
// imageurl: imgarr
// })
wx.showLoading({
title: ‘加载中…’,
mask: true
})
wx.request({
url: app.globalData.url + ‘Delete’,
data: {
fileid: imgarr[index].fileid,
filepath: imgarr[index].filepath
},
header: {
‘content-type’: ‘application/json’ // 默认值
},
success: function (res) {
wx.hideLoading();
if (res.data.code == 200) {
imgarr.splice(index, 1);
that.setData({
imageurl: imgarr
})
}
else {
wx.showModal({
content: res.data.msg,
showCancel: false
})
}
},
fail: function () {
wx.hideLoading();
wx.showModal({
content: ‘请求数据失败’,
showCancel: false
})
}
})
},
rate_value:function(e){
this.setData({
rate_value: e.detail.value
})
},
userInfo1: function(e){
this.setData({
userInfo1: e.detail.value
})
},
createInsurance: function () {
debugger;
var that = this;
that.setData({
maskFlag: false
})
wx.showLoading({
title: ‘加载中…’,
mask: false
})
var caseDate = {
orderno: that.data.orderno,
openid: app.globalData.openid,
ywyid: that.data.userid,
ywyname: that.data.username,
idcard: that.data.idcard,
mobile: that.data.mobile,
realname: that.data.realname,
area_address: that.data.area_address,
bank_name: that.data.bank_name,
bank_cardno: that.data.bank_cardno,
crop_name: that.data.crop_name,
insured_areasize: that.data.insured_areasize,
direct_areasize: that.data.direct_areasize,
insured_amount: that.data.insured_amount,
rate_value: that.data.rate_value,
premium: that.data.premium,
is_landcircle: that.data.is_landcircle,
premium_sum: that.data.premium_sum,
self_premium: that.data.self_premium,
imgData: JSON.stringify(that.data.imgData),
allowance_amount: this.data.allowance_amount,
area1 : that.data.dao1,
area2 : that.data.dao3,
area3 : that.data.dao5,
}
if (this.data.is_landcircle == 1 && this.data.imageurl.length == 0) {
wx.showModal({
content: '请先上传证明图片',
showCancel: false
})
return;
}
wx.request({
url: app.globalData.url + 'CreateInsurance',
data: caseDate,
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
that.setData({
maskFlag: true
})
wx.hideLoading();
if (res.data.code == 200) {
wx.setStorageSync('orderno',"");
wx.showToast({
title: '操作成功',
})
setTimeout(function () {
wx.switchTab({
url: '../insurancelist/index',
})
}, 1000)
}
}
});
},
checkChange: function (e) {
/获取的是一个数组, 包含的是选中的value的值, 如[‘早稻’, ‘中稻’], 即要传递的值/
this.setData({
crop_name: e.detail.value.join(’,’),
isShow1: false,
isShow2: false,
isShow3: false
})
/**
* 根据用户选择作物名称,展示相应模块得信息录入
*/
for (var i = 0; i < e.detail.value.length; i++){
if (e.detail.value[i] === ‘早稻’){
this.setData({
isShow1:true,
})
}else if(e.detail.value[i] === ‘中稻’){
this.setData({
isShow2: true,
})
}else{
this.setData({
isShow3: true,
})
}
}
if(this.data.isShow1 == false){
this.setData({
dao1: 0
})
}else if(this.data.isShow2 == false){
this.setData({
dao3: 0
})
}else if(this.data.isShow3 == false){
this.setData({
dao5: 0
})
}
/**
/**
premium_sum: function(){
// debugger;
var _rate_value = Number(this.data.rate_value.replace(’%’, ‘’)) / 100;
var _allowance_amount = Number(this.data.allowance_amount.replace(’%’, ‘’)) / 100;
this.setData({
premium_sum: (this.data.insured_areasize * _rate_value * Number(this.data.insured_amount)).toFixed(2),
self_premium: (this.data.insured_areasize * _rate_value * Number(this.data.insured_amount)
* (1 - _allowance_amount)).toFixed(2)
})
},
/**
*/
regInput: function(e) {
if (/^(\d?)+(.\d{0,2})?$/.test(e.detail.value)) {
return e.detail.value;
} else {
return e.detail.value.substring(0, e.detail.value.length - 1);
}
},
/**
dao5: function (event) {
var value = this.regInput(event);
this.setData({
dao5: value,
insured_areasize: (Number(this.data.dao1) + Number(this.data.dao3) + Number(value)).toFixed(2),
})
this.premium_sum();
},
})