selfetch.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  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/selfetch/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/selfetch/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/selfetch/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. function debounce(handle, delay) {
  76. let time = null;
  77. return function () {
  78. let self = this,
  79. arg = arguments;
  80. clearTimeout(time);
  81. time = setTimeout(function () {
  82. handle.apply(self, arg);
  83. }, delay)
  84. }
  85. }
  86. var dispatchDetail = new Vue({
  87. el: "#dispatchDetail",
  88. data() {
  89. return {
  90. optType: type,
  91. dispatchForm: {},
  92. rules: {
  93. name: [{
  94. required: true,
  95. message: '请输入自提点名称',
  96. trigger: 'blur'
  97. }],
  98. expire_type: [{
  99. required: true,
  100. message: '请选择有效时间',
  101. trigger: 'blur'
  102. }],
  103. expire_day: [{
  104. required: true,
  105. message: '请输入有效天数',
  106. trigger: 'blur'
  107. }],
  108. expire_time: [{
  109. required: true,
  110. message: '请选择截至日期',
  111. trigger: 'blur'
  112. }],
  113. store_ids: [{
  114. required: true,
  115. message: '请选择自提门店',
  116. trigger: 'blur'
  117. }],
  118. },
  119. dispatchFormInit: {
  120. name: '',
  121. store_ids: [],
  122. expire_type: 'day',
  123. expire_day: 0,
  124. expire_time: '',
  125. },
  126. storeOptions: [],
  127. dispatch_id: null,
  128. limit: 6,
  129. offset: 0,
  130. currentPage: 1,
  131. totalPage: 0,
  132. searchPage: '',
  133. self_user_type: 'all'
  134. }
  135. },
  136. mounted() {
  137. if (this.optType == 'add') {
  138. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  139. } else {
  140. this.dispatch_id = Config.row.id;
  141. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  142. for (key in this.dispatchForm) {
  143. this.dispatchForm[key] = Config.row.selfetch[key]
  144. }
  145. this.dispatchForm.name = Config.row.name;
  146. // this.dispatchForm.store_ids = this.dispatchForm.store_ids.split(',');
  147. if (this.dispatchForm.expire_time) {
  148. this.dispatchForm.expire_time = moment(this.dispatchForm.expire_time * 1000).format('YYYY-MM-DD HH:mm:ss');
  149. }
  150. this.storeOptions=this.dispatchForm.store_ids_list
  151. if (this.dispatchForm.store_ids.length>0) {
  152. this.self_user_type = 'part'
  153. }
  154. }
  155. this.getstoreOptions()
  156. },
  157. methods: {
  158. getstoreOptions() {
  159. let that = this;
  160. Fast.api.ajax({
  161. url: 'shopro/store/store/select',
  162. loading: true,
  163. type: 'GET',
  164. data: {
  165. limit: that.limit,
  166. offset: that.offset,
  167. filter: '{"selfetch":"1"}',
  168. op: '{"selfetch":"="}',
  169. searchWhere: that.searchPage,
  170. }
  171. }, function (ret, res) {
  172. that.storeOptions = res.data.rows;
  173. that.totalPage = res.data.total;
  174. return false;
  175. })
  176. },
  177. debounceFilter: debounce(function () {
  178. this.getstoreOptions()
  179. }, 3000),
  180. dataFilter(val) {
  181. this.searchPage = val;
  182. this.limit = 6;
  183. this.offset = 0;
  184. this.currentPage = 1;
  185. this.debounceFilter()
  186. },
  187. //分页
  188. pageSizeChange(val) {
  189. this.offset = 0;
  190. this.limit = val;
  191. this.currentPage = 1;
  192. this.getstoreOptions();
  193. },
  194. pageCurrentChange(val) {
  195. this.offset = (val - 1) * 6;
  196. this.limit = 6;
  197. this.currentPage = 1;
  198. this.getstoreOptions();
  199. },
  200. dispatchSub(type, issub) {
  201. let that = this;
  202. if (type == 'yes') {
  203. this.$refs[issub].validate((valid) => {
  204. if (valid) {
  205. let subData = JSON.parse(JSON.stringify(that.dispatchForm));
  206. if (that.self_user_type == 'all') {
  207. subData.store_ids = ''
  208. } else {
  209. subData.store_ids = subData.store_ids.join(',');
  210. }
  211. if (subData.expire_type == 'day') {
  212. delete subData.expire_time
  213. } else {
  214. delete subData.expire_day
  215. subData.expire_time = moment(subData.expire_time).valueOf() / 1000;
  216. }
  217. // return false;
  218. if (this.optType != 'add') {
  219. Fast.api.ajax({
  220. url: 'shopro/dispatch/selfetch/edit?ids=' + that.dispatch_id,
  221. loading: true,
  222. data: {
  223. data: JSON.stringify(subData)
  224. }
  225. }, function (ret, res) {
  226. Fast.api.close({
  227. data: true
  228. })
  229. })
  230. } else {
  231. Fast.api.ajax({
  232. url: 'shopro/dispatch/selfetch/add',
  233. loading: true,
  234. type: "POST",
  235. data: {
  236. data: JSON.stringify(subData)
  237. }
  238. }, function (ret, res) {
  239. Fast.api.close({
  240. data: true
  241. })
  242. })
  243. }
  244. } else {
  245. return false;
  246. }
  247. });
  248. } else {
  249. Fast.api.close({
  250. data: false
  251. })
  252. }
  253. },
  254. createStore() {
  255. let that = this;
  256. Fast.api.open('shopro/store/store/add', '增加门店', {
  257. callback(data) {
  258. that.getstoreOptions();
  259. }
  260. })
  261. }
  262. },
  263. })
  264. },
  265. api: {
  266. bindevent: function () {
  267. Form.api.bindevent($("form[role=form]"));
  268. }
  269. }
  270. };
  271. return Controller;
  272. });