index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. options: {
  4. addGlobalClass: true
  5. },
  6. data: {
  7. sys_enterpriseid: 0,
  8. list: [],
  9. radio: 0, //默认
  10. content: {
  11. "nacache": true,
  12. "pageNumber": 1,
  13. "pageSize": 15,
  14. "pageTotal": 1,
  15. "total": null,
  16. "where": {
  17. "condition": "",
  18. "workaddress": 1
  19. }
  20. }
  21. },
  22. methods: {
  23. /* 获取地址列表 */
  24. getList(id, init) {
  25. let content = this.data.content;
  26. content.sys_enterpriseid = id;
  27. if (init) {
  28. content.pageNumber = 1
  29. content.pageTotal = 1
  30. }
  31. _Http.basic({
  32. "id": "20221022165503",
  33. content
  34. }).then(res => {
  35. console.log("地址列表", res)
  36. if (res.msg != '成功') return wx.showToast({
  37. title: res.data,
  38. icon: "none"
  39. })
  40. this.setData({
  41. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  42. "content.pageNumber": res.pageNumber + 1,
  43. "content.pageSize": res.pageSize,
  44. "content.pageTotal": res.pageTotal,
  45. "content.total": res.total,
  46. sys_enterpriseid: id
  47. })
  48. let index = this.data.list.findIndex(v => v.isdefault == 1);
  49. this.setData({
  50. radio: index != -1 ? res.data[index].contactsid : 0
  51. })
  52. })
  53. },
  54. // 修改默认
  55. radioChange({
  56. detail
  57. }) {
  58. let list = this.data.list,
  59. index = list.findIndex(v => v.contactsid == detail)
  60. _Http.basic({
  61. "id": "20221018144702",
  62. "content": {
  63. "contactsid": list[index].contactsid,
  64. "sys_enterpriseid": list[index].sys_enterpriseid
  65. }
  66. }, false).then(res => {
  67. if (res.msg != '成功') return wx.showToast({
  68. title: res.data,
  69. icon: "none"
  70. });
  71. list = list.map((v, i) => {
  72. v.isdefault = i == index ? 1 : 0
  73. return v
  74. })
  75. this.setData({
  76. list
  77. })
  78. console.log(list)
  79. })
  80. },
  81. //处理操作
  82. handleItem(e) {
  83. const {
  84. name,
  85. item
  86. } = e.target.dataset,
  87. that = this;
  88. if (!name) return;
  89. switch (name) {
  90. case 'copy':
  91. let str = `收货人:${item.name}\n手机号码:${item.phonenumber}\n所在地区:${item.province+item.city+item.county}\n详细地址:${item.province+item.city+item.county+item.address}`
  92. wx.setClipboardData({
  93. data: str,
  94. })
  95. break;
  96. case 'edit':
  97. wx.navigateTo({
  98. url: '/packageA/setclient/modules/address/add/index?data=' + JSON.stringify(item),
  99. })
  100. break;
  101. case 'delete':
  102. wx.showModal({
  103. title: '提示',
  104. content: `是否确认删除"${item.name}"`,
  105. complete: (res) => {
  106. if (res.confirm) {
  107. _Http.basic({
  108. "id": "20221018145502",
  109. "content": {
  110. "contactsid": item.contactsid,
  111. "sys_enterpriseid": item.sys_enterpriseid
  112. }
  113. }).then(res => {
  114. console.log("删除地址", res)
  115. if (res.msg != '成功') return wx.showToast({
  116. title: res.data,
  117. icon: "none"
  118. });
  119. wx.showToast({
  120. title: `删除成功!`,
  121. icon: "none"
  122. })
  123. that.setData({
  124. list: that.data.list.filter(v => v.contactsid != item.contactsid),
  125. "content.total": that.data.content.total - 1
  126. });
  127. })
  128. }
  129. }
  130. })
  131. break;
  132. }
  133. }
  134. }
  135. })