index.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import React, { Component } from "react";
  2. import style from "../index.less";
  3. import deleteIcon from '@common/images/delete.png';
  4. import tableIcon from '@common/images/table.png';
  5. import printIcon from '@common/images/team.png';
  6. import allTableIcon from '@common/images/all-table.png';
  7. import level1 from "@common/images/级别1.png";
  8. import checkIcon from '@common/images/check.png';
  9. import {ComplexModal,MiniToast,Radio} from '@commonComp';
  10. import ScaleTable from '@containers/ScaleTable';
  11. import $ from "jquery";
  12. /**
  13. * 来源于页面选择
  14. *
  15. * **/
  16. class ScaleItem extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.$area = React.createRef();
  20. this.state = {
  21. scaleId:'',
  22. scaleName:'',
  23. parentId:'',
  24. showScale:false,
  25. optionId:'',
  26. radioVal:props.radioVal||{},
  27. formulaId:''
  28. };
  29. this.getItems = this.getItems.bind(this);
  30. this.getDetailItems = this.getDetailItems.bind(this);
  31. this.showOption = this.showOption.bind(this);
  32. this.closeOption = this.closeOption.bind(this);
  33. this.closeFormula = this.closeFormula.bind(this);
  34. this.onPrint = this.onPrint.bind(this);
  35. }
  36. showOption(id){
  37. this.setState({
  38. optionId:id
  39. })
  40. }
  41. closeOption(){
  42. this.setState({
  43. optionId:null
  44. })
  45. }
  46. confirmOption(parentId){
  47. const {handleRes} = this.props;
  48. const {radioVal,possible} = this.state;
  49. handleRes&&handleRes(parentId,{
  50. possible:Object.assign({},possible,radioVal),
  51. radioVal:Object.assign({},possible,radioVal),//不设置radioVal只有最近一次选中的值
  52. });
  53. this.closeOption();
  54. }
  55. handleShowScale(item,parentId){
  56. const {showScaleFn,closeAssess} = this.props;
  57. closeAssess&&closeAssess(); //关闭评估弹窗
  58. showScaleFn&&showScaleFn(item,parentId); //显示量表
  59. }
  60. handleRadio(item,parent,pIndex){
  61. let {radioVal} = this.props;
  62. this.setState({
  63. radioVal:Object.assign({},radioVal,{[pIndex]:item.detailName})
  64. })
  65. }
  66. handleForRadio(){
  67. }
  68. showFormula(id){
  69. this.setState({
  70. formulaId:id
  71. })
  72. }
  73. confirmFormula(){
  74. }
  75. closeFormula(){
  76. this.setState({
  77. formulaId:null
  78. })
  79. }
  80. getDetailItems(item,i){
  81. let arr = [],temp='';
  82. const {indexs,result} = this.props;
  83. const {optionId,formulaId,radioVal} = this.state;
  84. const possible=result&&result[item.id]&&result[item.id].possible;
  85. item.details.map((it,j)=>{
  86. if(indexs[i]&&indexs[i].includes(j)){
  87. if(it.type==1){ //量表
  88. temp =<span className={style['scale']} onClick={()=>this.handleShowScale(it.content,item.id)}>【{it.content.name}】</span>;
  89. }else if(it.type==2){ //计算公式
  90. temp = <div className={style['results']}>
  91. <span>计算公式:</span>
  92. <span className={style["blue"]} onClick={this.showFormula.bind(this,item.id)}>请选择</span>
  93. <img src={level1} />
  94. <MiniToast title={it.content.name}
  95. icon={allTableIcon}
  96. show={formulaId&&formulaId==item.id?true:false}
  97. close={this.closeFormula}
  98. confirm={this.confirmFormula.bind(this,item,i)}
  99. footer="true">
  100. <table>
  101. {it.content.details.map((item,idd)=>{
  102. if(item.controlType==0){//单选
  103. return <tr>
  104. <td>
  105. <span>{'请选择'+item.name+':'}</span>
  106. </td>
  107. <td>
  108. {item.details.map((ii,ind)=>{
  109. return <div className={style["chooseItem"]}>
  110. <Radio label={ii.detailName}
  111. isSelect={radioVal[i]==ii.detailName}
  112. handleClick={this.handleForRadio.bind(this,ii,item,i)}>
  113. </Radio>
  114. </div>
  115. })}
  116. </td>
  117. </tr>
  118. }else if(item.controlType==1){//多选
  119. }else if(item.controlType==2){//输入框
  120. return <tr>
  121. <td>
  122. <span>{'请输入'+item.name+':'}</span>
  123. </td>
  124. <td>
  125. <input type="text" placeholder="请输入"/>
  126. </td>
  127. </tr>
  128. }else if(item.controlType==3){//下拉
  129. return <tr>
  130. <td>
  131. <span>{'请选择'+item.name+':'}</span>
  132. </td>
  133. <td>
  134. {item.details.map((ii,ind)=>{
  135. return <div className={style["chooseItem"]}>
  136. <Radio label={ii.detailName}
  137. isSelect={radioVal[i]==ii.detailName}
  138. handleClick={this.handleForRadio.bind(this,ii,item,i)}>
  139. </Radio>
  140. </div>
  141. })}
  142. </td>
  143. </tr>
  144. }
  145. })}
  146. </table>
  147. <div className={style["forMulBtn"]}>计算</div>
  148. </MiniToast>
  149. </div>
  150. }else if(it.type==3){
  151. temp = <div className={style['results']}>
  152. <span>可能结果:</span>
  153. <span onClick={this.showOption.bind(this,item.id)} className={style["blue"]}>{possible&&possible[i]?possible[i]:'请选择'}</span>
  154. <img src={level1} />
  155. <MiniToast title='结果选择'
  156. icon={checkIcon}
  157. show={optionId&&optionId==item.id?true:false}
  158. close={this.closeOption}
  159. confirm={this.confirmOption.bind(this,item.id)}
  160. footer="true">
  161. <div className={style["infoOption"]}>
  162. <span>{it.content.name?it.content.name+':':''}</span>
  163. {it.content.details&&it.content.details.map((lis,ind)=>{
  164. return <div className={style["chooseItem"]}>
  165. <Radio label={lis.detailName}
  166. isSelect={radioVal&&radioVal[i]==lis.detailName}
  167. handleClick={this.handleRadio.bind(this,lis,item,i)}>
  168. </Radio>
  169. </div>
  170. })}
  171. </div>
  172. </MiniToast>
  173. </div>;
  174. }
  175. arr.push(<li>
  176. <span>{item.name}:</span>
  177. <div className={style['row']}>{temp}</div>
  178. <div className={style["recommend"]} onClick={()=>this.props.handleRemove(i,j)}>
  179. <img src={deleteIcon} />
  180. </div>
  181. </li>);
  182. }
  183. });
  184. return arr;
  185. }
  186. getItems(){
  187. const { data } = this.props;
  188. return data&&data.map((it,i)=>{
  189. return this.getDetailItems(it,i);
  190. });
  191. }
  192. onPrint() {
  193. let dom = this.state.showTable?$("#printcontent"):$("#AssistResult");
  194. dom.jqprint({
  195. debug: false,
  196. importCSS: true,
  197. printContainer: true,
  198. operaSupport: false,
  199. });
  200. }
  201. componentDidMount(){
  202. if(this.props.text){
  203. this.$area.current.value = this.props.text;
  204. }
  205. }
  206. render() {
  207. const {title,handleInp,disabled} = this.props;
  208. return <div className={style['assess-item']}>
  209. <h2>{title}</h2>
  210. <div className={style['item-content']}>
  211. <ul>
  212. {
  213. this.getItems()
  214. }
  215. <li>
  216. <textarea className={style['edit-row']}
  217. ref={this.$area}
  218. name="supplement"
  219. rows="6"
  220. placeholder='评估描述' onBlur={disabled?null:(e)=>handleInp(e.target.value)} disabled={disabled}></textarea>
  221. </li>
  222. </ul>
  223. </div>
  224. </div>;
  225. }
  226. }
  227. export default ScaleItem;