index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. options: {
  4. addGlobalClass: true
  5. },
  6. properties: {
  7. list: {
  8. type: Array
  9. },
  10. changeTotal: {
  11. type: Function
  12. },
  13. disabled: {
  14. type: Boolean
  15. },
  16. type: {
  17. type: String
  18. }
  19. },
  20. data: {
  21. radio: 0, //默认
  22. },
  23. methods: {
  24. // 修改默认
  25. radioChange({
  26. detail
  27. }) {
  28. let list = this.data.list,
  29. data = list.find(v => v.contactsid == detail)
  30. _Http.basic({
  31. "id": "20221018144702",
  32. "content": {
  33. "contactsid": data.contactsid,
  34. "sys_enterpriseid": data.sys_enterpriseid
  35. }
  36. }, false).then(res => {
  37. if (res.msg != '成功') return wx.showToast({
  38. title: res.data,
  39. icon: "none"
  40. });
  41. getCurrentPages().forEach(v => {
  42. //更新列表
  43. if (["packageA/setclient/detail", "packageA/setclient/modules/contacts/detail/index"].includes(v.__route__)) {
  44. let page = v.selectComponent("#Address").selectComponent("#List");
  45. const lists = page.data.list.map(value => {
  46. value.isdefault = value.contactsid == data.contactsid ? 1 : 0
  47. return value
  48. });
  49. page.setData({
  50. list: lists
  51. })
  52. setTimeout(() => {
  53. page.initRadio();
  54. }, 200)
  55. };
  56. if (["packageA/setclient/modules/address/search/index"].includes(v.__route__)) {
  57. let page = v.selectComponent("#List");
  58. const lists = page.data.list.map(value => {
  59. value.isdefault = value.contactsid == data.contactsid ? 1 : 0
  60. return value
  61. });
  62. page.setData({
  63. list: lists
  64. })
  65. setTimeout(() => {
  66. page.initRadio();
  67. }, 200)
  68. };
  69. })
  70. })
  71. }, //处理操作
  72. handleItem(e) {
  73. const {
  74. name,
  75. item
  76. } = e.target.dataset,
  77. that = this;
  78. if (!name) return;
  79. switch (name) {
  80. case 'call':
  81. wx.makePhoneCall({
  82. phoneNumber: item.phonenumber,
  83. })
  84. break;
  85. case 'copy':
  86. let str = `联系人:${item.name}\n手机号码:${item.phonenumber}\n所在地区:${item.province+item.city+item.county}\n详细地址:${item.province+item.city+item.county+item.address}`
  87. wx.setClipboardData({
  88. data: str,
  89. })
  90. break;
  91. case 'edit':
  92. wx.navigateTo({
  93. url: '/packageA/setclient/modules/address/add/index?data=' + JSON.stringify(item) + '&type=' + this.data.type,
  94. })
  95. break;
  96. case 'delete':
  97. wx.showModal({
  98. title: '提示',
  99. content: `是否确认删除"${item.name}"`,
  100. complete: (res) => {
  101. if (res.confirm) {
  102. _Http.basic({
  103. "id": "20221018145502",
  104. "content": {
  105. "contactsid": item.contactsid,
  106. "sys_enterpriseid": item.sys_enterpriseid
  107. }
  108. }).then(res => {
  109. console.log("删除地址", res)
  110. if (res.msg != '成功') return wx.showToast({
  111. title: res.data,
  112. icon: "none"
  113. });
  114. wx.showToast({
  115. title: `删除成功!`,
  116. icon: "none"
  117. });
  118. getCurrentPages().forEach(v => {
  119. if (v.__route__ == "packageA/setclient/detail" || v.__route__ == "packageA/opponent/detail" || v.__route__ == "packageA/publicCustomer/detail") {
  120. let model = v.selectComponent("#Address");
  121. model.setData({
  122. list: model.data.list.filter(value => value.contactsid != item.contactsid)
  123. });
  124. model.changeTotal();
  125. } else if (v.__route__ == "packageA/setclient/modules/address/search/index") {
  126. v.setData({
  127. list: v.data.list.filter(value => value.contactsid != item.contactsid)
  128. });
  129. }
  130. })
  131. })
  132. }
  133. }
  134. })
  135. break;
  136. }
  137. },
  138. initRadio() {
  139. let data = this.data.list.find(v => v.isdefault == 1);
  140. this.setData({
  141. radio: data ? data.contactsid : 0
  142. })
  143. },
  144. }
  145. })