|
@@ -1,7 +1,6 @@
|
|
|
import { value, switchs, date } from "./config";
|
|
|
import Dialog from "../../miniprogram_npm/@vant/weapp/dialog/dialog";
|
|
|
var _value = value;
|
|
|
-const app = getApp();
|
|
|
Component({
|
|
|
options: {
|
|
|
addGlobalClass: true,//解决继承全局样式问题
|
|
@@ -10,7 +9,7 @@ Component({
|
|
|
attached: function () { this.init(); }
|
|
|
},
|
|
|
properties: {
|
|
|
- type: { type: String, value: "edit" },
|
|
|
+ type: { type: String, value: "add" },
|
|
|
key: String
|
|
|
},
|
|
|
observers: {
|
|
@@ -18,11 +17,11 @@ Component({
|
|
|
let A = value[0][1]["value"] * 1 || 0;
|
|
|
let B = (value[0][3]["value"] * 1 || 0) + (value[0][4]["value"] * 1 || 0) + (value[0][5]["value"] * 1 || 0) +
|
|
|
(value[0][6]["value"] * 1 || 0) + (value[0][7]["value"] * 1 || 0);
|
|
|
- let C = value[0][9]["value"] * 1 || 0;
|
|
|
+ let C = value[0][8]["value"] * 1 || 0;
|
|
|
if (A == 0 || C == 0) return false;
|
|
|
- value[0][8]["value"] = ((parseFloat(A - C + B) / parseFloat(A + B)) * 100).toFixed(2) + "%";
|
|
|
- if (this.result && this.result == value[0][8]["value"]) return false;
|
|
|
- this.result = value[0][8]["value"];
|
|
|
+ value[0][9]["value"] = ((parseFloat(A - C + B) / parseFloat(A + B)) * 100).toFixed(2) + "%";
|
|
|
+ if (this.result && this.result == value[0][9]["value"]) return false;
|
|
|
+ this.result = value[0][9]["value"];
|
|
|
this.setData({
|
|
|
value
|
|
|
})
|
|
@@ -52,31 +51,116 @@ Component({
|
|
|
laompany = res.data.map(item => ({ key: item.id, value: item.name, month: item.month }));
|
|
|
let { type, value, switchs } = this.data;
|
|
|
switchs['laompany'] = laompany;
|
|
|
-
|
|
|
- var obj = {};
|
|
|
switch (type) {
|
|
|
+ // 已填报查看
|
|
|
case 'watch':
|
|
|
- obj = this.watchFunc(value);
|
|
|
+ var resA = await wx.$request({ url: `/order/${this.data.key}/`, method: "get" });
|
|
|
+ var data = resA.data.data;
|
|
|
+ value = this.watchFunc(value, data, switchs);
|
|
|
+ break;
|
|
|
+ case 'draftsupdate':
|
|
|
+ // 修改草稿
|
|
|
+ var resB = await wx.$request({ url: `/order/${this.data.key}/`, method: "get" });
|
|
|
+ var data = resB.data;
|
|
|
+ console.log(data)
|
|
|
+ value = this.draftUpdataFunc(value, data, switchs);
|
|
|
break;
|
|
|
+ case 'providedupdate':
|
|
|
+ // 修改已填报
|
|
|
+ var resA = await wx.$request({ url: `/order/${this.data.key}/`, method: "get" });
|
|
|
+ var { data, edit_values } = resA.data;
|
|
|
+ value = this.updataFunc(value, data, edit_values, switchs);
|
|
|
default:
|
|
|
- // 针对商品操作 非观看模式
|
|
|
+ // 新增
|
|
|
this.data.key && laompany.forEach((item, index) => {
|
|
|
if (item.key == this.data.key) {
|
|
|
value[0][10]["value"] = item.key;
|
|
|
value[0][10]["index"] = index;
|
|
|
+ value[0][11]['value'] = item['month'] + '个月';
|
|
|
}
|
|
|
})
|
|
|
break;
|
|
|
}
|
|
|
- this.setData({ value, ...obj, switchs })
|
|
|
+ this.setData({ value, switchs })
|
|
|
} catch (err) { wx.$err(err) }
|
|
|
},
|
|
|
|
|
|
// 查看模式
|
|
|
- watchFunc (data) {
|
|
|
- data = data.map(itemA => itemA.map(itemB => { if (itemB.hasOwnProperty('value')) itemB['disabled'] = true; return itemB })
|
|
|
+ watchFunc (value, data, switchs) {
|
|
|
+ return value.map(itemA => itemA.map(itemB => {
|
|
|
+ if (!itemB.hasOwnProperty('value')) return itemB;
|
|
|
+ if (itemB.name != "maturity") { itemB['value'] = data[itemB.name] === 0 ? 0 : data[itemB.name] || ''; }
|
|
|
+ itemB['disabled'] = true;
|
|
|
+ switchs.hasOwnProperty(itemB.name) && switchs[itemB.name].forEach((itemC, indexC) => {
|
|
|
+ if (itemC.key === itemB.value) itemB["index"] = indexC;
|
|
|
+ // 申请贷款产品 申请贷款期限关联
|
|
|
+ if (itemB.name == 'laompany') {
|
|
|
+ value[0][11]['value'] = itemC['month'] + '个月';
|
|
|
+ }
|
|
|
+ // 第一借款人与申请人关系特殊处理
|
|
|
+ if (itemB.name == 'mstatus' && itemB.value == 1) {
|
|
|
+ value[2][2] = { ...value[2][2], disabled: true, value: 0, index: 0 }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return itemB
|
|
|
+ })
|
|
|
)
|
|
|
- return { value: data, btn: false }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 修改草稿
|
|
|
+ draftUpdataFunc (value, data, switchs) {
|
|
|
+ console.log("打卡")
|
|
|
+ return value.map(itemA => itemA.map(itemB => {
|
|
|
+ if (!itemB.hasOwnProperty('value')) return itemB;
|
|
|
+ if (itemB.name != "maturity") {
|
|
|
+ itemB['value'] = data[itemB.name] === 0 ? 0 : data[itemB.name] || '';
|
|
|
+ }
|
|
|
+ switchs.hasOwnProperty(itemB.name) && switchs[itemB.name].forEach((itemC, indexC) => {
|
|
|
+ if (itemC.key === itemB.value) {
|
|
|
+ itemB["index"] = indexC;
|
|
|
+ };
|
|
|
+ // 申请贷款产品 申请贷款期限关联
|
|
|
+ if (itemB.name == 'laompany') {
|
|
|
+ value[0][11]['value'] = itemC['month'] + '个月';
|
|
|
+ }
|
|
|
+ // 第一借款人与申请人关系特殊处理
|
|
|
+ if (itemB.name == 'mstatus' && itemB.value == 1) {
|
|
|
+ value[2][2] = { ...value[2][2], disabled: true, value: 0, index: 0 }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return itemB
|
|
|
+ }));
|
|
|
+ },
|
|
|
+
|
|
|
+ // 已填报修改模式
|
|
|
+ updataFunc (value, data, edit_values, switchs) {
|
|
|
+ // 后台更改贷款商品key
|
|
|
+ return value.map(itemA => itemA.map(itemB => {
|
|
|
+ if (!itemB.hasOwnProperty('value')) return itemB;
|
|
|
+ if (itemB.name != "maturity") { itemB['value'] = data[itemB.name] === 0 ? 0 : data[itemB.name] || ''; }
|
|
|
+ switchs.hasOwnProperty(itemB.name) && switchs[itemB.name].forEach((itemC, indexC) => {
|
|
|
+ if (itemC.key === itemB.value) itemB["index"] = indexC;
|
|
|
+ // 申请贷款产品 申请贷款期限关联
|
|
|
+ if (itemB.name == 'laompany') {
|
|
|
+ value[0][11]['value'] = itemC['month'] + '个月';
|
|
|
+ }
|
|
|
+ // 第一借款人与申请人关系特殊处理
|
|
|
+ if (itemB.name == 'mstatus' && itemB.value == 1) {
|
|
|
+ value[2][2] = { ...value[2][2], disabled: true, value: 0, index: 0 }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ edit_values.some(itemC => {
|
|
|
+ if (itemC.name == itemB.name) {
|
|
|
+ itemB['err'] = itemC['reason'];
|
|
|
+ }
|
|
|
+ return itemC.name == itemB.name;
|
|
|
+ }) ? '' : itemB['disabled'] = true;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return itemB
|
|
|
+ }));
|
|
|
},
|
|
|
|
|
|
// 提交
|
|
@@ -108,7 +192,7 @@ Component({
|
|
|
megs.push(`${item.title}格式不正确!`); return false;
|
|
|
};
|
|
|
// 号码不能相同 tel tstel ctel cttel
|
|
|
- if (item.name == 'tel' || item.name == 'tstel' || item.name == 'ctel' || item.name == 'cttel') (!tels.some(item.value) || item.vlaue == '') && tels.push(item.value)
|
|
|
+ if (item.name == 'tel' || item.name == 'tstel' || item.name == 'ctel' || item.name == 'cttel') (!tels.some(itemT => itemT == item.value) || item.vlaue == '') && tels.push(item.value)
|
|
|
;
|
|
|
data[item.name] = item.value;
|
|
|
});
|
|
@@ -126,7 +210,7 @@ Component({
|
|
|
} catch (err) { wx.$err(err) }
|
|
|
},
|
|
|
|
|
|
- // 保存
|
|
|
+ // 新增保存
|
|
|
async saveFunc () {
|
|
|
try {
|
|
|
let { value, saveLock } = this.data, data = {};
|
|
@@ -164,12 +248,97 @@ Component({
|
|
|
}
|
|
|
|
|
|
},
|
|
|
+ // 保存草稿
|
|
|
+ async draftsUpdateSaveFunc () {
|
|
|
+ try {
|
|
|
+ let { value, saveLock, key } = this.data, data = {};
|
|
|
+ if (saveLock) return false;
|
|
|
+ this.setData({ saveLock: true });
|
|
|
+ // 拦截
|
|
|
+ var requeire = ['name', 'tel'], megs = [];
|
|
|
+ value = [...value[0], ...value[1], ...value[2], ...value[3]];
|
|
|
+ var cvalue = [..._value[0], ..._value[1], ..._value[2], ..._value[3]];
|
|
|
+ value.forEach((item, index) => {
|
|
|
+ if (!item.hasOwnProperty('value')) return false;
|
|
|
+ if (requeire.some(itemB => itemB == item.name)) {
|
|
|
+ if (!item.value) {
|
|
|
+ megs.push(`${item.title}不能为空!`)
|
|
|
+ return false
|
|
|
+ };
|
|
|
+ if (cvalue[index].reg && !cvalue[index].reg.test(item.value)) {
|
|
|
+ megs.push(`${item.title}格式不正确!`); return false;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ data[item.name] = item.value;
|
|
|
+ });
|
|
|
+ data['category'] = 0;
|
|
|
+ // 申请贷款期限 不用传
|
|
|
+ delete data['maturity'];
|
|
|
+ if (megs.length != 0) {
|
|
|
+ this.setData({ errorShow: true, megs, saveLock: false });
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ console.log(data)
|
|
|
+ await wx.$request({ method: "put", url: `/order/${key}/`, data });
|
|
|
+ this.setData({ saveLock: false })
|
|
|
+ Dialog.alert({ message: "已保存!" }).then(res => wx.navigateBack({ delta: 1 }))
|
|
|
+ } catch (err) {
|
|
|
+ wx.$err(err)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 已填报修改上报
|
|
|
+ async UpdateSaveFunc () {
|
|
|
+ try {
|
|
|
+ let { value, submitLock } = this.data, megs = [], data = {}, cvalue = [], tels = [];
|
|
|
+ if (submitLock) return false;
|
|
|
+ this.setData({ submitLock: true });
|
|
|
+ if (value[2][6]['value'] == 0) {
|
|
|
+ value = [...value[0], ...value[1], ...value[2]];
|
|
|
+ cvalue = [..._value[0], ..._value[1], ..._value[2]];
|
|
|
+ } else {
|
|
|
+ value = [...value[0], ...value[1], ...value[2], ...value[3]];
|
|
|
+ cvalue = [..._value[0], ..._value[1], ..._value[2], ..._value[3]];
|
|
|
+ }
|
|
|
+ value.forEach((item, index) => {
|
|
|
+ // 特殊格式 非必须
|
|
|
+ if (!item.hasOwnProperty('value') || item.norequire) {
|
|
|
+ if (item.hasOwnProperty('value')) data[item.name] = item.value;
|
|
|
+ return false
|
|
|
+ };
|
|
|
+ // 正常流程
|
|
|
+ // 判断是否为空
|
|
|
+ if (!item.value) { megs.push(`${item.title}不能为空!`); return false; };
|
|
|
+ // 数字类型
|
|
|
+ if (item.type == 'number' && !/^\d+.?\d*$/.test(item.value)) { megs.push(`${item.title}必须是数字!`); return false; }
|
|
|
+ // 正则判断
|
|
|
+ if (cvalue[index].reg && !cvalue[index].reg.test(item.value)) {
|
|
|
+ megs.push(`${item.title}格式不正确!`); return false;
|
|
|
+ };
|
|
|
+ // 号码不能相同 tel tstel ctel cttel
|
|
|
+ if (item.name == 'tel' || item.name == 'tstel' || item.name == 'ctel' || item.name == 'cttel') (!tels.some(item.value) || item.vlaue == '') && tels.push(item.value)
|
|
|
+ ;
|
|
|
+ data[item.name] = item.value;
|
|
|
+ });
|
|
|
+ (tels.length !== 4 && tels.length != 0) && megs.push(`手机号码不能重复`);
|
|
|
+ if (megs.length != 0) {
|
|
|
+ this.setData({ errorShow: true, megs, submitLock: false });
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ data['category'] = 1;
|
|
|
+ // 申请贷款期限 不用传
|
|
|
+ delete data['maturity'];
|
|
|
+ await wx.$request({ method: "put", url: `/order/${key}/`, data });
|
|
|
+ this.setData({ submitLock: false });
|
|
|
+ Dialog.alert({ message: "已提交!" }).then(res => wx.reLaunch({ url: '/pages/index/index' }))
|
|
|
+ } catch (err) { wx.$err(err) }
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
// 输入
|
|
|
inputFunc (e) {
|
|
|
let { value } = this.data, { index } = e.currentTarget.dataset;
|
|
|
value[index[0]][index[1]]['value'] = e.detail.value;
|
|
|
- console.log(value[index[0]][index[1]]['name'], e.detail.value)
|
|
|
this.setData({ value })
|
|
|
},
|
|
|
|
|
@@ -184,6 +353,7 @@ Component({
|
|
|
|
|
|
// 隐藏单选框
|
|
|
hideModal () { this.setData({ switchB: false }) },
|
|
|
+
|
|
|
// 单选框赋值
|
|
|
changeFunc (e) {
|
|
|
let { activeIndex, value, switchs } = this.data;
|
|
@@ -192,7 +362,7 @@ Component({
|
|
|
value[activeIndex[0]][activeIndex[1]]['index'] = _value[1] * 1;
|
|
|
|
|
|
// 申请贷款产品 申请贷款期限关联
|
|
|
- if (value[activeIndex[0]][activeIndex[1]]['name'] = 'laompany') {
|
|
|
+ if (value[activeIndex[0]][activeIndex[1]]['name'] == 'laompany') {
|
|
|
value[0][11]['value'] = switchs['laompany'][_value[1] * 1]['month'] + '个月';
|
|
|
}
|
|
|
|
|
@@ -208,6 +378,7 @@ Component({
|
|
|
value[activeIndex[0]][(activeIndex[1] + i)]['norequire'] = _value[0] == 0 ? false : true;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
this.setData({ value, switchB: false })
|
|
|
},
|
|
|
|