express.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. function debounce(handle, delay) {
  5. let time = null;
  6. return function () {
  7. let self = this,
  8. arg = arguments;
  9. clearTimeout(time);
  10. time = setTimeout(function () {
  11. handle.apply(self, arg);
  12. }, delay)
  13. }
  14. }
  15. var companyIndex = new Vue({
  16. el: "#companyIndex",
  17. data() {
  18. return {
  19. indexData: [],
  20. searchKey: '',
  21. offset: 0,
  22. limit: 10,
  23. totalPage: 0,
  24. currentPage: 1,
  25. isAjax:false,
  26. }
  27. },
  28. created() {
  29. this.getData();
  30. },
  31. methods: {
  32. getData() {
  33. let that = this;
  34. that.isAjax=true
  35. Fast.api.ajax({
  36. url: 'shopro/express/index',
  37. loading: false,
  38. type: 'GET',
  39. data: {
  40. searchWhere: that.searchKey,
  41. offset: that.offset,
  42. limit: that.limit,
  43. }
  44. }, function (ret, res) {
  45. that.indexData = res.data.rows;
  46. that.totalPage = res.data.total;
  47. that.isAjax=false
  48. return false;
  49. }, function (ret, res) {
  50. that.isAjax=false;
  51. })
  52. },
  53. operation(type, id) {
  54. let that = this;
  55. switch (type) {
  56. case 'create':
  57. Fast.api.open("shopro/express/add", "新建", {
  58. callback(data) {
  59. if(data.data){
  60. that.getData();
  61. }
  62. }
  63. });
  64. break;
  65. case 'edit':
  66. parent.Fast.api.open("shopro/express/edit?ids=" + id, "编辑", {
  67. callback: function (data) {
  68. if(data.data){
  69. that.getData();
  70. }
  71. }
  72. });
  73. break;
  74. case 'del':
  75. let ids;
  76. if (id) {
  77. ids = id;
  78. } else {
  79. let idArr = []
  80. if (that.multipleSelection.length > 0) {
  81. that.multipleSelection.forEach(i => {
  82. idArr.push(i.id)
  83. })
  84. ids = idArr.join(',')
  85. }
  86. }
  87. if (ids) {
  88. that.$confirm('此操作将删除快递公司, 是否继续?', '提示', {
  89. confirmButtonText: '确定',
  90. cancelButtonText: '取消',
  91. type: 'warning'
  92. }).then(() => {
  93. Fast.api.ajax({
  94. url: 'shopro/express/del/ids/' + ids,
  95. loading: true,
  96. type: 'POST',
  97. }, function (ret, res) {
  98. that.getData();
  99. return false;
  100. })
  101. }).catch(() => {
  102. that.$message({
  103. type: 'info',
  104. message: '已取消删除'
  105. });
  106. });
  107. }
  108. break;
  109. case 'recycle':
  110. Fast.api.open('shopro/express/recyclebin', '查看回收站')
  111. break;
  112. }
  113. },
  114. handleSizeChange(val) {
  115. this.offset = 0
  116. this.limit = val;
  117. this.currentPage = 1;
  118. this.getData()
  119. },
  120. handleCurrentChange(val) {
  121. this.currentPage = val;
  122. this.offset = (val - 1) * this.limit;
  123. this.getData()
  124. },
  125. tableRowClassName({
  126. rowIndex
  127. }) {
  128. if (rowIndex % 2 == 1) {
  129. return 'bg-color';
  130. }
  131. return '';
  132. },
  133. tableCellClassName({
  134. columnIndex
  135. }) {
  136. if (columnIndex == 1 || columnIndex == 4) {
  137. return 'cell-left';
  138. }
  139. return '';
  140. },
  141. debounceFilter: debounce(function () {
  142. this.getData()
  143. }, 1000),
  144. },
  145. watch: {
  146. searchKey(newVal, oldVal) {
  147. if (newVal != oldVal) {
  148. this.offset = 0;
  149. this.limit = 10;
  150. this.currentPage = 1;
  151. this.debounceFilter();
  152. }
  153. },
  154. },
  155. })
  156. },
  157. add: function () {
  158. Controller.detailInit('add');
  159. },
  160. edit: function () {
  161. Controller.detailInit('edit');
  162. },
  163. detailInit: function (type) {
  164. function urlParmas(par) {
  165. let value = ""
  166. window.location.search.replace("?", '').split("&").forEach(i => {
  167. if (i.split('=')[0] == par) {
  168. value = JSON.parse(decodeURI(i.split('=')[1]))
  169. }
  170. })
  171. return value
  172. }
  173. var detailInit = new Vue({
  174. el: "#detailInit",
  175. data() {
  176. return {
  177. optType: type,
  178. id: urlParmas('ids'),
  179. detailForm: {},
  180. detailFormInit: {
  181. name: '',
  182. code: '',
  183. weigh: ''
  184. },
  185. rules: {
  186. name: [{
  187. required: true,
  188. message: '请输入快递公司',
  189. trigger: 'blur'
  190. }],
  191. code: [{
  192. required: true,
  193. message: '请输入快递编号',
  194. trigger: 'blur'
  195. }],
  196. }
  197. }
  198. },
  199. created() {
  200. this.detailForm = JSON.parse(JSON.stringify(this.detailFormInit));
  201. if (this.optType == 'edit') {
  202. for(key in this.detailForm){
  203. this.detailForm[key]=Config.row[key]
  204. }
  205. }
  206. },
  207. methods: {
  208. getdetailForm() {
  209. let that = this;
  210. Fast.api.ajax({
  211. url: 'shopro/express/edit/ids/' + that.id,
  212. loading: true,
  213. }, function (ret, res) {
  214. that.detailForm = res.data
  215. return false;
  216. })
  217. },
  218. submitForm(type, formName) {
  219. let that = this;
  220. if (type) {
  221. this.$refs[formName].validate((valid) => {
  222. if (valid) {
  223. let formData = JSON.stringify(that.detailForm);
  224. if (that.optType == 'edit') {
  225. Fast.api.ajax({
  226. url: 'shopro/express/edit/ids/' + that.id,
  227. loading: true,
  228. data: {
  229. data:formData
  230. }
  231. }, function (ret, res) {
  232. Fast.api.close({data:true});
  233. })
  234. } else {
  235. Fast.api.ajax({
  236. url: 'shopro/express/add',
  237. loading: true,
  238. data: {
  239. data:formData
  240. }
  241. }, function (ret, res) {
  242. Fast.api.close({data:true});
  243. })
  244. }
  245. } else {
  246. return false;
  247. }
  248. });
  249. } else {
  250. Fast.api.close({data:false});
  251. }
  252. },
  253. },
  254. })
  255. },
  256. api: {
  257. bindevent: function () {
  258. Form.api.bindevent($("form[role=form]"));
  259. }
  260. }
  261. };
  262. return Controller;
  263. });