tender.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /**
  2. * 标段相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2018/2/5
  6. * @version
  7. */
  8. // 整理数据
  9. let tenderData = [];
  10. try {
  11. if (tenderList.length <= 0) {
  12. throw '数据为空';
  13. }
  14. for(const tmp of tenderList) {
  15. const tmpData = {
  16. value: 7814964.00,
  17. name: tmp.name,
  18. };
  19. tenderData.push(tmpData);
  20. }
  21. } catch (error) {
  22. }
  23. // 属性
  24. function loadCommonProperty () {
  25. // 合同信息
  26. $('#build-name').val(property.deal_info.buildName);
  27. $('#deal-code').val(property.deal_info.dealCode);
  28. $('#deal-name').val(property.deal_info.dealName);
  29. // 参建单位
  30. // 建设单位
  31. $('#build-company').val(property.construction_unit.build.company);
  32. $('#build-corporation').val(property.construction_unit.build.corporation);
  33. $('#build-date').val(property.construction_unit.build.date);
  34. // 承包单位1
  35. $('#contract1-company').val(property.construction_unit.contract1.company);
  36. $('#contract1-corporation').val(property.construction_unit.contract1.corporation);
  37. $('#contract1-date').val(property.construction_unit.contract1.date);
  38. // 承包单位2
  39. $('#contract2-company').val(property.construction_unit.contract2.company);
  40. $('#contract2-corporation').val(property.construction_unit.contract2.corporation);
  41. $('#contract2-date').val(property.construction_unit.contract2.date);
  42. // 监理单位1
  43. $('#supervision1-company').val(property.construction_unit.supervision1.company);
  44. $('#supervision1-corporation').val(property.construction_unit.supervision1.corporation);
  45. $('#supervision1-date').val(property.construction_unit.supervision1.date);
  46. // 监理单位2
  47. $('#supervision2-company').val(property.construction_unit.supervision2.company);
  48. $('#supervision2-corporation').val(property.construction_unit.supervision2.corporation);
  49. $('#supervision2-date').val(property.construction_unit.supervision2.date);
  50. // 技术参数
  51. $('#loadLevel').val(property.tech_param.loadLevel);
  52. $('#length').val(property.tech_param.loadLength);
  53. $('#start-peg').val(property.tech_param.startPeg);
  54. $('#end-peg').val(property.tech_param.endPeg);
  55. $('#lane-count').val(property.tech_param.laneCount);
  56. $('#deal-period').val(property.tech_param.dealPeriod);
  57. $('#start-date').val(property.tech_param.startDate);
  58. $('#plan-end-date').val(property.tech_param.planEndDate);
  59. }
  60. // 小数位数
  61. function loadCalculateProperty () {
  62. $('#decimal-up').val(property.decimal.up);
  63. $('#decimal-tp').val(property.decimal.tp);
  64. $('#decimal-pay')[0].checked = property.decimal.pay;
  65. $('#decimal-pay-tp').val(property.decimal.payTp);
  66. }
  67. // 清单精度
  68. function loadPrecisionProperty () {
  69. $('#unit-t').val(property.precision.t.value);
  70. $('#unit-km').val(property.precision.km.value);
  71. $('#unit-m').val(property.precision.m.value);
  72. $('#unit-m2').val(property.precision.m2.value);
  73. $('#unit-m3').val(property.precision.m3.value);
  74. $('#unit-kg').val(property.precision.kg.value);
  75. $('#unit-ge').val(property.precision.ge.value);
  76. $('#unit-tai').val(property.precision.tai.value);
  77. $('#unit-tao').val(property.precision.tao.value);
  78. $('#unit-ke').val(property.precision.ke.value);
  79. $('#unit-zu').val(property.precision.zu.value);
  80. $('#unit-xitong').val(property.precision.xitong.value);
  81. $('#unit-other').val(property.precision.other.value);
  82. }
  83. // 合同参数
  84. function loadDealProperty () {
  85. $('#contract-price').val(property.deal_param.contractPrice);
  86. $('#zan-lie-price').val(property.deal_param.zanLiePrice);
  87. const iDecimal = property.decimal.pay ? property.decimal.payTp : property.decimal.tp;
  88. $('#c-zl').val(ZhCalc.round(ZhCalc.minus(property.deal_param.contractPrice, property.deal_param.zanLiePrice), iDecimal));
  89. $('#start-advance').val(property.deal_param.startAdvance);
  90. $('#material-advance').val(property.deal_param.materialAdvance);
  91. }
  92. // 显示设置
  93. function loadDisplayProperty () {
  94. $('#ledger-dgn-qty')[0].checked = property.display.ledger.dgnQty;
  95. $('#ledger-cl-qty')[0].checked = property.display.ledger.clQty;
  96. }
  97. // 设置某个div下全部的input、select是否只读
  98. function setReadOnly(obj, readOnly) {
  99. if (readOnly) {
  100. $('input', obj).attr('readonly', '');
  101. $('select', obj).attr('disabled', '');
  102. $('input[type=checkbox]', obj).attr('disabled', '');
  103. } else {
  104. $('input', obj).removeAttr('readonly');
  105. $('select', obj).removeAttr('disabled');
  106. $('input[type=checkbox]', obj).removeAttr('disabled');
  107. }
  108. }
  109. // 获取当前合同支付应该使用的小数位数
  110. function getDealTpDecimal() {
  111. const spec = $('#decimal-pay')[0].checked;
  112. return spec ? _.toNumber($('#decimal-pay-tp').val()) : _.toNumber($('#decimal-tp').val());
  113. }
  114. // 四舍五入
  115. function roundPrice(obj) {
  116. const iDecimal = getDealTpDecimal();
  117. obj.val(ZhCalc.round(_.toNumber(obj.val()), iDecimal));
  118. }
  119. // 计算签约合同价(不含暂列金额)
  120. function calculateC2() {
  121. const constract = _.toNumber($('#contract-price').val());
  122. const zanLie = _.toNumber($('#zan-lie-price').val());
  123. const iDecimal = getDealTpDecimal();
  124. $('#c-zl').val(ZhCalc.round(constract - zanLie, iDecimal));
  125. }
  126. // 根据小数位数,计算全部的合同参数
  127. function CalculateAllDealParam() {
  128. roundPrice($('#contract-price'));
  129. roundPrice($('#zan-lie-price'));
  130. roundPrice($('#start-advance'));
  131. roundPrice($('#material-advance'));
  132. calculateC2();
  133. }
  134. // 根据Min Max限制Input输入
  135. function limitInputMinMax (obj) {
  136. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  137. obj.value = obj.max;
  138. }
  139. if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  140. obj.value = obj.min;
  141. }
  142. }
  143. // 根据Maxlength限制input输入
  144. function limitMaxLength (obj) {
  145. if (obj.value.length > obj.maxLength) {
  146. obj.value = obj.value.substr(0, obj.maxLength);
  147. }
  148. }
  149. // 根据正则限制输入
  150. function limitReg(obj, reg) {
  151. obj.value = obj.value.replace(reg, '');
  152. }
  153. // 小数位数 input 输入限制
  154. function limitDecimal(obj) {
  155. limitReg(obj, /[^\d]/g);
  156. limitMaxLength(obj);
  157. limitInputMinMax(obj);
  158. }
  159. function limitDealParamLength(obj) {
  160. limitReg(obj, /[^\d\.]/g); // 过滤数字和.
  161. limitReg(obj, /\.{2,}/g); // 过滤第二个.
  162. limitInputMinMax(obj);
  163. }
  164. function checkNumberValid(obj) {
  165. const value = _.toNumber(obj.value);
  166. obj.value = value ? value : '';
  167. }
  168. $(document).ready(function() {
  169. // 章节设置
  170. const chapterObj = (function () {
  171. const spreadSetting = {
  172. cols: [
  173. {title: '章节', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  174. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  175. ],
  176. emptyRows: 0,
  177. headRows: 1,
  178. headRowHeight: [40],
  179. defaultRowHeight: 21,
  180. };
  181. const spread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
  182. spread.options.showVerticalScrollbar = false;
  183. spread.options.showHorizontalScrollbar = false;
  184. SpreadJsObj.initSheet(spread.getActiveSheet(), spreadSetting);
  185. function checkSheetData(sheet) {
  186. let hint = '';
  187. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  188. const cell = sheet.getCell(iRow, 1);
  189. const defaultStype = sheet.getDefaultStyle();
  190. if (cell.text().length > 50) {
  191. cell.backColor('#f8d7da');
  192. hint = '章节名称的长度超出范围,请重新输入';
  193. } else {
  194. cell.backColor(defaultStype.backColor);
  195. }
  196. }
  197. if (hint === '') {
  198. $('#hint-6').hide();
  199. } else {
  200. $('#hint-6').html('<i class="fa fa-smile-o mr-2"></i>' + hint).show();
  201. }
  202. }
  203. spread.bind(spreadNS.Events.EditEnding, function (e, info) {
  204. checkSheetData(info.sheet);
  205. });
  206. spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  207. checkSheetData(info.sheet);
  208. });
  209. function loadChapterProperty() {
  210. SpreadJsObj.loadSheetData(spread.getActiveSheet(), SpreadJsObj.DataType.Data, property.chapter);
  211. $('#hint-6').hide();
  212. const sheet = spread.getActiveSheet();
  213. const defaultStype = sheet.getDefaultStyle();
  214. sheet.getRange(0, 0, sheet.getRowCount(), sheet.getColumnCount()).backColor(defaultStype.backColor);
  215. }
  216. function setReadOnly(readOnly) {
  217. SpreadJsObj.resetFieldReadOnly(spread.getActiveSheet(), 'name', readOnly);
  218. }
  219. function getNewChapterData() {
  220. const result = [];
  221. const sheet = spread.getActiveSheet();
  222. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  223. const data = {};
  224. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  225. const col = spreadSetting.cols[iCol];
  226. data[col.field] = sheet.getText(iRow, iCol);
  227. if (col.field === 'name') {
  228. if (data.name.length > 50) {
  229. return null;
  230. }
  231. }
  232. }
  233. result.push(data);
  234. }
  235. return result;
  236. }
  237. return { loadChapterProperty, setReadOnly, getNewChapterData, }
  238. })();
  239. // 标段属性
  240. function loadTenderProperty() {
  241. // 加载属性
  242. loadCommonProperty();
  243. loadCalculateProperty();
  244. loadPrecisionProperty();
  245. loadDealProperty();
  246. loadDisplayProperty();
  247. chapterObj.loadChapterProperty();
  248. // 设置只读
  249. setReadOnly('#shuxing', true);
  250. }
  251. loadTenderProperty();
  252. /**
  253. * 属性
  254. */
  255. // 编辑
  256. $('#edit-1').click(() => {
  257. setReadOnly('#v-pills-1', false);
  258. $('#post-1').parent().show();
  259. $('#edit-1').parent().hide();
  260. });
  261. // 取消
  262. $('#cancel-1').click(() => {
  263. setReadOnly('#v-pills-1', true);
  264. loadCommonProperty();
  265. $('#post-1').parent().hide();
  266. $('#edit-1').parent().show();
  267. });
  268. // 提交
  269. $('#post-1').click(() => {
  270. const prop = {
  271. deal_info: {
  272. buildName: $('#build-name').val(),
  273. dealCode: $('#deal-code').val(),
  274. dealName: $('#deal-name').val(),
  275. },
  276. construction_unit: {
  277. build: {
  278. company: $('#build-company').val(),
  279. corporation: $('#build-corporation').val(),
  280. date: $('#build-date').val(),
  281. },
  282. contract1: {
  283. company: $('#contract1-company').val(),
  284. corporation: $('#contract1-corporation').val(),
  285. date: $('#contract1-date').val(),
  286. },
  287. contract2: {
  288. company: $('#contract2-company').val(),
  289. corporation: $('#contract2-corporation').val(),
  290. date: $('#contract2-date').val(),
  291. },
  292. supervision1: {
  293. company: $('#supervision1-company').val(),
  294. corporation: $('#supervision1-corporation').val(),
  295. date: $('#supervision1-date').val(),
  296. },
  297. supervision2: {
  298. company: $('#supervision2-company').val(),
  299. corporation: $('#supervision2-corporation').val(),
  300. date: $('#supervision2-date').val(),
  301. },
  302. },
  303. tech_param: {
  304. loadLevel: _.toNumber($('#loadLevel').val()),
  305. loadLength: _.toNumber($('#length').val()),
  306. startPeg: $('#start-peg').val(),
  307. endPeg: $('#end-peg').val(),
  308. laneCount: _.toNumber($('#lane-count').val()),
  309. dealPeriod: $('#deal-period').val(),
  310. startDate: $('#start-date').val(),
  311. planEndDate: $('#plan-end-date').val(),
  312. }
  313. };
  314. const tenderId = window.location.pathname.split('/')[2];
  315. postData('/tender/' + tenderId + '/save', prop, function (data) {
  316. setReadOnly('#v-pills-1', true);
  317. property.deal_info = data.deal_info;
  318. property.construction_unit = data.construction_unit;
  319. property.tech_param = data.tech_param;
  320. $('#post-1').parent().hide();
  321. $('#edit-1').parent().show();
  322. });
  323. });
  324. /**
  325. * 计算参数
  326. */
  327. // 编辑
  328. $('#edit-2').click(() => {
  329. setReadOnly('#v-pills-2', false);
  330. $('#post-2').parent().show();
  331. $('#edit-2').parent().hide();
  332. });
  333. // 取消
  334. $('#cancel-2').click(() => {
  335. setReadOnly('#v-pills-2', true);
  336. loadCalculateProperty();
  337. $('#post-2').parent().hide();
  338. $('#edit-2').parent().show();
  339. });
  340. // 提交
  341. $('#post-2').click(() => {
  342. const prop = {
  343. decimal: {
  344. up: _.toNumber($('#decimal-up').val()),
  345. tp: _.toNumber($('#decimal-tp').val()),
  346. pay: $('#decimal-pay')[0].checked,
  347. payTp: _.toNumber($('#decimal-pay-tp').val()),
  348. }
  349. };
  350. const tenderId = window.location.pathname.split('/')[2];
  351. postData('/tender/' + tenderId + '/save', prop, function (data) {
  352. setReadOnly('#v-pills-2', true);
  353. property.decimal = data.decimal;
  354. $('#post-2').parent().hide();
  355. $('#edit-2').parent().show();
  356. });
  357. });
  358. /**
  359. * 清单精度
  360. */
  361. // 编辑
  362. $('#edit-3').click(() => {
  363. setReadOnly('#v-pills-3', false);
  364. $('#post-3').parent().show();
  365. $('#edit-3').parent().hide();
  366. });
  367. // 取消
  368. $('#cancel-3').click(() => {
  369. setReadOnly('#v-pills-3', true);
  370. loadPrecisionProperty();
  371. $('#post-3').parent().hide();
  372. $('#edit-3').parent().show();
  373. });
  374. // 提交
  375. $('#post-3').click(() => {
  376. const prop = { precision: JSON.parse(JSON.stringify(property.precision)) };
  377. prop.precision.t.value = _.toNumber($('#unit-t').val());
  378. prop.precision.km.value = _.toNumber($('#unit-km').val());
  379. prop.precision.m.value = _.toNumber($('#unit-m').val());
  380. prop.precision.m2.value = _.toNumber($('#unit-m2').val());
  381. prop.precision.m3.value = _.toNumber($('#unit-m3').val());
  382. prop.precision.kg.value = _.toNumber($('#unit-kg').val());
  383. prop.precision.ge.value = _.toNumber($('#unit-ge').val());
  384. prop.precision.tai.value = _.toNumber($('#unit-tai').val());
  385. prop.precision.tao.value = _.toNumber($('#unit-tao').val());
  386. prop.precision.ke.value = _.toNumber($('#unit-ke').val());
  387. prop.precision.zu.value = _.toNumber($('#unit-zu').val());
  388. prop.precision.xitong.value = _.toNumber($('#unit-xitong').val());
  389. prop.precision.other.value = _.toNumber($('#unit-other').val());
  390. const tenderId = window.location.pathname.split('/')[2];
  391. postData('/tender/' + tenderId + '/save', prop, function (data) {
  392. setReadOnly('#v-pills-3', true);
  393. property.precision = data.precision;
  394. $('#post-3').parent().hide();
  395. $('#edit-3').parent().show();
  396. });
  397. });
  398. /**
  399. * 合同参数
  400. */
  401. // 编辑
  402. $('#edit-4').click(() => {
  403. setReadOnly('#v-pills-4', false);
  404. $('#post-4').parent().show();
  405. $('#edit-4').parent().hide();
  406. });
  407. // 取消
  408. $('#cancel-4').click(() => {
  409. setReadOnly('#v-pills-4', true);
  410. loadDealProperty();
  411. $('#post-4').parent().hide();
  412. $('#edit-4').parent().show();
  413. });
  414. // 提交
  415. $('#post-4').click(() => {
  416. const prop = {
  417. deal_param: {
  418. contractPrice: _.toNumber($('#contract-price').val()),
  419. zanLiePrice: _.toNumber($('#zan-lie-price').val()),
  420. startAdvance: _.toNumber($('#start-advance').val()),
  421. materialAdvance: _.toNumber($('#material-advance').val()),
  422. }
  423. };
  424. const tenderId = window.location.pathname.split('/')[2];
  425. postData('/tender/' + tenderId + '/save', prop, function (data) {
  426. setReadOnly('#v-pills-4', true);
  427. property.deal_param = data.deal_param;
  428. $('#post-4').parent().hide();
  429. $('#edit-4').parent().show();
  430. });
  431. });
  432. /**
  433. * 显示设置
  434. */
  435. // 编辑
  436. $('#edit-5').click(() => {
  437. setReadOnly('#v-pills-5', false);
  438. $('#post-5').parent().show();
  439. $('#edit-5').parent().hide();
  440. });
  441. // 取消
  442. $('#cancel-5').click(() => {
  443. setReadOnly('#v-pills-5', true);
  444. loadDisplayProperty();
  445. $('#post-5').parent().hide();
  446. $('#edit-5').parent().show();
  447. });
  448. // 提交
  449. $('#post-5').click(() => {
  450. const prop = {
  451. display: {
  452. ledger: { dgnQty: $('#ledger-dgn-qty')[0].checked, clQty: $('#ledger-cl-qty')[0].checked, },
  453. },
  454. };
  455. const tenderId = window.location.pathname.split('/')[2];
  456. postData('/tender/' + tenderId + '/save', prop, function (data) {
  457. setReadOnly('#v-pills-5', true);
  458. property.display = data.display;
  459. $('#post-5').parent().hide();
  460. $('#edit-5').parent().show();
  461. });
  462. });
  463. /**
  464. * 章节设置
  465. */
  466. // 编辑
  467. $('#edit-6').click(() => {
  468. chapterObj.setReadOnly(false);
  469. $('#post-6').parent().show();
  470. $('#edit-6').parent().hide();
  471. });
  472. // 取消
  473. $('#cancel-6').click(() => {
  474. chapterObj.loadChapterProperty();
  475. chapterObj.setReadOnly(true);
  476. $('#hint-6').hide();
  477. $('#post-6').parent().hide();
  478. $('#edit-6').parent().show();
  479. });
  480. // 提交
  481. $('#post-6').click(() => {
  482. const chapter = chapterObj.getNewChapterData();
  483. if (!chapter) { return; }
  484. const tenderId = window.location.pathname.split('/')[2];
  485. postData('/tender/' + tenderId + '/save', { chapter: chapter }, function (data) {
  486. chapterObj.setReadOnly(true);
  487. property.chapter = data.chapter;
  488. $('#post-6').parent().hide();
  489. $('#edit-6').parent().show();
  490. });
  491. });
  492. //标段类型选择
  493. $('#tender_type_select').change(function () {
  494. const type = $(this).val() != 0 ? '/?type='+$(this).val() : '';
  495. window.location.href = '/tender' + type;
  496. });
  497. //编辑标段 选择
  498. $('.save-btn').on('click',function () {
  499. $('#saveid').val($(this).attr('tender-id'));
  500. $('#savename').val($(this).attr('tender-name'));
  501. $('#savetype').val($(this).attr('tender-type'));
  502. });
  503. //删除标段 选择
  504. $('.del-btn').on('click',function () {
  505. $('#delid').val($(this).attr('tender-id'));
  506. });
  507. });