index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. "id": "2026031010523201",
  5. list: [],
  6. content: {
  7. isAll: false,
  8. nocache: true,
  9. pageNumber: 1,
  10. pageSize: 20,
  11. pageTotal: 1,
  12. where: {
  13. condition: ""
  14. }
  15. }
  16. },
  17. onLoad() {
  18. this.getList();
  19. },
  20. onShow() {
  21. if (this.data._loaded) {
  22. this.getList(true);
  23. }
  24. this.setData({ _loaded: true });
  25. },
  26. /* 获取门店列表 */
  27. getList(init = false) {
  28. if (init.detail != undefined) init = init.detail;
  29. if (init) {
  30. this.setData({
  31. 'content.pageNumber': 1
  32. });
  33. }
  34. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  35. this.setListHeight();
  36. _Http.basic({
  37. id: this.data.id,
  38. content: this.data.content
  39. }).then(res => {
  40. console.log("门店列表数据", res);
  41. this.selectComponent('#ListBox').RefreshToComplete();
  42. this.setData({
  43. 'content.pageNumber': res.pageNumber + 1,
  44. 'content.pageTotal': res.pageTotal,
  45. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  46. total: res.total
  47. });
  48. }).catch(err => {
  49. console.error("获取门店列表失败", err);
  50. this.selectComponent('#ListBox').RefreshToComplete();
  51. wx.showToast({
  52. title: '获取门店列表失败',
  53. icon: 'none'
  54. });
  55. });
  56. },
  57. /* 设置页面高度 */
  58. setListHeight() {
  59. this.selectComponent("#ListBox").setHeight(".header", this);
  60. },
  61. /* 搜索 */
  62. onSearch({ detail }) {
  63. this.setData({
  64. 'content.where.condition': detail
  65. });
  66. this.getList(true);
  67. },
  68. /* 跳转到详情页 */
  69. goToDetail(e) {
  70. const id = e.currentTarget.dataset.id;
  71. wx.navigateTo({
  72. url: `./detail?id=${id}`
  73. });
  74. },
  75. /* 跳转新建门店 */
  76. goToCreate() {
  77. wx.navigateTo({
  78. url: '/CRM/myStore/create'
  79. });
  80. },
  81. /* 编辑 */
  82. onEdit(e) {
  83. const item = e.currentTarget.dataset.item;
  84. _Http.detail = item;
  85. wx.navigateTo({
  86. url: '/CRM/myStore/create?edit=true'
  87. });
  88. },
  89. /* 启用申请 */
  90. onApplyEnable(e) {
  91. const item = e.currentTarget.dataset.item;
  92. wx.showModal({
  93. title: '门店启用申请',
  94. content: '确定要启用该门店吗?',
  95. success: (res) => {
  96. if (res.confirm) {
  97. _Http.basic({
  98. id: '2026031011291801',
  99. content: {
  100. shoplistid: item.sa_storeid,
  101. type: 'enable'
  102. }
  103. }).then(res => {
  104. if (res.code == 1) {
  105. wx.showToast({ title: '申请提交成功', icon: 'none' });
  106. this.getList(true);
  107. } else {
  108. wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
  109. }
  110. }).catch(() => {
  111. wx.showToast({ title: '网络错误', icon: 'none' });
  112. });
  113. }
  114. }
  115. });
  116. },
  117. /* 停用申请 */
  118. onApplyDisable(e) {
  119. const item = e.currentTarget.dataset.item;
  120. wx.showModal({
  121. title: '门店停用申请',
  122. content: '确定要停用该门店吗?',
  123. success: (res) => {
  124. if (res.confirm) {
  125. _Http.basic({
  126. id: '2026031011291801',
  127. content: {
  128. shoplistid: item.sa_storeid,
  129. type: 'disable'
  130. }
  131. }).then(res => {
  132. if (res.code == 1) {
  133. wx.showToast({ title: '申请提交成功', icon: 'none' });
  134. this.getList(true);
  135. } else {
  136. wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
  137. }
  138. }).catch(() => {
  139. wx.showToast({ title: '网络错误', icon: 'none' });
  140. });
  141. }
  142. }
  143. });
  144. },
  145. /* 删除 */
  146. onDelete(e) {
  147. const item = e.currentTarget.dataset.item;
  148. wx.showModal({
  149. title: '提示',
  150. content: '确定要删除该门店吗?',
  151. success: (res) => {
  152. if (res.confirm) {
  153. _Http.basic({
  154. id: '2026031013094201',
  155. content: {
  156. sa_storeid: item.sa_storeid
  157. }
  158. }).then(res => {
  159. if (res.code == 1) {
  160. wx.showToast({ title: '删除成功', icon: 'none' });
  161. this.getList(true);
  162. } else {
  163. wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
  164. }
  165. }).catch(() => {
  166. wx.showToast({ title: '网络错误', icon: 'none' });
  167. });
  168. }
  169. }
  170. });
  171. }
  172. });