customer-view.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. var sysT = require('../../../tool/sys-tool.js')
  2. var businessT = require('../../../tool/business-tool.js')
  3. var url = require('../../../constant/url.js')
  4. import Net from '../../../tool/net.js'
  5. var net = new Net()
  6. var p = require('../../../page/home/public/model/public.js')
  7. import PurchaseOrder from '../../../page/home/public/model/purchaseOrder.js'
  8. var businessType = require('../../business-type.js')
  9. var app = getApp()
  10. var publicData = require('../../../constant/data.js')
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. type: 'nPurchase',
  17. businessType: 's',//快速购买用
  18. header: {
  19. t: '',
  20. s: ''
  21. },
  22. adapter: {
  23. suffix: ''
  24. },
  25. data: [],
  26. chose: '0'
  27. },
  28. nextStep: businessT.action(function (sender) {
  29. businessT.debugLog(app.globalData.customerList[this.data.chose])
  30. var customer = app.globalData.customerList[this.data.chose]
  31. if (this.data.type == 'nPurchase') {
  32. var order = p.getOrder()
  33. order.customerData = {
  34. 'user_name': customer.user_name,
  35. 'id_card': customer.id_card,
  36. 'nation': customer.nation,
  37. 'gender': customer.gender,
  38. 'phone': customer.phone,
  39. 'sbuId': customer.id
  40. }
  41. order.isNewCustomer = false
  42. if (order.purchaseType == businessType.PurchaseType.socialInsurance || order.purchaseType == businessType.PurchaseType.socialInsurancePackage) {
  43. wx.navigateTo({
  44. url: '../../../page/home/pages/purchase-s-imformation/purchase-s-imformation',
  45. })
  46. } else {
  47. wx.navigateTo({
  48. url: '../../../page/home/pages/purchase-a-imformation/purchase-a-imformation',
  49. })
  50. }
  51. } else {
  52. wx.showLoading({
  53. title: '加载中',
  54. mask: true
  55. })
  56. businessT.debugLog(p.getOrder())
  57. net.connectNeedLogin({
  58. url: url.app_host + url.getQuickPurchaseData,
  59. data: {
  60. sbuId: customer.id,
  61. pay_for: this.data.businessType == 's' ? 1 : 2
  62. },
  63. success: (err, res) => {
  64. if (!res.data.buyShebao && res.data.fund_price == 0) {
  65. wx.hideLoading()
  66. var order = p.getOrder()
  67. var title = '此购买人没有成功下单记录哦,请返回选择“立即' + (order.purchaseType == businessType.PurchaseType.socialInsurance ? '参保”' : '缴存”')
  68. wx.showToast({
  69. title: title,
  70. icon: 'none'
  71. })
  72. } else {
  73. this.handleQuickPurchaseData(res.data, customer)
  74. }
  75. },
  76. fail: (err, res) => {
  77. wx.hideLoading()
  78. businessT.showFailTips(err, '加载失败')
  79. }
  80. }, true)
  81. }
  82. }),
  83. handleQuickPurchaseData: function (data, customer) {
  84. var p_code = Number(String(data.city_code).slice(0, 2) + '00')
  85. var citys = publicData.purchaseCity[p_code]
  86. var cityName = null
  87. for (var index in citys) {
  88. if (data.city_code == citys[index].id) {
  89. cityName = citys[index].name
  90. break
  91. }
  92. }
  93. if (!cityName) {
  94. wx.hideLoading()
  95. businessT.showFailTips({
  96. code: 0,
  97. msg: ''}, '加载失败')
  98. return
  99. }
  100. businessT.debugLog(cityName)
  101. var order = new PurchaseOrder()
  102. order.isNewCustomer = false
  103. order.city = data.city_code
  104. order.cityName = cityName
  105. order.accountType = data.hukou_type
  106. order.customerData = {
  107. 'user_name': customer.user_name,
  108. 'id_card': customer.id_card,
  109. 'nation': customer.nation,
  110. 'gender': customer.gender,
  111. 'phone': customer.phone,
  112. 'sbuId': customer.id
  113. }
  114. order.beginTime = String(data.start_month).slice(0,4) + '年' + String(data.start_month).slice(4, 6) + '月'
  115. order.accumulationFund = data.fund_price
  116. order.id = data.cid
  117. if (this.data.businessType == 's' && data.fund_price != 0) {
  118. order.pack = true
  119. order.purchaseType = businessType.PurchaseType.socialInsurancePackage
  120. } else if (this.data.businessType == 'a' && data.buyShebao) {
  121. order.pack = true
  122. order.purchaseType = businessType.PurchaseType.accumulationFundPackage
  123. } else {
  124. order.pack = false
  125. order.purchaseType = this.data.businessType == 's' ? businessType.PurchaseType.socialInsurance : businessType.PurchaseType.accumulationFund
  126. }
  127. app.purchase.order = order
  128. if ((this.data.businessType == 'a' && !order.pack) || !data.mutli_cid) {
  129. var showCity = cityName
  130. } else {
  131. var showCity = cityName + '(' + data.cid_name + ')'
  132. }
  133. wx.hideLoading()
  134. var isNeedSalary = 0
  135. if (data.wage_flow) {
  136. isNeedSalary = 1
  137. }
  138. wx.navigateTo({
  139. url: '../../../page/home/pages/quick-purchase/quick-purchase?businessType=' + this.data.businessType + '&cityName=' + showCity + '&minMonths=' + data.min_months + '&beginTime=' + order.beginTime + '&isNeedSalary=' + isNeedSalary,
  140. })
  141. },
  142. chooseAction: businessT.action(function (sender) {
  143. businessT.debugLog(this.data.chose)
  144. businessT.debugLog(sender.currentTarget.id)
  145. if (this.data.chose == sender.currentTarget.id) {
  146. return
  147. }
  148. businessT.debugLog(this.data.data)
  149. businessT.debugLog(sender.currentTarget.id)
  150. this.data.data[this.data.chose].img = 'filter_n.png'
  151. this.data.data[sender.currentTarget.id].img = 'filter_s.png'
  152. this.data.chose = sender.currentTarget.id
  153. this.setData({
  154. data: this.data.data
  155. })
  156. }, 100),
  157. editAction: businessT.action(function (sender) {
  158. businessT.debugLog(sender.currentTarget.id)
  159. wx.navigateTo({
  160. url: '../edit-customer/edit-customer?i=' + sender.currentTarget.id,
  161. })
  162. }),
  163. deleteAction: businessT.action(function (sender) {
  164. businessT.debugLog(sender.currentTarget.id)
  165. var that = this
  166. wx.showModal({
  167. title: '删除后将无法恢复',
  168. content: '是否删除TA',
  169. confirmText: '删除',
  170. cancelText: '取消',
  171. confirmColor: '#3296FB',
  172. cancelColor: '#3296FB',
  173. success: function (res) {
  174. if (res.confirm) {
  175. that.deleteCustomer(sender.currentTarget.id)
  176. }
  177. }
  178. })
  179. }),
  180. deleteCustomer: function (i) {
  181. var customer = this.data.data[i]
  182. this.data.data.splice(Number(i), 1)
  183. app.globalData.customerList.splice(Number(i), 1)
  184. this.setData({
  185. data: this.data.data
  186. })
  187. net.connectNeedLogin({
  188. url: url.app_host + url.deleteCustomer,
  189. data: {
  190. id: customer.id
  191. },
  192. success: (err, res) => {
  193. },
  194. fail: (err, res) => {
  195. }
  196. })
  197. },
  198. newCustomerAction: businessT.action(function (sender) {
  199. businessT.debugLog('newCustomerAction')
  200. wx.navigateTo({
  201. url: '../../../page/home/pages/new-customer/new-customer',
  202. })
  203. }),
  204. /**
  205. * 生命周期函数--监听页面加载
  206. */
  207. onLoad: function (options) {
  208. if (options.type) {
  209. this.data.type = options.type
  210. }
  211. if (options.businessType) {
  212. this.data.businessType = options.businessType
  213. }
  214. wx.setNavigationBarTitle({
  215. title: this.data.type == 'manager' ? '人员管理' : '选择人员'
  216. })
  217. if (this.data.type == 'manager') {
  218. this.data.header = {
  219. t: '人员信息管理',
  220. s: '可对人员信息进行编辑、查看、删除'
  221. }
  222. } else {
  223. this.data.header = {
  224. t: '选择人员',
  225. s: '系统会默认上次最后购买的人'
  226. }
  227. }
  228. this.data.adapter = {
  229. suffix: sysT.suffixOfClass(),
  230. }
  231. var list = []
  232. for (var i in app.globalData.customerList) {
  233. var item = app.globalData.customerList[i]
  234. if (i == 0) {
  235. item.img = 'filter_s.png'
  236. } else {
  237. item.img = 'filter_n.png'
  238. }
  239. var h = ''
  240. if (item.user_name.length > 2) {
  241. h = item.user_name.substr(item.user_name.length - 2, 2)
  242. } else {
  243. h = item.user_name
  244. }
  245. item.h = h
  246. list.push(item)
  247. }
  248. this.data.data = list
  249. this.setData({
  250. adapter: this.data.adapter,
  251. type: this.data.type,
  252. header: this.data.header,
  253. data: this.data.data
  254. })
  255. },
  256. /**
  257. * 生命周期函数--监听页面初次渲染完成
  258. */
  259. onReady: function () {
  260. },
  261. /**
  262. * 生命周期函数--监听页面显示
  263. */
  264. onShow: function () {
  265. },
  266. /**
  267. * 生命周期函数--监听页面隐藏
  268. */
  269. onHide: function () {
  270. },
  271. /**
  272. * 生命周期函数--监听页面卸载
  273. */
  274. onUnload: function () {
  275. },
  276. /**
  277. * 页面相关事件处理函数--监听用户下拉动作
  278. */
  279. onPullDownRefresh: function () {
  280. },
  281. /**
  282. * 页面上拉触底事件的处理函数
  283. */
  284. onReachBottom: function () {
  285. },
  286. /**
  287. * 用户点击右上角分享
  288. */
  289. onShareAppMessage: function () {
  290. return {
  291. path: '/page/home/index',
  292. imageUrl: '../../../icon/public/share_img.png',
  293. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  294. }
  295. }
  296. })