Cell.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Created by Jacky.gao on 2016/9/18.
  3. */
  4. export default class Cell{
  5. constructor(row,col,cellData){
  6. row.cells.push(this);
  7. this.row=row;
  8. this.col=col;
  9. this.init(cellData);
  10. }
  11. init(cellData){
  12. this.td=$(`<td style="border:1px solid #607D8B"></td>`);
  13. this.initCell(cellData);
  14. }
  15. toXml(){
  16. let xml="<card-cell type=\""+this.type+"\" row=\""+this.row.getRowNumber()+"\" col=\""+this.col.getColNumber()+"\"";
  17. if(this.type==='attribute'){
  18. if(!this.variable){
  19. throw "请先选择属性";
  20. }
  21. if(this.row.scoreCardTable.weightSupport){
  22. if(!this.weight){
  23. throw "请先定义["+this.variable.label+"]属性的权重值";
  24. }else{
  25. xml+=" weight=\""+this.weight+"\"";
  26. }
  27. }
  28. xml+=" var=\""+this.variable.name+"\"";
  29. xml+=" var-label=\""+this.variable.label+"\"";
  30. xml+=" datatype=\""+this.variable.type+"\">";
  31. }else if(this.type==='condition'){
  32. xml+=">";
  33. if(!this.cellCondition){
  34. throw "请配置好条件.";
  35. }
  36. xml+=this.cellCondition.toXml();
  37. }else if(this.type==='score'){
  38. if(!this.inputType){
  39. throw "请配置好分值";
  40. }
  41. const contentXml=this.inputType.toXml();
  42. if(contentXml===''){
  43. throw "请配置好分值";
  44. }
  45. xml+=">";
  46. xml+=contentXml;
  47. }else if(this.type==='custom'){
  48. if(!this.inputType){
  49. throw "请配置好自定义值";
  50. }
  51. const contentXml=this.inputType.toXml();
  52. if(contentXml===''){
  53. throw "请配置好自定义值";
  54. }
  55. xml+=">";
  56. xml+=contentXml;
  57. }
  58. xml+="</card-cell>";
  59. return xml;
  60. }
  61. };