榆山
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
7.0 KiB

// @ts-nocheck
import {
getHouseInfo,
updateHouseInfo
} from '../../utils/api.js';
import validate from "../../utils/validate/index.js";
Page({
/**
* 页面的初始数据
*/
data: {
submitBtnIsAllowed: false,
fmData: {
houseId:'',
ownerName:'', // 房主姓名
idCard: '', // 身份证
mobile:'', // 房主电话
},
buildingunitlist: [], // 单元
houseTypeIndex: 0,
houseType: [ // 房屋类型
{
value: "1",
label: "楼房",
},
{
value: "2",
label: "平房",
},
{
value: "3",
label: "别墅",
}
],
purposeIndex: 0,
purposeArr: [ // 房屋用途
{ value: '1', label: '住宅' },
{ value: '2', label: '商业' },
{ value: '3', label: '办公' },
{ value: '4', label: '工业' },
{ value: '5', label: '仓储' },
{ value: '6', label: '商住混用' },
{ value: '7', label: '其他' }
],
rentFlagArrIndex: 0,
rentFlagArr: [ // 居住情况
{ value: '1', label: '出租' },
{ value: '2', label: '闲置' },
{ value: '0', label: '自住' }
]
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
wx.showLoading({
title: "加载中",
mask: true,
});
this.setData({
fmData: options
});
await this.getBuildingunitlist();
wx.hideLoading()
},
// 单元
async getBuildingunitlist() {
const { fmData } = this.data;
if (!fmData.roomCode) return
const res = await getHouseInfo({roomCode: fmData.roomCode});
if (res.msg === 'success' && res.code === 0) {
this.setData({
fmData: res.data
})
this.data.houseType.forEach((item, index) => {
if (item.value == res.data.roomType) {
this.setData({
houseTypeIndex: index
})
}
})
this.data.purposeArr.forEach((item, index) => {
if (item.value == res.data.roomUse) {
this.setData({
purposeArrIndex: index
})
}
})
this.data.rentFlagArr.forEach((item, index) => {
if (item.value == res.data.livingStatus) {
this.setData({
rentFlagArrIndex: index
})
}
})
console.log(this.data.fmData);
}
},
ownerNameSync(e){
this.setData({
'fmData.ownerName' : e.detail.value
})
},
ownerIdCardSync(e){
this.setData({
'fmData.ownerIdCard' : e.detail.value
})
},
ownerPhoneSync(e){
this.setData({
'fmData.ownerPhone' : e.detail.value
})
},
remarkSync(e){
this.setData({
'fmData.remark' : e.detail.value
})
},
// 房屋类型
houseTypePicker(e){
console.log('111111111', e)
this.setData({
houseTypeIndex: e.detail.value,
'fmData.roomType' : this.data.houseType[e.detail.value].value
})
},
// 房屋途径
housePurposePicker(e){
this.setData({
purposeArrIndex: e.detail.value,
'fmData.roomUse' : this.data.purposeArr[e.detail.value].value
})
},
// 房屋状态
houseStatePicker(e){
this.setData({
rentFlagArrIndex: e.detail.value,
'fmData.livingStatus' : this.data.rentFlagArr[e.detail.value].value
})
},
// 身份证失去焦点
handleValidBlur(e) {
let { fmData } = this.data;
const right = this.identityCodeValid(e.detail.value)
if (right) {
console.log('输入正确就没什么::::');
} else {
fmData.gender = ''
this.setData({ fmData })
wx.showToast({
title: '身份证号不正确,请重新输入',
icon: "none",
duration: 1500,
});
}
},
// 校验身份证是否正确
identityCodeValid (idcode) {
// 加权因子
var weightFactor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
// 校验码
var checkCode = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
var code = idcode + ''
var last = idcode[17]// 最后一位
var seventeen = code.substring(0, 17)
// ISO 7064:1983.MOD 11-2
// 判断最后一位校验码是否正确
var arr = seventeen.split('')
var len = arr.length
var num = 0
for (var i = 0; i < len; i++) {
num = num + arr[i] * weightFactor[i]
}
// 获取余数
var resisue = num % 11
var lastNo = checkCode[resisue]
// 格式的正则
// 正则思路
/*
第一位不可能是0
第二位到第六位可以是0-9
第七位到第十位是年份所以七八位为19或者20
十一位和十二位是月份这两位是01-12之间的数值
十三位和十四位是日期是从01-31之间的数值
十五十六十七都是数字0-9
十八位可能是数字0-9也可能是X
*/
var idcardPatter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/
// 判断格式是否正确
var format = idcardPatter.test(idcode)
// 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
return !!(last === lastNo && format)
},
// 修改提交
async editSubmit () {
if (!this.computeSubmitBtnIsAllowed(false)) return;
const { fmData } = this.data;
wx.showLoading({
title: "提交中",
mask: true,
});
const res = await updateHouseInfo({...fmData});
wx.hideLoading();
if (res.msg === "success" && res.code === 0) {
wx.showToast({
title: "修改成功",
duration: 2000,
});
setTimeout(()=>{
wx.reLaunch({
url: `../index/index?roomCode=${!this.data.fmData.roomCode ? this.data.fmData.roomNo : this.data.fmData.roomCode}`
})
},2000)
}
},
// 更新data数据后需主动触发
$afterUpdateData() {
this.computeSubmitBtnIsAllowed();
},
// 校验
computeSubmitBtnIsAllowed(isQuiet = true) {
const { fmData } = this.data,
vlt = validate(fmData, {
buildingUnitId: [
{
rule: "required",
message: "请先选择【单元号】",
},
],
doorName: [
{
rule: "required",
message: "请先输入【门牌号】",
},
],
houseType: [
{
rule: "required",
message: "请先选择【房屋类型】",
},
],
purpose: [
{
rule: "required",
message: "请先选择【房屋用途】",
},
],
rentFlag: [
{
rule: "required",
message: "请先选择【房屋状态】",
},
]
});
if (!vlt.valid) {
if (!isQuiet) {
wx.showToast({
title: vlt.error,
icon: "none",
duration: 1500,
});
}
this.setData({
submitBtnIsAllowed: false,
});
return false;
} else {
this.setData({
submitBtnIsAllowed: true,
});
return true;
}
},
});