express.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'toastr'], function ($, undefined, Backend, Table, Form, Toastr) {
  2. var Controller = {
  3. index: function () {},
  4. recyclebin: function () {
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. 'dragsort_url': ''
  9. }
  10. });
  11. var table = $("#table");
  12. // 初始化表格
  13. table.bootstrapTable({
  14. url: 'shopro/dispatch/express/recyclebin' + location.search,
  15. pk: 'id',
  16. sortName: 'deletetime',
  17. columns: [
  18. [{
  19. checkbox: true
  20. },
  21. {
  22. field: 'id',
  23. title: __('Id')
  24. },
  25. {
  26. field: 'name',
  27. title: __('Title'),
  28. align: 'left'
  29. },
  30. {
  31. field: 'deletetime',
  32. title: __('Deletetime'),
  33. operate: 'RANGE',
  34. addclass: 'datetimerange',
  35. formatter: Table.api.formatter.datetime
  36. },
  37. {
  38. field: 'operate',
  39. width: '130px',
  40. title: __('Operate'),
  41. table: table,
  42. events: Table.api.events.operate,
  43. buttons: [{
  44. name: 'Restore',
  45. text: __('Restore'),
  46. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  47. icon: 'fa fa-rotate-left',
  48. url: 'shopro/dispatch/express/restore',
  49. refresh: true
  50. },
  51. {
  52. name: 'Destroy',
  53. text: __('Destroy'),
  54. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  55. icon: 'fa fa-times',
  56. url: 'shopro/dispatch/express/destroy',
  57. refresh: true
  58. }
  59. ],
  60. formatter: Table.api.formatter.operate
  61. }
  62. ]
  63. ]
  64. });
  65. // 为表格绑定事件
  66. Table.api.bindevent(table);
  67. },
  68. add: function () {
  69. Controller.detailInit('add');
  70. },
  71. edit: function () {
  72. Controller.detailInit('edit');
  73. },
  74. detailInit: function (type) {
  75. // 大于0的数、最多两位小数
  76. Vue.directive('enterNumber', {
  77. inserted: function (el) {
  78. let changeValue = (el, type) => {
  79. const e = document.createEvent('HTMLEvents')
  80. e.initEvent(type, true, true)
  81. el.dispatchEvent(e)
  82. }
  83. el.addEventListener("keyup", function (e) {
  84. let input = e.target;
  85. let reg = new RegExp('^((?:(?:[1-9]{1}\\d*)|(?:[0]{1}))(?:\\.(?:\\d){0,2})?)(?:\\d*)?$');
  86. let matchRes = input.value.match(reg);
  87. if (matchRes === null) {
  88. input.value = "";
  89. } else {
  90. if (matchRes[1] !== matchRes[0]) {
  91. input.value = matchRes[1];
  92. }
  93. }
  94. changeValue(input, 'input')
  95. });
  96. }
  97. });
  98. var dispatchDetail = new Vue({
  99. el: "#dispatchDetail",
  100. data() {
  101. return {
  102. optType: type,
  103. dispatchForm: {},
  104. rules: {
  105. name: [{
  106. required: true,
  107. message: '请输入模板名称',
  108. trigger: 'blur'
  109. }],
  110. type: [{
  111. required: true,
  112. message: '请选择计价方式',
  113. trigger: 'change'
  114. }],
  115. },
  116. dispatchFormInit: {
  117. name: '',
  118. type: 'number',
  119. express: [{
  120. first_num: 0,
  121. first_price: 0.00,
  122. additional_num: 0,
  123. additional_price: 0.00,
  124. area_text: '',
  125. province_ids: '',
  126. city_ids: '',
  127. area_ids: '',
  128. weigh: '',
  129. }],
  130. },
  131. dispatch_id: null,
  132. deleteArr: ['createtime', 'deletetime', 'name', 'type', 'type_text', 'updatetime'],
  133. }
  134. },
  135. mounted() {
  136. if (this.optType == 'add') {
  137. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  138. } else {
  139. this.dispatch_id = Config.row.id;
  140. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  141. for (key in this.dispatchForm) {
  142. if (key == 'type') {
  143. this.dispatchForm[key] = Config.row.express[0].type
  144. } else {
  145. this.dispatchForm[key] = Config.row[key]
  146. }
  147. }
  148. this.dispatchForm.express.forEach(i => {
  149. this.deleteArr.forEach(j => {
  150. delete i[j]
  151. })
  152. })
  153. }
  154. },
  155. methods: {
  156. dispatchSub(type, issub) {
  157. let that = this;
  158. if (type == 'yes') {
  159. this.$refs[issub].validate((valid) => {
  160. if (valid) {
  161. if (that.dispatchForm.express.length == 0) {
  162. Toastr.error('请选择配送规则');
  163. return false;
  164. }
  165. let isArea = true;
  166. that.dispatchForm.express.forEach((i, index) => {
  167. if (i.province_ids == '' && i.city_ids == '' && i.area_ids == '') {
  168. isArea = false
  169. }
  170. })
  171. if (!isArea) {
  172. Toastr.error('请选择地址');
  173. return false;
  174. }
  175. let subData = JSON.parse(JSON.stringify(that.dispatchForm));
  176. let leng = subData.express.length;
  177. subData.express.forEach((i, index) => {
  178. i.weigh = leng - index;
  179. delete i.area_text
  180. })
  181. if (this.optType != 'add') {
  182. Fast.api.ajax({
  183. url: 'shopro/dispatch/express/edit?ids=' + that.dispatch_id,
  184. loading: true,
  185. data: {
  186. data: JSON.stringify(subData)
  187. }
  188. }, function (ret, res) {
  189. Fast.api.close({
  190. data: true
  191. })
  192. })
  193. } else {
  194. Fast.api.ajax({
  195. url: 'shopro/dispatch/express/add',
  196. loading: true,
  197. type: "POST",
  198. data: {
  199. data: JSON.stringify(subData)
  200. }
  201. }, function (ret, res) {
  202. Fast.api.close({
  203. data: true
  204. })
  205. })
  206. }
  207. } else {
  208. return false;
  209. }
  210. });
  211. } else {
  212. Fast.api.close({
  213. data: false
  214. })
  215. }
  216. },
  217. editArea(index) {
  218. let that = this;
  219. let parmas = {
  220. name: that.dispatchForm.express[index].area_text,
  221. province_ids: that.dispatchForm.express[index].province_ids,
  222. city_ids: that.dispatchForm.express[index].city_ids,
  223. area_ids: that.dispatchForm.express[index].area_ids,
  224. }
  225. Fast.api.open('shopro/area/select?parmas=' + encodeURI(JSON.stringify(parmas)), '区域选择', {
  226. callback(data) {
  227. that.dispatchForm.express[index].area_text = data.data.name.join(',');
  228. that.dispatchForm.express[index].province_ids = data.data.province.join(',')
  229. that.dispatchForm.express[index].city_ids = data.data.city.join(',')
  230. that.dispatchForm.express[index].area_ids = data.data.area.join(',')
  231. }
  232. })
  233. },
  234. delArea(index) {
  235. this.dispatchForm.express.splice(index, 1);
  236. },
  237. addExpress() {
  238. this.dispatchForm.express.push({
  239. first_num: 0,
  240. first_price: 0.00,
  241. additional_num: 0,
  242. additional_price: 0.00,
  243. area_text: '',
  244. province_ids: '',
  245. city_ids: '',
  246. area_ids: '',
  247. weigh: '',
  248. });
  249. },
  250. },
  251. })
  252. },
  253. api: {
  254. bindevent: function () {
  255. Form.api.bindevent($("form[role=form]"));
  256. }
  257. }
  258. };
  259. return Controller;
  260. });