order.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数
  5. Table.api.init({
  6. extend: {
  7. index_url: 'commission/order/index' + location.search,
  8. add_url: '',
  9. edit_url: 'commission/order/edit',
  10. del_url: 'commission/order/del',
  11. multi_url: 'commission/order/multi',
  12. import_url: 'commission/order/import',
  13. table: 'commission_order',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('ID'), width: 60},
  26. {field: 'order.order_sn', title: __('订单号'), operate: 'LIKE', formatter: function(value, row, index) {
  27. if (row.order && row.order.order_sn) {
  28. return '<a href="javascript:;" data-order-id="' + row.order_id + '" class="searchit order-detail">' + row.order.order_sn + '</a>';
  29. }
  30. return '-';
  31. }},
  32. {field: 'order_item.goods_title', title: __('商品名称'), operate: 'LIKE', formatter: function(value, row, index) {
  33. if (row.order_item && row.order_item.goods_title) {
  34. return '<a href="javascript:;" data-goods-id="' + row.order_item.goods_id + '" class="searchit goods-detail">' + row.order_item.goods_title + '</a>';
  35. }
  36. return '-';
  37. }},
  38. {field: 'buyer.nickname', title: __('下单用户'), operate: 'LIKE'},
  39. {field: 'buyer.mobile', title: __('手机号'), operate: 'LIKE'},
  40. {field: 'agent.nickname', title: __('推广分销商'), operate: 'LIKE'},
  41. {field: 'agent.mobile', title: __('推广手机号'), operate: 'LIKE'},
  42. {field: 'amount', title: __('结算金额'), operate: 'BETWEEN'},
  43. {field: 'commission_order_status', title: __('业绩状态'), searchList: {
  44. "-2": __('已扣除'),
  45. "-1": __('已取消'),
  46. "0": __('不计入'),
  47. "1": __('已计入')
  48. }, formatter: function(value, row, index) {
  49. var statusMap = {
  50. '-2': {text: '已扣除', color: 'danger'},
  51. '-1': {text: '已取消', color: 'warning'},
  52. '0': {text: '不计入', color: 'info'},
  53. '1': {text: '已计入', color: 'success'}
  54. };
  55. var status = statusMap[value] || {text: value, color: 'default'};
  56. return '<span class="label label-' + status.color + '">' + status.text + '</span>';
  57. }},
  58. {field: 'commission_reward_status', title: __('佣金状态'), searchList: {
  59. "-2": __('已退回'),
  60. "-1": __('已取消'),
  61. "0": __('未结算'),
  62. "1": __('已结算')
  63. }, formatter: function(value, row, index) {
  64. var statusMap = {
  65. '-2': {text: '已退回', color: 'danger'},
  66. '-1': {text: '已取消', color: 'warning'},
  67. '0': {text: '未结算', color: 'info'},
  68. '1': {text: '已结算', color: 'success'}
  69. };
  70. var status = statusMap[value] || {text: value, color: 'default'};
  71. return '<span class="label label-' + status.color + '">' + status.text + '</span>';
  72. }},
  73. {field: 'commission_time', title: __('结算时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
  74. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  75. buttons: [
  76. {
  77. name: 'confirm',
  78. text: __('结算'),
  79. title: __('结算佣金'),
  80. classname: 'btn btn-xs btn-success',
  81. icon: 'fa fa-check',
  82. visible: function (row) {
  83. return row.commission_reward_status == 0;
  84. },
  85. click: function (data) {
  86. Layer.confirm('确认结算此订单的佣金?', function(index) {
  87. Fast.api.ajax({
  88. url: 'commission/order/confirm',
  89. data: {commission_order_id: data.id}
  90. }, function(data, ret) {
  91. table.bootstrapTable('refresh');
  92. Layer.close(index);
  93. });
  94. });
  95. }
  96. },
  97. {
  98. name: 'cancel',
  99. text: __('取消'),
  100. title: __('取消佣金'),
  101. classname: 'btn btn-xs btn-warning',
  102. icon: 'fa fa-times',
  103. visible: function (row) {
  104. return row.commission_reward_status == 0;
  105. },
  106. click: function (data) {
  107. Layer.confirm('确认取消此订单的佣金?', function(index) {
  108. Fast.api.ajax({
  109. url: 'commission/order/cancel',
  110. data: {commission_order_id: data.id}
  111. }, function(data, ret) {
  112. table.bootstrapTable('refresh');
  113. Layer.close(index);
  114. });
  115. });
  116. }
  117. },
  118. {
  119. name: 'back',
  120. text: __('退回'),
  121. title: __('退回佣金'),
  122. classname: 'btn btn-xs btn-danger',
  123. icon: 'fa fa-undo',
  124. visible: function (row) {
  125. return row.commission_reward_status == 1;
  126. },
  127. click: function (data) {
  128. Layer.confirm('确认退回此订单的佣金?', function(index) {
  129. Fast.api.ajax({
  130. url: 'commission/order/back',
  131. data: {commission_order_id: data.id, deduct_order_money: 1}
  132. }, function(data, ret) {
  133. table.bootstrapTable('refresh');
  134. Layer.close(index);
  135. });
  136. });
  137. }
  138. }
  139. ],
  140. formatter: Table.api.formatter.operate}
  141. ]
  142. ]
  143. });
  144. // 为表格绑定事件
  145. Table.api.bindevent(table);
  146. // 绑定订单详情点击事件
  147. $(document).on('click', '.order-detail', function() {
  148. var orderId = $(this).data('order-id');
  149. Fast.api.open('order/order/detail?id=' + orderId, '订单详情');
  150. });
  151. // 绑定商品详情点击事件
  152. $(document).on('click', '.goods-detail', function() {
  153. var goodsId = $(this).data('goods-id');
  154. Fast.api.open('goods/goods/detail?id=' + goodsId, '商品详情');
  155. });
  156. },
  157. api: {
  158. bindevent: function () {
  159. Form.api.bindevent($("form[role=form]"));
  160. }
  161. }
  162. };
  163. return Controller;
  164. });