index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. options: {
  4. addGlobalClass: true
  5. },
  6. properties: {
  7. list: Array
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. radio: 0, //默认
  14. },
  15. /**
  16. * 组件的方法列表
  17. */
  18. methods: {
  19. // 修改默认
  20. radioChange({
  21. detail
  22. }) {
  23. let list = this.data.list,
  24. data = list.find(v => v.contactsid == detail)
  25. _Http.basic({
  26. "id": "20221018144702",
  27. "content": {
  28. "contactsid": data.contactsid,
  29. "sys_enterpriseid": data.sys_enterpriseid
  30. }
  31. }, false).then(res => {
  32. if (res.msg != '成功') return wx.showToast({
  33. title: res.data,
  34. icon: "none"
  35. });
  36. list = list.map((v, i) => {
  37. v.isdefault = v.contactsid == data.contactsid ? 1 : 0
  38. return v
  39. })
  40. this.setData({
  41. list
  42. })
  43. console.log(list)
  44. })
  45. }, //处理操作
  46. handleItem(e) {
  47. const {
  48. name,
  49. item
  50. } = e.target.dataset,
  51. that = this;
  52. if (!name) return;
  53. switch (name) {
  54. case 'copy':
  55. let str = `联系人:${item.name}\n手机号码:${item.phonenumber}\n所在地区:${item.province+item.city+item.county}\n详细地址:${item.province+item.city+item.county+item.address}`
  56. wx.setClipboardData({
  57. data: str,
  58. })
  59. break;
  60. case 'edit':
  61. wx.navigateTo({
  62. url: '/packageA/setclient/modules/address/add/index?data=' + JSON.stringify(item),
  63. })
  64. break;
  65. case 'delete':
  66. wx.showModal({
  67. title: '提示',
  68. content: `是否确认删除"${item.name}"`,
  69. complete: (res) => {
  70. if (res.confirm) {
  71. _Http.basic({
  72. "id": "20221018145502",
  73. "content": {
  74. "contactsid": item.contactsid,
  75. "sys_enterpriseid": item.sys_enterpriseid
  76. }
  77. }).then(res => {
  78. console.log("删除地址", res)
  79. if (res.msg != '成功') return wx.showToast({
  80. title: res.data,
  81. icon: "none"
  82. });
  83. wx.showToast({
  84. title: `删除成功!`,
  85. icon: "none"
  86. })
  87. that.setData({
  88. list: that.data.list.filter(v => v.contactsid != item.contactsid),
  89. "content.total": that.data.content.total - 1
  90. });
  91. })
  92. }
  93. }
  94. })
  95. break;
  96. }
  97. },
  98. initRadio() {
  99. let data = this.data.list.find(v => v.isdefault == 1);
  100. this.setData({
  101. radio: data ? data.contactsid : 0
  102. })
  103. },
  104. }
  105. })