quality_inspection.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/21
  7. * @version
  8. */
  9. // 向后端请求中间计量号
  10. function getNewCode() {
  11. postData('/tender/'+ tenderId +'/change/newCode', { type: rulesType }, function (code) {
  12. if (code !== '') {
  13. $('#bj-code').val(code);
  14. }
  15. });
  16. }
  17. class codeRuleSet {
  18. constructor (obj) {
  19. this.body = obj;
  20. // 切换规则组件类型
  21. $('.rule-change', obj).change(function () {
  22. const codeType = this.selectedIndex-1;
  23. if (codeType === ruleConst.ruleType.addNo) {
  24. $('#format', obj).show();
  25. $('#text', obj).show();
  26. $('#text>label', obj).text('起始编号');
  27. $('#text>input', obj).val('001');
  28. const s = '0000000000' + 1;
  29. $('#text>input', obj).val(s.substr(s.length - $('#format>input', obj).val()));
  30. } else if (codeType === ruleConst.ruleType.text) {
  31. $('#format', obj).hide();
  32. $('#text', obj).show();
  33. $('#text>label', obj).text('文本');
  34. $('#text>input', obj).val('').attr('placeholder', '请在这里输入需要的文本');
  35. } else {
  36. $('#format', obj).hide();
  37. $('#text', obj).hide();
  38. }
  39. });
  40. // 修改编号位数
  41. $('#format>input', obj).change(function () {
  42. const s = '0000000000' + parseInt($('#text>input', obj).val());
  43. $('#text>input', obj).val(s.substr(s.length - $(this).val()));
  44. });
  45. // 修改连接符
  46. $('.connector-change', obj).change(function () {
  47. const connectorType = this.options[this.selectedIndex].text;
  48. const rules = $('span>span', obj), ruleText = [];
  49. for (const r of rules) {
  50. ruleText.push($.trim(r.innerText));
  51. }
  52. if (connectorType === '无') {
  53. $('#preview', obj).text(ruleText.join(''));
  54. } else {
  55. $('#preview', obj).text(ruleText.join(connectorType));
  56. }
  57. connectorRule = this.options[this.selectedIndex].value;
  58. });
  59. // 新增规则组件
  60. $('#addRule', obj).click(function () {
  61. const codeType = $('select', obj)[1].selectedIndex-1;
  62. const rule = {rule_type: codeType}, html = [];
  63. let preview;
  64. switch (codeType) {
  65. case ruleConst.ruleType.dealCode: {
  66. if (dealCode === '') {
  67. toastr.error('当前标段合同编号为空,请选择其他组件。');
  68. return false;
  69. }
  70. preview = dealCode;
  71. break;
  72. }
  73. case ruleConst.ruleType.tenderName: {
  74. preview = tenderName;
  75. break;
  76. }
  77. case ruleConst.ruleType.text: {
  78. rule.text = $('#text>input', obj).val();
  79. if (rule.text === '') {
  80. toastr.error('文本内容不允许为空。');
  81. return false;
  82. }
  83. preview = rule.text;
  84. break;
  85. }
  86. case ruleConst.ruleType.inDate: {
  87. preview = moment().format('YYYY');
  88. break;
  89. }
  90. case ruleConst.ruleType.addNo: {
  91. rule.format = parseInt($('#format>input', obj).val());
  92. rule.start = parseInt($('#text>input', obj).val());
  93. if ($('#text>input', obj).val().length !== rule.format) {
  94. toastr.error('起始编号位数和自动编号位数不一致。');
  95. return false;
  96. }
  97. const s = '0000000000';
  98. preview = s.substr(s.length - rule.format);
  99. break;
  100. }
  101. default: {
  102. toastr.error('请选择组件再添加');
  103. return false;
  104. }
  105. }
  106. // 更新规则
  107. codeRule.push(rule);
  108. // 更新规则显示
  109. html.push('<span class="badge badge-light" title="' + ruleConst.ruleString[codeType] + '" rule="' + JSON.stringify(rule) + '">');
  110. html.push('<span>' + preview + '</span>');
  111. html.push('<a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>');
  112. html.push('</span>');
  113. const part = $('#ruleParts', obj).append(html.join(''));
  114. // 更新规则预览
  115. const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
  116. const previewtext = $.trim($('#preview', obj).text()) === '' ? preview : $.trim($('#preview', obj).text()) + connectorType + preview;
  117. $('#preview', obj).text(previewtext);
  118. });
  119. // 删除规则组件
  120. $($('#ruleParts', obj)).on('click', 'a', function () {
  121. const index = $('a', obj).index(this);
  122. codeRule.splice(index-1, 1);
  123. $(this).parent().remove();
  124. const rules = $('span>span', obj), ruleText = [];
  125. for (const r of rules) {
  126. ruleText.push($.trim(r.innerText));
  127. }
  128. const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
  129. $('#preview', obj).text(ruleText.join(connectorType));
  130. });
  131. }
  132. }
  133. $(document).ready(() => {
  134. // 首次进入设置
  135. let showNoNeed = false;
  136. if (cRuleFirst) {
  137. codeRule = [];
  138. showNoNeed = true;
  139. $('#setting').modal('show');
  140. }
  141. // 设置
  142. const ruleSet = new codeRuleSet($('div.modal-body', '#setting'));
  143. $('#setRule', '#setting').bind('click', function () {
  144. const data = {
  145. rule: ruleType,
  146. type: rulesType,
  147. connector: connectorRule,
  148. data: JSON.stringify(codeRule),
  149. };
  150. if (codeRule.length !== 0) {
  151. $('#autoCodeShow').show();
  152. }
  153. postData('/tender/rule', data, function () {
  154. if (cRuleFirst && showNoNeed) {
  155. $('#changeFirst').click();
  156. $('.ml-auto a[href="#add-bj"]').click();
  157. } else {
  158. $('#setting').modal('hide');
  159. }
  160. });
  161. })
  162. $('.ml-auto').on('click', 'a', function () {
  163. const content = $(this).attr('href');
  164. if (content === '#add-bj') {
  165. $('#add-bj-modal').modal('show')
  166. getNewCode();
  167. if ($('#changeList').children.length === 0) {
  168. $('#addCancel').hide();
  169. } else {
  170. $('#addCancel').show();
  171. }
  172. $('#bj-code').removeClass('is-invalid');
  173. }
  174. });
  175. // 获取最新可用变更令号
  176. $('#autoCode').click(getNewCode);
  177. // 新增变更令 确认
  178. $('#addOk').click(function () {
  179. $(this).attr('disabled', true);
  180. if ($('#check_item').val().length === 0) {
  181. $('#check_item').addClass('is-invalid');
  182. $('#name_error_msg').show();
  183. $('#name_error_msg').text('检查项不能为空。');
  184. $(this).attr('disabled', false);
  185. setTimeout(function () {
  186. $('#check_item').removeClass('is-invalid');
  187. $('#name_error_msg').hide();
  188. }, 2000);
  189. return;
  190. }
  191. if ($('#check_item').val().length > 255) {
  192. $('#chek_item').addClass('is-invalid');
  193. $('#name_error_msg').show();
  194. $('#name_error_msg').text('检查项超过255个字,请缩减。');
  195. $(this).attr('disabled', false);
  196. setTimeout(function () {
  197. $('#check_item').removeClass('is-invalid');
  198. $('#name_error_msg').hide();
  199. }, 2000);
  200. return;
  201. }
  202. if ($('#check_date').val() === '') {
  203. $('#check_date').addClass('is-invalid');
  204. $('#check_date').siblings('.invalid-feedback').show();
  205. $('#check_date').siblings('.invalid-feedback').text('检查日期不能为空。');
  206. $(this).attr('disabled', false);
  207. setTimeout(function () {
  208. $('#check_date').removeClass('is-invalid');
  209. $('#check_date').siblings('.invalid-feedback').hide();
  210. }, 2000);
  211. return;
  212. } else {
  213. // 判断日期格式
  214. const reg = /^\d{4}-\d{2}-\d{2}$/;
  215. if (!reg.test($('#check_date').val())) {
  216. $('#check_date').addClass('is-invalid');
  217. $('#check_date').siblings('.invalid-feedback').show();
  218. $('#check_date').siblings('.invalid-feedback').text('检查日期格式错误,应为YYYY-MM-DD。');
  219. $(this).attr('disabled', false);
  220. setTimeout(function () {
  221. $('#check_date').removeClass('is-invalid');
  222. $('#check_date').siblings('.invalid-feedback').hide();
  223. }, 2000);
  224. return;
  225. }
  226. }
  227. const data = {
  228. type: 'add',
  229. code: $('#bj-code').val(),
  230. check_item: $('#check_item').val(),
  231. check_date: $('#check_date').val(),
  232. };
  233. if (data.code || data.code !== '') {
  234. postData(`/sp/${spid}/quality/tender/${tenderId}/inspection/save`, data, function (rst) {
  235. $('#bj-code').removeClass('is-invalid');
  236. $('#add-bj-modal').modal('hide');
  237. $(this).attr('disabled', false);
  238. window.location.href = `/sp/${spid}/quality/tender/${tenderId}/inspection/${rst.id}/information`;
  239. }, function () {
  240. $('#bj-code').addClass('is-invalid');
  241. $('#bjHint').show();
  242. $(this).attr('disabled', false);
  243. });
  244. }
  245. });
  246. //状态切换
  247. $('#status_select a').on('click', function () {
  248. const status = $(this).data('val');
  249. let url = `/sp/${spid}/quality/tender/${tenderId}/inspection`;
  250. const filterString = setChangeFilterData('quality-inspection-'+ tenderId +'-list-order', status !== 0 ? '?status='+ status : '');
  251. if (filterString) url = url + filterString;
  252. window.location.href = url;
  253. });
  254. // 不再显示首次使用
  255. $('#changeFirst').click(function () {
  256. showNoNeed = false;
  257. $('#changeFirst').remove();
  258. $('#hide_modal').show();
  259. $('#setting').modal('hide');
  260. postData('/tender/'+ tenderId +'/rule/first', { type: rulesType }, function () {
  261. });
  262. });
  263. // 排序初始化
  264. let orderSetting = getLocalCache('quality-inspection-'+ tenderId +'-list-order');
  265. if (!orderSetting) orderSetting = 'time|desc';
  266. const orders = orderSetting.split('|');
  267. $("#sort-radio input[value='"+ orders[0] +"']").prop('checked', true);
  268. $("#order-radio input[value='"+ orders[1] +"']").prop('checked', true);
  269. if (orders[0] === 'time') {
  270. $('#bpaixu').text('排序:创建时间');
  271. } else {
  272. $('#bpaixu').text('排序:编号');
  273. }
  274. $('#sort-radio input[name="paizhi"]').click(function () {
  275. const orderStr = $(this).val() + '|' + $('#order-radio input[name="paixu"]:checked').val();
  276. setLocalCache('quality-inspection-'+ tenderId +'-list-order', orderStr);
  277. let link = window.location.origin + window.location.pathname;
  278. const filterData = [];
  279. if ($('#zhankai').data('status') !== '0') {
  280. filterData.push('status=' + $('#zhankai').data('status'));
  281. }
  282. filterData.push('sort='+ $(this).val());
  283. filterData.push('order=' + $('#order-radio input[name="paixu"]:checked').val());
  284. if (getLocalCache('account-pageSize')) {
  285. filterData.push('pageSize=' + getLocalCache('account-pageSize'));
  286. }
  287. if (filterData.length > 0) {
  288. link += '?' + filterData.join('&');
  289. }
  290. window.location.href = link;
  291. });
  292. $('#order-radio input[name="paixu"]').click(function () {
  293. const orderStr = $('#sort-radio input[name="paizhi"]:checked').val() + '|' + $(this).val();
  294. setLocalCache('quality-inspection-'+ tenderId +'-list-order', orderStr);
  295. let link = window.location.origin + window.location.pathname;
  296. const filterData = [];
  297. if ($('#zhankai').data('status') !== '0') {
  298. filterData.push('status=' + $('#zhankai').data('status'));
  299. }
  300. filterData.push('sort='+ $('#sort-radio input[name="paizhi"]:checked').val());
  301. filterData.push('order=' + $(this).val());
  302. if (getLocalCache('account-pageSize')) {
  303. filterData.push('pageSize=' + getLocalCache('account-pageSize'));
  304. }
  305. if (filterData.length > 0) {
  306. link += '?' + filterData.join('&');
  307. }
  308. window.location.href = link;
  309. });
  310. $('.show-files').on('click', function () {
  311. const id = parseInt($(this).data('id'));
  312. const info = _.find(inspectionList, { id: id });
  313. console.log(info);
  314. handleFileList(info.attList || []);
  315. });
  316. function handleFileList(files = []) {
  317. $('#file-content').empty();
  318. let html = '';
  319. files.forEach((file, idx) => {
  320. html += `<tr><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/sp/${spid}/quality/tender/${file.tid}/inspection/${file.qiid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  321. })
  322. $('#file-content').append(html);
  323. }
  324. $.subMenu({
  325. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  326. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  327. key: 'menu.1.0.0',
  328. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  329. callback: function (info) {
  330. if (info.mini) {
  331. $('.panel-title').addClass('fluid');
  332. $('#sub-menu').removeClass('panel-sidebar');
  333. } else {
  334. $('.panel-title').removeClass('fluid');
  335. $('#sub-menu').addClass('panel-sidebar');
  336. }
  337. autoFlashHeight();
  338. }
  339. });
  340. });