new-customer.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. var sysT = require('../../../../tool/sys-tool.js')
  2. var verify = require('../../../../tool/verify.js')
  3. var businessT = require('../../../../tool/business-tool.js')
  4. var businessType = require('../../../../public/business-type.js')
  5. var purchaseO = require('../../public/model/purchaseOrder.js')
  6. var p = require('../../public/model/public.js')
  7. var url = require('../../../../constant/url.js')
  8. import Net from '../../../../tool/net.js'
  9. var net = new Net()
  10. var app = getApp()
  11. //input是原生组件会覆盖非原生组件
  12. var inputViewS = [
  13. { id: '1', title: '真实姓名', p: '请输入参保人姓名', l: '16', t: 'text', h: false },
  14. { id: '2', title: '民族', p: '请输入民族', l: '16', t: 'text', h: false },
  15. { id: '3', title: '身份证号', p: '请输入身份证号', l: '18', t: 'idcard', h: false },
  16. { id: '5', title: '户籍地址', p: '请输入身份证户籍地址', l: '100', t: 'text', h: false ,textarea: true },
  17. { id: '4', title: '手机号码', p: '请输入联系方式', l: '11', t: 'number', h: false, interval: true}
  18. ]
  19. // var inputViewH = [
  20. // { title: '真实姓名', h: true },
  21. // { title: '民族', h: true },
  22. // { title: '身份证号', h: true },
  23. // { title: '手机号码', h: true }
  24. // ]
  25. Page({
  26. /**
  27. * 页面的初始数据
  28. */
  29. data: {
  30. adapter: {
  31. bgHeight: '',
  32. suffix: ''
  33. },
  34. inputView: [],
  35. scroll: true,
  36. requireView: {
  37. animation: {},
  38. hidden: true
  39. },
  40. idCard:{
  41. currentChose: '1',
  42. front: { id: 1, i: '../../../../icon/home/idcard_front.png', c: '上传身份证正面' },
  43. back: { id: 2, i: '../../../../icon/home/idcard_back.png', c: '上传身份证背面' }
  44. },
  45. },
  46. hiddenRequireView:businessT.action(function (sender) {
  47. var animation = wx.createAnimation({
  48. duration: 300,
  49. timingFunction: 'ease',
  50. })
  51. animation.bottom('-800rpx').step()
  52. this.setData({
  53. requireView: {
  54. animation: animation.export(),
  55. hidden: false
  56. }
  57. })
  58. setTimeout(function () {
  59. this.data.requireView.hidden = true
  60. this.data.inputView[3].h = false
  61. this.setData({
  62. requireView: this.data.requireView,
  63. inputView: this.data.inputView,
  64. scroll: true
  65. })
  66. }.bind(this), 300)
  67. }),
  68. requireAction:businessT.action(function (sender) {
  69. if (!this.data.requireView.hidden) {
  70. return
  71. }
  72. this.data.requireView.hidden = false
  73. this.data.inputView[3].h = true
  74. this.setData({
  75. requireView: this.data.requireView,
  76. scroll: false,
  77. inputView: this.data.inputView,
  78. })
  79. var animation = wx.createAnimation({
  80. duration: 300,
  81. timingFunction: 'ease',
  82. })
  83. animation.bottom('0rpx').step()
  84. this.setData({
  85. requireView: {
  86. animation: animation.export(),
  87. hidden: false
  88. }
  89. })
  90. }),
  91. toTakePhoto: function (id) {
  92. this.data.idCard.currentChose = id
  93. wx.navigateTo({
  94. url: '../../../../public/pages/take-photo/take-photo',
  95. })
  96. },
  97. photographAction: businessT.action(function (sender) {
  98. businessT.debugLog(sender.currentTarget.id)
  99. this.toTakePhoto(sender.currentTarget.id)
  100. }),
  101. imageAction: businessT.action(function (sender) {
  102. businessT.debugLog(sender)
  103. var order = p.getOrder()
  104. if (sender.currentTarget.id == '1' && order.imageDict.first != '') {
  105. wx.previewImage({
  106. urls: [order.imageDict.first],
  107. })
  108. } else if (sender.currentTarget.id == '2' && order.imageDict.second != '') {
  109. wx.previewImage({
  110. urls: [order.imageDict.second],
  111. })
  112. } else {
  113. this.toTakePhoto(sender.currentTarget.id)
  114. }
  115. }),
  116. finishTakePhoto: function(path) {
  117. var order = p.getOrder()
  118. if (this.data.idCard.currentChose == '1') {
  119. this.data.idCard.front.i = path
  120. order.imageDict.first = path
  121. this.setData({
  122. idCard: this.data.idCard
  123. })
  124. } else if (this.data.idCard.currentChose == '2') {
  125. this.data.idCard.back.i = path
  126. order.imageDict.second = path
  127. this.setData({
  128. idCard: this.data.idCard
  129. })
  130. }
  131. },
  132. formSubmit: businessT.action(function (sender) {
  133. businessT.debugLog(sender)
  134. var order = p.getOrder()
  135. if (order.imageDict.first == '') {
  136. wx.showToast({
  137. title: '请拍摄身份证正面',
  138. icon: 'none'
  139. })
  140. } else if (order.imageDict.second == '') {
  141. wx.showToast({
  142. title: '请拍摄身份证反面',
  143. icon: 'none'
  144. })
  145. } else if (sender.detail.value['1'].length <= 1) {
  146. wx.showToast({
  147. title: '请正确输入姓名',
  148. icon: 'none'
  149. })
  150. } else if (sender.detail.value['2'] == '') {
  151. wx.showToast({
  152. title: '请输入民族',
  153. icon: 'none'
  154. })
  155. } else if (sender.detail.value['3'].length != 18 || !verify.isIdentityCard(sender.detail.value['3'])) {
  156. wx.showToast({
  157. title: '请填写正确的身份证号',
  158. icon: 'none'
  159. })
  160. } else if (verify.getIdentityCardAge(sender.detail.value['3']) >= 60) {
  161. wx.showToast({
  162. title: '暂时只受理60岁以下用户哦',
  163. icon: 'none'
  164. })
  165. } else if (sender.detail.value['5'] == '') {
  166. wx.showToast({
  167. title: '请正确输入户籍地址',
  168. icon: 'none'
  169. })
  170. } else if (sender.detail.value['4'].length != 11 || !verify.isPhoneNum(sender.detail.value['4'])) {
  171. wx.showToast({
  172. title: '请填写正确的手机号',
  173. icon: 'none'
  174. })
  175. } else {
  176. order.customerData = {
  177. 'user_name': sender.detail.value['1'],
  178. 'id_card': sender.detail.value['3'],
  179. 'nation': sender.detail.value['2'],
  180. 'gender': verify.getIdentityCardGender(sender.detail.value['3']),
  181. 'phone': sender.detail.value['4'],
  182. 'hk_address': sender.detail.value['5'],
  183. 'sbuId': ''
  184. }
  185. order.isNewCustomer = true
  186. this.uploadImage()
  187. businessT.debugLog(order.customerData)
  188. }
  189. }),
  190. uploadImage: function() {
  191. wx.showLoading({
  192. title: '正在生成参保人',
  193. mask: true
  194. })
  195. this.uploadFirstImage()
  196. },
  197. uploadFirstImage: function() {
  198. var order = p.getOrder()
  199. net.uploadImage({
  200. url: url.www_host + url.uploadIdcardByNumber,
  201. imgPath: order.imageDict.first,
  202. imgName: 'file1',
  203. data: { id_card: order.customerData.id_card, pos: 0 },
  204. success: (err, res) => {
  205. this.uploadSecondImage(res.data)
  206. },
  207. fail: (err, res) => {
  208. wx.hideLoading()
  209. businessT.showFailTips(err, '生成参保人信息失败')
  210. }
  211. }, true)
  212. },
  213. uploadSecondImage: function(firstPath) {
  214. var order = p.getOrder()
  215. net.uploadImage({
  216. url: url.www_host + url.uploadIdcardByNumber,
  217. imgPath: order.imageDict.second,
  218. imgName: 'file2',
  219. data: { id_card: order.customerData.id_card, pos: 1 },
  220. success: (err, res) => {
  221. this.uploadCustomerImformation(firstPath, res.data)
  222. },
  223. fail: (err, res) => {
  224. wx.hideLoading()
  225. businessT.showFailTips(err, '生成参保人信息失败')
  226. }
  227. }, true)
  228. },
  229. uploadCustomerImformation: function(fp, sp) {
  230. businessT.debugLog(fp)
  231. businessT.debugLog(sp)
  232. var order = p.getOrder()
  233. var data = order.customerData
  234. data.id_card_img = fp
  235. data.id_card_img1 = sp
  236. net.connectNeedLogin({
  237. url: url.app_host + url.modifyCustomer,
  238. data: data,
  239. success: (err, res) => {
  240. this.modifyCustomerNetworkGetData(res.data.id)
  241. },
  242. fail: (err, res) => {
  243. wx.hideLoading()
  244. businessT.showFailTips(err, '生成参保人信息失败')
  245. }
  246. })
  247. },
  248. modifyCustomerNetworkGetData: function(id) {
  249. var order = p.getOrder()
  250. order.customerData.sbuId = id
  251. order.customerData.id = id
  252. order.customerData.id_card_img = null
  253. order.customerData.id_card_img1 = null
  254. order.customerData.id_card = String(order.customerData.id_card).slice(0, 2) + '**************' + String(order.customerData.id_card).slice(16, 18)
  255. var isNew = true
  256. for (var i in app.globalData.customerList) {
  257. var customer = app.globalData.customerList[i]
  258. if (customer.id == order.customerData.id) {
  259. order.customerData.shebao_card = customer.shebao_card
  260. order.customerData.fund_card = customer.fund_card
  261. app.globalData.customerList[i] = order.customerData
  262. isNew = false
  263. break
  264. }
  265. }
  266. if (isNew) {
  267. app.globalData.customerList.push(order.customerData)
  268. }
  269. if (order.purchaseType == businessType.PurchaseType.socialInsurance || order.purchaseType == businessType.PurchaseType.socialInsurancePackage) {
  270. wx.navigateTo({
  271. url: '../purchase-s-imformation/purchase-s-imformation',
  272. })
  273. } else {
  274. wx.navigateTo({
  275. url: '../purchase-a-imformation/purchase-a-imformation',
  276. })
  277. }
  278. },
  279. wxvoid: function () {
  280. },
  281. /**
  282. * 生命周期函数--监听页面加载
  283. */
  284. onLoad: function (options) {
  285. sysT.adaptor()
  286. businessT.debugLog(sysT.usableHeight(112))
  287. this.data.adapter = {
  288. bgHeight: sysT.usableHeight(112),
  289. suffix: sysT.suffixOfClass(),
  290. }
  291. this.data.inputView = inputViewS
  292. var isIos = sysT.sysInfo().system.indexOf("iOS") == 0
  293. this.data.inputView[3].isIos = isIos
  294. this.setData({
  295. adapter: this.data.adapter,
  296. inputView: this.data.inputView
  297. })
  298. var order = p.getOrder()
  299. order.customerData = {
  300. 'user_name': '',
  301. 'id_card': '',
  302. 'nation': '',
  303. 'gender': '',
  304. 'phone': '',
  305. 'sbuId': ''
  306. }//参保人(购买人)信息
  307. order.imageDict = {
  308. 'first': '',
  309. 'second': ''
  310. }//身份证照图片
  311. },
  312. /**
  313. * 生命周期函数--监听页面初次渲染完成
  314. */
  315. onReady: function () {
  316. },
  317. /**
  318. * 生命周期函数--监听页面显示
  319. */
  320. onShow: function () {
  321. },
  322. /**
  323. * 生命周期函数--监听页面隐藏
  324. */
  325. onHide: function () {
  326. },
  327. /**
  328. * 生命周期函数--监听页面卸载
  329. */
  330. onUnload: function () {
  331. },
  332. /**
  333. * 页面相关事件处理函数--监听用户下拉动作
  334. */
  335. onPullDownRefresh: function () {
  336. },
  337. /**
  338. * 页面上拉触底事件的处理函数
  339. */
  340. onReachBottom: function () {
  341. },
  342. /**
  343. * 用户点击右上角分享
  344. */
  345. // onShareAppMessage: function () {
  346. // }
  347. })