bxs-tools-ui 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +20 -20
  2. package/es/add-and-take/index.css +1 -1
  3. package/es/add-and-take/index.js +283 -64
  4. package/es/adjust-baoe/index.css +1 -1
  5. package/es/adjust-baoe/index.js +444 -195
  6. package/es/business-card/index.css +1 -1
  7. package/es/business-card/index.js +1 -0
  8. package/es/canvas-poster/index.css +1 -1
  9. package/es/canvas-poster/index.js +1 -0
  10. package/es/index.css +1 -1
  11. package/es/index.js +950 -839
  12. package/es/insure-calculate/index.css +1 -1
  13. package/es/insure-calculate/index.js +438 -265
  14. package/es/person-info/index.css +1 -1
  15. package/es/person-info/index.js +296 -1370
  16. package/es/product-info/index.css +1 -1
  17. package/es/product-info/index.js +644 -548
  18. package/es/share-sheet/index.css +1 -1
  19. package/es/share-sheet/index.js +321 -30
  20. package/es/utils/index.js +530 -429
  21. package/lib/add-and-take/index.css +1 -1
  22. package/lib/add-and-take/index.js +283 -64
  23. package/lib/adjust-baoe/index.css +1 -1
  24. package/lib/adjust-baoe/index.js +441 -194
  25. package/lib/business-card/index.css +1 -1
  26. package/lib/business-card/index.js +1 -0
  27. package/lib/canvas-poster/index.css +1 -1
  28. package/lib/canvas-poster/index.js +1 -0
  29. package/lib/index.css +1 -1
  30. package/lib/index.js +953 -841
  31. package/lib/insure-calculate/index.css +1 -1
  32. package/lib/insure-calculate/index.js +438 -268
  33. package/lib/person-info/index.css +1 -1
  34. package/lib/person-info/index.js +295 -1372
  35. package/lib/product-info/index.css +1 -1
  36. package/lib/product-info/index.js +645 -550
  37. package/lib/share-sheet/index.css +1 -1
  38. package/lib/share-sheet/index.js +321 -34
  39. package/lib/utils/index.js +531 -433
  40. package/package.json +9 -7
  41. package/packages/add-and-take/components/interest-form.less +144 -0
  42. package/packages/add-and-take/components/interest-form.vue +179 -179
  43. package/packages/add-and-take/components/interest-items.less +87 -0
  44. package/packages/add-and-take/components/interest-items.vue +67 -80
  45. package/packages/add-and-take/components/interest-table.less +111 -0
  46. package/packages/add-and-take/components/interest-table.vue +31 -31
  47. package/packages/add-and-take/constant.ts +2 -2
  48. package/packages/add-and-take/demo/index.vue +89 -86
  49. package/packages/add-and-take/handler.ts +52 -57
  50. package/packages/add-and-take/index.less +69 -0
  51. package/packages/add-and-take/index.vue +156 -156
  52. package/packages/add-and-take/readme.md +87 -98
  53. package/packages/adjust-baoe/demo/index.vue +37 -47
  54. package/packages/adjust-baoe/index.less +125 -0
  55. package/packages/adjust-baoe/index.vue +134 -147
  56. package/packages/adjust-baoe/readme.md +35 -45
  57. package/packages/business-card/demo/index.vue +7 -7
  58. package/packages/business-card/index.less +100 -0
  59. package/packages/business-card/index.vue +18 -21
  60. package/packages/business-card/readme.md +46 -53
  61. package/packages/bxs-utils/demo/index.vue +2 -2
  62. package/packages/bxs-utils/index.ts +5 -5
  63. package/packages/bxs-utils/planbook/common.ts +56 -92
  64. package/packages/bxs-utils/planbook/index.ts +4 -4
  65. package/packages/bxs-utils/planbook/insurance.ts +137 -127
  66. package/packages/bxs-utils/planbook/person.ts +143 -147
  67. package/packages/bxs-utils/planbook/product.ts +473 -509
  68. package/packages/bxs-utils/readme.md +94 -84
  69. package/packages/bxs-utils/trade/index.js +1 -1
  70. package/packages/bxs-utils/trade/insureCalculate.js +91 -204
  71. package/packages/canvas-poster/demo/index.vue +9 -13
  72. package/packages/canvas-poster/index.less +5 -0
  73. package/packages/canvas-poster/index.vue +68 -79
  74. package/packages/canvas-poster/readme.md +106 -109
  75. package/packages/index.ts +1 -1
  76. package/packages/insure-calculate/demo/index.vue +20 -20
  77. package/packages/insure-calculate/index.less +366 -0
  78. package/packages/insure-calculate/index.vue +305 -329
  79. package/packages/insure-calculate/readme.md +99 -106
  80. package/packages/person-info/crm-popup.vue +81 -80
  81. package/packages/person-info/demo/index.vue +25 -37
  82. package/packages/person-info/index-inline.less +11 -0
  83. package/packages/person-info/index.vue +53 -83
  84. package/packages/person-info/readme.md +109 -115
  85. package/packages/planbook-input/components/footer.less +54 -0
  86. package/packages/planbook-input/components/footer.vue +8 -64
  87. package/packages/planbook-input/components/handler.js +33 -44
  88. package/packages/planbook-input/components/product-table.less +235 -0
  89. package/packages/planbook-input/components/product-table.vue +114 -108
  90. package/packages/planbook-input/demo/index.vue +3 -3
  91. package/packages/planbook-input/helper.js +852 -465
  92. package/packages/planbook-input/index.less +30 -0
  93. package/packages/planbook-input/index.vue +86 -103
  94. package/packages/planbook-input/readme.md +72 -90
  95. package/packages/product-info/demo/constant.js +1 -1
  96. package/packages/product-info/demo/index.vue +31 -43
  97. package/packages/product-info/index.less +271 -0
  98. package/packages/product-info/index.vue +198 -210
  99. package/packages/product-info/readme.md +72 -75
  100. package/packages/share-sheet/constant.js +6 -11
  101. package/packages/share-sheet/demo/index.vue +24 -24
  102. package/packages/share-sheet/handler.js +14 -14
  103. package/packages/share-sheet/index.less +201 -0
  104. package/packages/share-sheet/index.vue +43 -43
  105. package/packages/share-sheet/readme.md +121 -127
  106. package/src/api/add-and-take.js +45 -0
  107. package/src/api/adjust-baoe.js +16 -0
  108. package/src/api/index.js +6 -0
  109. package/src/api/planbook.js +93 -0
  110. package/src/api/request.js +211 -0
  111. package/src/api/trade.js +56 -0
  112. package/src/api/user.js +18 -0
  113. package/src/components/common/common-age-birthday.less +66 -0
  114. package/src/components/common/common-age-birthday.vue +27 -95
  115. package/src/components/common/common-popup.less +81 -0
  116. package/src/components/common/common-popup.vue +12 -96
  117. package/src/components/common/common-radio.less +75 -0
  118. package/src/components/common/common-radio.vue +13 -91
  119. package/src/components/common/common-select.less +13 -0
  120. package/src/components/common/common-select.vue +21 -38
  121. package/src/components/common/common-title.less +115 -0
  122. package/src/components/common/common-title.vue +24 -24
  123. package/src/js/loading.js +6 -6
  124. package/src/js/md5Token.js +38 -44
  125. package/src/js/utils.js +45 -53
  126. package/src/js/variables.js +47 -25
  127. package/src/style/base.less +18 -0
  128. package/src/style/color.less +40 -0
  129. package/src/style/variables.less +21 -42
  130. package/packages/add-and-take/api.ts +0 -70
  131. package/packages/add-and-take/components/interest-form.css +0 -146
  132. package/packages/add-and-take/components/interest-items.css +0 -87
  133. package/packages/add-and-take/components/interest-table.css +0 -113
  134. package/packages/add-and-take/index.css +0 -70
  135. package/packages/adjust-baoe/index.css +0 -123
  136. package/packages/business-card/index.css +0 -101
  137. package/packages/canvas-poster/index.css +0 -5
  138. package/packages/insure-calculate/index.css +0 -368
  139. package/packages/planbook-input/api.js +0 -29
  140. package/packages/planbook-input/components/product-table.css +0 -236
  141. package/packages/planbook-input/index.css +0 -31
  142. package/packages/product-info/index.css +0 -264
  143. package/packages/share-sheet/index.css +0 -190
  144. package/src/components/common/common-title.css +0 -116
  145. package/src/js/request.js +0 -64
  146. package/src/style/apply.css +0 -25
  147. package/src/style/base.css +0 -36
  148. package/src/style/color.css +0 -74
@@ -1,169 +1,226 @@
1
- import { Toast } from 'vant';
2
- import QS from 'qs';
3
- import { get as _get, cloneDeep } from 'lodash';
4
- import { PLANBOOK_API_HOSTNAME } from '@src/js/variables.js';
1
+ import qs from 'qs'
2
+ import { get as _get, cloneDeep } from 'lodash'
3
+ import { Toast, Dialog } from 'vant'
5
4
  import {
6
5
  initPersonData,
7
6
  personDataHandler,
8
7
  convertPersonData,
8
+ calcTotalBaof,
9
9
  initProductData,
10
10
  productDataHandler,
11
+ multipleInsuredHandler,
12
+ clearAddAndTakeAndAdjustBaoeData,
11
13
  convertProductData,
12
14
  verifyProductRules,
13
15
  convertEleOrderListToObj,
14
16
  getExpressionParamMap
15
- } from 'packages/bxs-utils/index';
16
- import { createMd5Token } from '@src/js/md5Token.js';
17
+ } from '../bxs-utils/index'
18
+ import { calcPlanbookProduct, uploadPlanBookResult, getUnderwriteEffectiveRules } from '../../src/api/index.js'
19
+ import { parseTime, getSecurityToken, goBack } from '../../src/js/utils.js'
20
+ import { isIos, appVersion, URL_PARAM } from '../../src/js/variables'
17
21
 
18
- export async function initPageData(data) {
19
- const inputData = data && data.initData && data.initData.inputData;
20
- if (inputData) {
21
- initPersonData(inputData, data.verifyData);
22
- personDataHandler(inputData.personData);
23
- const productGroupList = inputData.productGroupList || [];
24
- const promises = [];
25
- productGroupList
26
- .filter(g => g.prodOrderList)
27
- .forEach(g => {
28
- return g.prodOrderList.forEach(p => {
29
- initProductData(p);
30
- promises.push(
31
- productDataHandler(p, data.verifyData[p.key], inputData.personData, {
32
- planbookId: data.pbId
33
- })
34
- );
35
- });
36
- });
37
- await Promise.all(promises);
22
+ let productCalcVuexStore = null
23
+ export function setProductCalcVuexStore(storeInstance) {
24
+ productCalcVuexStore = storeInstance
25
+ }
26
+
27
+ function getProductCalcVuexStore() {
28
+ return productCalcVuexStore
29
+ }
30
+
31
+ function commitProductCalcError(productUniqueKey, message) {
32
+ const calcStore = getProductCalcVuexStore()
33
+ if (productUniqueKey && calcStore && calcStore._mutations && calcStore._mutations.SET_PRODUCT_CALC_ERROR) {
34
+ calcStore.commit('SET_PRODUCT_CALC_ERROR', { id: productUniqueKey, message })
38
35
  }
39
- return data;
40
36
  }
41
37
 
42
- export function setPageDataBaseOnResult(data) {
43
- if (!data) {
44
- return data;
38
+ export async function initPageData(data, options = {}) {
39
+ const planbookId = data.pbId
40
+ const pbType = _get(options, 'pbType')
41
+ const { user } = options || {}
42
+
43
+ // 承保规则赋值
44
+ if (!['annual_survey'].includes(pbType)) {
45
+ const _inputData = await setupUnderwriteRuleToInputData(_get(data, 'initData.inputData')).catch(() => null)
46
+ if (_inputData) {
47
+ data.initData.inputData = _inputData
48
+ }
45
49
  }
46
- let inputData = data.initData && data.initData.inputData;
47
- let exportData = data.exportData ? JSON.parse(data.exportData) : null;
50
+
51
+ data.interestProductList = data.interestProductList || []
52
+ const inputData = _get(data, 'initData.inputData')
53
+ if (inputData) {
54
+ const verifyData = data.verifyData
55
+ const exportData = data.exportData ? JSON.parse(data.exportData) : null
56
+ const policyInfo = data.policyInfo
57
+ const personData = inputData.personData
58
+ initPersonData(inputData, verifyData)
59
+ const productFlatList = (inputData.productGroupList || []).map(g => g.prodOrderList || []).flat()
60
+ productFlatList.forEach(p => {
61
+ initProductData(p)
62
+ multipleInsuredHandler(p, personData)
63
+ })
64
+
65
+ // 导入已有数据,重新赋值到初始化中的产品对象中
66
+ setPageDataBaseOnResult(inputData, exportData, policyInfo, options)
67
+
68
+ personDataHandler(personData)
69
+ const promises = productFlatList.map(p => {
70
+ return productDataHandler(p, _get(verifyData, p.key), personData, {
71
+ user,
72
+ planbookId,
73
+ executeSource: exportData ? 'import' : 'init'
74
+ })
75
+ })
76
+ await Promise.all(promises)
77
+ }
78
+ return data
79
+ }
80
+
81
+ export function setPageDataBaseOnResult(inputData, exportData, policyInfo, options = {}) {
48
82
  if (inputData && exportData) {
49
83
  // 人员信息赋值
50
- let iPersonData = inputData.personData;
51
- let ePersonData = exportData.personData;
84
+ const iPersonData = inputData.personData
85
+ const ePersonData = exportData.personData
52
86
  if (iPersonData && ePersonData) {
53
87
  for (let k in iPersonData) {
54
88
  if (k == 'personOrderList' && ePersonData[k]) {
55
- iPersonData[k].forEach((person, pi) => {
56
- person.eleOrderList &&
57
- person.eleOrderList.forEach(ele => {
58
- if (ePersonData[k][pi] && ePersonData[k][pi][ele.key] !== undefined && ePersonData[k][pi][ele.key] !== null) {
59
- ele.value = ePersonData[k][pi][ele.key];
60
- }
61
- });
62
- });
89
+ iPersonData[k].forEach(person => {
90
+ if (!person.eleOrderList) {
91
+ return
92
+ }
93
+ const ePerson = ePersonData[k].find(e => e.key === person.key)
94
+ person.eleOrderList.forEach(ele => {
95
+ let value = ePerson && ePerson[ele.key]
96
+ if (ele.key === 'insuranceDay' && policyInfo) {
97
+ value = parseTime(policyInfo.insuranceDay, '{y}/{m}/{d}')
98
+ }
99
+ if (value !== undefined && value !== null) {
100
+ ele.value = value
101
+ }
102
+ })
103
+
104
+ const cid = policyInfo ? policyInfo[person.key.replace(/Info/, 'Uuid')] : ePerson.cid
105
+ if (ePerson && cid) {
106
+ person.cid = cid
107
+ }
108
+ })
63
109
  }
64
110
  if (k == 'recipientInfo' && ePersonData[k]) {
65
111
  iPersonData[k].eleOrderList &&
66
112
  iPersonData[k].eleOrderList.forEach(ele => {
67
113
  if (iPersonData[k][ele.key]) {
68
- ele.value = ePersonData[k][ele.key];
114
+ ele.value = ePersonData[k][ele.key]
69
115
  }
70
- });
116
+ })
71
117
  }
72
118
  }
73
119
  }
74
120
 
75
121
  // 产品赋值
76
- let iGroupList = inputData.productGroupList;
77
- let eGroupList = exportData.productGroupList;
122
+ const iGroupList = inputData.productGroupList
123
+ const eGroupList = exportData.productGroupList
78
124
  if (iGroupList && eGroupList) {
79
125
  iGroupList.forEach((group, gi) => {
80
- let eGroupData = eGroupList[gi];
81
- if (eGroupData && group.prodOrderList) {
82
- group.prodOrderList.forEach(prod => {
83
- let eProductData = eGroupData.prodOrderList.find(p => p.key === prod.key);
84
- if (eProductData) {
85
- // 取调整保额数据
86
- if (eProductData.adjustBaoeData) {
87
- prod.adjustBaoeData = eProductData.adjustBaoeData;
88
- }
89
- prod.inputResultSwitch = !!eProductData.inputResultSwitch;
90
- prod.resultImport = true;
91
- // 已生成的计划书取回的产品数据,赋值到初始化中的产品对象中
92
- for (let k in prod) {
93
- if (k == 'mulInsOrderList') {
94
- // 清除组合险
95
- prod.mulInsOrderList = prod.mulInsOrderList.filter(ins => !ins.isGroup);
96
- // 已生成的计划书取回的险种数据,赋值到初始化中的险种对象中
97
- prod.mulInsOrderList.forEach(ins => {
98
- let eInsuranceData = eProductData.mulInsOrderList.find(m => m.key === ins.key);
99
- if (eInsuranceData) {
100
- if (ins.eleOrderList) {
101
- // 下为处理从结果页中导入数值时,保额保费互算问题 2018.12.11
102
- let calMethod = ins.eleOrderList.find(e => e.key === 'calMethod');
103
- let baoe = ins.eleOrderList.find(e => e.key === 'baoe');
104
- let baof = ins.eleOrderList.find(e => e.key === 'baof') || ins.eleOrderList.find(e => e.key === 'payModePremium');
105
- if (calMethod && baoe && baof && eInsuranceData.calMethod) {
106
- baoe.isHide = eInsuranceData.calMethod !== 'baoe2baof';
107
- baof.isHide = eInsuranceData.calMethod === 'baoe2baof';
108
- }
109
- ins.eleOrderList.forEach(ele => {
110
- if (eInsuranceData[ele.key]) {
111
- ele.value = eInsuranceData[ele.key];
112
- }
113
- });
126
+ let eGroupData = eGroupList[gi]
127
+ if (!eGroupData || !group.prodOrderList) {
128
+ return
129
+ }
130
+ group.prodOrderList.forEach(prod => {
131
+ let eProductData = eGroupData.prodOrderList.find(p => p.key === prod.key)
132
+ if (!eProductData) {
133
+ return
134
+ }
135
+ // 取调整保额数据
136
+ if (eProductData.adjustBaoeData) {
137
+ prod.adjustBaoeData = eProductData.adjustBaoeData
138
+ }
139
+ prod.inputResultSwitch = !!eProductData.inputResultSwitch
140
+ prod.resultImport = true
141
+ // 已生成的计划书取回的产品数据,赋值到初始化中的产品对象中
142
+ for (let k in prod) {
143
+ if (k == 'mulInsOrderList') {
144
+ // 清除组合险
145
+ prod.mulInsOrderList = prod.mulInsOrderList.filter(ins => !ins.isGroup)
146
+ // 已生成的计划书取回的险种数据,赋值到初始化中的险种对象中
147
+ prod.mulInsOrderList.forEach(ins => {
148
+ const eInsuranceData = eProductData.mulInsOrderList.find(m => m.key === ins.key)
149
+ if (eInsuranceData) {
150
+ if (ins.eleOrderList) {
151
+ // 下为处理从结果页中导入数值时,保额保费互算问题 2018.12.11
152
+ let calMethod = ins.eleOrderList.find(e => e.key === 'calMethod')
153
+ let baoe = ins.eleOrderList.find(e => e.key === 'baoe')
154
+ let baof = ins.eleOrderList.find(e => e.key === 'baof') || ins.eleOrderList.find(e => e.key === 'payModePremium')
155
+ if (calMethod && baoe && baof && eInsuranceData.calMethod) {
156
+ baoe.isHide = eInsuranceData.calMethod !== 'baoe2baof'
157
+ baof.isHide = eInsuranceData.calMethod === 'baoe2baof'
158
+ }
159
+ ins.eleOrderList.forEach(ele => {
160
+ if (!options.uuid && options.ocrUuid) {
161
+ ele.value = eInsuranceData[ele.key]
162
+ return
114
163
  }
115
- if (eInsuranceData.inputResult !== undefined) {
116
- ins.inputResult = eInsuranceData.inputResult;
164
+ if (eInsuranceData[ele.key]) {
165
+ ele.value = eInsuranceData[ele.key]
117
166
  }
167
+ })
168
+ }
169
+ if (eInsuranceData.inputResult !== undefined) {
170
+ ins.inputResult = eInsuranceData.inputResult
171
+ }
118
172
 
119
- // 万能账户存在,可以不加追加领取数据
120
- for (let ik in ins) {
121
- if (['reduceBaof'].indexOf(ik) !== -1) {
122
- if (eInsuranceData[ik + 'Data']) {
123
- ins[ik + 'Data'] = eInsuranceData[ik + 'Data'];
124
- }
125
- }
173
+ // 万能账户存在,可以不加追加领取数据
174
+ for (let ik in ins) {
175
+ if (['reduceBaof'].includes(ik)) {
176
+ if (eInsuranceData[ik + 'Data']) {
177
+ ins[ik + 'Data'] = eInsuranceData[ik + 'Data']
126
178
  }
127
- } else {
128
- // 结果页数据中没有对应险种,对应的初始化数据置为未选中
129
- if (ins.eleOrderList) {
130
- ins.eleOrderList.forEach(ele => {
131
- if (ele.key == 'title') {
132
- ele.value = false;
133
- }
134
- });
179
+ if (eInsuranceData.duplicateReduceBaofData) {
180
+ ins.duplicateReduceBaofData = eInsuranceData.duplicateReduceBaofData
135
181
  }
136
182
  }
137
- });
183
+ }
184
+ if ('policyInsuranceCategory' in eInsuranceData) {
185
+ ins.policyInsuranceCategory = eInsuranceData.policyInsuranceCategory
186
+ }
187
+ } else {
188
+ // 结果页数据中没有对应险种,对应的初始化数据置为未选中
189
+ if (ins.eleOrderList) {
190
+ ins.eleOrderList.forEach(ele => {
191
+ if (ele.key == 'title') {
192
+ ele.value = false
193
+ }
194
+ })
195
+ }
138
196
  }
139
- }
197
+ })
140
198
  }
141
- });
142
- }
143
- });
199
+ }
200
+ })
201
+ })
144
202
  }
145
203
  }
146
- return initPageData(data);
204
+ return inputData
147
205
  }
148
206
 
149
- export function createdProductDataToCalc(inputData, options = {}) {
207
+ export async function createdProductDataToCalc(inputData, options = {}) {
150
208
  if (inputData && inputData.personData && inputData.productGroupList && inputData.productGroupList.length) {
151
209
  const productData = getProductFromInputData(inputData, {
152
210
  groupKey: options.groupKey,
153
211
  productKey: options.productKey
154
- });
155
-
156
- const tempProductForm = convertProductData(productData);
212
+ })
213
+ const tempProductForm = convertProductData(productData)
157
214
  // 过滤一些不必要的数据
158
- const productForm = {};
215
+ const productForm = {}
159
216
  for (let k in tempProductForm) {
160
- if (!['hadChoice', 'hide', 'totalBaof', 'insShowArr', 'autoImport'].includes(k)) {
161
- productForm[k] = tempProductForm[k];
217
+ if (!['hadChoice', 'hide', 'totalBaof', 'insShowArr', 'autoImport', 'restrictList', 'resultImport', 'adjustBaoeData'].includes(k)) {
218
+ productForm[k] = tempProductForm[k]
162
219
  }
163
220
  }
164
221
  if (productForm.mulInsOrderList) {
165
222
  productForm.mulInsOrderList = productForm.mulInsOrderList.map(ins => {
166
- let tempIns = {};
223
+ const tempIns = {}
167
224
  for (let k in ins) {
168
225
  if (
169
226
  ![
@@ -172,38 +229,37 @@ export function createdProductDataToCalc(inputData, options = {}) {
172
229
  'baoeDesc',
173
230
  'baofDesc',
174
231
  'iDurationDesc',
232
+ 'payModeDesc',
233
+ 'payModePremiumDesc',
175
234
  'accountData',
176
235
  'reduceBaofData',
177
236
  'duplicateReduceBaofData',
178
237
  'isCheckbox',
179
238
  'groupKey',
180
239
  'groupName',
240
+ 'shmInsData',
241
+ 'totalBaof',
181
242
  'customVariableExp',
182
- 'calcResultExp',
243
+ // 'calcResultExp', // 不能删除,后面有依赖
183
244
  'revalidateFlag'
184
245
  ].includes(k)
185
246
  ) {
186
- tempIns[k] = ins[k];
247
+ tempIns[k] = ins[k]
187
248
  }
188
249
  }
189
- return tempIns;
190
- });
250
+ return tempIns
251
+ })
191
252
  }
192
253
 
193
254
  // 产品是否有选中的险种
255
+ if (productForm && productForm.policyType === 'online_trade') {
256
+ return Promise.resolve({})
257
+ }
194
258
  if (productForm && productForm.mulInsOrderList && productForm.mulInsOrderList.length) {
195
259
  const errorMsg = verifyProductRules({
196
260
  personData: inputData.personData,
197
261
  productData
198
- });
199
-
200
- // 清除产品中的一些不必要的险种数据
201
- productForm.mulInsOrderList.forEach(ins => {
202
- if (ins.shmInsData) {
203
- delete ins.shmInsData;
204
- }
205
- });
206
-
262
+ })
207
263
  const reqData = {
208
264
  publicPbUuid: options.publicPbUuid || null,
209
265
  insuranceTypeId: options.planbookId ? options.planbookId * 1 : null,
@@ -219,414 +275,745 @@ export function createdProductDataToCalc(inputData, options = {}) {
219
275
  prodOrderList: [productForm] //转换后的产品数据
220
276
  }
221
277
  ]
222
- };
278
+ }
279
+ const reqDataStr = JSON.stringify(reqData)
280
+ const signature = await getSecurityToken(reqDataStr, {
281
+ groupDataKey: options.groupKey
282
+ })
223
283
  return Promise.resolve({
224
284
  errorMsg,
225
- jd: JSON.stringify(reqData),
226
- signature: createMd5Token(reqData, {
227
- groupDataKey: options.groupKey
228
- })
229
- });
285
+ jd: reqDataStr,
286
+ signature,
287
+ clientVersion: appVersion,
288
+ isIos
289
+ })
230
290
  } else {
231
- return Promise.reject('请选择险种');
291
+ return Promise.reject('请选择险种')
232
292
  }
233
293
  } else {
234
- return Promise.reject('请填写投保数据');
294
+ return Promise.reject('请填写投保数据')
235
295
  }
236
296
  }
237
297
 
238
298
  export function receiveProductData(inputData, rProductData, options = {}) {
239
- let productData = getProductFromInputData(inputData, options);
240
- rProductData.mulInsOrderList.forEach(ins => {
241
- let insuranceData = productData.mulInsOrderList.find(i => i.key === ins.key);
242
- if (insuranceData) {
243
- if (ins.huomian === 'shm_spouse') {
244
- insuranceData.shmInsData = ins;
245
- } else {
246
- //将返回来的险种数据,赋值到现在数据中
247
- for (let k in ins) {
248
- if (insuranceData.eleOrderList.some(e => e.key === k)) {
249
- insuranceData.eleOrderList.forEach(e => {
250
- if (ins[e.key] !== undefined) {
251
- e.value = ins[e.key];
252
- }
253
- });
254
- } else {
255
- insuranceData[k] = ins[k];
299
+ const productData = getProductFromInputData(inputData, options)
300
+ if (productData) {
301
+ rProductData.mulInsOrderList.forEach(ins => {
302
+ let insuranceData = productData.mulInsOrderList.find(i => i.key === ins.key)
303
+ if (insuranceData) {
304
+ if (ins.huomian === 'shm_spouse') {
305
+ insuranceData.shmInsData = ins
306
+ } else {
307
+ //将返回来的险种数据,赋值到现在数据中
308
+ for (let k in ins) {
309
+ if (insuranceData.eleOrderList.some(e => e.key === k)) {
310
+ insuranceData.eleOrderList.forEach(e => {
311
+ if (ins[e.key] !== undefined) {
312
+ e.value = ins[e.key]
313
+ }
314
+ })
315
+ }
316
+ insuranceData[k] = ins[k]
256
317
  }
257
318
  }
258
319
  }
259
- }
260
- });
261
- productData.mulInsOrderList.forEach(ins => {
262
- if (ins.isGroup) {
263
- let groupInsData = convertEleOrderListToObj(ins);
264
- let insuranceId = groupInsData.isCheckbox ? groupInsData.insuranceId[0] : groupInsData.insuranceId;
265
- let checkedIns = productData.mulInsOrderList.find(i => i.key === insuranceId);
266
- for (let key in checkedIns) {
267
- if (!['allowSamePerson', 'code', 'eleOrderList', 'groupKey', 'groupName', 'huomian', 'key', 'name'].includes(key)) {
268
- ins[key] = checkedIns[key];
269
- }
320
+ })
321
+
322
+ productData.mulInsOrderList.forEach(ins => {
323
+ if (ins.isGroup) {
324
+ return
270
325
  }
271
- }
272
- });
273
-
274
- const hasSomeCheckedIns = rProductData.mulInsOrderList.some(ins => ins.title);
275
- productData.hadChoice = hasSomeCheckedIns;
276
- productData.totalBaof = hasSomeCheckedIns ? rProductData.totalBaof : null;
277
- productData.companyName = rProductData.companyName;
278
-
279
- let insShowArr = null;
280
- if (rProductData.insShowArr) {
281
- insShowArr = rProductData.insShowArr;
282
- } else if (hasSomeCheckedIns) {
283
- const hasPayModePremium = rProductData.mulInsOrderList.some(ins => 'payModePremium' in ins && (ins.payModePremium || ins.payModePremium === 0));
284
- insShowArr = [['险种', '保额', '保费', '交费期', hasPayModePremium ? '期交保费' : ''].filter(Boolean)];
285
- rProductData.mulInsOrderList.forEach(function(ins) {
286
- if (ins.title && !ins.resultFormulaRef) {
287
- const insResultItem = [
288
- ins.name,
289
- ins.showPlanDesc ? ins.planDesc : ins.baoeDesc || '-',
290
- ins.baofDesc === 0 || ins.baofDesc === '0' || ins.baofDesc ? ins.baof : '-',
291
- ins.pPeriodDesc
292
- ];
293
- if (hasPayModePremium) {
294
- insResultItem.push(ins.payModePremiumDesc || '-');
326
+ const groupInsData = convertEleOrderListToObj(ins)
327
+ const insuranceId = groupInsData.isCheckbox ? groupInsData.insuranceId[0] : groupInsData.insuranceId
328
+ const checkedIns = productData.mulInsOrderList.find(i => i.key === insuranceId)
329
+ for (const key in checkedIns) {
330
+ if (['allowSamePerson', 'code', 'eleOrderList', 'groupKey', 'groupName', 'huomian', 'key', 'name'].indexOf(key) === -1) {
331
+ ins[key] = checkedIns[key]
295
332
  }
296
- insShowArr.push(insResultItem);
297
333
  }
298
- });
299
- }
300
- if (insShowArr && insShowArr.length > 1) {
301
- productData.insShowArr = insShowArr;
302
- } else {
303
- productData.insShowArr = null;
334
+ })
335
+
336
+ const hasSomeCheckedIns = rProductData.mulInsOrderList.some(ins => ins.title)
337
+ productData.hadChoice = hasSomeCheckedIns
338
+ productData.totalBaof = hasSomeCheckedIns ? rProductData.totalBaof : null
339
+ productData.companyName = rProductData.companyName
340
+
341
+ let insShowArr = null
342
+ if (rProductData.insShowArr) {
343
+ insShowArr = rProductData.insShowArr
344
+ } else if (hasSomeCheckedIns) {
345
+ const hasPayModePremium = rProductData.mulInsOrderList.some(ins => ins.payModeDesc && ins.payModePremiumDesc)
346
+ insShowArr = [['投保险种', '保额', '保险期', '交费期', '首年保费', hasPayModePremium ? '期交保费' : ''].filter(Boolean)]
347
+ rProductData.mulInsOrderList.forEach(function(ins) {
348
+ if (ins.title && !ins.resultFormulaRef) {
349
+ const insResultItem = [
350
+ ins.name,
351
+ ins.showPlanDesc ? ins.planDesc : ins.baoeDesc || '-',
352
+ ins.iDurationDesc,
353
+ ins.pPeriodDesc,
354
+ ins.baofDesc === 0 || ins.baofDesc === '0' || ins.baofDesc ? ins.baofDesc : '-'
355
+ ]
356
+ if (hasPayModePremium) {
357
+ insResultItem.push(ins.payModePremiumDesc ? `${ins.payModeDesc}${ins.payModePremiumDesc}` : '-')
358
+ }
359
+ insShowArr.push(insResultItem)
360
+ }
361
+ })
362
+ }
363
+ if (insShowArr && insShowArr.length > 1) {
364
+ productData.insShowArr = insShowArr
365
+ } else {
366
+ productData.insShowArr = null
367
+ }
304
368
  }
305
- return productData;
369
+ return productData
306
370
  }
307
371
 
308
- export function defaultProductData(eleOrderList) {
309
- let timeStamp = new Date().getTime();
310
- return {
311
- key: timeStamp,
312
- titleName: '待完善险种',
313
- policyType: 'manual_insurance',
314
- mulInsOrderList: [
315
- {
316
- eleOrderList: eleOrderList,
317
- key: timeStamp,
318
- title: true
372
+ export function createPlanbookDataToMake(inputData = {}, options = {}) {
373
+ const { title, theme, categorySort, displayFormatSort, commonData, personData, productGroupList } = cloneDeep(inputData)
374
+ const _prodOrderList0 = _get(productGroupList, '[0].prodOrderList') || []
375
+ if (!_prodOrderList0.some(ele => !!ele.hadChoice && !ele.hide)) {
376
+ return
377
+ }
378
+ let hasMultipleInsured = false
379
+ const _productGroupList = productGroupList.filter(g => g.prodOrderList.some(p => p.hadChoice && !p.hide))
380
+ _productGroupList.forEach(g => {
381
+ const _prodOrderList = g.prodOrderList.filter(p => !!p.hadChoice && !p.hide)
382
+ _prodOrderList.forEach(p => {
383
+ if (p.multipleInsured) {
384
+ hasMultipleInsured = true
319
385
  }
320
- ],
321
- liabilityOrderList: [],
322
- companyId: null,
323
- hide: false,
324
- trade: false,
325
- companyName: '',
326
- autoImport: false,
327
- liabilityShowType: 0,
328
- required: false
329
- };
330
- }
331
-
332
- export function createPlanbookDataToMake(planbookData = {}, options = {}) {
333
- let inputData = planbookData && planbookData.initData && planbookData.initData.inputData;
334
- let productGroup = inputData.productGroupList && inputData.productGroupList[0];
335
- let hadChoiceProducts = productGroup && productGroup.prodOrderList && productGroup.prodOrderList.some(ele => !!ele.hadChoice && !ele.hide);
336
- if (hadChoiceProducts) {
337
- let resultData = {
338
- ...options,
339
- companyId: inputData.companyId,
340
- recordSetting: inputData.recordSetting,
341
- personData: convertPersonData(inputData.personData),
342
- productGroupList: [],
343
- theme: inputData.theme,
344
- commonData: inputData.commonData,
345
- displayFormatSort: inputData.displayFormatSort,
346
- categorySort: inputData.categorySort,
347
- title: inputData.title || document.title,
348
- videoTypeKey: planbookData.videoTypeKey
349
- };
350
-
351
- inputData.productGroupList.forEach(group => {
352
- let reqProductGroup = {
353
- key: group.key,
354
- prodOrderList: []
355
- };
356
- group.prodOrderList.forEach(prod => {
357
- if (!!prod.hadChoice && !prod.hide) {
358
- prod.mulInsOrderList.forEach((ins, iIdx, arr) => {
359
- // 结果页需要显示的数据
360
- ins.eleOrderInResult = [];
361
- let refInsuranceData;
362
- //refInsuranceId: -1,关联主险;-2,关联险种自身
363
- if (ins.refInsuranceId && ins.refInsuranceId != -2) {
364
- if (ins.refInsuranceId == -1) {
365
- refInsuranceData = arr[arr[0].key == 'common' ? 1 : 0];
366
- } else {
367
- refInsuranceData = arr.find(e => e.key === ins.refInsuranceId);
386
+ })
387
+ })
388
+ // 高客-险种类型逻辑:当用户选择的险种类型与后台定义的默认值一致时,服务端不要保存该值
389
+ // 解决方案:如果元素有 unnecessaryValue,且与元素的 value 值相同时,该元素的 value 设置为 null。该逻辑适用于所有字段
390
+ _productGroupList.forEach(g => {
391
+ const _prodOrderList = g.prodOrderList.filter(p => !!p.hadChoice && !p.hide)
392
+ _prodOrderList
393
+ .filter(p => Array.isArray(p.mulInsOrderList))
394
+ .forEach(p => {
395
+ p.mulInsOrderList
396
+ .filter(ins => Array.isArray(ins.eleOrderList))
397
+ .forEach(ins => {
398
+ ins.eleOrderList.forEach(e => {
399
+ if (e.unnecessaryValue && e.unnecessaryValue === e.value) {
400
+ e.value = null
368
401
  }
369
- }
370
- if (refInsuranceData && refInsuranceData.eleOrderList && ins.eleOrderList) {
371
- ins.eleOrderList.forEach(ele => {
372
- let refElementData = refInsuranceData.eleOrderList.find(e => e.key === ele.key);
373
- if (
374
- ['title', 'calMethod', 'customRate', 'company'].indexOf(ele.key) === -1 &&
375
- (!ele.isHide || (ele.isHide && !ele.isDisabled && refElementData && !refElementData.isHide))
376
- ) {
377
- ins.eleOrderInResult.push({
378
- value: ele.key,
379
- label: ele.labelName
380
- });
381
- }
382
- });
383
- }
384
- });
402
+ })
403
+ })
404
+ })
405
+ })
406
+ personData.personOrderList = personData.personOrderList.filter(p => hasMultipleInsured || p.key !== 'insured2Info')
407
+ const resultData = {
408
+ ...options,
409
+ title: title || document.title,
410
+ theme,
411
+ displayFormatSort,
412
+ categorySort,
413
+ commonData,
414
+ totalBaof: options.totalBaof || calcTotalBaof(_productGroupList),
415
+ personData: convertPersonData(personData),
416
+ productGroupList: []
417
+ }
418
+ const productKeyList = []
419
+ _productGroupList.forEach(group => {
420
+ const reqProductGroup = {
421
+ key: group.key,
422
+ prodOrderList: []
423
+ }
424
+ const _prodOrderList = group.prodOrderList.filter(p => !!p.hadChoice && !p.hide)
425
+ _prodOrderList.forEach(prod => {
426
+ prod.mulInsOrderList.forEach((ins, i, arr) => {
427
+ let refInsuranceData = null
428
+ const _refId = ins.refInsuranceId
429
+ //refInsuranceId: -1,关联主险;-2,关联险种自身
430
+ if (_refId && _refId != -2) {
431
+ if (_refId == -1) {
432
+ refInsuranceData = arr[arr[0].key == 'common' ? 1 : 0]
433
+ } else {
434
+ refInsuranceData = arr.find(e => e.key === _refId)
435
+ }
436
+ }
385
437
 
386
- let productData = convertProductData(prod);
387
- productData.mulInsOrderList.forEach(ins => {
388
- if (ins.huomian == 'shuangHuomian' && ins.shmInsData && ins.shmInsData.title) {
389
- productData.mulInsOrderList.push(ins.shmInsData);
438
+ const eleOrderInResult = []
439
+ const _eleOrderList = ins.eleOrderList || []
440
+ const _refEleOrderList = _get(refInsuranceData, 'eleOrderList') || []
441
+ _eleOrderList
442
+ .filter(e => !['title', 'calMethod', 'customRate', 'company'].includes(e.key))
443
+ .forEach(e => {
444
+ const _refElementData = _refEleOrderList.find(e => e.key === e.key)
445
+ if (!e.isHide || (e.isHide && !e.isDisabled && _refElementData && !_refElementData.isHide)) {
446
+ eleOrderInResult.push({
447
+ value: e.key,
448
+ label: e.labelName
449
+ })
390
450
  }
391
- });
392
- reqProductGroup.prodOrderList.push(productData);
451
+ })
452
+ if ('payMode' in ins && ins.payMode) {
453
+ if (!eleOrderInResult.some(e => e.value === 'payModePremium')) {
454
+ eleOrderInResult.push({
455
+ value: 'payModePremium',
456
+ label: '期交保费'
457
+ })
458
+ }
393
459
  }
394
- });
395
- resultData.productGroupList.push(reqProductGroup);
396
- });
397
- return resultData;
398
- } else {
399
- return;
400
- }
460
+ ins.eleOrderInResult = eleOrderInResult
461
+ })
462
+
463
+ const productData = convertProductData(prod)
464
+ productData.mulInsOrderList.forEach(ins => {
465
+ if (ins.huomian == 'shuangHuomian' && ins.shmInsData && ins.shmInsData.title) {
466
+ productData.mulInsOrderList.push(ins.shmInsData)
467
+ }
468
+ })
469
+ reqProductGroup.prodOrderList.push(productData)
470
+ productKeyList.push(productData.key)
471
+ })
472
+ resultData.productGroupList.push(reqProductGroup)
473
+ })
474
+
475
+ const insuredInfo = resultData.personData.personOrderList.find(e => e.key === 'insuredInfo')
476
+ window.WeiyiStatSDK &&
477
+ window.WeiyiStatSDK.submit('scjhs', {
478
+ productList: productKeyList.join(),
479
+ insuredName: insuredInfo.name
480
+ })
481
+
482
+ return cleanNeedlessResultData(resultData)
401
483
  }
402
484
 
403
485
  export function getProductFromInputData(inputData, options = {}) {
404
- let product = null;
486
+ let product = null
405
487
  if (inputData.productGroupList && inputData.productGroupList.length) {
406
- let groupData = inputData.productGroupList.find(g => g.key === options.groupKey);
407
- product = groupData && groupData.prodOrderList && groupData.prodOrderList.find(p => p.key === options.productKey);
488
+ let groupData = inputData.productGroupList.find(g => g.key === options.groupKey)
489
+ product = groupData && groupData.prodOrderList && groupData.prodOrderList.find(p => p.key === options.productKey)
408
490
  }
409
- return product;
491
+ return product
410
492
  }
411
493
 
412
- export function initRecipientData(personData) {
413
- let eleOrderList = cloneDeep(personData.eleOrderList);
414
- eleOrderList = eleOrderList.filter(ele => !['name', 'sex'].includes(ele.key));
415
- eleOrderList.forEach(ele => {
416
- if (ele.key === 'title') {
417
- ele.componentName = 'cmCommonTitle';
418
- ele.isDisabled = false;
419
- (ele.label = '封面信息'), (ele.rules = []);
420
- }
421
- });
422
- if (!eleOrderList.find(ele => ele.key === 'shareTitle')) {
423
- eleOrderList.push({
424
- componentName: 'cmCommonInput',
425
- key: 'shareTitle',
426
- label: '计划书标题',
427
- labelIcon: 'icon-common_problem',
428
- maxlength: 16,
429
- placeholder: '请输入计划书标题',
430
- rules: [
431
- {
432
- type: 'string',
433
- validator(rule, value, callback, source, options) {
434
- if (value && value.match(/本金|利息|额度有限|回本|返本|复利|存钱|理财|返佣|赠送|免费|暴利/)) {
435
- return new Error('标题不能包含禁用词');
436
- }
437
- return true;
438
- }
439
- }
440
- ],
441
- value: ''
442
- });
494
+ export function genProductUniqueKeyWithNS(namespace, groupKey, productKey) {
495
+ if (groupKey == null || productKey == null) {
496
+ return ''
443
497
  }
444
- if (!eleOrderList.find(ele => ele.key === 'coverId')) {
445
- eleOrderList.push({
446
- componentName: 'cmCommonSelect',
447
- key: 'coverId',
448
- label: '封面样式',
449
- placeholder: '请选择封面样式',
450
- isDisabled: true,
451
- options: [],
452
- value: 1,
453
- rules: []
454
- });
455
- }
456
- personData.eleOrderList = eleOrderList;
498
+ const ns = namespace ? String(namespace) : ''
499
+ return ns ? `ns:${ns}:${groupKey}:${productKey}` : `${groupKey}:${productKey}`
457
500
  }
458
501
 
459
- export async function calculateProductData(inputData, options = {}) {
460
- const { planbookId, publicPbUuid, groupKey, productKey, isIgnoreError } = options;
461
- if (inputData) {
462
- const calcData = await createdProductDataToCalc(inputData, {
502
+ export async function calcProductData(inputData, options, cb) {
503
+ const { planbookId, publicPbUuid, groupKey, productKey, isIgnoreError, isIgnoreLoading, productCalcNamespace } = options || {}
504
+ const productUniqueKey = genProductUniqueKeyWithNS(productCalcNamespace, groupKey, productKey)
505
+ try {
506
+ const params = await createdProductDataToCalc(inputData, {
463
507
  planbookId,
464
508
  publicPbUuid,
465
509
  groupKey,
466
510
  productKey
467
- });
468
- if (calcData.errorMsg) {
469
- if (!isIgnoreError) {
470
- Toast(calcData.errorMsg);
471
- return Promise.reject(calcData.errorMsg);
511
+ })
512
+
513
+ if (params.errorMsg && !isIgnoreError) {
514
+ commitProductCalcError(productUniqueKey, params.errorMsg)
515
+ Toast(params.errorMsg)
516
+ return Promise.reject(params.errorMsg)
517
+ }
518
+ if (['annual_survey', 'compare2'].includes(URL_PARAM.pbType)) {
519
+ if (inputData.productGroupList) {
520
+ inputData.productGroupList.forEach(g => {
521
+ g.defNum = 0
522
+ g.prodOrderList.forEach(p => {
523
+ p.required = false
524
+ })
525
+ })
472
526
  }
473
527
  }
474
- return fetch(`${PLANBOOK_API_HOSTNAME}/planBook/${publicPbUuid ? 'public' : 'V2'}/calculate`, {
475
- method: 'POST',
476
- credentials: 'include',
477
- headers: {
478
- Accept: 'application/json, text/plain, */*',
479
- 'Content-Type': 'application/x-www-form-urlencoded'
480
- },
481
- body: QS.stringify(calcData)
482
- })
483
- .then(response => response.json())
484
- .then(res => {
485
- const { success, code, info, data } = res;
486
- if (success && data) {
487
- const productList = [];
488
- data.productGroupList.forEach(g => {
489
- g.prodOrderList.forEach(p => {
490
- productList.push(
491
- receiveProductData(inputData, p, {
492
- publicPbUuid,
493
- groupKey,
494
- productKey
495
- })
496
- );
497
- });
498
- });
499
-
500
- // 计算结果校验
501
- if (Array.isArray(inputData.productGroupList)) {
502
- let errorMessage = '';
503
- const allProductList = inputData.productGroupList.map(g => g.prodOrderList).flat();
504
- const productData = allProductList.find(p => p && p.key === productKey);
505
- const mulInsOrderList = _get(productData, 'mulInsOrderList') || [];
506
- const hasCalcResultExp = mulInsOrderList.some(ins => ins.calcResultExp);
507
- if (hasCalcResultExp) {
508
- mulInsOrderList
509
- .filter(ins => ins.calcResultExp)
510
- .forEach(ins => {
511
- if (!errorMessage) {
512
- const paramMap = getExpressionParamMap(inputData.personData, productData, ins, options);
513
- if (paramMap) {
514
- const exp = ins.calcResultExp.replace(/(%)(\d+)(\.*\w*)(%)/g, 'paramMap.i$2$3').replace(/(%)(\w*\.*\w*)(%)/g, 'paramMap.$2');
515
- errorMessage = eval(exp);
516
- console.log('计算结果校验公式: ', ins.calcResultExp);
517
- console.log('计算结果校验结果: ', errorMessage);
518
- }
519
- }
520
- });
521
- }
522
- if (errorMessage) {
523
- return Promise.reject(new Error(errorMessage));
524
- }
525
- }
528
+ let resData = null
529
+ if (publicPbUuid) {
530
+ resData = await calcPlanbookProduct({
531
+ jd: params.jd
532
+ })
533
+ } else {
534
+ resData = await calcPlanbookProduct(
535
+ qs.stringify({
536
+ jd: params.jd,
537
+ signature: params.signature,
538
+ clientVersion: params.clientVersion,
539
+ isIos: params.isIos
540
+ }),
541
+ {
542
+ isIgnoreLoading
543
+ }
544
+ ).catch(err => {
545
+ return Promise.reject(err)
546
+ })
547
+ }
548
+
549
+ if (!resData.success || !resData.data) {
550
+ if (resData.code === '002017') {
551
+ window.WeiyiStatSDK && window.WeiyiStatSDK.submit('crawler_warning')
552
+ }
553
+ const calcFailMsg = resData.info || '计算请求出错'
554
+ commitProductCalcError(productUniqueKey, calcFailMsg)
555
+ Toast(calcFailMsg)
556
+ return
557
+ }
558
+
559
+ if (resData.data.productGroupList) {
560
+ const productGroupList = resData.data.productGroupList || []
561
+ productGroupList
562
+ .filter(g => g.key === groupKey)
563
+ .map(g =>
564
+ g.prodOrderList
565
+ .filter(p => p.key === productKey)
566
+ .map(p => {
567
+ return receiveProductData(inputData, p, {
568
+ planbookId,
569
+ groupKey: g.key,
570
+ productKey: p.key
571
+ })
572
+ })
573
+ )
574
+ }
526
575
 
527
- return Promise.resolve(productList);
576
+ if (Array.isArray(inputData.productGroupList)) {
577
+ const productList = inputData.productGroupList
578
+ .map(g => g.prodOrderList)
579
+ .flat()
580
+ .filter(Boolean)
581
+ const currentProduct = productList.find(p => p.key === productKey)
582
+
583
+ if (currentProduct) {
584
+ clearAddAndTakeAndAdjustBaoeData(currentProduct)
585
+ }
586
+
587
+ // 计算结果校验
588
+ const mulInsOrderList = _get(currentProduct, 'mulInsOrderList') || []
589
+ const hasCalcResultExp = mulInsOrderList.some(ins => ins.calcResultExp)
590
+ if (hasCalcResultExp) {
591
+ let errorMessage = ''
592
+ mulInsOrderList
593
+ .filter(ins => ins.calcResultExp)
594
+ .forEach(ins => {
595
+ if (!errorMessage) {
596
+ const paramMap = getExpressionParamMap(inputData.personData, currentProduct, ins, options)
597
+ if (paramMap) {
598
+ try {
599
+ const exp = ins.calcResultExp.replace(/(%)(\d+)(\.*\w*)(%)/g, 'paramMap.i$2$3').replace(/(%)(\w*\.*\w*)(%)/g, 'paramMap.$2')
600
+ errorMessage = eval(exp)
601
+ console.log('计算结果约束结果: ', errorMessage)
602
+ } catch (error) {
603
+ errorMessage = '校验公式语法错误!'
604
+ }
605
+ if (ins.calcResultExp) {
606
+ console.log('计算结果约束公式: ', ins.calcResultExp)
607
+ }
608
+ }
609
+ }
610
+ })
611
+ if (errorMessage) {
612
+ commitProductCalcError(productUniqueKey, errorMessage)
613
+ return Promise.reject({
614
+ type: 'calcResultError',
615
+ message: errorMessage
616
+ })
528
617
  }
529
- return Promise.reject(new Error(info || `计算失败:${code || ''}`));
530
- });
618
+ }
619
+ }
620
+
621
+ cb && cb()
622
+ commitProductCalcError(productUniqueKey, null)
623
+ return Promise.resolve(resData)
624
+ } catch (err) {
625
+ const errMsg = typeof err === 'string' ? err : _get(err, 'message') || _get(err, 'info') || '计算请求出错'
626
+ if (!(_get(err, 'type') === 'calcResultError')) {
627
+ commitProductCalcError(productUniqueKey, errMsg)
628
+ }
629
+ if (typeof err === 'string') {
630
+ Toast(err)
631
+ }
632
+ return Promise.reject(err)
531
633
  }
532
- return Promise.reject();
533
634
  }
534
635
 
535
636
  export async function doubleCalcProductData(inputData, verifyData, options = {}) {
536
- const { planbookId, publicPbUuid, groupKey, productKey, isIgnoreError, eventTarget } = options;
537
- const personData = inputData && inputData.personData;
538
- const productGroupList = inputData && inputData.productGroupList ? inputData.productGroupList : [];
539
- const productGroup = productGroupList.find(g => g.key === groupKey);
540
- const prodOrderList = productGroup && productGroup.prodOrderList ? productGroup.prodOrderList : [];
541
- const productData = prodOrderList.find(p => p.key === productKey);
542
- const mulInsOrderList = productData && productData.mulInsOrderList ? productData.mulInsOrderList : [];
543
- const productVerifyData = verifyData && verifyData[productKey];
544
- const hasRevalidateFlag = mulInsOrderList.some(ins => ins.revalidateFlag);
637
+ const { user, planbookId, publicPbUuid, groupKey, productKey, isIgnoreError, productCalcNamespace, executeSource } = options
638
+ const personData = inputData && inputData.personData
639
+ const productGroupList = inputData && inputData.productGroupList ? inputData.productGroupList : []
640
+ const productGroup = productGroupList.find(g => g.key === groupKey)
641
+ const prodOrderList = productGroup && productGroup.prodOrderList ? productGroup.prodOrderList : []
642
+ const productData = prodOrderList.find(p => p.key === productKey)
643
+ const mulInsOrderList = productData && productData.mulInsOrderList ? productData.mulInsOrderList : []
644
+ const productVerifyData = verifyData && verifyData[productKey]
645
+ const hasRevalidateFlag = mulInsOrderList.some(ins => ins.revalidateFlag)
545
646
  if (productData) {
647
+ if (productData.multipleInsured) {
648
+ multipleInsuredHandler(productData, personData)
649
+ }
546
650
  await productDataHandler(productData, productVerifyData, personData, {
651
+ user,
547
652
  planbookId,
548
- eventTarget
549
- });
550
- await calculateProductData(inputData, {
653
+ executeSource
654
+ })
655
+ await calcProductData(inputData, {
656
+ user,
551
657
  planbookId,
552
658
  publicPbUuid,
553
659
  groupKey,
554
660
  productKey,
555
- isIgnoreError
556
- });
661
+ executeSource,
662
+ isIgnoreError,
663
+ productCalcNamespace
664
+ })
557
665
  if (hasRevalidateFlag) {
558
666
  await productDataHandler(productData, productVerifyData, personData, {
667
+ user,
559
668
  planbookId,
560
- eventTarget
561
- });
562
- await calculateProductData(inputData, {
669
+ executeSource
670
+ })
671
+ await calcProductData(inputData, {
672
+ user,
563
673
  planbookId,
564
674
  publicPbUuid,
565
675
  groupKey,
566
676
  productKey,
567
- isIgnoreError
568
- });
677
+ executeSource,
678
+ isIgnoreError,
679
+ productCalcNamespace
680
+ })
569
681
  }
570
682
  }
571
683
  }
572
684
 
573
- export function setupUnderwriteRuleToInputData(data) {
574
- const inputData = cloneDeep(data);
575
- if (inputData) {
576
- const productGroupList = _get(inputData, 'productGroupList') || [];
577
- const productList = productGroupList
578
- .map(g => g.prodOrderList)
579
- .filter(Boolean)
580
- .flat();
581
- const insuranceList = productList
582
- .map(p => p.mulInsOrderList)
583
- .filter(Boolean)
584
- .flat();
585
- const insuranceIds = insuranceList
586
- .map(ins => ins.key)
587
- .filter(k => !['common'].includes(k))
588
- .filter(Boolean);
589
-
590
- return fetch(`${PLANBOOK_API_HOSTNAME}/planBook/interest/underwrite/effective-rules`, {
591
- method: 'POST',
592
- credentials: 'include',
593
- headers: {
594
- Accept: 'application/json, text/plain, */*',
595
- 'Content-Type': 'application/json;'
596
- },
597
- body: JSON.stringify(insuranceIds)
685
+ export function calcAllProductData(inputData, verifyData, options) {
686
+ const { planbookId, publicPbUuid, userUuid, appid, productCalcNamespace, executeSource } = options
687
+ const productGroupList = (_get(inputData, 'productGroupList') || []).filter(g => g.prodOrderList)
688
+ const prodOrderList = productGroupList
689
+ .map(g => g.prodOrderList)
690
+ .flat()
691
+ .filter(p => p.hadChoice)
692
+ if (prodOrderList.length) {
693
+ let allProductCalcCount = options.allProductCalcCount != null ? options.allProductCalcCount : 0
694
+ const calcStore = getProductCalcVuexStore()
695
+ if (calcStore && calcStore._mutations && calcStore._mutations.CLEAR_PRODUCT_CALC_ERROR_MAP) {
696
+ calcStore.commit('CLEAR_PRODUCT_CALC_ERROR_MAP', productCalcNamespace)
697
+ }
698
+ const promises = productGroupList
699
+ .map(g => {
700
+ return g.prodOrderList
701
+ .filter(p => p.hadChoice)
702
+ .filter(p => !['single_insurance', 'noconfig_insurance', 'manual_insurance'].includes(p.policyType))
703
+ .map(p => {
704
+ if (p.policyType === 'online_trade') {
705
+ return
706
+ }
707
+ return doubleCalcProductData(inputData, verifyData, {
708
+ planbookId,
709
+ executeSource,
710
+ publicPbUuid,
711
+ groupKey: g.key,
712
+ productKey: p.key,
713
+ isIgnoreError: true,
714
+ isIgnoreLoading: true,
715
+ productCalcNamespace
716
+ })
717
+ })
718
+ })
719
+ .flat()
720
+
721
+ window.appBridge.showLoading()
722
+ return Promise.all(promises)
723
+ .then(res => {
724
+ Dialog.close()
725
+ return res
726
+ })
727
+ .catch(err => {
728
+ const errorType = err && err.type
729
+ const errorMessage = typeof err === 'string' ? err : _get(err, 'message') || '未知错误'
730
+ const isVerifyError = errorMessage === '请选择险种'
731
+ const isRestrictError = ['002012', '002013', '002015'].includes(_get(err, 'code'))
732
+ const isNeedConfirm = !(isVerifyError || isRestrictError || ['calcResultError'].includes(errorType))
733
+ if (isNeedConfirm) {
734
+ allProductCalcCount += 1
735
+ Dialog.confirm({
736
+ title: '保费计算超时',
737
+ message: allProductCalcCount > 1 ? '建议检查网络或点击反馈问题。' : '当前网络不稳定,导致保费计算失败。为避免保费不准确,请检查网络后重试。',
738
+ cancelButtonText: '退出',
739
+ confirmButtonText: allProductCalcCount > 1 ? '反馈问题' : '重试'
740
+ })
741
+ .then(() => {
742
+ window.WeiyiStatSDK && window.WeiyiStatSDK.submit(allProductCalcCount > 1 ? 'JHS_JSCW_FK' : 'JHS_JSCW_CS')
743
+ if (allProductCalcCount > 1) {
744
+ location.href = `https://pbf.winbaoxian.cn/planBook/projectGroup/feedback/index.html?type=0&planbookId=${planbookId}&tagId=3`
745
+ } else {
746
+ calcAllProductData(inputData, verifyData, {
747
+ ...options,
748
+ allProductCalcCount
749
+ })
750
+ }
751
+ })
752
+ .catch(() => {
753
+ goBack()
754
+ })
755
+ } else if (['calcResultError'].includes(errorType) && errorMessage) {
756
+ Toast(errorMessage)
757
+ }
758
+
759
+ window.WeiyiStatSDK &&
760
+ window.WeiyiStatSDK.submit('JHS_JSCW', {
761
+ localUuid: localStorage.getItem('intellectScheme') ? JSON.parse(localStorage.getItem('intellectScheme'))[`s${planbookId}`] : null,
762
+ productIds: prodOrderList.map(p => p.key).join(','),
763
+ errorMessage
764
+ })
765
+ return Promise.reject(err)
766
+ })
767
+ .finally(() => {
768
+ window.appBridge.hideLoading()
769
+ })
770
+ }
771
+ return Promise.reject('请选择投保产品')
772
+ }
773
+
774
+ export async function makePlanbook(inputData, options = {}) {
775
+ if (!inputData) {
776
+ return Promise.reject()
777
+ }
778
+ const { pbType, userUuid, insuranceTypeId, videoTypeKey } = options
779
+ const reqData = createPlanbookDataToMake(inputData, {
780
+ pbType: pbType || '',
781
+ userUuid,
782
+ insuranceTypeId,
783
+ videoTypeKey
784
+ })
785
+ if (!reqData) {
786
+ Toast('请选择险种')
787
+ return Promise.reject()
788
+ }
789
+
790
+ const reqDataStr = JSON.stringify(reqData)
791
+ const groupDataKey = _get(inputData, 'productGroupList[0].key')
792
+ const signature = await getSecurityToken(reqDataStr, {
793
+ groupDataKey
794
+ })
795
+ return uploadPlanBookResult(
796
+ qs.stringify({
797
+ jd: JSON.stringify(reqData),
798
+ userUuid,
799
+ signature,
800
+ clientVersion: appVersion,
801
+ isIos
598
802
  })
599
- .then(response => response.json())
600
- .then(({ success, data }) => {
601
- if (success && Array.isArray(data)) {
602
- insuranceList.forEach(ins => {
603
- const ruleData = data.find(rule => rule.insruanceId === ins.key);
604
- if (ruleData) {
605
- const insExpKeys = ['customVariableExp', 'calcResultExp', 'revalidateFlag'];
606
- insExpKeys
607
- .filter(k => k in ruleData)
608
- .forEach(key => {
609
- ins[key] = ruleData[key];
610
- });
611
- if (Array.isArray(ins.eleOrderList) && Array.isArray(ruleData.eleRules)) {
612
- ins.eleOrderList.forEach(ele => {
613
- const eleRule = ruleData.eleRules.find(rule => rule.elementKey === ele.key);
614
- const eleExpkeys = ['defaultValueExp', 'maxExp', 'minExp', 'multiExp', 'underwriteExp'];
615
- if (eleRule) {
616
- eleExpkeys
617
- .filter(k => k in eleRule)
618
- .forEach(key => {
619
- ele[key] = eleRule[key];
620
- });
803
+ ).then(({ success, data, info }) => {
804
+ if (!success || !data) {
805
+ Toast(info || '生成计划书失败')
806
+ return Promise.reject()
807
+ }
808
+ return Promise.resolve(data)
809
+ })
810
+ }
811
+
812
+ export function convertInputDataToResultData(inputData, options = {}) {
813
+ let resultData = null
814
+ if (inputData) {
815
+ const { title, theme, categorySort, displayFormatSort, commonData, personData, productGroupList, addedServiceList = [] } = cloneDeep(inputData)
816
+ const { insuranceTypeId, pbType, planName, userUuid } = options
817
+ resultData = {
818
+ insuranceTypeId,
819
+ pbType,
820
+ planName,
821
+ userUuid,
822
+ title: title || document.title,
823
+ theme,
824
+ displayFormatSort,
825
+ categorySort,
826
+ addedServiceList,
827
+ commonData,
828
+ personData: convertPersonData(personData),
829
+ productGroupList: [],
830
+ totalBaof: null
831
+ }
832
+
833
+ const _productGroupList = productGroupList.filter(g => (g.prodOrderList || []).some(p => p.hadChoice && !p.hide))
834
+ if (_productGroupList.length) {
835
+ _productGroupList.forEach(g => {
836
+ g.prodOrderList = g.prodOrderList.filter(p => p.hadChoice && !p.hide)
837
+ })
838
+
839
+ _productGroupList.forEach(group => {
840
+ const _productGroup = {
841
+ key: group.key,
842
+ prodOrderList: []
843
+ }
844
+ group.prodOrderList.forEach(prod => {
845
+ const mainInsurance = prod.mulInsOrderList.find(ins => ins.key !== 'common')
846
+ prod.mulInsOrderList.forEach((ins, i, arr) => {
847
+ if (Array.isArray(ins.eleOrderList)) {
848
+ // 用于结果页控制字段显示顺序
849
+ const eleOrderInResult = []
850
+ // refInsuranceId: -1-主险 -2-险种自身
851
+ const _refId = Number(ins.refInsuranceId)
852
+ let refInsuranceData = null
853
+ if (_refId && _refId !== -2) {
854
+ refInsuranceData = _refId === -1 ? mainInsurance : arr.find(e => e.key === _refId)
855
+ }
856
+
857
+ const _refEleOrderList = _get(refInsuranceData, 'eleOrderList') || []
858
+ ins.eleOrderList
859
+ .filter(e => !['title', 'calMethod', 'customRate', 'company'].includes(e.key))
860
+ .forEach(e => {
861
+ const _refElementData = _refEleOrderList.find(e => e.key === e.key)
862
+ if (!e.isHide || (e.isHide && !e.isDisabled && _refElementData && !_refElementData.isHide)) {
863
+ eleOrderInResult.push({
864
+ value: e.key,
865
+ label: e.labelName
866
+ })
621
867
  }
622
- });
868
+ })
869
+ if ('payMode' in ins && ins.payMode) {
870
+ if (!eleOrderInResult.some(e => e.value === 'payModePremium')) {
871
+ eleOrderInResult.push({
872
+ value: 'payModePremium',
873
+ label: '期交保费'
874
+ })
875
+ }
623
876
  }
877
+ ins.eleOrderInResult = eleOrderInResult
624
878
  }
625
- });
626
- return inputData;
627
- }
628
- });
879
+ })
880
+
881
+ const productData = convertProductData(prod)
882
+ // 双豁免险种处理
883
+ productData.mulInsOrderList.forEach(ins => {
884
+ const { huomian, shmInsData } = ins
885
+ if (huomian === 'shuangHuomian' && shmInsData && shmInsData.title) {
886
+ productData.mulInsOrderList.push(shmInsData)
887
+ }
888
+ })
889
+ _productGroup.prodOrderList.push(productData)
890
+ })
891
+ resultData.productGroupList.push(_productGroup)
892
+ })
893
+ resultData.totalBaof = calcTotalBaof(_productGroupList)
894
+ }
629
895
  }
896
+ return resultData
897
+ }
630
898
 
631
- return inputData;
899
+ export function cleanNeedlessResultData(resultData) {
900
+ const pureResultData = cloneDeep(resultData)
901
+ if (pureResultData) {
902
+ const productGroupList = _get(pureResultData, 'productGroupList') || []
903
+ productGroupList
904
+ .filter(g => g.prodOrderList)
905
+ .forEach(g => {
906
+ g.prodOrderList.forEach(p => {
907
+ const noNeedProductKeys = ['constraintRules', 'inputResultSwitch', 'insShowArr', 'isShowDeleteButton', 'restrictList']
908
+ noNeedProductKeys.forEach(k => {
909
+ if (k in p) {
910
+ delete p[k]
911
+ }
912
+ })
913
+ if (Array.isArray(p.mulInsOrderList)) {
914
+ p.mulInsOrderList.forEach(ins => {
915
+ const noNeedInsuranceKeys = ['isFollowing', 'isCheckbox', 'condotionList', 'customVariableExp', 'calcResultExp', 'revalidateFlag']
916
+ noNeedInsuranceKeys.forEach(k => {
917
+ if (k in ins) {
918
+ delete ins[k]
919
+ }
920
+ })
921
+ })
922
+ }
923
+ })
924
+ })
925
+ }
926
+ return pureResultData
927
+ }
928
+
929
+ // 获取产品险种标签;入参过滤与 findInsuranceTag().catch 与 compare3 fetchInsuranceSaleStatusMap 一致
930
+ export async function getProductInsuranceTags(inputData, options = {}, key = 'salesStatus') {
931
+ const product = getProductFromInputData(inputData, options)
932
+ const mulInsOrderList = (_get(product, 'mulInsOrderList') || []).filter(ins => !ins.isGroup)
933
+
934
+ if (!mulInsOrderList.length) {
935
+ return {}
936
+ }
937
+ const insuranceKeys = mulInsOrderList.map(ins => ins.key)
938
+ const keys = insuranceKeys.filter(k => {
939
+ if (k == null) return false
940
+ if (typeof k === 'number') return Number.isFinite(k)
941
+ if (typeof k === 'string') {
942
+ const t = k.trim()
943
+ if (t === '') return false
944
+ return Number.isFinite(Number(t))
945
+ }
946
+ return false
947
+ })
948
+ if (!keys.length) {
949
+ return {}
950
+ }
951
+ const res = await findInsuranceTag(keys).catch(() => {})
952
+ const list = _get(res, 'data') || []
953
+ const byInsuranceId = new Map()
954
+ list.forEach(item => {
955
+ if (item && item.insuranceId != null) {
956
+ byInsuranceId.set(String(item.insuranceId), item)
957
+ }
958
+ })
959
+ const tagMap = {}
960
+ mulInsOrderList.forEach(ins => {
961
+ const row = byInsuranceId.get(String(ins.key))
962
+ if (row && Object.prototype.hasOwnProperty.call(row, key)) {
963
+ tagMap[ins.key] = row[key]
964
+ }
965
+ })
966
+ return tagMap
967
+ }
968
+
969
+ export async function setupUnderwriteRuleToInputData(data) {
970
+ const inputData = cloneDeep(data)
971
+ if (inputData) {
972
+ const insuranceList = (_get(inputData, 'productGroupList') || [])
973
+ .map(g => g.prodOrderList)
974
+ .flat()
975
+ .map(p => p && p.mulInsOrderList)
976
+ .flat()
977
+ .filter(ins => ins && !['common'].includes(ins.key))
978
+ await setupUnderwriteRuleToInsuranceList(insuranceList).catch(() => {})
979
+ }
980
+ return inputData
981
+ }
982
+
983
+ export function setupUnderwriteRuleToInsuranceList(list) {
984
+ if (Array.isArray(list)) {
985
+ const insuranceIds = list.map(ins => ins.key)
986
+ return getUnderwriteEffectiveRules(insuranceIds).then(data => {
987
+ if (Array.isArray(data)) {
988
+ data.forEach(rule => {
989
+ const { insruanceId, eleRules } = rule
990
+ const insurance = list.find(ins => ins.key === insruanceId)
991
+ if (insurance) {
992
+ const insExpKeys = ['customVariableExp', 'calcResultExp', 'revalidateFlag']
993
+ insExpKeys
994
+ .filter(k => k in rule)
995
+ .forEach(key => {
996
+ insurance[key] = rule[key]
997
+ })
998
+ const eleOrderList = insurance.eleOrderList || []
999
+ if (eleOrderList && Array.isArray(eleRules)) {
1000
+ eleOrderList.forEach(ele => {
1001
+ const eleRule = eleRules.find(e => e.elementKey === ele.key)
1002
+ if (eleRule) {
1003
+ const eleExpkeys = ['defaultValueExp', 'maxExp', 'minExp', 'multiExp', 'underwriteExp']
1004
+ eleExpkeys
1005
+ .filter(k => k in eleRule)
1006
+ .forEach(key => {
1007
+ ele[key] = eleRule[key]
1008
+ })
1009
+ }
1010
+ })
1011
+ }
1012
+ }
1013
+ })
1014
+ return list
1015
+ }
1016
+ })
1017
+ }
1018
+ return list
632
1019
  }