service.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. })
  13. function getData() {
  14. Fast.api.ajax({
  15. url: 'shopro/goods/service',
  16. type: 'GET',
  17. data: {
  18. page: pagination.page,
  19. list_rows: pagination.list_rows,
  20. order: state.order,
  21. sort: state.sort,
  22. },
  23. }, function (ret, res) {
  24. state.data = res.data.data
  25. pagination.total = res.data.total
  26. return false
  27. }, function (ret, res) { })
  28. }
  29. function onChangeSort({ prop, order }) {
  30. state.order = order == 'ascending' ? 'asc' : 'desc';
  31. state.sort = prop;
  32. getData();
  33. }
  34. const pagination = reactive({
  35. page: 1,
  36. list_rows: 10,
  37. total: 0,
  38. })
  39. const batchHandle = reactive({
  40. data: [],
  41. })
  42. function onChangeSelection(val) {
  43. batchHandle.data = val
  44. }
  45. function onBatchHandle(type) {
  46. let ids = []
  47. batchHandle.data.forEach((item) => {
  48. ids.push(item.id)
  49. })
  50. switch (type) {
  51. case 'delete':
  52. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  53. confirmButtonText: '确定',
  54. cancelButtonText: '取消',
  55. type: 'warning',
  56. }).then(() => {
  57. onDelete(ids.join(','))
  58. });
  59. break;
  60. }
  61. }
  62. function onAdd() {
  63. Fast.api.open("shopro/goods/service/add?type=add", "添加", {
  64. callback() {
  65. getData()
  66. }
  67. })
  68. }
  69. function onEdit(id) {
  70. Fast.api.open(`shopro/goods/service/edit?type=edit&id=${id}`, "编辑", {
  71. callback() {
  72. getData()
  73. }
  74. })
  75. }
  76. function onDelete(id) {
  77. Fast.api.ajax({
  78. url: `shopro/goods/service/delete/id/${id}`,
  79. type: 'DELETE',
  80. }, function (ret, res) {
  81. getData()
  82. }, function (ret, res) { })
  83. }
  84. onMounted(() => {
  85. getData()
  86. })
  87. return {
  88. state,
  89. getData,
  90. onChangeSort,
  91. pagination,
  92. batchHandle,
  93. onChangeSelection,
  94. onBatchHandle,
  95. onAdd,
  96. onEdit,
  97. onDelete
  98. }
  99. }
  100. }
  101. createApp('index', index);
  102. },
  103. add: () => {
  104. Controller.form();
  105. },
  106. edit: () => {
  107. Controller.form();
  108. },
  109. form: () => {
  110. const { reactive, onMounted, getCurrentInstance } = Vue
  111. const addEdit = {
  112. setup() {
  113. const { proxy } = getCurrentInstance();
  114. const state = reactive({
  115. type: new URLSearchParams(location.search).get('type'),
  116. id: new URLSearchParams(location.search).get('id')
  117. })
  118. const form = reactive({
  119. model: {
  120. name: '',
  121. image: '',
  122. description: '',
  123. },
  124. rules: {
  125. name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  126. },
  127. })
  128. function getDetail() {
  129. Fast.api.ajax({
  130. url: `shopro/goods/service/detail/id/${state.id}`,
  131. type: 'GET',
  132. }, function (ret, res) {
  133. form.model = res.data;
  134. return false
  135. }, function (ret, res) { })
  136. }
  137. function onConfirm() {
  138. proxy.$refs['formRef'].validate((valid) => {
  139. if (valid) {
  140. Fast.api.ajax({
  141. url: state.type == 'add' ? 'shopro/goods/service/add' : `shopro/goods/service/edit/id/${state.id}`,
  142. type: 'POST',
  143. data: form.model,
  144. }, function (ret, res) {
  145. Fast.api.close()
  146. }, function (ret, res) { })
  147. }
  148. });
  149. }
  150. onMounted(() => {
  151. state.type == 'edit' && getDetail()
  152. })
  153. return {
  154. state,
  155. form,
  156. onConfirm
  157. }
  158. }
  159. }
  160. createApp('addEdit', addEdit);
  161. }
  162. };
  163. return Controller;
  164. });