freight_items.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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: 'shop/freight_items/index/freight_id/'+Config.freight_id + location.search,
  8. add_url: 'shop/freight_items/add/freight_id/' + Config.freight_id,
  9. edit_url: 'shop/freight_items/edit',
  10. del_url: 'shop/freight_items/del',
  11. multi_url: 'shop/freight_items/multi',
  12. import_url: 'shop/freight_items/import',
  13. table: 'shop_freight_items',
  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. },
  26. {
  27. field: 'id',
  28. title: __('Id')
  29. },
  30. {
  31. field: 'freight.name',
  32. title: __('Freight_id')
  33. },
  34. {
  35. field: 'first_num',
  36. title: __('First_num'),
  37. operate: 'BETWEEN'
  38. },
  39. {
  40. field: 'first_price',
  41. title: __('First_price'),
  42. operate: 'BETWEEN'
  43. },
  44. {
  45. field: 'continue_num',
  46. title: __('Continue_num'),
  47. operate: 'BETWEEN'
  48. },
  49. {
  50. field: 'continue_price',
  51. title: __('Continue_price'),
  52. operate: 'BETWEEN'
  53. },
  54. // {
  55. // field: 'area_ids',
  56. // title: __('Area_ids'),
  57. // operate: 'LIKE'
  58. // },
  59. {
  60. field: 'type',
  61. title: __('Type'),
  62. searchList: {
  63. "0": __('Type 0'),
  64. "1": __('Type 1'),
  65. "2": __('Type 2')
  66. },
  67. formatter: Table.api.formatter.normal
  68. },
  69. // {
  70. // field: 'postage_area_ids',
  71. // title: __('Postage_area_ids'),
  72. // operate: 'LIKE'
  73. // },
  74. {
  75. field: 'postage_num',
  76. title: __('Postage_num'),
  77. operate: 'BETWEEN'
  78. },
  79. {
  80. field: 'postage_price',
  81. title: __('Postage_price'),
  82. operate: 'BETWEEN'
  83. },
  84. {
  85. field: 'createtime',
  86. title: __('Createtime'),
  87. operate: 'RANGE',
  88. addclass: 'datetimerange',
  89. autocomplete: false,
  90. formatter: Table.api.formatter.datetime
  91. },
  92. {
  93. field: 'updatetime',
  94. title: __('Updatetime'),
  95. operate: 'RANGE',
  96. addclass: 'datetimerange',
  97. autocomplete: false,
  98. formatter: Table.api.formatter.datetime
  99. },
  100. {
  101. field: 'operate',
  102. title: __('Operate'),
  103. table: table,
  104. events: Table.api.events.operate,
  105. formatter: Table.api.formatter.operate
  106. }
  107. ]
  108. ]
  109. });
  110. // 为表格绑定事件
  111. Table.api.bindevent(table);
  112. },
  113. loadJsTree() {
  114. require(['jstree'], function () {
  115. $('.channeltree').on("changed.jstree", function (e, data) {
  116. let id = $(this).data('id');
  117. $('#' + id).val(data.selected.join(','));
  118. return false;
  119. });
  120. //渲染默认
  121. $(".channeltree").on("loaded.jstree", function (event, data) {
  122. let id = $(this).data('id');
  123. let childNodes = event.target.firstChild.childNodes;
  124. for (let i = 0, len = childNodes.length; i < len; i++) {
  125. let root = data.instance.get_node(childNodes[i].lastChild);
  126. let nodes = root.children_d;
  127. for (let j in nodes) {
  128. let node = data.instance.get_node(nodes[j]);
  129. if (id == 'c-postage_area_ids' && Config.postage_area_ids) {
  130. let postage_area_ids = Config.postage_area_ids.split(',');
  131. if (postage_area_ids.includes(node.id)) {
  132. data.instance.select_node(node);
  133. }
  134. } else if (Config.area_ids) {
  135. let area_ids = Config.area_ids.split(',');
  136. if (area_ids.includes(node.id)) {
  137. data.instance.select_node(node);
  138. }
  139. }
  140. }
  141. }
  142. });
  143. $('.channeltree').jstree({
  144. "themes": {
  145. "stripes": true
  146. },
  147. "checkbox": {
  148. "keep_selected_style": false,
  149. },
  150. "types": {
  151. "channel": {
  152. "icon": false,
  153. },
  154. "list": {
  155. "icon": false,
  156. },
  157. "link": {
  158. "icon": false,
  159. },
  160. "disabled": {
  161. "check_node": false,
  162. "uncheck_node": false
  163. }
  164. },
  165. 'plugins': ["types", "checkbox"],
  166. "core": {
  167. "multiple": true,
  168. 'check_callback': true,
  169. "data": Config.areas
  170. }
  171. });
  172. })
  173. $('#c-type').on('change', function () {
  174. let v = $(this).val();
  175. if (v == 2) {
  176. $('.c-postage_num').addClass('hide');
  177. $('.c-postage_price').removeClass('hide');
  178. } else if (v == 1) {
  179. $('.c-postage_price').addClass('hide');
  180. $('.c-postage_num').removeClass('hide');
  181. } else {
  182. $('.c-postage_price').addClass('hide');
  183. $('.c-postage_num').addClass('hide');
  184. }
  185. })
  186. },
  187. add: function () {
  188. this.loadJsTree();
  189. Controller.api.bindevent();
  190. },
  191. edit: function () {
  192. this.loadJsTree();
  193. Controller.api.bindevent();
  194. },
  195. api: {
  196. bindevent: function () {
  197. Form.api.bindevent($("form[role=form]"));
  198. }
  199. }
  200. };
  201. return Controller;
  202. });