rota.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','selectpage'], function ($, undefined, Backend, Table, Form,selectpage) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'institution/rota/index' + location.search,
  8. add_url: 'institution/rota/add',
  9. edit_url: 'institution/rota/edit',
  10. del_url: 'institution/rota/del',
  11. multi_url: '',
  12. table: 'rota',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. // {checkbox: true},
  24. {field: 'id', title: __('Id'),searchable: false, visible: false},
  25. {field: 'doctor_id', title: __('Doctor_id'),searchable: false, visible: false},
  26. {field: 'institution_name', title: __('Institution_name'),searchable: false},
  27. {field: 'doctor_name', title: __('Doctor_name'),searchable: false},
  28. {field: 'institution_id', title: __('Institution_id'), visible: false},
  29. {field: 'createdAt', title: __('Createdat'), operate:'RANGE', addclass:'datetimerange',searchable: false, visible: false},
  30. {field: 'rota_datetime', title: __('Rota_datetime'), addclass:'datetimepicker',data:'data-date-format="YYYYMMDD" autocomplete="off"'},
  31. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  32. ]
  33. ]
  34. });
  35. $.ajax({
  36. url: 'institution/institution/institutionSelectList',
  37. type: 'post',
  38. dataType: 'json',
  39. success: function success(res) {
  40. var data = res.rows;
  41. $('#institution_id').selectPage({
  42. data : data,
  43. orderBy: 'index',
  44. });
  45. }
  46. });
  47. // 为表格绑定事件
  48. Table.api.bindevent(table);
  49. },
  50. add: function () {
  51. Controller.api.bindevent();
  52. initInstitutionSearchList('c-institution_id');
  53. },
  54. edit: function () {
  55. Controller.api.bindevent();
  56. let ins_val = $('#ins_id').val();
  57. initDoctorList(ins_val);
  58. },
  59. api: {
  60. bindevent: function () {
  61. Form.api.bindevent($("form[role=form]"));
  62. }
  63. }
  64. };
  65. // 选择机构下拉列表
  66. let initInstitutionSearchList = function (id) {
  67. $.ajax({
  68. url: 'institution/institution/institutionSelectList',
  69. type: 'post',
  70. dataType: 'json',
  71. success: function success(res) {
  72. let data = res.rows;
  73. $('#'+id).selectPage({
  74. data : data,
  75. orderBy: 'index',
  76. pagination: true,
  77. eSelect: function (data) {
  78. if($('#c-doctor_id').length){
  79. let ins_id = data.id;
  80. initDoctorSearchList(ins_id)
  81. }
  82. }
  83. });
  84. }
  85. });
  86. };
  87. // 选择医生多选下拉列表
  88. let initDoctorSearchList = function (ins_id) {
  89. $.ajax({
  90. url: 'institution/institution/doctorSelectList/institution_id/' + ins_id,
  91. type: 'post',
  92. dataType: 'json',
  93. success: function success(res) {
  94. let val = $('#c-doctor_id').val();
  95. let html = '<input id="c-doctor_id" class="form-control" name="row[doctor_id]" type="text" value="'+ val +'">';
  96. $('#d-doctor_id').children().remove();
  97. $('#d-doctor_id').append(html);
  98. let data = res.rows;
  99. $('#c-doctor_id').selectPage({
  100. data : data,
  101. orderBy: 'index',
  102. multiple: true
  103. });
  104. }
  105. });
  106. };
  107. // 选择医生单选下拉列表
  108. let initDoctorList = function (ins_id) {
  109. $.ajax({
  110. url: 'institution/institution/doctorSelectList/institution_id/' + ins_id,
  111. type: 'post',
  112. dataType: 'json',
  113. success: function success(res) {
  114. let val = $('#c-doctor_id').val();
  115. let html = '<input id="c-doctor_id" class="form-control" name="row[doctor_id]" type="text" value="'+ val +'">';
  116. $('#d-doctor_id').children().remove();
  117. $('#d-doctor_id').append(html);
  118. let data = res.rows;
  119. $('#c-doctor_id').selectPage({
  120. data : data,
  121. orderBy: 'index'
  122. });
  123. }
  124. });
  125. };
  126. return Controller;
  127. });