tender.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. }
  211. function setReadOnly(readOnly) {
  212. SpreadJsObj.resetFieldReadOnly(spread.getActiveSheet(), 'name', readOnly);
  213. }
  214. function getNewChapterData() {
  215. const result = [];
  216. const sheet = spread.getActiveSheet();
  217. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  218. const data = {};
  219. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  220. const col = spreadSetting.cols[iCol];
  221. data[col.field] = sheet.getText(iRow, iCol);
  222. if (col.field === 'name') {
  223. if (data.name.length > 50) {
  224. return null;
  225. }
  226. }
  227. }
  228. result.push(data);
  229. }
  230. return result;
  231. }
  232. return { loadChapterProperty, setReadOnly, getNewChapterData, }
  233. })();
  234. // 标段属性
  235. function loadTenderProperty() {
  236. // 加载属性
  237. loadCommonProperty();
  238. loadCalculateProperty();
  239. loadPrecisionProperty();
  240. loadDealProperty();
  241. loadDisplayProperty();
  242. chapterObj.loadChapterProperty();
  243. // 设置只读
  244. setReadOnly('#shuxing', true);
  245. }
  246. loadTenderProperty();
  247. /**
  248. * 属性
  249. */
  250. // 编辑
  251. $('#edit-1').click(() => {
  252. setReadOnly('#v-pills-1', false);
  253. $('#post-1').parent().show();
  254. $('#edit-1').parent().hide();
  255. });
  256. // 取消
  257. $('#cancel-1').click(() => {
  258. setReadOnly('#v-pills-1', true);
  259. loadCommonProperty();
  260. $('#post-1').parent().hide();
  261. $('#edit-1').parent().show();
  262. });
  263. // 提交
  264. $('#post-1').click(() => {
  265. const prop = {
  266. deal_info: {
  267. buildName: $('#build-name').val(),
  268. dealCode: $('#deal-code').val(),
  269. dealName: $('#deal-name').val(),
  270. },
  271. construction_unit: {
  272. build: {
  273. company: $('#build-company').val(),
  274. corporation: $('#build-corporation').val(),
  275. date: $('#build-date').val(),
  276. },
  277. contract1: {
  278. company: $('#contract1-company').val(),
  279. corporation: $('#contract1-corporation').val(),
  280. date: $('#contract1-date').val(),
  281. },
  282. contract2: {
  283. company: $('#contract2-company').val(),
  284. corporation: $('#contract2-corporation').val(),
  285. date: $('#contract2-date').val(),
  286. },
  287. supervision1: {
  288. company: $('#supervision1-company').val(),
  289. corporation: $('#supervision1-corporation').val(),
  290. date: $('#supervision1-date').val(),
  291. },
  292. supervision2: {
  293. company: $('#supervision2-company').val(),
  294. corporation: $('#supervision2-corporation').val(),
  295. date: $('#supervision2-date').val(),
  296. },
  297. },
  298. tech_param: {
  299. loadLevel: _.toNumber($('#loadLevel').val()),
  300. loadLength: _.toNumber($('#length').val()),
  301. startPeg: $('#start-peg').val(),
  302. endPeg: $('#end-peg').val(),
  303. laneCount: _.toNumber($('#lane-count').val()),
  304. dealPeriod: $('#deal-period').val(),
  305. startDate: $('#start-date').val(),
  306. planEndDate: $('#plan-end-date').val(),
  307. }
  308. };
  309. const tenderId = window.location.pathname.split('/')[2];
  310. postData('/tender/' + tenderId + '/save', prop, function (data) {
  311. setReadOnly('#v-pills-1', true);
  312. property.deal_info = data.deal_info;
  313. property.construction_unit = data.construction_unit;
  314. property.tech_param = data.tech_param;
  315. $('#post-1').parent().hide();
  316. $('#edit-1').parent().show();
  317. });
  318. });
  319. /**
  320. * 计算参数
  321. */
  322. // 编辑
  323. $('#edit-2').click(() => {
  324. setReadOnly('#v-pills-2', false);
  325. $('#post-2').parent().show();
  326. $('#edit-2').parent().hide();
  327. });
  328. // 取消
  329. $('#cancel-2').click(() => {
  330. setReadOnly('#v-pills-2', true);
  331. loadCalculateProperty();
  332. $('#post-2').parent().hide();
  333. $('#edit-2').parent().show();
  334. });
  335. // 提交
  336. $('#post-2').click(() => {
  337. const prop = {
  338. decimal: {
  339. up: _.toNumber($('#decimal-up').val()),
  340. tp: _.toNumber($('#decimal-tp').val()),
  341. pay: $('#decimal-pay')[0].checked,
  342. payTp: _.toNumber($('#decimal-pay-tp').val()),
  343. }
  344. };
  345. const tenderId = window.location.pathname.split('/')[2];
  346. postData('/tender/' + tenderId + '/save', prop, function (data) {
  347. setReadOnly('#v-pills-2', true);
  348. property.decimal = data.decimal;
  349. $('#post-2').parent().hide();
  350. $('#edit-2').parent().show();
  351. });
  352. });
  353. /**
  354. * 清单精度
  355. */
  356. // 编辑
  357. $('#edit-3').click(() => {
  358. setReadOnly('#v-pills-3', false);
  359. $('#post-3').parent().show();
  360. $('#edit-3').parent().hide();
  361. });
  362. // 取消
  363. $('#cancel-3').click(() => {
  364. setReadOnly('#v-pills-3', true);
  365. loadPrecisionProperty();
  366. $('#post-3').parent().hide();
  367. $('#edit-3').parent().show();
  368. });
  369. // 提交
  370. $('#post-3').click(() => {
  371. const prop = { precision: JSON.parse(JSON.stringify(property.precision)) };
  372. prop.precision.t.value = _.toNumber($('#unit-t').val());
  373. prop.precision.km.value = _.toNumber($('#unit-km').val());
  374. prop.precision.m.value = _.toNumber($('#unit-m').val());
  375. prop.precision.m2.value = _.toNumber($('#unit-m2').val());
  376. prop.precision.m3.value = _.toNumber($('#unit-m3').val());
  377. prop.precision.kg.value = _.toNumber($('#unit-kg').val());
  378. prop.precision.ge.value = _.toNumber($('#unit-ge').val());
  379. prop.precision.tai.value = _.toNumber($('#unit-tai').val());
  380. prop.precision.tao.value = _.toNumber($('#unit-tao').val());
  381. prop.precision.ke.value = _.toNumber($('#unit-ke').val());
  382. prop.precision.zu.value = _.toNumber($('#unit-zu').val());
  383. prop.precision.xitong.value = _.toNumber($('#unit-xitong').val());
  384. prop.precision.other.value = _.toNumber($('#unit-other').val());
  385. const tenderId = window.location.pathname.split('/')[2];
  386. postData('/tender/' + tenderId + '/save', prop, function (data) {
  387. setReadOnly('#v-pills-3', true);
  388. property.precision = data.precision;
  389. $('#post-3').parent().hide();
  390. $('#edit-3').parent().show();
  391. });
  392. });
  393. /**
  394. * 合同参数
  395. */
  396. // 编辑
  397. $('#edit-4').click(() => {
  398. setReadOnly('#v-pills-4', false);
  399. $('#post-4').parent().show();
  400. $('#edit-4').parent().hide();
  401. });
  402. // 取消
  403. $('#cancel-4').click(() => {
  404. setReadOnly('#v-pills-4', true);
  405. loadDealProperty();
  406. $('#post-4').parent().hide();
  407. $('#edit-4').parent().show();
  408. });
  409. // 提交
  410. $('#post-4').click(() => {
  411. const prop = {
  412. deal_param: {
  413. contractPrice: _.toNumber($('#contract-price').val()),
  414. zanLiePrice: _.toNumber($('#zan-lie-price').val()),
  415. startAdvance: _.toNumber($('#start-advance').val()),
  416. materialAdvance: _.toNumber($('#material-advance').val()),
  417. }
  418. };
  419. const tenderId = window.location.pathname.split('/')[2];
  420. postData('/tender/' + tenderId + '/save', prop, function (data) {
  421. setReadOnly('#v-pills-4', true);
  422. property.deal_param = data.deal_param;
  423. $('#post-4').parent().hide();
  424. $('#edit-4').parent().show();
  425. });
  426. });
  427. /**
  428. * 显示设置
  429. */
  430. // 编辑
  431. $('#edit-5').click(() => {
  432. setReadOnly('#v-pills-5', false);
  433. $('#post-5').parent().show();
  434. $('#edit-5').parent().hide();
  435. });
  436. // 取消
  437. $('#cancel-5').click(() => {
  438. setReadOnly('#v-pills-5', true);
  439. loadDisplayProperty();
  440. $('#post-5').parent().hide();
  441. $('#edit-5').parent().show();
  442. });
  443. // 提交
  444. $('#post-5').click(() => {
  445. const prop = {
  446. display: {
  447. ledger: { dgnQty: $('#ledger-dgn-qty')[0].checked, },
  448. },
  449. };
  450. const tenderId = window.location.pathname.split('/')[2];
  451. console.log(prop);
  452. postData('/tender/' + tenderId + '/save', prop, function (data) {
  453. setReadOnly('#v-pills-5', true);
  454. property.display = data.display;
  455. $('#post-5').parent().hide();
  456. $('#edit-5').parent().show();
  457. });
  458. });
  459. /**
  460. * 章节设置
  461. */
  462. // 编辑
  463. $('#edit-6').click(() => {
  464. chapterObj.setReadOnly(false);
  465. $('#post-6').parent().show();
  466. $('#edit-6').parent().hide();
  467. });
  468. // 取消
  469. $('#cancel-6').click(() => {
  470. chapterObj.loadChapterProperty();
  471. chapterObj.setReadOnly(true);
  472. $('#hint-6').hide();
  473. $('#post-6').parent().hide();
  474. $('#edit-6').parent().show();
  475. });
  476. // 提交
  477. $('#post-6').click(() => {
  478. const chapter = chapterObj.getNewChapterData();
  479. if (!chapter) { return; }
  480. const tenderId = window.location.pathname.split('/')[2];
  481. postData('/tender/' + tenderId + '/save', { chapter: chapter }, function (data) {
  482. chapterObj.setReadOnly(true);
  483. property.chapter = data.chapter;
  484. $('#post-6').parent().hide();
  485. $('#edit-6').parent().show();
  486. });
  487. });
  488. //标段类型选择
  489. $('#tender_type_select').change(function () {
  490. const type = $(this).val() != 0 ? '/?type='+$(this).val() : '';
  491. window.location.href = '/tender' + type;
  492. });
  493. //编辑标段 选择
  494. $('.save-btn').on('click',function () {
  495. $('#saveid').val($(this).attr('tender-id'));
  496. $('#savename').val($(this).attr('tender-name'));
  497. $('#savetype').val($(this).attr('tender-type'));
  498. });
  499. //删除标段 选择
  500. $('.del-btn').on('click',function () {
  501. $('#delid').val($(this).attr('tender-id'));
  502. });
  503. });