business-card.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { VueLikePage } from '../../utils/page'
  2. import UserApi from '../../apis/user'
  3. import Router from '../../utils/routes'
  4. VueLikePage([], {
  5. data: {
  6. my_info: getApp().globalData.userinfo,
  7. activeType: 0,
  8. business_0: [],
  9. business_1: []
  10. },
  11. methods: {
  12. onShow () {
  13. this.getBusinessCardList()
  14. this.getBusinessCardList(1)
  15. this.getMyCardInfo()
  16. },
  17. getMyCardInfo () {
  18. return UserApi.getVisitCardDetail(getApp().globalData.userinfo.viewerId).then(res => {
  19. console.log(res, )
  20. this.setData({
  21. my_info: res.data
  22. })
  23. })
  24. },
  25. getBusinessCardList (type=0) {
  26. return UserApi.getVisitCardList(type).then(res => {
  27. let list = res.data.list
  28. this.origin_list = list
  29. let activeType = this.data.activeType
  30. let data = {}
  31. data[`business_${type}`] = list.map(item => {
  32. item.createTime = item.createTime.slice(0, 10)
  33. return item
  34. })
  35. if (activeType == type) {
  36. data.business_list = data[`business_${type}`]
  37. }
  38. this.setData(data)
  39. })
  40. },
  41. bindinput (e) {
  42. const value = e.detail
  43. let { business_0, business_1, activeType } = this.data
  44. let noData = false
  45. let business_list = business_0.filter(item => item.name.indexOf(value) > -1)
  46. activeType = 0
  47. if (business_list.length === 0) {
  48. business_list = business_1.filter(item => item.name.indexOf(value) > -1)
  49. if (business_list.length > 0) {
  50. activeType = 1
  51. }
  52. }
  53. if (business_list.length === 0 && value) {
  54. noData = true
  55. }
  56. this.setData({
  57. business_list,
  58. activeType,
  59. noData
  60. })
  61. },
  62. toBusinessCard (e) {
  63. const { id } = e.currentTarget.dataset
  64. Router.push({
  65. url: 'businessCardDetail',
  66. query: {
  67. id
  68. }
  69. })
  70. },
  71. toScan () {
  72. Router.push('scan')
  73. },
  74. callPhone (e) {
  75. const { phone } = e.currentTarget.dataset
  76. wx.makePhoneCall({
  77. phoneNumber: phone
  78. })
  79. },
  80. changeActiveType (e) {
  81. let { type } = e.currentTarget.dataset
  82. let obj = {
  83. activeType: type
  84. }
  85. obj.business_list = this.data[`business_${type}`]
  86. this.setData(obj)
  87. }
  88. }
  89. })