order.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. // del_url: 'unishop/order/del',
  28. multi_url: 'unishop/order/multi',
  29. delivere_url: 'unishop/order/delivery',
  30. product_url: 'unishop/order/product',
  31. refund_url: 'unishop/order/refund',
  32. confirmpay_url: 'unishop/order/confirmpay',
  33. table: 'unishop_order',
  34. }
  35. });
  36. // 合并操作方法
  37. Table.api.events.operate = $.extend(Table.api.events.operate,
  38. {
  39. 'click .btn-delivery': 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), __('Delivery'), $(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. url: $.fn.bootstrapTable.defaults.extend.index_url,
  79. pk: 'id',
  80. sortName: 'id',
  81. fixedColumns:true,
  82. fixedRightNumber:1,
  83. columns: [
  84. [
  85. {checkbox: true},
  86. {field: 'id', title: __('Id'),visible:false},
  87. {field: 'user_id', title: __('User_id')},
  88. {field: 'user.username', title: __('User name')},
  89. {field: 'out_trade_no', title: __('Out_trade_no')},
  90. {field: 'order_price', title: __('Order_price'), operate:'BETWEEN'},
  91. {field: 'discount_price', title: __('Discount_price'), operate:'BETWEEN'},
  92. {field: 'delivery_price', title: __('Delivery_price'), operate:'BETWEEN'},
  93. {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
  94. {field: 'status', title: __('Status'), searchList: {"-1":__('Refund'),"0":__('Cancel'),"1":__('Normal')}, formatter: Table.api.formatter.status},
  95. {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Online'),"2":__('Offline'),"3":__('wxPay'),"4":__('aliPay')}, formatter: Table.api.formatter.normal},
  96. {field: 'ip', title: __('Ip'), visible:false},
  97. {field: 'have_paid_status', title: __('Have_paid'), searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  98. {field: 'have_delivered_status', title: __('Have_delivered'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  99. {field: 'have_received_status', title: __('Have_received'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  100. {field: 'have_commented_status', title: __('Have_commented'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  101. {field: 'refund_status', title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Waiting for shipment'),"3":__('Pass'),"4":__('Refuse')}, formatter: Table.api.formatter.status},
  102. {field: 'have_paid', title: __('Pay time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  103. {field: 'have_delivered', title: __('Delivered time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  104. {field: 'have_received', title: __('Received time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  105. {field: 'have_commented', title: __('Commented time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  106. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  107. {field: 'remark', title: __('Remark'), operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符'},
  108. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  109. {
  110. field: 'operate',
  111. title: __('Operate'),
  112. table: table,
  113. events: Table.api.events.operate,
  114. formatter: Table.api.formatter.operate,
  115. buttons:[
  116. /*{
  117. name: 'refund',
  118. text: __('Refund'),
  119. classname: 'btn btn-xs btn-info btn-refund',
  120. extend: 'data-toggle="tooltip"',
  121. icon: 'fa fa-handshake-o'
  122. },*/
  123. {
  124. name: 'delivery',
  125. text: __('Delivery'),
  126. classname: 'btn btn-xs btn-info btn-delivery',
  127. extend: 'data-toggle="tooltip"',
  128. icon: 'fa fa-plane'
  129. },
  130. {
  131. name: 'product',
  132. text: __('Product'),
  133. classname: 'btn btn-xs btn-info btn-product',
  134. extend: 'data-toggle="tooltip"',
  135. icon: 'fa fa-star-half'
  136. },
  137. {
  138. name: 'edit',
  139. icon: 'fa fa-pencil',
  140. text: '发货',
  141. extend: 'data-toggle="tooltip"',
  142. classname: 'btn btn-xs btn-success btn-editone',
  143. url: $.fn.bootstrapTable.defaults.extend.edit_url
  144. },
  145. {
  146. name: 'confirmpay',
  147. icon: 'fa fa-pencil',
  148. text: '线下支付',
  149. title: '线下支付',
  150. extend: 'data-toggle="tooltip"',
  151. classname: 'btn btn-xs btn-info btn-dialog',
  152. url: 'unishop/order/confirmpay/ids/{ids}?dialog=1',
  153. hidden:function(row){
  154. if(row.status == 1 && row.pay_type == 2 && row.have_paid == 0){
  155. return false;
  156. }
  157. return true;
  158. }
  159. }
  160. ]
  161. }
  162. ]
  163. ]
  164. });
  165. // 为表格绑定事件
  166. Table.api.bindevent(table);
  167. },
  168. recyclebin: function () {
  169. // 初始化表格参数配置
  170. Table.api.init({
  171. extend: {
  172. 'dragsort_url': ''
  173. }
  174. });
  175. var table = $("#table");
  176. // 初始化表格
  177. table.bootstrapTable({
  178. url: 'unishop/order/recyclebin' + location.search,
  179. pk: 'id',
  180. sortName: 'id',
  181. columns: [
  182. [
  183. {checkbox: true},
  184. {field: 'id', title: __('Id'),visible:false},
  185. {field: 'user_id', title: __('User_id')},
  186. {field: 'user.username', title: __('User name')},
  187. {field: 'out_trade_no', title: __('Out_trade_no')},
  188. {field: 'order_price', title: __('Order_price'), operate:'BETWEEN'},
  189. {field: 'discount_price', title: __('Discount_price'), operate:'BETWEEN'},
  190. {field: 'delivery_price', title: __('Delivery_price'), operate:'BETWEEN'},
  191. {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
  192. {field: 'pay_type', title: __('Pay_type'), searchList: {"1":__('Online'),"2":__('Offline'),"3":__('wxPay'),"4":__('aliPay')}, formatter: Table.api.formatter.normal},
  193. {field: 'ip', title: __('Ip'), visible:false},
  194. {field: 'status', title: __('Status'), searchList: {"-1":__('Refund'),"0":__('Cancel'),"1":__('Normal')}, formatter: Table.api.formatter.status},
  195. {field: 'have_paid_status', title: __('Have_paid'), searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  196. {field: 'have_delivered_status', title: __('Have_delivered'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  197. {field: 'have_received_status', title: __('Have_received'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  198. {field: 'have_commented_status', title: __('Have_commented'),searchList: {"0":__('No'),"1":__('Yes')}, formatter: Table.api.formatter.statusCustom},
  199. {field: 'refund_status', title: __('Refund status'),searchList: {"0":__('None'),"1":__('Apply'),"2":__('Waiting for shipment'),"3":__('Pass'),"4":__('Refuse')}, formatter: Table.api.formatter.status},
  200. {field: 'have_paid', title: __('Pay time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  201. {field: 'have_delivered', title: __('Delivered time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  202. {field: 'have_received', title: __('Received time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  203. {field: 'have_commented', title: __('Commented time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,visible:false},
  204. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  205. {field: 'remark', title: __('Remark'), operate: 'LIKE %...%', placeholder: '模糊搜索,*表示任意字符'},
  206. {
  207. field: 'deletetime',
  208. title: __('Deletetime'),
  209. operate: 'RANGE',
  210. addclass: 'datetimerange',
  211. formatter: Table.api.formatter.datetime
  212. },
  213. {
  214. field: 'operate',
  215. width: '130px',
  216. title: __('Operate'),
  217. table: table,
  218. events: Table.api.events.operate,
  219. buttons: [
  220. {
  221. name: 'Restore',
  222. text: __('Restore'),
  223. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  224. icon: 'fa fa-rotate-left',
  225. url: 'unishop/order/restore',
  226. refresh: true
  227. },
  228. {
  229. name: 'Destroy',
  230. text: __('Destroy'),
  231. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  232. icon: 'fa fa-times',
  233. url: 'unishop/order/destroy',
  234. refresh: true
  235. }
  236. ],
  237. formatter: Table.api.formatter.operate
  238. }
  239. ]
  240. ]
  241. });
  242. // 为表格绑定事件
  243. Table.api.bindevent(table);
  244. },
  245. add: function () {
  246. Controller.api.bindevent();
  247. },
  248. confirmpay: function () {
  249. Controller.api.bindevent();
  250. },
  251. edit: function () {
  252. Controller.api.bindevent();
  253. },
  254. delivery: function(){
  255. Controller.api.bindevent();
  256. },
  257. product: function(){
  258. Controller.api.bindevent();
  259. },
  260. refund: function(){
  261. Controller.api.bindevent();
  262. },
  263. api: {
  264. bindevent: function () {
  265. Form.api.bindevent($("form[role=form]"));
  266. }
  267. }
  268. };
  269. return Controller;
  270. });