DeviceMgPlan.cshtml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. @using ShwasherSys
  2. @using ShwasherSys.Authorization.Permissions
  3. @using ShwasherSys.Models.Layout
  4. @using ShwasherSys.Views.Shared.New.Modals
  5. @using ShwasherSys.Views.Shared.New.Table
  6. @{
  7. ViewBag.Title = "设备维护计划";
  8. string activeMenu = PermissionNames.PagesCompanyDieMaintenanceDeviceMgPlan; //The menu item will be active for this page.
  9. List<SelectListItem> fixedAsset = ViewBag.FixedAsset, planType = ViewBag.PlanType;
  10. ViewBag.ActiveMenu = activeMenu;
  11. var searchForm = new SearchFormViewModal(new List<SearchItem>()
  12. {
  13. new SearchItem("no","计划编号"),
  14. new SearchItem("name","设备名称").SetSearchItem(fixedAsset,isAddBlank:false),
  15. new SearchItem("expireDate","有效期限",FiledType.D,ExpType.GreaterOrEqual),
  16. new SearchItem("expireDate","至",FiledType.D,ExpType.LessOrEqual),
  17. new SearchItem("maintenanceDate","维护时间",FiledType.D,ExpType.GreaterOrEqual),
  18. new SearchItem("maintenanceDate","至",FiledType.D,ExpType.LessOrEqual),
  19. // new SearchItem("nextMaintenanceDate","下一次维护时间",FiledType.Dnull,ExpType.GreaterOrEqual),
  20. // new SearchItem("nextMaintenanceDate","至",FiledType.Dnull,ExpType.LessOrEqual),
  21. }, "search-form", false);
  22. var table = new TableViewModel("/api/services/app/DeviceMgPlan/GetAll", activeMenu, searchForm)
  23. .SetFields(new List<FieldItem>()
  24. {
  25. new FieldItem("no", "计划编号"),
  26. new FieldItem("planType", "计划类型","PlanTypeFormatter"),
  27. new FieldItem("name", "设备名称"),
  28. new FieldItem("deviceNo", "设备编号"),
  29. new FieldItem("expireDate", "有效期限","ExDateFormatter"),
  30. new FieldItem("maintenanceCycle", "维护周期"),
  31. new FieldItem("maintenanceDate", "维护时间","DateFormatter"),
  32. new FieldItem("nextMaintenanceDate", "下一次维护","MtDateFormatter"),
  33. });
  34. }
  35. @section css{
  36. }
  37. @Html.Partial("New/Table/_Table", table)
  38. @section modal{
  39. <!--Main Modal-->
  40. @{
  41. var modal = new ModalViewModel("设备计划", new ModalBodyViewModel(new List<Input>()
  42. {
  43. new InputHide("id"),
  44. new InputHide("no", "计划编号"),
  45. new Input("planType", "计划类型").SetSelectOptions(planType),
  46. new InputHide("deviceNo").SetNotRequired(),
  47. //new Input("deviceName1", "设备名称",@class:"type type1",other:"onchange=DeviceNameChange(this)").SetSelectOptions(fixedAsset,isAddBlank:false),
  48. new Input("deviceName1", "模具名称",@class:"type type1").SetSearchIcon("query_mold_modal","#modal"),
  49. new Input("deviceName2", "设备名称",@class:"type type2").SetSearchIcon("query_device_modal","#modal"),
  50. new Input("name","设备名称",@class:"type type3"),
  51. new InputDate("expireDate", "有效期限"),
  52. new InputNumber("maintenanceCycle", "维护周期",other:"min=1"),
  53. new InputDate("maintenanceDate", "维护时间"),
  54. new InputTextarea("description", "维护内容").SetNotRequired(),
  55. }));
  56. }
  57. @{
  58. var recordModal = new ModalViewModel("添加维护记录", "", new ModalBodyViewModel(new List<Input>()
  59. {
  60. new InputHide("id"),
  61. new InputHide("no", "计划编号"),
  62. new Input("name", "设备名称"),
  63. new Input("address", "维护地点"),
  64. new InputDate("planDate", "计划维护时间").SetNotRequired(),
  65. new InputTextarea("description", "维护内容").SetNotRequired(),
  66. }), "record-modal");
  67. }
  68. @Html.Partial("New/Modals/_Modal", modal)
  69. @Html.Partial("New/Modals/_Modal", recordModal)
  70. @Html.Partial("Modals/Query/_Device", "deviceNo,name|deviceName2")
  71. @Html.Partial("Modals/Query/_Mold", "deviceNo,name|deviceName1,maintenanceCycle")
  72. }
  73. @section scripts
  74. {
  75. <script type="text/javascript">
  76. var $table = $('#table');
  77. $(function () {
  78. LoadTable();
  79. var funs = window.funs || { none: function () { console.log("No type"); } };
  80. funs["btnCreate"] = function (url) {
  81. $("#modal .type").closest('.form-group-sm').hide();
  82. $('#modal #planType').off("change.planType").off("change.planType1").on("change.planType",PlanTypeChange);
  83. BtnCreate({ data: { id: "", no: "1" }, disabled: "no,deviceName1,deviceName2", readonly:"maintenanceCycle" });
  84. $('#modal #deviceName1 + .input-group-addon').show();
  85. }
  86. funs["btnUpdate"] = function () {
  87. var row = $table.bootstrapTable("getSelections")[0];
  88. if (row) {
  89. $("#modal .type").closest('.form-group-sm').hide();
  90. var data = $.extend({}, row, { deviceName1: row.deviceNo, deviceName2: row.deviceNo });
  91. $('#modal #planType').off("change.planType").on("change.planType1",
  92. function() {
  93. PlanTypeChange(row.deviceNo);
  94. });
  95. BtnUpdate({ disabled: "no,maintenanceDate,planType,deviceName1,deviceName2", data: data, readonly: "maintenanceCycle" });
  96. //$("#modal .type").removeClass('required').closest('.form-group-sm').hide();
  97. //$("#modal .type3").addClass('required').closest('.form-group-sm').fadeIn();
  98. $('#modal #planType').off("change.planType1").on("change.planType",PlanTypeChange);
  99. $('#modal #deviceName1 + .input-group-addon').hide();
  100. //$('#modal #deviceName2 + .input-group-addon').hide();
  101. //$('#modal #planType').trigger("change");
  102. }
  103. };
  104. funs["btnMaintain"] = function (url) {
  105. var row = $table.bootstrapTable("getSelections")[0];
  106. if (row) {
  107. var data = $.extend({}, row, { name: row.deviceName });
  108. OpenModal({
  109. url: url,
  110. disabled: "no,name",
  111. modal: $('#record-modal'),
  112. data: data
  113. });
  114. }
  115. };
  116. $("#Tool1").append(
  117. '<div class="tool-radio"><input name="radioType" type="radio" id="radioType1" checked value=""/><label for="radioType1">全部</label></div>' +
  118. '<div class="tool-radio"><input name="radioType" type="radio" id="radioType2" value="1"/><label for="radioType2">待维护</label></div>');
  119. $(".tool-radio input[type='radio']").on('click',
  120. function(e) {
  121. document.getElementById("SearchForm").reset();
  122. GetSearchList();
  123. RefreshTable();
  124. });
  125. });
  126. function GetSearchList() {
  127. var count = $("#SearchForm").find(".KeyWords").length;
  128. window._searchList = [];
  129. var radioType = $('input[name="radioType"]:checked').val();
  130. if (radioType) {
  131. window._searchList.push({ KeyWords: radioType, KeyField: "mpType", FieldType: "1", ExpType: "0" });
  132. }
  133. for (var i = 1; i <= count; i++) {
  134. var keyWords = $("#KeyWords-" + i).val();
  135. if (keyWords) {
  136. var keyField = $("#KeyField-" + i).val();
  137. var fieldType = $("#FieldType-" + i).val();
  138. var expType = $("#ExpType-" + i).val();
  139. window._searchList.push({
  140. KeyWords: keyWords,
  141. KeyField: keyField,
  142. FieldType: fieldType,
  143. ExpType: expType
  144. });
  145. }
  146. }
  147. }
  148. function PlanTypeChange(name) {
  149. if (typeof name !=="string") {
  150. name = "";
  151. }
  152. var type = $('#modal #planType').val();
  153. $('#modal #deviceName1').val(name);
  154. $('#modal #deviceName2').val(name);
  155. $('#modal #name').val('');
  156. $('#modal #deviceNo').val('');
  157. $("#modal .type").removeClass('required').closest('.form-group-sm').hide();
  158. if (type) {
  159. $("#modal .type" + type).addClass('required').closest('.form-group-sm').fadeIn();
  160. }
  161. }
  162. function DeviceNameChange(that) {
  163. $('#modal #name').val($(that).find('option:selected').text());
  164. $('#modal #deviceNo').val($(that).val());
  165. }
  166. </script>
  167. <!--格式化-->
  168. <script id="formatter-script" type="text/javascript">
  169. function ExDateFormatter(v, r, i, f) {
  170. return CheckDateFormatter(v, r, i, f, 3 * 30);
  171. }
  172. function MtDateFormatter(v, r, i, f) {
  173. if (r.planType === 1) {
  174. value = `${r.numberOfUsers}/${r.maintenanceCycle}`
  175. if (r.numberOfUsers >= r.maintenanceCycle) {
  176. return '<span style="color:red" class="iwb-flash2">' + value + ' [已到期]</span>'
  177. }
  178. if ((r.maintenanceCycle - r.numberOfUsers) > 0 && (r.maintenanceCycle - r.numberOfUsers) <= 10000) {
  179. return '<span style="color:red" class="iwb-flash2">' + value + ' [即将到期]</span>'
  180. }
  181. return value
  182. }
  183. return CheckDateFormatter(v, r, i, f, 10);
  184. }
  185. function CheckDateFormatter(v, r, i, f, day) {
  186. var value = DateFormatter(v, r, i, f);
  187. if (value <= new Date().format('yyyy-MM-dd')) {
  188. return '<span style="color:red" class="iwb-flash2">' + value + ' [已到期]</span>';
  189. }
  190. var date = new Date(new Date(new Date().getTime() + day * 1000 * 60 * 60 * 24)).format('yyyy-MM-dd');
  191. if (date >= value) {
  192. return '<span style="color:orange" class="iwb-flash">' + value + ' [即将到期]</span>';
  193. }
  194. return value;
  195. }
  196. function PlanTypeFormatter(v) {
  197. var name = $('#hid-planType option[value="' + v + '"]').text();
  198. switch (v) {
  199. case 1:
  200. return '<span class="label label-info">' + name + '</span>';
  201. case 2:
  202. return '<span class="label label-warning">' + name + '</span>';
  203. default:
  204. return '<span class="label label-danger">' + name + '</span>';
  205. }
  206. }
  207. function TypeFormatter(v) {
  208. var name = $('#hid-type option[value="' + v + '"]').text();
  209. switch (v) {
  210. case 0:
  211. return '<span class="label label-danger">' + name + '</span>';
  212. default:
  213. return '<span class="label label-info">' + name + '</span>';
  214. }
  215. }
  216. </script>
  217. }
  218. <section style="display: none">
  219. <select id="hid-type">
  220. <option value=""></option>
  221. </select>
  222. @Html.DropDownList("hid-planType", planType)
  223. </section>