You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

315 lines
18 KiB

  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. // 合并格式化方法
  3. Table.api.formatter = $.extend(Table.api.formatter,
  4. {
  5. statusCustom : function (value, row, index) {
  6. let number = value == 0 ? 0 : 1;
  7. let display = value == 0 ? '否' : '是';
  8. let color = value == 0 ? 'primary' : 'success';
  9. var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + display + '</span>';
  10. if (value != 0){
  11. html = '<a href="javascript:;" class="searchit" data-operate="=" data-field="' + this.field + '" data-value="' + number + '" data-toggle="tooltip" title="' + __('Time: %s', Moment(parseInt(value) * 1000).format('YYYY-MM-DD HH:mm:ss')) + '" >' + html + '</a>';
  12. } else {
  13. html = '<a href="javascript:;" class="searchit" data-operate="=" data-field="' + this.field + '" data-value="' + number + '" data-toggle="tooltip" title="' + __('Click to search %s', display) + '" >' + html + '</a>';
  14. }
  15. return html;
  16. }
  17. }
  18. );
  19. var Controller = {
  20. index: function () {
  21. // 初始化表格参数配置
  22. Table.api.init({
  23. extend: {
  24. index_url: 'unishop/order/index' + location.search,
  25. add_url: 'unishop/order/add',
  26. edit_url: 'unishop/order/edit',
  27. carry_url: 'unishop/order/carry',
  28. del_url: 'unishop/order/del',
  29. multi_url: 'unishop/order/multi',
  30. delivere_url: 'unishop/order/delivery',
  31. product_url: 'unishop/order/product',
  32. refund_url: 'unishop/order/refund',
  33. table: 'unishop_order',
  34. }
  35. });
  36. // 合并操作方法
  37. Table.api.events.operate = $.extend(Table.api.events.operate,
  38. {
  39. 'click .btn-delivere': function (e, value, row, index) {
  40. e.stopPropagation();
  41. e.preventDefault();
  42. var table = $(this).closest('table');
  43. var options = table.bootstrapTable('getOptions');
  44. var ids = row[options.pk];
  45. row = $.extend({}, row ? row : {}, {ids: ids});
  46. var url = options.extend.delivere_url;
  47. Fast.api.open(Table.api.replaceurl(url, row, table), __('Delivere'), $(this).data() || {});
  48. }
  49. },
  50. {
  51. 'click .btn-product': function (e, value, row, index) {
  52. e.stopPropagation();
  53. e.preventDefault();
  54. var table = $(this).closest('table');
  55. var options = table.bootstrapTable('getOptions');
  56. var ids = row[options.pk];
  57. row = $.extend({}, row ? row : {}, {ids: ids});
  58. var url = options.extend.product_url;
  59. Fast.api.open(Table.api.replaceurl(url, row, table), __('Product'), $(this).data() || {});
  60. }
  61. },
  62. {
  63. 'click .btn-refund': function (e, value, row, index) {
  64. e.stopPropagation();
  65. e.preventDefault();
  66. var table = $(this).closest('table');
  67. var options = table.bootstrapTable('getOptions');
  68. var ids = row[options.pk];
  69. row = $.extend({}, row ? row : {}, {ids: ids});
  70. var url = options.extend.refund_url;
  71. Fast.api.open(Table.api.replaceurl(url, row, table), __('Refund'), $(this).data() || {});
  72. }
  73. }
  74. );
  75. var table = $("#table");
  76. // 初始化表格
  77. table.bootstrapTable({
  78. pageSize: 20,
  79. pageList: [20, 50, 100],
  80. url: $.fn.bootstrapTable.defaults.extend.index_url,
  81. pk: 'id',
  82. sortName: 'id',
  83. showExport: false,
  84. commonSearch: true,
  85. search: false,
  86. showToggle: false,
  87. columns: [
  88. [
  89. {checkbox: true},
  90. // {field: 'id', title: __('Id'),visible:false},
  91. // {field: 'user_id', title: __('User_id')},
  92. {field: 'user.username', title: __('工号'),operate: 'LIKE'},
  93. {field: 'user.nickname', title: __('名字'),visible:false,operate: 'LIKE'},
  94. {field: 'out_trade_no', title: __('Out_trade_no'),operate:false},
  95. {field: 'order_price', title: __('Order_price'), operate:false},
  96. {field: 'is_carry', title: __('是否提货'), operate:false},
  97. // {field: 'discount_price', title: __('Discount_price'), operate:'BETWEEN'},
  98. // {field: 'delivery_price', title: __('Delivery_price'), operate:'BETWEEN'},
  99. {field: 'total_price', title: __('Total_price'), operate:false},
  100. {field: 'status', title: __('Status'),operate:false, searchList: {"-1":__('Refund'),"0":__('Cancel'),"1":__('Normal')}, formatter: Table.api.formatter.status},
  101. {field: 'pay_type', title: __('Pay_type'),operate:false, searchList: {"1":__('Online'),"2":__('Offline'),"3":__('wxPay'),"4":__('aliPay')}, formatter: Table.api.formatter.normal},
  102. // {field: 'ip', title: __('Ip'), visible:false},
  103. // {field: 'have_paid_status', title: __('Have_paid'), searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  104. // {field: 'have_delivered_status', title: __('Have_delivered'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  105. // {field: 'have_received_status', title: __('Have_received'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  106. // {field: 'have_commented_status', title: __('Have_commented'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  107. // {field: 'refund_status', title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Waiting for shipment'),"3":__('Pass'),"4":__('Refuse')}, formatter: Table.api.formatter.status},
  108. // {field: 'have_paid', title: __('Pay time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  109. // {field: 'have_delivered', title: __('Delivered time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  110. // {field: 'have_received', title: __('Received time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  111. // {field: 'have_commented', title: __('Commented time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  112. {field: 'createtime', title: __('Createtime'),operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  113. {field: 'remark', title: __('Remark'),operate:false},
  114. {field: 'updatetime', title: __('Updatetime'),operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  115. {
  116. field: 'operate',
  117. title: __('Operate'),
  118. table: table,
  119. events: Table.api.events.operate,
  120. formatter: Table.api.formatter.operate,
  121. buttons:[
  122. {
  123. name: 'refund',
  124. text: __('Refund'),
  125. classname: 'btn btn-xs btn-info btn-ajax',
  126. extend: 'data-toggle="tooltip"',
  127. icon: 'fa fa-handshake-o',
  128. url:function(row){
  129. return "unishop/order/doRefund?id="+row.id;
  130. },
  131. confirm:"是否确认退款"
  132. },
  133. // {
  134. // name: 'delivere',
  135. // text: __('Delivere'),
  136. // classname: 'btn btn-xs btn-info btn-delivere',
  137. // extend: 'data-toggle="tooltip"',
  138. // icon: 'fa fa-plane'
  139. // },
  140. {
  141. name: 'product',
  142. text: __('Product'),
  143. classname: 'btn btn-xs btn-info btn-product',
  144. extend: 'data-toggle="tooltip"',
  145. icon: 'fa fa-star-half'
  146. },
  147. {
  148. name: 'edit',
  149. icon: 'fa fa-pencil',
  150. text: __('Edit'),
  151. extend: 'data-toggle="tooltip"',
  152. classname: 'btn btn-xs btn-success btn-editone',
  153. url: $.fn.bootstrapTable.defaults.extend.edit_url
  154. }
  155. ]
  156. }
  157. ]
  158. ]
  159. });
  160. // 为表格绑定事件
  161. Table.api.bindevent(table);
  162. $(document).on("click", ".btn-export", function () {
  163. window.location.href="order/export";
  164. });
  165. $(document).on("click", ".btn-finish", function () {
  166. Layer.confirm(
  167. __('确定要完成所有订单?'),
  168. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  169. function (index) {
  170. Fast.api.ajax({
  171. url:"unishop/order/finish",
  172. loading:false
  173. }, function(data, ret){
  174. //成功回调
  175. Layer.close(index);
  176. // layer.msg('操作成功!');
  177. });
  178. }
  179. );
  180. });
  181. $(document).on("click", ".btn-carry", function () {
  182. var ids = Table.api.selectedids(table);
  183. Layer.confirm(
  184. __('确定要提货吗?'),
  185. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  186. function (index) {
  187. Fast.api.ajax({
  188. url:"unishop/order/carry",
  189. loading:false,
  190. data:{"ids":ids}
  191. }, function(data, ret){
  192. //成功回调
  193. Layer.close(index);
  194. // layer.msg('操作成功!');
  195. });
  196. }
  197. );
  198. });
  199. },
  200. recyclebin: function () {
  201. // 初始化表格参数配置
  202. Table.api.init({
  203. extend: {
  204. 'dragsort_url': ''
  205. }
  206. });
  207. var table = $("#table");
  208. // 初始化表格
  209. table.bootstrapTable({
  210. url: 'unishop/order/recyclebin' + location.search,
  211. pk: 'id',
  212. sortName: 'id',
  213. pageSize: 20,
  214. pageList: [20, 50, 100],
  215. columns: [
  216. [
  217. {checkbox: true},
  218. {field: 'id', title: __('Id'),visible:false},
  219. {field: 'user_id', title: __('User_id')},
  220. {field: 'user.username', title: __('User name')},
  221. {field: 'out_trade_no', title: __('Out_trade_no'),operate:false},
  222. {field: 'order_price', title: __('Order_price'), operate:false},
  223. {field: 'discount_price', title: __('Discount_price'), operate:false},
  224. {field: 'delivery_price', title: __('Delivery_price'), operate:false},
  225. {field: 'total_price', title: __('Total_price'),operate:false},
  226. {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Online'),"2":__('Offline'),"3":__('wxPay'),"4":__('aliPay')},operate:false, formatter: Table.api.formatter.normal},
  227. {field: 'ip', title: __('Ip'), visible:false},
  228. {field: 'status', title: __('Status'), searchList: {"-1":__('Refund'),"0":__('Cancel'),"1":__('Normal')},operate:false, formatter: Table.api.formatter.status},
  229. {field: 'have_paid_status', title: __('Have_paid'), searchList: {"0":__('No'),"1":__('Yes')},operate:false, formatter: Table.api.formatter.statusCustom},
  230. {field: 'have_delivered_status', title: __('Have_delivered'),searchList: {"0":__('No'),"1":__('Yes')},operate:false, formatter: Table.api.formatter.statusCustom},
  231. {field: 'have_received_status', title: __('Have_received'),searchList: {"0":__('No'),"1":__('Yes')},operate:false, formatter: Table.api.formatter.statusCustom},
  232. {field: 'have_commented_status', title: __('Have_commented'),searchList: {"0":__('No'),"1":__('Yes')},operate:false, formatter: Table.api.formatter.statusCustom},
  233. {field: 'refund_status',operate:false, title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Waiting for shipment'),"3":__('Pass'),"4":__('Refuse')}, formatter: Table.api.formatter.status},
  234. {field: 'have_paid', title: __('Pay time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  235. {field: 'have_delivered', title: __('Delivered time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  236. {field: 'have_received', title: __('Received time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  237. {field: 'have_commented', title: __('Commented time'),operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  238. {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  239. {field: 'remark', title: __('Remark'), operate:false, placeholder: '模糊搜索,*表示任意字符'},
  240. {
  241. field: 'deletetime',
  242. title: __('Deletetime'),
  243. operate: 'RANGE',
  244. addclass: 'datetimerange',
  245. formatter: Table.api.formatter.datetime
  246. },
  247. {
  248. field: 'operate',
  249. width: '130px',
  250. title: __('Operate'),
  251. table: table,
  252. events: Table.api.events.operate,
  253. buttons: [
  254. {
  255. name: 'Restore',
  256. text: __('Restore'),
  257. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  258. icon: 'fa fa-rotate-left',
  259. url: 'unishop/order/restore',
  260. refresh: true
  261. },
  262. {
  263. name: 'Destroy',
  264. text: __('Destroy'),
  265. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  266. icon: 'fa fa-times',
  267. url: 'unishop/order/destroy',
  268. refresh: true
  269. }
  270. ],
  271. formatter: Table.api.formatter.operate
  272. }
  273. ]
  274. ]
  275. });
  276. // 为表格绑定事件
  277. Table.api.bindevent(table);
  278. },
  279. add: function () {
  280. Controller.api.bindevent();
  281. },
  282. edit: function () {
  283. Controller.api.bindevent();
  284. },
  285. carry: function () {
  286. console(1);
  287. Controller.api.bindevent();
  288. },
  289. delivery: function(){
  290. Controller.api.bindevent();
  291. },
  292. product: function(){
  293. Controller.api.bindevent();
  294. },
  295. refund: function(){
  296. Controller.api.bindevent();
  297. },
  298. api: {
  299. bindevent: function () {
  300. Form.api.bindevent($("form[role=form]"));
  301. }
  302. }
  303. };
  304. return Controller;
  305. });