user.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const { ElMessageBox } = ElementPlus
  6. const index = {
  7. setup() {
  8. const state = reactive({
  9. data: [],
  10. order: '',
  11. sort: '',
  12. filter: {
  13. drawer: false,
  14. data: {
  15. user: { field: 'id', value: '' },
  16. },
  17. tools: {
  18. user: {
  19. type: 'tinputprepend',
  20. label: '查询内容',
  21. placeholder: '请输入查询内容',
  22. value: {
  23. field: 'id',
  24. value: '',
  25. },
  26. options: {
  27. data: [{
  28. label: 'ID',
  29. value: 'id',
  30. },
  31. {
  32. label: '昵称',
  33. value: 'nickname',
  34. },
  35. {
  36. label: '手机号',
  37. value: 'user.mobile',
  38. }],
  39. }
  40. },
  41. },
  42. condition: {},
  43. }
  44. })
  45. function getData() {
  46. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  47. let search = composeFilter(tempSearch, {
  48. nickname: 'like',
  49. 'user.mobile': 'like',
  50. });
  51. Fast.api.ajax({
  52. url: 'shopro/chat/user',
  53. type: 'GET',
  54. data: {
  55. page: pagination.page,
  56. list_rows: pagination.list_rows,
  57. order: state.order,
  58. sort: state.sort,
  59. ...search,
  60. },
  61. }, function (ret, res) {
  62. state.data = res.data.data
  63. pagination.total = res.data.total
  64. return false
  65. }, function (ret, res) { })
  66. }
  67. function onChangeSort({ prop, order }) {
  68. state.order = order == 'ascending' ? 'asc' : 'desc';
  69. state.sort = prop;
  70. getData();
  71. }
  72. function onOpenFilter() {
  73. state.filter.drawer = true
  74. }
  75. function onChangeFilter() {
  76. pagination.page = 1
  77. getData()
  78. state.filter.drawer && (state.filter.drawer = false)
  79. }
  80. const pagination = reactive({
  81. page: 1,
  82. list_rows: 10,
  83. total: 0,
  84. })
  85. const batchHandle = reactive({
  86. data: [],
  87. })
  88. function onChangeSelection(val) {
  89. batchHandle.data = val
  90. }
  91. function onBatchHandle(type) {
  92. let ids = []
  93. batchHandle.data.forEach((item) => {
  94. ids.push(item.id)
  95. })
  96. switch (type) {
  97. case 'delete':
  98. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  99. confirmButtonText: '确定',
  100. cancelButtonText: '取消',
  101. type: 'warning',
  102. }).then(() => {
  103. onDelete(ids.join(','))
  104. });
  105. break;
  106. }
  107. }
  108. function onRecord(item) {
  109. Fast.api.open(`shopro/chat/record/index?id=${item.id}&nickname=${item.nickname}`, "聊天记录", {
  110. callback() {
  111. getData()
  112. }
  113. })
  114. }
  115. function onDelete(id) {
  116. Fast.api.ajax({
  117. url: `shopro/chat/user/delete/id/${id}`,
  118. type: 'DELETE',
  119. }, function (ret, res) {
  120. getData()
  121. }, function (ret, res) { })
  122. }
  123. onMounted(() => {
  124. getData()
  125. })
  126. return {
  127. Fast,
  128. state,
  129. getData,
  130. onChangeSort,
  131. onOpenFilter,
  132. onChangeFilter,
  133. pagination,
  134. batchHandle,
  135. onChangeSelection,
  136. onBatchHandle,
  137. onRecord,
  138. onDelete
  139. }
  140. }
  141. }
  142. createApp('index', index);
  143. },
  144. };
  145. return Controller;
  146. });