rpt_show_level.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const rptShowLevel = (function (){
  2. const ratio = [{value: '2', title: '项'}, {value: '3', title: '目'}, {value: '4', title: '节'}, {value: '5', title: '细目'}, {value: 'leafXmj', title: '最底层项目节'}, {value: 'last', title: '最底层'}];
  3. const info = {
  4. show_level: { title: '请选择显示层级', ratioValue: ['2', '3', '4', '5', 'last'] },
  5. };
  6. const data = {};
  7. let curType = '';
  8. const initList = function () {
  9. const ratioHtml = [];
  10. const ratioValue = info[curType].ratioValue;
  11. for (const r of ratio) {
  12. if (ratioValue.indexOf(r.value) >= 0) {
  13. ratioHtml.push(`<div class="form-check form-check-inline"><input class="form-check-input" type="radio" value="${r.value}" id="ratio_${r.value}" name="show-level"><label class="form-check-label" for="radio_${r.value}" name="show-level">${r.title}</label></div>`);
  14. }
  15. }
  16. $('#ssl-list').html(ratioHtml.join(''));
  17. $(`#ratio_${data[curType]}`)[0].checked = true;
  18. };
  19. const show = async function (type) {
  20. curType = type;
  21. document.getElementById('ssl-title').innerText = info[type].title;
  22. if (!data[type]) {
  23. const result = await postDataAsync(`/tender/${window.location.pathname.split('/')[2]}/load`, { filter: curType });
  24. data[curType] = result[curType];
  25. }
  26. initList();
  27. $('#select-show-level').modal('show');
  28. };
  29. const update = async function () {
  30. const updateData = {};
  31. updateData[curType] = $('[name=show-level]:checked').val();
  32. if (updateData[curType].length > 0) {
  33. await postData(`/tender/${window.location.pathname.split('/')[2]}/saveRela`, updateData);
  34. data[curType] = updateData[curType];
  35. }
  36. $('#select-show-level').modal('hide');
  37. };
  38. return { show, update }
  39. })();