dispatch.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. var dispatchIndex = new Vue({
  5. el: "#dispatchIndex",
  6. data() {
  7. return {
  8. dispatchData: [],
  9. isData: false,
  10. activeName: "express",
  11. limit: 10,
  12. offset: 0,
  13. currentPage: 1,
  14. totalPage: 0,
  15. }
  16. },
  17. mounted() {
  18. this.getData();
  19. },
  20. methods: {
  21. getData() {
  22. let that = this;
  23. that.isData = false;
  24. Fast.api.ajax({
  25. url: 'shopro/dispatch/' + that.activeName + '/index',
  26. loading: true,
  27. type: 'GET',
  28. data: {
  29. limit: that.limit,
  30. offset: that.offset,
  31. }
  32. }, function (ret, res) {
  33. that.dispatchData = res.data.rows;
  34. if (that.dispatchData.length == 0) {
  35. that.isData = true
  36. }
  37. that.totalPage = res.data.total
  38. return false;
  39. })
  40. },
  41. tabClick(tab, event) {
  42. this.dispatchData=[];
  43. this.isData = false;
  44. this.activeName = tab.name;
  45. this.limit = 10;
  46. this.offset = 0;
  47. this.currentPage = 1;
  48. this.getData();
  49. },
  50. operation(opttype, id, idx, type) {
  51. let that = this;
  52. switch (opttype) {
  53. case 'delete':
  54. that.$confirm('此操作将删除模板, 是否继续?', '提示', {
  55. confirmButtonText: '确定',
  56. cancelButtonText: '取消',
  57. type: 'warning'
  58. }).then(() => {
  59. Fast.api.ajax({
  60. url: 'shopro/dispatch/' + type + '/del/ids/' + id,
  61. loading: true,
  62. type: 'POST',
  63. }, function (ret, res) {
  64. that.getData();
  65. })
  66. }).catch(() => {
  67. that.$message({
  68. type: 'info',
  69. message: '已取消删除'
  70. });
  71. });
  72. break;
  73. case 'create':
  74. Fast.api.open("shopro/dispatch/" + type + "/add", "创建模板", {
  75. callback(data) {
  76. if (data.data) {
  77. that.getData();
  78. }
  79. }
  80. });
  81. break;
  82. case 'edit':
  83. Fast.api.open("shopro/dispatch/" + type + "/edit?ids=" + id, "编辑模板", {
  84. callback(data) {
  85. if (data.data) {
  86. that.getData();
  87. }
  88. }
  89. });
  90. break;
  91. case 'recycle':
  92. Fast.api.open('shopro/dispatch/' + type + '/recyclebin', '查看回收站')
  93. break;
  94. }
  95. },
  96. pageSizeChange(val) {
  97. this.limit = val;
  98. this.offset = 0;
  99. this.getData();
  100. },
  101. pageCurrentChange(val) {
  102. this.offset = (val - 1) * 10,
  103. this.limit = 10
  104. this.getData();
  105. },
  106. tableRowClassName({
  107. rowIndex
  108. }) {
  109. if (rowIndex % 2 == 1) {
  110. return 'bg-color';
  111. }
  112. return '';
  113. },
  114. tableCellClassName({
  115. columnIndex
  116. }) {
  117. if (columnIndex == 0) {
  118. return 'cell-left';
  119. } else if (columnIndex == 4) {
  120. return 'border-right';
  121. }
  122. return '';
  123. },
  124. tableCellClassName2({
  125. columnIndex
  126. }) {
  127. if (columnIndex == 1 || columnIndex == 2) {
  128. return 'cell-left';
  129. } else if (columnIndex == 4) {
  130. return 'cell-left border-right';
  131. }
  132. return '';
  133. },
  134. },
  135. })
  136. },
  137. recyclebin: function () {
  138. // 初始化表格参数配置
  139. Table.api.init({
  140. extend: {
  141. 'dragsort_url': ''
  142. }
  143. });
  144. var table = $("#table");
  145. // 初始化表格
  146. table.bootstrapTable({
  147. url: 'shopro/dispatch/dispatch/recyclebin' + location.search,
  148. pk: 'id',
  149. sortName: 'id',
  150. columns: [
  151. [{
  152. checkbox: true
  153. },
  154. {
  155. field: 'id',
  156. title: __('Id')
  157. },
  158. {
  159. field: 'name',
  160. title: __('Name'),
  161. align: 'left'
  162. },
  163. {
  164. field: 'deletetime',
  165. title: __('Deletetime'),
  166. operate: 'RANGE',
  167. addclass: 'datetimerange',
  168. formatter: Table.api.formatter.datetime
  169. },
  170. {
  171. field: 'operate',
  172. width: '130px',
  173. title: __('Operate'),
  174. table: table,
  175. events: Table.api.events.operate,
  176. buttons: [{
  177. name: 'Restore',
  178. text: __('Restore'),
  179. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  180. icon: 'fa fa-rotate-left',
  181. url: 'shopro/dispatch/dispatch/restore',
  182. refresh: true
  183. },
  184. {
  185. name: 'Destroy',
  186. text: __('Destroy'),
  187. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  188. icon: 'fa fa-times',
  189. url: 'shopro/dispatch/dispatch/destroy',
  190. refresh: true
  191. }
  192. ],
  193. formatter: Table.api.formatter.operate
  194. }
  195. ]
  196. ]
  197. });
  198. // 为表格绑定事件
  199. Table.api.bindevent(table);
  200. },
  201. add: function () {
  202. },
  203. edit: function () {
  204. Controller.api.bindevent();
  205. },
  206. api: {
  207. bindevent: function () {
  208. Form.api.bindevent($("form[role=form]"));
  209. }
  210. }
  211. };
  212. return Controller;
  213. });