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(_.round(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. }
  96. // 设置某个div下全部的input、select是否只读
  97. function setReadOnly(obj, readOnly) {
  98. if (readOnly) {
  99. $('input', obj).attr('readonly', '');
  100. $('select', obj).attr('disabled', '');
  101. $('input[type=checkbox]', obj).attr('disabled', '');
  102. } else {
  103. $('input', obj).removeAttr('readonly');
  104. $('select', obj).removeAttr('disabled');
  105. $('input[type=checkbox]', obj).removeAttr('disabled');
  106. }
  107. }
  108. // 获取当前合同支付应该使用的小数位数
  109. function getDealTpDecimal() {
  110. const spec = $('#decimal-pay')[0].checked;
  111. return spec ? _.toNumber($('#decimal-pay-tp').val()) : _.toNumber($('#decimal-tp').val());
  112. }
  113. // 四舍五入
  114. function roundPrice(obj) {
  115. const iDecimal = getDealTpDecimal();
  116. obj.val(_.round(_.toNumber(obj.val()), iDecimal));
  117. }
  118. // 计算签约合同价(不含暂列金额)
  119. function calculateC2() {
  120. const constract = _.toNumber($('#contract-price').val());
  121. const zanLie = _.toNumber($('#zan-lie-price').val());
  122. const iDecimal = getDealTpDecimal();
  123. $('#c-zl').val(_.round(constract - zanLie, iDecimal));
  124. }
  125. // 根据小数位数,计算全部的合同参数
  126. function CalculateAllDealParam() {
  127. roundPrice($('#contract-price'));
  128. roundPrice($('#zan-lie-price'));
  129. roundPrice($('#start-advance'));
  130. roundPrice($('#material-advance'));
  131. calculateC2();
  132. }
  133. // 根据Min Max限制Input输入
  134. function limitInputMinMax (obj) {
  135. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  136. obj.value = obj.max;
  137. }
  138. if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  139. obj.value = obj.min;
  140. }
  141. }
  142. // 根据Maxlength限制input输入
  143. function limitMaxLength (obj) {
  144. if (obj.value.length > obj.maxLength) {
  145. obj.value = obj.value.substr(0, obj.maxLength);
  146. }
  147. }
  148. // 根据正则限制输入
  149. function limitReg(obj, reg) {
  150. obj.value = obj.value.replace(reg, '');
  151. }
  152. // 小数位数 input 输入限制
  153. function limitDecimal(obj) {
  154. limitReg(obj, /[^\d]/g);
  155. //limitMaxLength(obj);
  156. limitInputMinMax(obj);
  157. }
  158. function limitDealParamLength(obj) {
  159. limitReg(obj, /[^\d\.]/g); // 过滤数字和.
  160. limitReg(obj, /\.{2,}/g); // 过滤第二个.
  161. limitInputMinMax(obj);
  162. }
  163. function checkNumberValid(obj) {
  164. const value = _.toNumber(obj.value);
  165. obj.value = value ? value : '';
  166. }
  167. $(document).ready(function() {
  168. // 章节设置
  169. const chapterObj = (function () {
  170. const spreadSetting = {
  171. cols: [
  172. {title: '章节', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  173. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  174. ],
  175. emptyRows: 0,
  176. headRows: 1,
  177. headRowHeight: [40],
  178. defaultRowHeight: 21,
  179. };
  180. const spread = SpreadJsObj.createNewSpread($('#chapter-spread')[0]);
  181. spread.options.showVerticalScrollbar = false;
  182. spread.options.showHorizontalScrollbar = false;
  183. SpreadJsObj.initSheet(spread.getActiveSheet(), spreadSetting);
  184. function checkSheetData(sheet) {
  185. let hint = '';
  186. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  187. const cell = sheet.getCell(iRow, 1);
  188. const defaultStype = sheet.getDefaultStyle();
  189. if (cell.text().length > 50) {
  190. cell.backColor('#f8d7da');
  191. hint = '章节名称的长度超出范围,请重新输入';
  192. } else {
  193. cell.backColor(defaultStype.backColor);
  194. }
  195. }
  196. if (hint === '') {
  197. $('#hint-6').hide();
  198. } else {
  199. $('#hint-6').html('<i class="fa fa-smile-o mr-2"></i>' + hint).show();
  200. }
  201. }
  202. spread.bind(spreadNS.Events.EditEnding, function (e, info) {
  203. checkSheetData(info.sheet);
  204. });
  205. spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  206. checkSheetData(info.sheet);
  207. });
  208. function loadChapterProperty() {
  209. SpreadJsObj.loadSheetData(spread.getActiveSheet(), SpreadJsObj.DataType.Data, property.chapter);
  210. $('#hint-6').hide();
  211. const sheet = spread.getActiveSheet();
  212. const defaultStype = sheet.getDefaultStyle();
  213. sheet.getRange(0, 0, sheet.getRowCount(), sheet.getColumnCount()).backColor(defaultStype.backColor);
  214. }
  215. function setReadOnly(readOnly) {
  216. SpreadJsObj.resetFieldReadOnly(spread.getActiveSheet(), 'name', readOnly);
  217. }
  218. function getNewChapterData() {
  219. const result = [];
  220. const sheet = spread.getActiveSheet();
  221. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  222. const data = {};
  223. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  224. const col = spreadSetting.cols[iCol];
  225. data[col.field] = sheet.getText(iRow, iCol);
  226. if (col.field === 'name') {
  227. if (data.name.length > 50) {
  228. return null;
  229. }
  230. }
  231. }
  232. result.push(data);
  233. }
  234. return result;
  235. }
  236. return { loadChapterProperty, setReadOnly, getNewChapterData, }
  237. })();
  238. // 标段属性
  239. function loadTenderProperty() {
  240. // 加载属性
  241. loadCommonProperty();
  242. loadCalculateProperty();
  243. loadPrecisionProperty();
  244. loadDealProperty();
  245. loadDisplayProperty();
  246. chapterObj.loadChapterProperty();
  247. // 设置只读
  248. setReadOnly('#shuxing', true);
  249. }
  250. loadTenderProperty();
  251. /**
  252. * 属性
  253. */
  254. // 编辑
  255. $('#edit-1').click(() => {
  256. setReadOnly('#v-pills-1', false);
  257. $('#post-1').parent().show();
  258. $('#edit-1').parent().hide();
  259. });
  260. // 取消
  261. $('#cancel-1').click(() => {
  262. setReadOnly('#v-pills-1', true);
  263. loadCommonProperty();
  264. $('#post-1').parent().hide();
  265. $('#edit-1').parent().show();
  266. });
  267. // 提交
  268. $('#post-1').click(() => {
  269. const prop = {
  270. deal_info: {
  271. buildName: $('#build-name').val(),
  272. dealCode: $('#deal-code').val(),
  273. dealName: $('#deal-name').val(),
  274. },
  275. construction_unit: {
  276. build: {
  277. company: $('#build-company').val(),
  278. corporation: $('#build-corporation').val(),
  279. date: $('#build-date').val(),
  280. },
  281. contract1: {
  282. company: $('#contract1-company').val(),
  283. corporation: $('#contract1-corporation').val(),
  284. date: $('#contract1-date').val(),
  285. },
  286. contract2: {
  287. company: $('#contract2-company').val(),
  288. corporation: $('#contract2-corporation').val(),
  289. date: $('#contract2-date').val(),
  290. },
  291. supervision1: {
  292. company: $('#supervision1-company').val(),
  293. corporation: $('#supervision1-corporation').val(),
  294. date: $('#supervision1-date').val(),
  295. },
  296. supervision2: {
  297. company: $('#supervision2-company').val(),
  298. corporation: $('#supervision2-corporation').val(),
  299. date: $('#supervision2-date').val(),
  300. },
  301. },
  302. tech_param: {
  303. loadLevel: _.toNumber($('#loadLevel').val()),
  304. loadLength: _.toNumber($('#length').val()),
  305. startPeg: $('#start-peg').val(),
  306. endPeg: $('#end-peg').val(),
  307. laneCount: _.toNumber($('#lane-count').val()),
  308. dealPeriod: $('#deal-period').val(),
  309. startDate: $('#start-date').val(),
  310. planEndDate: $('#plan-end-date').val(),
  311. }
  312. };
  313. const tenderId = window.location.pathname.split('/')[2];
  314. postData('/tender/' + tenderId + '/save', prop, function (data) {
  315. setReadOnly('#v-pills-1', true);
  316. property.deal_info = data.deal_info;
  317. property.construction_unit = data.construction_unit;
  318. property.tech_param = data.tech_param;
  319. $('#post-1').parent().hide();
  320. $('#edit-1').parent().show();
  321. });
  322. });
  323. /**
  324. * 计算参数
  325. */
  326. // 编辑
  327. $('#edit-2').click(() => {
  328. setReadOnly('#v-pills-2', false);
  329. $('#post-2').parent().show();
  330. $('#edit-2').parent().hide();
  331. });
  332. // 取消
  333. $('#cancel-2').click(() => {
  334. setReadOnly('#v-pills-2', true);
  335. loadCalculateProperty();
  336. $('#post-2').parent().hide();
  337. $('#edit-2').parent().show();
  338. });
  339. // 提交
  340. $('#post-2').click(() => {
  341. const prop = {
  342. decimal: {
  343. up: _.toNumber($('#decimal-up').val()),
  344. tp: _.toNumber($('#decimal-tp').val()),
  345. pay: $('#decimal-pay')[0].checked,
  346. payTp: _.toNumber($('#decimal-pay-tp').val()),
  347. }
  348. };
  349. const tenderId = window.location.pathname.split('/')[2];
  350. postData('/tender/' + tenderId + '/save', prop, function (data) {
  351. setReadOnly('#v-pills-2', true);
  352. property.decimal = data.decimal;
  353. $('#post-2').parent().hide();
  354. $('#edit-2').parent().show();
  355. });
  356. });
  357. /**
  358. * 清单精度
  359. */
  360. // 编辑
  361. $('#edit-3').click(() => {
  362. setReadOnly('#v-pills-3', false);
  363. $('#post-3').parent().show();
  364. $('#edit-3').parent().hide();
  365. });
  366. // 取消
  367. $('#cancel-3').click(() => {
  368. setReadOnly('#v-pills-3', true);
  369. loadPrecisionProperty();
  370. $('#post-3').parent().hide();
  371. $('#edit-3').parent().show();
  372. });
  373. // 提交
  374. $('#post-3').click(() => {
  375. const prop = { precision: JSON.parse(JSON.stringify(property.precision)) };
  376. prop.precision.t.value = _.toNumber($('#unit-t').val());
  377. prop.precision.km.value = _.toNumber($('#unit-km').val());
  378. prop.precision.m.value = _.toNumber($('#unit-m').val());
  379. prop.precision.m2.value = _.toNumber($('#unit-m2').val());
  380. prop.precision.m3.value = _.toNumber($('#unit-m3').val());
  381. prop.precision.kg.value = _.toNumber($('#unit-kg').val());
  382. prop.precision.ge.value = _.toNumber($('#unit-ge').val());
  383. prop.precision.tai.value = _.toNumber($('#unit-tai').val());
  384. prop.precision.tao.value = _.toNumber($('#unit-tao').val());
  385. prop.precision.ke.value = _.toNumber($('#unit-ke').val());
  386. prop.precision.zu.value = _.toNumber($('#unit-zu').val());
  387. prop.precision.xitong.value = _.toNumber($('#unit-xitong').val());
  388. prop.precision.other.value = _.toNumber($('#unit-other').val());
  389. const tenderId = window.location.pathname.split('/')[2];
  390. postData('/tender/' + tenderId + '/save', prop, function (data) {
  391. setReadOnly('#v-pills-3', true);
  392. property.precision = data.precision;
  393. $('#post-3').parent().hide();
  394. $('#edit-3').parent().show();
  395. });
  396. });
  397. /**
  398. * 合同参数
  399. */
  400. // 编辑
  401. $('#edit-4').click(() => {
  402. setReadOnly('#v-pills-4', false);
  403. $('#post-4').parent().show();
  404. $('#edit-4').parent().hide();
  405. });
  406. // 取消
  407. $('#cancel-4').click(() => {
  408. setReadOnly('#v-pills-4', true);
  409. loadDealProperty();
  410. $('#post-4').parent().hide();
  411. $('#edit-4').parent().show();
  412. });
  413. // 提交
  414. $('#post-4').click(() => {
  415. const prop = {
  416. deal_param: {
  417. contractPrice: _.toNumber($('#contract-price').val()),
  418. zanLiePrice: _.toNumber($('#zan-lie-price').val()),
  419. startAdvance: _.toNumber($('#start-advance').val()),
  420. materialAdvance: _.toNumber($('#material-advance').val()),
  421. }
  422. };
  423. const tenderId = window.location.pathname.split('/')[2];
  424. postData('/tender/' + tenderId + '/save', prop, function (data) {
  425. setReadOnly('#v-pills-4', true);
  426. property.deal_param = data.deal_param;
  427. $('#post-4').parent().hide();
  428. $('#edit-4').parent().show();
  429. });
  430. });
  431. /**
  432. * 显示设置
  433. */
  434. // 编辑
  435. $('#edit-5').click(() => {
  436. setReadOnly('#v-pills-5', false);
  437. $('#post-5').parent().show();
  438. $('#edit-5').parent().hide();
  439. });
  440. // 取消
  441. $('#cancel-5').click(() => {
  442. setReadOnly('#v-pills-5', true);
  443. loadDisplayProperty();
  444. $('#post-5').parent().hide();
  445. $('#edit-5').parent().show();
  446. });
  447. // 提交
  448. $('#post-5').click(() => {
  449. const prop = {
  450. display: {
  451. ledger: { dgnQty: $('#ledger-dgn-qty')[0].checked, },
  452. },
  453. };
  454. const tenderId = window.location.pathname.split('/')[2];
  455. console.log(prop);
  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. });