index.js 4.8 KB

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