PopupInput.js
2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// components/CarBrands/CarBrands.js
// import api from '../../api/api.js'
const formRule = {
// owner: [{ required: true, message: '姓名不能为空' }],
typeName: [{ required: true, message: '商业名称不能为空' }],
compensation: [{ required: true, message: '险种不能为空' }],
payPrice: [{ required: true, message: '保费不能为空' }]
}
import fn from '../constant/ruleFn'
Component({
options: {
styleIsolation: 'shared'
},
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function (n) {
console.log('n', n)
n && this.init()
}
},
testdata: {
type: Boolean
// observer: function (n) {
// console.log('n', n)
// n && this.init()
// }
},
popinputobj: {
type: Object,
observer: function (n) {
this.init()
}
}
},
/**
* 组件的初始数据
*/
data: {
typeName: '1',
compensation: '1',
payPrice: '1'
},
pageLifetimes: {
show: function () {},
hide: function () {}
},
/**
* 组件的方法列表
*/
methods: {
init() {
let { popinputobj } = this.data
let { typeName, compensation, payPrice, handletype } = popinputobj
// console.log(popinputobj, 'popinputobj')
if (handletype == 'add') {
this.setData({
typeName: '',
compensation: '',
payPrice: ''
})
} else {
// let { typeName, compensation, payPrice } = popinputobj
this.setData({
typeName,
compensation,
payPrice
})
}
},
handleInput(e) {
console.log(e)
let value = e.detail
console.log('value', value)
let { attrname, type } = e.target.dataset
value = type == 'number' ? wx.$util.numberFixedDigit(value) : value
this.setData({
[attrname]: value
})
},
confirm() {
let { compensation, payPrice, typeName, popinputobj } = this.data
let otherInsuranceObj = {
compensation,
payPrice,
typeName,
type: 4
}
let validObj = fn.checkRequired(otherInsuranceObj, formRule)
if (validObj) {
wx.$util.showToast(validObj.message)
return
}
// 新增
console.log(otherInsuranceObj, 'otherInsuranceObj')
if (popinputobj.handletype == 'add') {
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
['orderInfo' + '.' + 'otherInsuranceList']: [...thisPage.data.orderInfo?.otherInsuranceList, otherInsuranceObj]
})
} else {
let thisPage = wx.$router.getPageInstance()
let { index } = popinputobj
thisPage.setData({
['orderInfo' + '.' + 'otherInsuranceList' + '[' + index + ']']: otherInsuranceObj
})
}
this.setData({
show: false
})
this.triggerEvent('confirm')
}
}
})