lists.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'area','vue', 'ELEMENT', ], function ($, undefined, Backend, Table, Form, Area, Vue, ELEMENT, ) {
  2. ELEMENT.install(Vue)
  3. Vue.use(ELEMENT)
  4. var Controller = {
  5. index: function () {
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'product/lists/index' + location.search,
  10. add_url: 'product/lists/add',
  11. edit_url: 'product/lists/edit',
  12. del_url: 'product/lists/del',
  13. multi_url: 'product/lists/multi',
  14. import_url: 'product/lists/import',
  15. dragsort_url: "",
  16. table: 'product_list',
  17. }
  18. });
  19. var table = $("#table");
  20. // 初始化表格
  21. table.bootstrapTable({
  22. url: $.fn.bootstrapTable.defaults.extend.index_url,
  23. pk: 'id',
  24. sortName: 'weigh',
  25. fixedColumns: true,
  26. fixedRightNumber: 1,
  27. columns: [
  28. [
  29. {checkbox: true},
  30. {field: 'id', title: __('Id')},
  31. {field: 'products.zh_title', title: __('Type_id'), operate: false},
  32. {field: 'zh_name', title: __('Zh_name'), operate: false,
  33. formatter : function(value, row, index, field){
  34. return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.zh_name + "'>" + value + "</span>";
  35. },
  36. cellStyle : function(value, row, index, field){
  37. return {
  38. css: {
  39. "white-space": "nowrap",
  40. "text-overflow": "ellipsis",
  41. "overflow": "hidden",
  42. "max-width":"200px"
  43. }
  44. };
  45. }
  46. },
  47. {field: 'en_name', title: __('En_name'), operate: false,
  48. formatter : function(value, row, index, field){
  49. return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.en_name + "'>" + value + "</span>";
  50. },
  51. cellStyle : function(value, row, index, field){
  52. return {
  53. css: {
  54. "white-space": "nowrap",
  55. "text-overflow": "ellipsis",
  56. "overflow": "hidden",
  57. "max-width":"200px"
  58. }
  59. };
  60. }
  61. },
  62. {field: 'thum', title: __('Thum'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  63. {field: 'weigh', title: __('Weigh'), operate: false},
  64. {field: 'status', title: __('Status'), searchList: {"1":__('上架'),"0":__('下架')}, formatter: Table.api.formatter.toggle},
  65. {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  66. {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  67. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  68. ]
  69. ]
  70. });
  71. // 为表格绑定事件
  72. Table.api.bindevent(table);
  73. // 修改添加窗口的大小
  74. $(".btn-add").data("area", ["80%", "80%"]);
  75. table.on('post-body.bs.table',function () {
  76. $('.btn-editone').data("area",["80%","80%"]);
  77. });
  78. },
  79. add: function () {
  80. Controller.api.bindevent();
  81. },
  82. edit: function () {
  83. Controller.api.bindevent();
  84. },
  85. api: {
  86. bindevent: function () {
  87. Form.api.bindevent($("form[role=form]"));
  88. Vue.component('treeselect', VueTreeselect.Treeselect)
  89. let areaData = [];
  90. if((Config.areaData).length > 0) areaData = JSON.parse(Config.areaData);
  91. console.log("dataCode", areaData)
  92. new Vue({
  93. el: '#app',
  94. data(){
  95. return {
  96. data: areaData,
  97. options: area,
  98. sortValueBy: "ORDER_SELECTED",
  99. selectedNodes: [],
  100. }
  101. },
  102. methods:{
  103. handleChange(selectedValues) {
  104. let ids= []
  105. let labels= []
  106. this.selectedNodes = this.data.map((item) => {
  107. let obj = this.getNode1(this.$refs.treeselect.getNode(item))
  108. ids.push(obj.result)
  109. labels.push(obj.labels)
  110. return { label: obj.labels,result: obj.result};
  111. });
  112. //console.log(JSON.stringify(ids),JSON.stringify(labels));
  113. $('#c-product_area').val(JSON.stringify(ids))
  114. $('#c-product_area_txt').val(JSON.stringify(labels))
  115. },
  116. getNode(e1) {
  117. let labels = [];
  118. // 递归获取 label
  119. function recurse(node) {
  120. if (node && node.label) {
  121. labels.push(node.label);
  122. if (node.parentNode) {
  123. recurse(node.parentNode); // 继续向上递归
  124. }
  125. }
  126. }
  127. recurse(e1);
  128. // console.log(labels.reverse().join("/"));
  129. // 返回拼接的 label 路径
  130. return labels.reverse().join("-");
  131. },
  132. getNode1(e1) {
  133. let labels = [];
  134. let result = [];
  135. // 递归获取 label
  136. function recurse(node) {
  137. if (node && node.label) {
  138. labels.push(node.label);
  139. result.push(node.id);
  140. if (node.parentNode) {
  141. recurse(node.parentNode); // 继续向上递归
  142. }
  143. }
  144. }
  145. recurse(e1);
  146. // 返回拼接的 label 路径
  147. return {labels:[labels.reverse().join("-")], result:result.reverse()};
  148. },
  149. }
  150. })
  151. },
  152. }
  153. };
  154. return Controller;
  155. });