change_apply.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. // else if ($('#changeList').children.length === 0) {
  142. // $('#add-bj').modal('show');
  143. // }
  144. // 设置
  145. const ruleSet = new codeRuleSet($('div.modal-body', '#setting'));
  146. $('#setRule', '#setting').bind('click', function () {
  147. const data = {
  148. rule: ruleType,
  149. type: rulesType,
  150. connector: connectorRule,
  151. data: JSON.stringify(codeRule),
  152. };
  153. if (codeRule.length !== 0) {
  154. $('#autoCodeShow').show();
  155. }
  156. postData('/tender/rule', data, function () {
  157. if (cRuleFirst && showNoNeed) {
  158. $('#changeFirst').click();
  159. $('.ml-auto a[href="#add-bj"]').click();
  160. // $('#add-bj-modal').modal('show');
  161. } else {
  162. $('#setting').modal('hide');
  163. }
  164. });
  165. })
  166. $('.ml-auto').on('click', 'a', function () {
  167. const content = $(this).attr('href');
  168. if (content === '#add-bj') {
  169. $('#add-bj-modal').modal('show')
  170. getNewCode();
  171. if ($('#changeList').children.length === 0) {
  172. $('#addCancel').hide();
  173. } else {
  174. $('#addCancel').show();
  175. }
  176. $('#bj-code').removeClass('is-invalid');
  177. }
  178. });
  179. // 获取最新可用变更令号
  180. $('#autoCode').click(getNewCode);
  181. // 新增变更令 确认
  182. $('#addOk').click(function () {
  183. $(this).attr('disabled', true);
  184. if (!openChangeProject && $('#bj-name').val().length === 0) {
  185. $('#bj-name').addClass('is-invalid');
  186. $('#name_error_msg').show();
  187. $('#name_error_msg').text('变更工程名称不能为空。');
  188. $(this).attr('disabled', false);
  189. setTimeout(function () {
  190. $('#bj-name').removeClass('is-invalid');
  191. $('#name_error_msg').hide();
  192. }, 2000);
  193. return;
  194. }
  195. if (!openChangeProject && $('#bj-name').val().length > 100) {
  196. $('#bj-name').addClass('is-invalid');
  197. $('#name_error_msg').show();
  198. $('#name_error_msg').text('名称超过100个字,请缩减名称。');
  199. $(this).attr('disabled', false);
  200. setTimeout(function () {
  201. $('#bj-name').removeClass('is-invalid');
  202. $('#name_error_msg').hide();
  203. }, 2000);
  204. return;
  205. }
  206. const data = {
  207. code: $('#bj-code').val(),
  208. project_code: $('#project-code').val(),
  209. name: $('#bj-name').val(),
  210. };
  211. if (data.code || data.code !== '') {
  212. postData('/tender/'+ tenderId +'/change/apply/add', data, function (rst) {
  213. $('#bj-code').removeClass('is-invalid');
  214. $('#mj-add').modal('hide');
  215. $(this).attr('disabled', false);
  216. window.location.href = '/tender/'+ tenderId +'/change/apply/' + rst.id + '/information';
  217. }, function () {
  218. $('#mj-code').addClass('is-invalid');
  219. $('#mj-Hint').show();
  220. $(this).attr('disabled', false);
  221. });
  222. }
  223. });
  224. $('#project-code').change(function () {
  225. if ($(this).val() === '') {
  226. $('#bj-name').val('');
  227. } else {
  228. const info = _.find(changeProjectList, { code: $(this).val() });
  229. $('#bj-name').val(info.name);
  230. }
  231. });
  232. //状态切换
  233. $('#status_select a').on('click', function () {
  234. const status = $(this).data('val');
  235. let url = '/tender/'+ tenderId +'/change/apply';
  236. if (status !== 0) {
  237. url += '/status/'+ status;
  238. }
  239. let orderSetting = getLocalCache('change-apply-'+ tenderId +'-list-order');
  240. if (orderSetting) {
  241. const orders = orderSetting.split('|');
  242. url += '?sort=' + orders[0] + '&order=' + orders[1];
  243. }
  244. window.location.href = url;
  245. });
  246. // 不再显示首次使用
  247. $('#changeFirst').click(function () {
  248. showNoNeed = false;
  249. $('#changeFirst').remove();
  250. $('#hide_modal').show();
  251. $('#setting').modal('hide');
  252. postData('/tender/'+ tenderId +'/rule/first', { type: rulesType }, function () {
  253. });
  254. });
  255. // 弹出删除变更框赋值
  256. $('.delete-caid-modal').on('click', function () {
  257. $('#delete-caid').val($(this).attr('caid'));
  258. });
  259. // 排序初始化
  260. let orderSetting = getLocalCache('change-apply-'+ tenderId +'-list-order');
  261. if (!orderSetting) orderSetting = 'time|desc';
  262. const orders = orderSetting.split('|');
  263. $("#sort-radio input[value='"+ orders[0] +"']").prop('checked', true);
  264. $("#order-radio input[value='"+ orders[1] +"']").prop('checked', true);
  265. if (orders[0] === 'time') {
  266. $('#bpaixu').text('排序:创建时间');
  267. } else {
  268. $('#bpaixu').text('排序:变更申请编号');
  269. }
  270. // let sortSetting = getLocalCache('change-'+ $('#tenderId').val() +'-list-sort');
  271. // if (sortSetting && parseInt(sortSetting) === 1) {
  272. // $('#bpaixu').click();
  273. // }
  274. // $('#sort-dropdown').on('shown.bs.dropdown', function () {
  275. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  276. // });
  277. // $('#sort-dropdown').on('hidden.bs.dropdown', function () {
  278. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 0);
  279. // });
  280. $('#sort-radio input[name="paizhi"]').click(function () {
  281. const orderStr = $(this).val() + '|' + $('#order-radio input[name="paixu"]:checked').val();
  282. setLocalCache('change-apply-'+ tenderId +'-list-order', orderStr);
  283. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  284. const link = window.location.origin + window.location.pathname + '?sort='+ $(this).val() + '&order=' + $('#order-radio input[name="paixu"]:checked').val();
  285. window.location.href = link;
  286. });
  287. $('#order-radio input[name="paixu"]').click(function () {
  288. const orderStr = $('#sort-radio input[name="paizhi"]:checked').val() + '|' + $(this).val();
  289. setLocalCache('change-apply-'+ tenderId +'-list-order', orderStr);
  290. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  291. const link = window.location.origin + window.location.pathname + '?sort='+ $('#sort-radio input[name="paizhi"]:checked').val() + '&order=' + $(this).val();
  292. window.location.href = link;
  293. })
  294. $.subMenu({
  295. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  296. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  297. key: 'menu.1.0.0',
  298. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  299. callback: function (info) {
  300. if (info.mini) {
  301. $('.panel-title').addClass('fluid');
  302. $('#sub-menu').removeClass('panel-sidebar');
  303. } else {
  304. $('.panel-title').removeClass('fluid');
  305. $('#sub-menu').addClass('panel-sidebar');
  306. }
  307. autoFlashHeight();
  308. }
  309. });
  310. });