insurance-add.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <scroll-view class="container" scroll-y>
  3. <view class="form-card">
  4. <view class="form-group">
  5. <text class="form-label">保单名称 <text class="required">*</text></text>
  6. <input class="form-input" v-model="form.policyName" placeholder="请输入保单名称" />
  7. </view>
  8. <view class="form-group">
  9. <text class="form-label">保险公司</text>
  10. <input class="form-input" v-model="form.insuranceCompany" placeholder="请输入保险公司名称" />
  11. </view>
  12. <view class="form-group">
  13. <text class="form-label">保单类型</text>
  14. <picker class="form-picker" :value="policyTypeIndex" :range="policyTypes" @change="onTypeChange">
  15. <view class="picker-value">{{ policyTypes[policyTypeIndex] || '请选择保单类型' }}</view>
  16. </picker>
  17. </view>
  18. <view class="form-group">
  19. <text class="form-label">被保人 <text class="required">*</text></text>
  20. <input class="form-input" v-model="form.insuredPerson" placeholder="请输入被保人姓名" />
  21. </view>
  22. <view class="form-row">
  23. <view class="form-group half">
  24. <text class="form-label">保费</text>
  25. <input class="form-input" v-model="form.premium" placeholder="0.00" type="digit" />
  26. </view>
  27. <view class="form-group half">
  28. <text class="form-label">保额</text>
  29. <input class="form-input" v-model="form.sumInsured" placeholder="0.00" type="digit" />
  30. </view>
  31. </view>
  32. <view class="form-row">
  33. <view class="form-group half">
  34. <text class="form-label">生效日期</text>
  35. <picker class="form-picker" mode="date" :value="form.startDate" @change="onStartDateChange">
  36. <view class="picker-value">{{ form.startDate || '请选择' }}</view>
  37. </picker>
  38. </view>
  39. <view class="form-group half">
  40. <text class="form-label">到期日期</text>
  41. <picker class="form-picker" mode="date" :value="form.endDate" @change="onEndDateChange">
  42. <view class="picker-value">{{ form.endDate || '请选择' }}</view>
  43. </picker>
  44. </view>
  45. </view>
  46. <view class="form-group">
  47. <text class="form-label">续费类型</text>
  48. <picker class="form-picker" :value="renewalTypeIndex" :range="renewalTypes" @change="onRenewalChange">
  49. <view class="picker-value">{{ renewalTypes[renewalTypeIndex] || '请选择续费类型' }}</view>
  50. </picker>
  51. </view>
  52. <view class="form-group">
  53. <text class="form-label">保单号</text>
  54. <input class="form-input" v-model="form.policyNo" placeholder="请输入保单号" />
  55. </view>
  56. <view class="form-group">
  57. <text class="form-label">备注</text>
  58. <textarea class="form-textarea" v-model="form.remark" placeholder="备注信息" />
  59. </view>
  60. </view>
  61. <view class="submit-btn-wrap">
  62. <button class="submit-btn" :loading="submitting" @click="submitForm">
  63. {{ isEdit ? '更新保单' : '提交保存' }}
  64. </button>
  65. </view>
  66. </scroll-view>
  67. </template>
  68. <script>
  69. import { getInsuranceDetail, createInsurance, updateInsurance } from '../../utils/api'
  70. export default {
  71. data() {
  72. return {
  73. isEdit: false,
  74. submitting: false,
  75. policyTypes: ['医疗险', '重疾险', '意外险', '教育金', '养老险'],
  76. policyTypeValues: ['medical', 'life', 'accident', 'education', 'endowment'],
  77. policyTypeIndex: -1,
  78. renewalTypes: ['年缴', '月缴', '趸交'],
  79. renewalTypeValues: ['annual', 'monthly', 'single'],
  80. renewalTypeIndex: -1,
  81. form: {
  82. policyName: '',
  83. insuranceCompany: '',
  84. policyType: '',
  85. insuredPerson: '',
  86. premium: '',
  87. sumInsured: '',
  88. startDate: '',
  89. endDate: '',
  90. renewalType: 'annual',
  91. policyNo: '',
  92. remark: ''
  93. }
  94. }
  95. },
  96. onLoad(options) {
  97. if (options && options.id) {
  98. this.isEdit = true
  99. this.loadDetail(options.id)
  100. }
  101. },
  102. methods: {
  103. async loadDetail(id) {
  104. try {
  105. const res = await getInsuranceDetail(id)
  106. if (res && res.code === 200 && res.data) {
  107. const data = res.data
  108. this.form.policyName = data.policyName || ''
  109. this.form.insuranceCompany = data.insuranceCompany || ''
  110. this.form.policyType = data.policyType || ''
  111. this.form.insuredPerson = data.insuredPerson || ''
  112. this.form.premium = data.premium ? String(data.premium) : ''
  113. this.form.sumInsured = data.sumInsured ? String(data.sumInsured) : ''
  114. this.form.startDate = data.startDate ? data.startDate.substring(0, 10) : ''
  115. this.form.endDate = data.endDate ? data.endDate.substring(0, 10) : ''
  116. this.form.renewalType = data.renewalType || 'annual'
  117. this.form.policyNo = data.policyNo || ''
  118. this.form.remark = data.remark || ''
  119. this.policyTypeIndex = this.policyTypeValues.indexOf(data.policyType)
  120. this.renewalTypeIndex = this.renewalTypeValues.indexOf(data.renewalType)
  121. uni.setNavigationBarTitle({ title: '保单详情' })
  122. }
  123. } catch (e) {
  124. console.error('加载保单详情失败', e)
  125. }
  126. },
  127. onTypeChange(e) {
  128. this.policyTypeIndex = parseInt(e.detail.value)
  129. this.form.policyType = this.policyTypeValues[this.policyTypeIndex]
  130. },
  131. onRenewalChange(e) {
  132. this.renewalTypeIndex = parseInt(e.detail.value)
  133. this.form.renewalType = this.renewalTypeValues[this.renewalTypeIndex]
  134. },
  135. onStartDateChange(e) {
  136. this.form.startDate = e.detail.value
  137. },
  138. onEndDateChange(e) {
  139. this.form.endDate = e.detail.value
  140. },
  141. async submitForm() {
  142. if (!this.form.policyName) {
  143. uni.showToast({ title: '请输入保单名称', icon: 'none' })
  144. return
  145. }
  146. if (!this.form.insuredPerson) {
  147. uni.showToast({ title: '请输入被保人姓名', icon: 'none' })
  148. return
  149. }
  150. this.submitting = true
  151. try {
  152. var payload = {
  153. policyName: this.form.policyName,
  154. insuranceCompany: this.form.insuranceCompany,
  155. policyType: this.form.policyType,
  156. insuredPerson: this.form.insuredPerson,
  157. premium: this.form.premium ? parseFloat(this.form.premium) : null,
  158. sumInsured: this.form.sumInsured ? parseFloat(this.form.sumInsured) : null,
  159. startDate: this.form.startDate || null,
  160. endDate: this.form.endDate || null,
  161. renewalType: this.form.renewalType,
  162. policyNo: this.form.policyNo,
  163. remark: this.form.remark
  164. }
  165. var res
  166. if (this.isEdit) {
  167. payload.id = this.$mp.query && this.$mp.query.id
  168. res = await updateInsurance(payload)
  169. } else {
  170. res = await createInsurance(payload)
  171. }
  172. if (res && res.code === 200) {
  173. uni.showToast({ title: this.isEdit ? '更新成功' : '创建成功', icon: 'success' })
  174. setTimeout(function() {
  175. uni.navigateBack()
  176. }, 1500)
  177. } else {
  178. uni.showToast({ title: res && res.message || '提交失败', icon: 'none' })
  179. }
  180. } catch (e) {
  181. uni.showToast({ title: '网络错误', icon: 'none' })
  182. } finally {
  183. this.submitting = false
  184. }
  185. }
  186. }
  187. }
  188. </script>
  189. <style>
  190. .container {
  191. min-height: 100vh;
  192. background: #f5f7fa;
  193. padding: 20rpx 30rpx 120rpx;
  194. width: 100%;
  195. box-sizing: border-box;
  196. overflow-x: hidden;
  197. }
  198. .form-card {
  199. background: #fff;
  200. border-radius: 20rpx;
  201. padding: 30rpx;
  202. margin-bottom: 24rpx;
  203. }
  204. .form-group {
  205. margin-bottom: 28rpx;
  206. }
  207. .form-label {
  208. display: block;
  209. font-size: 28rpx;
  210. color: #333;
  211. font-weight: 500;
  212. margin-bottom: 12rpx;
  213. }
  214. .required {
  215. color: #DC2626;
  216. }
  217. .form-input {
  218. width: 100%;
  219. height: 88rpx;
  220. line-height: 88rpx;
  221. background: #F5F7FA;
  222. border-radius: 12rpx;
  223. padding: 0 20rpx;
  224. font-size: 28rpx;
  225. color: #333;
  226. box-sizing: border-box;
  227. }
  228. .form-picker {
  229. width: 100%;
  230. height: 80rpx;
  231. line-height: 80rpx;
  232. background: #F5F7FA;
  233. border-radius: 12rpx;
  234. padding: 0 20rpx;
  235. box-sizing: border-box;
  236. }
  237. .picker-value {
  238. font-size: 28rpx;
  239. color: #333;
  240. line-height: 80rpx;
  241. }
  242. .form-textarea {
  243. width: 100%;
  244. height: 160rpx;
  245. background: #F5F7FA;
  246. border-radius: 12rpx;
  247. padding: 20rpx;
  248. font-size: 28rpx;
  249. color: #333;
  250. box-sizing: border-box;
  251. }
  252. .form-row {
  253. display: flex;
  254. flex-direction: row;
  255. justify-content: space-between;
  256. }
  257. .form-group.half {
  258. width: 48%;
  259. }
  260. .submit-btn-wrap {
  261. padding: 20rpx 0 40rpx;
  262. }
  263. .submit-btn {
  264. width: 100%;
  265. height: 88rpx;
  266. line-height: 88rpx;
  267. text-align: center;
  268. background: #F97316;
  269. color: #fff;
  270. font-size: 30rpx;
  271. font-weight: 600;
  272. border-radius: 44rpx;
  273. border: none;
  274. }
  275. .submit-btn::after {
  276. border: none;
  277. }
  278. </style>