express.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. keyword: { field: 'name', value: '' },
  16. },
  17. tools: {
  18. keyword: {
  19. type: 'tinputprepend',
  20. label: '查询内容',
  21. placeholder: '请输入查询内容',
  22. value: {
  23. field: 'name',
  24. value: '',
  25. },
  26. options: {
  27. data: [{
  28. label: '快递公司',
  29. value: 'name',
  30. },
  31. {
  32. label: '快递编码',
  33. value: 'code',
  34. }]
  35. }
  36. },
  37. },
  38. condition: {},
  39. }
  40. })
  41. function getData() {
  42. let tempSearch = JSON.parse(JSON.stringify(state.filter.data));
  43. let search = composeFilter(tempSearch, {
  44. name: 'like',
  45. code: 'like',
  46. });
  47. Fast.api.ajax({
  48. url: 'shopro/data/express',
  49. type: 'GET',
  50. data: {
  51. page: pagination.page,
  52. list_rows: pagination.list_rows,
  53. order: state.order,
  54. sort: state.sort,
  55. ...search,
  56. },
  57. }, function (ret, res) {
  58. state.data = res.data.data
  59. pagination.total = res.data.total
  60. return false
  61. }, function (ret, res) { })
  62. }
  63. function onChangeSort({ prop, order }) {
  64. state.order = order == 'ascending' ? 'asc' : 'desc';
  65. state.sort = prop;
  66. getData();
  67. }
  68. function onOpenFilter() {
  69. state.filter.drawer = true
  70. }
  71. function onChangeFilter() {
  72. pagination.page = 1
  73. getData()
  74. state.filter.drawer && (state.filter.drawer = false)
  75. }
  76. const pagination = reactive({
  77. page: 1,
  78. list_rows: 10,
  79. total: 0,
  80. })
  81. const batchHandle = reactive({
  82. data: [],
  83. })
  84. function onChangeSelection(val) {
  85. batchHandle.data = val
  86. }
  87. function onBatchHandle(type) {
  88. let ids = []
  89. batchHandle.data.forEach((item) => {
  90. ids.push(item.id)
  91. })
  92. switch (type) {
  93. case 'delete':
  94. ElMessageBox.confirm('此操作将删除, 是否继续?', '提示', {
  95. confirmButtonText: '确定',
  96. cancelButtonText: '取消',
  97. type: 'warning',
  98. }).then(() => {
  99. onDelete(ids.join(','))
  100. });
  101. break;
  102. }
  103. }
  104. function onAdd() {
  105. Fast.api.open("shopro/data/express/add?type=add", "添加", {
  106. callback() {
  107. getData()
  108. }
  109. })
  110. }
  111. function onEdit(id) {
  112. Fast.api.open(`shopro/data/express/edit?type=edit&id=${id}`, "编辑", {
  113. callback() {
  114. getData()
  115. }
  116. })
  117. }
  118. function onDelete(id) {
  119. Fast.api.ajax({
  120. url: `shopro/data/express/delete/id/${id}`,
  121. type: 'DELETE',
  122. }, function (ret, res) {
  123. getData()
  124. }, function (ret, res) { })
  125. }
  126. onMounted(() => {
  127. getData()
  128. })
  129. return {
  130. state,
  131. getData,
  132. onChangeSort,
  133. onOpenFilter,
  134. onChangeFilter,
  135. pagination,
  136. batchHandle,
  137. onChangeSelection,
  138. onBatchHandle,
  139. onAdd,
  140. onEdit,
  141. onDelete
  142. }
  143. }
  144. }
  145. createApp('index', index);
  146. },
  147. add: () => {
  148. Controller.form();
  149. },
  150. edit: () => {
  151. Controller.form();
  152. },
  153. form: () => {
  154. const { reactive, onMounted, getCurrentInstance } = Vue
  155. const addEdit = {
  156. setup() {
  157. const { proxy } = getCurrentInstance();
  158. const state = reactive({
  159. type: new URLSearchParams(location.search).get('type'),
  160. id: new URLSearchParams(location.search).get('id')
  161. })
  162. const form = reactive({
  163. model: {
  164. name: '',
  165. code: '',
  166. weigh: 0,
  167. },
  168. rules: {
  169. name: [{ required: true, message: '请输入快递公司', trigger: 'blur' }],
  170. code: [{ required: true, message: '请输入快递编码', trigger: 'blur' }],
  171. weigh: [{ required: true, message: '请输入权重', trigger: 'blur' }],
  172. },
  173. })
  174. function getDetail() {
  175. Fast.api.ajax({
  176. url: `shopro/data/express/detail/id/${state.id}`,
  177. type: 'GET',
  178. }, function (ret, res) {
  179. form.model = res.data;
  180. return false
  181. }, function (ret, res) { })
  182. }
  183. function onConfirm() {
  184. proxy.$refs['formRef'].validate((valid) => {
  185. if (valid) {
  186. Fast.api.ajax({
  187. url: state.type == 'add' ? 'shopro/data/express/add' : `shopro/data/express/edit/id/${state.id}`,
  188. type: 'POST',
  189. data: form.model,
  190. }, function (ret, res) {
  191. Fast.api.close()
  192. }, function (ret, res) { })
  193. }
  194. });
  195. }
  196. onMounted(() => {
  197. state.type == 'edit' && getDetail()
  198. })
  199. return {
  200. state,
  201. form,
  202. onConfirm
  203. }
  204. }
  205. }
  206. createApp('addEdit', addEdit);
  207. }
  208. };
  209. return Controller;
  210. });