product.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 : 'qingdong/customer/product/index',
  8. add_url : 'qingdong/customer/product/add',
  9. detail_url : 'qingdong/customer/product/detail',
  10. del_url : 'qingdong/customer/product/del',
  11. table : 'customer',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url : $.fn.bootstrapTable.defaults.extend.index_url,
  18. pk : 'id',
  19. sortName : 'id',
  20. fixedColumns : true,
  21. fixedNumber : 2,
  22. columns : [
  23. [
  24. {checkbox : true},
  25. // {field : 'id', title : __('Id'), sortable : true},
  26. {
  27. field : 'name', title : '产品名称', fixedColumns : true, formatter : function (value, row, index) {
  28. return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
  29. }
  30. },
  31. {field : 'num', title : '产品编码'},
  32. {field : 'price', title : '标准价格'},
  33. {field : 'description', title : '产品描述'},
  34. ]
  35. ]
  36. });
  37. $(document).on('click', '.show-detail', function (data) {
  38. var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
  39. var options = {
  40. shadeClose : false,
  41. shade : [0.3, '#393D49'],
  42. area : area,
  43. callback : function (value) {
  44. //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
  45. console.log(value);
  46. }
  47. };
  48. Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '客户详情', options);
  49. });
  50. // 为表格绑定事件
  51. Table.api.bindevent(table);
  52. },
  53. add : function () {
  54. Controller.api.bindevent();
  55. },
  56. edit : function () {
  57. Controller.api.bindevent();
  58. },
  59. detail : function () {
  60. //编辑
  61. $(document).on('click', '.btn-edit', function () {
  62. var id = $('#ids').val();
  63. Fast.api.open("qingdong/customer/product/edit?ids=" + id, "产品编辑", {
  64. shadeClose : false,
  65. shade : false,
  66. maxmin : false,
  67. moveOut : false,
  68. scrollbars : false,
  69. callback : function () {
  70. location.reload()
  71. }
  72. });
  73. }).on('click', ".btn-del", function () {//删除
  74. var id = $('#ids').val();
  75. Layer.confirm('确定删除当前产品吗?', {
  76. btn : ['确定', '取消'],
  77. title : '提示',
  78. }, function (index, layero) {
  79. Fast.api.ajax("qingdong/customer/product/del?ids=" + id, function (data, ret) {
  80. if (ret.code == 1) {
  81. Layer.close(index);
  82. parent.location.reload();
  83. }
  84. }, function (data, ret) {
  85. });
  86. });
  87. });
  88. Controller.api.bindevent();
  89. },
  90. api : {
  91. bindevent : function () {
  92. Form.api.bindevent($("form[role=form]"));
  93. }
  94. }
  95. };
  96. return Controller;
  97. });