channel.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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: 'channel/index' + location.search,
  8. add_url: 'channel/add',
  9. edit_url: 'channel/edit',
  10. del_url: 'channel/del',
  11. multi_url: 'channel/multi',
  12. import_url: 'channel/import',
  13. table: 'channel',
  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. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'promotioner_name', title: "推广团队/人", operate: 'LIKE'},
  29. {field: 'promotioner_mobile', title: "联系方式", operate: 'LIKE'},
  30. {
  31. field: 'starttime',
  32. title: "开始时间",
  33. operate: 'RANGE',
  34. addclass: 'datetimerange',
  35. autocomplete: false,
  36. formatter: Table.api.formatter.datetime
  37. },
  38. {
  39. field: 'endtime',
  40. title: "结束时间",
  41. operate: 'RANGE',
  42. addclass: 'datetimerange',
  43. autocomplete: false,
  44. formatter: Table.api.formatter.datetime
  45. },
  46. {field: 'city_name', title: __('City_name'), operate: 'LIKE'},
  47. {field: 'description', title: __('Description'), operate: 'LIKE'},
  48. {field: 'key', title: __('Key'), operate: 'LIKE'},
  49. {
  50. field: 'download_qrcode_image',
  51. title: "下载二维码",
  52. operate: false,
  53. events: Table.api.events.image,
  54. formatter: Table.api.formatter.image
  55. },
  56. {
  57. field: 'register_qrcode_image',
  58. title: '注册二维码',
  59. operate: false,
  60. events: Table.api.events.image,
  61. formatter: Table.api.formatter.image
  62. },
  63. {field: 'download_config', title: __('Download_config'), operate: 'BETWEEN'},
  64. {field: 'register_config', title: __('Register_config'), operate: 'BETWEEN'},
  65. {field: 'order_config', title: __('Order_config'), operate: 'BETWEEN'},
  66. {field: 'download_count', title: __('Download_count')},
  67. {field: 'register_count', title: __('Register_count')},
  68. {field: 'order_count', title: __('Order_count')},
  69. {
  70. field: 'updatetime',
  71. title: __('Updatetime'),
  72. operate: 'RANGE',
  73. addclass: 'datetimerange',
  74. autocomplete: false,
  75. formatter: Table.api.formatter.datetime
  76. },
  77. {
  78. field: 'city_code',
  79. title: __('区域'),
  80. searchList: Config.allow_areas,
  81. visible: false
  82. },
  83. {
  84. field: 'operate',
  85. title: __('Operate'),
  86. table: table,
  87. buttons: [
  88. {
  89. name: 'detail',
  90. text: '结算明细',
  91. title: '结算明细',
  92. icon: 'fa fa-list',
  93. classname: 'btn btn-xs btn-primary btn-dialog',
  94. url: 'channel/detail?id={id}'
  95. }
  96. ],
  97. events: Table.api.events.operate,
  98. formatter: Table.api.formatter.operate
  99. }
  100. ]
  101. ]
  102. });
  103. // 为表格绑定事件
  104. Table.api.bindevent(table);
  105. },
  106. add: function () {
  107. Controller.api.bindevent();
  108. },
  109. edit: function () {
  110. $(document).on("click", "#closing_btn", function () {
  111. var msg = [
  112. {
  113. key: "下载",
  114. config: $("#c-download_config").val() || 0,
  115. count: $("#c-download_count").val() || 0
  116. },
  117. {
  118. key: "注册",
  119. config: $("#c-register_config").val() || 0,
  120. count: $("#c-register_count").val() || 0
  121. },
  122. {
  123. key: "下单",
  124. config: $("#c-order_config").val() || 0,
  125. count: $("#c-order_count").val() || 0,
  126. },
  127. ];
  128. var total = msg.reduce(function (p, cur) {
  129. p += Number(cur.count) * Number(cur.config);
  130. return p;
  131. }, 0);
  132. var fmt = msg.map((item) => {
  133. return item.key + ":" + item.config + " * " + item.count + " = " + (Number(item.config) * Number(item.count));
  134. });
  135. fmt.push("总计: " + total);
  136. var id = $("#c-id").val();
  137. if (isNaN(Number(id))) {
  138. Layer.msg("id 错误");
  139. return;
  140. }
  141. Layer.confirm(fmt.join("<br />"),
  142. {icon: 3, title: __('Warning'), offset: 0, shadeClose: true},
  143. function (index) {
  144. Fast.api.ajax("channel/closing?id=" + id, function (data, ret) {
  145. $("#closing_btn").css("display: none");
  146. //成功的回调
  147. Layer.msg(ret.msg,function () {
  148. parent.layer.close(parent.layer.getFrameIndex(window.name));
  149. location.reload();
  150. });
  151. return false;
  152. }, function (data, ret) {
  153. console.log(ret);
  154. Layer.msg(ret.msg);
  155. return false;
  156. });
  157. });
  158. });
  159. Controller.api.bindevent();
  160. },
  161. api: {
  162. bindevent: function () {
  163. Form.api.bindevent($("form[role=form]"));
  164. }
  165. }
  166. };
  167. return Controller;
  168. });