autosend.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/autosend/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/autosend/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/autosend/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. var dispatchDetail = new Vue({
  76. el: "#dispatchDetail",
  77. data() {
  78. return {
  79. optType: type,
  80. dispatchForm: {},
  81. rules: {
  82. name: [{
  83. required: true,
  84. message: '请输入自提点名称',
  85. trigger: 'blur'
  86. }],
  87. type: [{
  88. required: true,
  89. message: '请选择发货类型',
  90. trigger: 'blur'
  91. }],
  92. timecontent: [{
  93. required: true,
  94. message: '请输入发货内容',
  95. trigger: 'blur'
  96. }],
  97. },
  98. dispatchFormInit: {
  99. name: '',
  100. type: 'text',
  101. timecontent: '',
  102. },
  103. dispatch_id: null,
  104. }
  105. },
  106. mounted() {
  107. if (this.optType == 'add') {
  108. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  109. } else {
  110. this.dispatch_id = Config.row.id;
  111. this.dispatchForm = JSON.parse(JSON.stringify(this.dispatchFormInit));
  112. this.dispatchForm.type=Config.row.autosend.type;
  113. this.dispatchForm.name=Config.row.name;
  114. if(this.dispatchForm.type=='params'){
  115. let arr=[]
  116. Config.row.autosend.content.forEach((i,index)=>{
  117. arr.push({
  118. title:Object.keys(i)[0],
  119. content:Object.values(i)[0],
  120. })
  121. })
  122. this.dispatchForm.timecontent=arr;
  123. }else{
  124. this.dispatchForm.timecontent=Config.row.autosend.content
  125. }
  126. }
  127. },
  128. methods: {
  129. radioChange(val){
  130. if(val=='text'){
  131. this.dispatchForm.timecontent='';
  132. }else if(val=='params'){
  133. this.dispatchForm.timecontent=[];
  134. }
  135. },
  136. addParams() {
  137. this.dispatchForm.timecontent.push({
  138. title: '',
  139. content: ''
  140. })
  141. },
  142. delParams(index) {
  143. this.dispatchForm.timecontent.splice(index, 1)
  144. },
  145. dispatchSub(type, issub) {
  146. let that = this;
  147. if (type == 'yes') {
  148. this.$refs[issub].validate((valid) => {
  149. if (valid) {
  150. let subData = JSON.parse(JSON.stringify(that.dispatchForm));
  151. if(subData.type=='params'){
  152. let arrfield=[];
  153. let arrcontent=[];
  154. let paramsflg=true;
  155. subData.timecontent.forEach(i=>{
  156. for(key in i){
  157. if(!i[key]){
  158. paramsflg=false
  159. }
  160. }
  161. arrfield.push(i.title);
  162. arrcontent.push(i.content);
  163. })
  164. if(!paramsflg){
  165. Toastr.error('发货详情未填写完整');
  166. return false;
  167. }
  168. subData.content=[];
  169. arrfield.forEach((i,index)=>{
  170. let obj={}
  171. obj[i]=arrcontent[index]
  172. subData.content.push(obj)
  173. })
  174. } else{
  175. subData.content=subData.timecontent
  176. }
  177. delete subData.timecontent
  178. if (this.optType != 'add') {
  179. Fast.api.ajax({
  180. url: 'shopro/dispatch/autosend/edit?ids=' + that.dispatch_id,
  181. loading: true,
  182. data: {
  183. data: JSON.stringify(subData)
  184. }
  185. }, function (ret, res) {
  186. Fast.api.close({
  187. data: true
  188. })
  189. })
  190. } else {
  191. Fast.api.ajax({
  192. url: 'shopro/dispatch/autosend/add',
  193. loading: true,
  194. type: "POST",
  195. data: {
  196. data: JSON.stringify(subData)
  197. }
  198. }, function (ret, res) {
  199. Fast.api.close({
  200. data: true
  201. })
  202. })
  203. }
  204. } else {
  205. return false;
  206. }
  207. });
  208. } else {
  209. Fast.api.close({
  210. data: false
  211. })
  212. }
  213. },
  214. },
  215. })
  216. },
  217. api: {
  218. bindevent: function () {
  219. Form.api.bindevent($("form[role=form]"));
  220. }
  221. }
  222. };
  223. return Controller;
  224. });