index.jsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. possible:props.possible||{},
  27. radioVal:props.radioVal||{},
  28. formulaId:''
  29. };
  30. this.getItems = this.getItems.bind(this);
  31. this.getDetailItems = this.getDetailItems.bind(this);
  32. this.showScaleFn = this.showScaleFn.bind(this);
  33. this.closeScaleFn = this.closeScaleFn.bind(this);
  34. this.showOption = this.showOption.bind(this);
  35. this.closeOption = this.closeOption.bind(this);
  36. this.closeFormula = this.closeFormula.bind(this);
  37. this.onPrint = this.onPrint.bind(this);
  38. }
  39. showOption(id){
  40. this.setState({
  41. optionId:id
  42. })
  43. }
  44. closeOption(){
  45. this.setState({
  46. optionId:null
  47. })
  48. }
  49. confirmOption(parent,pIndex){
  50. const {radioVal,possible} = this.state;
  51. this.setState({
  52. possible:Object.assign({},possible,radioVal),
  53. radioVal:Object.assign({},possible,radioVal),//不设置radioVal只有最近一次选中的值
  54. optionId:null
  55. })
  56. }
  57. handleRadio(item,parent,pIndex){
  58. let {radioVal} = this.props;
  59. this.setState({
  60. radioVal:Object.assign({},radioVal,{[pIndex]:item.detailName})
  61. })
  62. }
  63. handleForRadio(){
  64. }
  65. showFormula(id){
  66. this.setState({
  67. formulaId:id
  68. })
  69. }
  70. confirmFormula(){
  71. }
  72. closeFormula(){
  73. this.setState({
  74. formulaId:null
  75. })
  76. }
  77. getDetailItems(item,i){
  78. let arr = [],temp='';
  79. const {indexs} = this.props;
  80. const {optionId,radioVal,possible,formulaId} = this.state;
  81. item.details.map((it,j)=>{
  82. if(indexs[i]&&indexs[i].includes(j)){
  83. if(it.type==1){ //量表
  84. temp =<span className={style['scale']} onClick={()=>this.showScaleFn(it.content.name,it.content.id,item.id)}>【{it.content.name}】</span>;
  85. }else if(it.type==2){ //计算公式
  86. temp = <div className={style['results']}>
  87. <span>计算公式:</span>
  88. <span className={style["blue"]} onClick={this.showFormula.bind(this,item.id)}>请选择</span>
  89. <img src={level1} />
  90. <MiniToast title={it.content.name}
  91. icon={allTableIcon}
  92. show={formulaId&&formulaId==item.id?true:false}
  93. close={this.closeFormula}
  94. confirm={this.confirmFormula.bind(this,item,i)}
  95. footer="true">
  96. <table>
  97. {it.content.details.map((item,idd)=>{
  98. if(item.controlType==0){//单选
  99. return <tr>
  100. <td>
  101. <span>{'请选择'+item.name+':'}</span>
  102. </td>
  103. <td>
  104. {item.details.map((ii,ind)=>{
  105. return <div className={style["chooseItem"]}>
  106. <Radio label={ii.detailName}
  107. isSelect={radioVal[i]==ii.detailName}
  108. handleClick={this.handleForRadio.bind(this,ii,item,i)}>
  109. </Radio>
  110. </div>
  111. })}
  112. </td>
  113. </tr>
  114. }else if(item.controlType==1){//多选
  115. }else if(item.controlType==2){//输入框
  116. return <tr>
  117. <td>
  118. <span>{'请输入'+item.name+':'}</span>
  119. </td>
  120. <td>
  121. <input type="text" placeholder="请输入"/>
  122. </td>
  123. </tr>
  124. }else if(item.controlType==3){//下拉
  125. return <tr>
  126. <td>
  127. <span>{'请选择'+item.name+':'}</span>
  128. </td>
  129. <td>
  130. {item.details.map((ii,ind)=>{
  131. return <div className={style["chooseItem"]}>
  132. <Radio label={ii.detailName}
  133. isSelect={radioVal[i]==ii.detailName}
  134. handleClick={this.handleForRadio.bind(this,ii,item,i)}>
  135. </Radio>
  136. </div>
  137. })}
  138. </td>
  139. </tr>
  140. }
  141. })}
  142. </table>
  143. <div className={style["forMulBtn"]}>计算</div>
  144. </MiniToast>
  145. </div>
  146. }else if(it.type==3){
  147. temp = <div className={style['results']}>
  148. <span>可能结果:</span>
  149. <span onClick={this.showOption.bind(this,item.id)} className={style["blue"]}>{possible[i]?possible[i]:'请选择'}</span>
  150. <img src={level1} />
  151. <MiniToast title='结果选择'
  152. icon={checkIcon}
  153. show={optionId&&optionId==item.id?true:false}
  154. close={this.closeOption}
  155. confirm={this.confirmOption.bind(this,item,i)}
  156. footer="true">
  157. <div className={style["infoOption"]}>
  158. <span>{it.content.name?it.content.name+':':''}</span>
  159. {it.content.details&&it.content.details.map((lis,ind)=>{
  160. return <div className={style["chooseItem"]}>
  161. <Radio label={lis.detailName}
  162. isSelect={radioVal[i]==lis.detailName}
  163. handleClick={this.handleRadio.bind(this,lis,item,i)}>
  164. </Radio>
  165. </div>
  166. })}
  167. </div>
  168. </MiniToast>
  169. </div>;
  170. }
  171. arr.push(<li>
  172. <span>{item.name}:</span>
  173. <div className={style['row']}>{temp}</div>
  174. <div className={style["recommend"]} onClick={()=>this.props.handleRemove(i,j)}>
  175. <img src={deleteIcon} />
  176. </div>
  177. </li>);
  178. }
  179. });
  180. return arr;
  181. }
  182. getItems(){
  183. const { data } = this.props;
  184. return data&&data.map((it,i)=>{
  185. return this.getDetailItems(it,i);
  186. });
  187. }
  188. showScaleFn(name,id,pid){
  189. const {getScaleData,scaleInfo} = this.props;
  190. this.setState({
  191. scaleId:id,
  192. scaleName:name,
  193. parentId:pid,
  194. showScale:true
  195. });
  196. if(!scaleInfo[id]){
  197. getScaleData&&getScaleData({id,name});
  198. }
  199. }
  200. closeScaleFn(){
  201. this.setState({
  202. showScale:false
  203. })
  204. }
  205. onPrint() {
  206. let dom = this.state.showTable?$("#printcontent"):$("#AssistResult");
  207. dom.jqprint({
  208. debug: false,
  209. importCSS: true,
  210. printContainer: true,
  211. operaSupport: false,
  212. });
  213. }
  214. componentDidMount(){
  215. if(this.props.text){
  216. this.$area.current.value = this.props.text;
  217. }
  218. }
  219. render() {
  220. const {title,handleInp,scaleInfo,disabled} = this.props;
  221. const {scaleName,scaleId,parentId,showScale} = this.state;
  222. const footer = <div className={style['footer']}>
  223. <span className={style['print']} onClick={this.onPrint}><img src={printIcon} alt=""/>打印</span>
  224. <span className={style['okBtn']} onClick={()=>{}}>确定</span>
  225. </div>;
  226. const scaleFooter = <div className={style['footer']}>
  227. <span className={style['print']} onClick={this.onPrint}><img src={printIcon} alt=""/>打印</span>
  228. <span className={style['okBtn']} onClick={()=>this.closeTable()}>确定</span>
  229. </div>;
  230. return <div className={style['assess-item']}>
  231. <h2>{title}</h2>
  232. <div className={style['item-content']}>
  233. <ul>
  234. {
  235. this.getItems()
  236. }
  237. <li>
  238. <textarea className={style['edit-row']}
  239. ref={this.$area}
  240. name="supplement"
  241. rows="6"
  242. placeholder='评估描述' onBlur={disabled?null:(e)=>handleInp(e.target.value)} disabled={disabled}></textarea>
  243. </li>
  244. </ul>
  245. </div>
  246. {showScale?<ComplexModal onclose={this.closeScaleFn} footer={scaleFooter}
  247. title={scaleName}
  248. icon={tableIcon}
  249. top={20}
  250. bottom={20}
  251. width={820}>
  252. <ScaleTable title={scaleName} tableId={scaleId} parentId={parentId}></ScaleTable>
  253. </ComplexModal>:''}
  254. </div>;
  255. }
  256. }
  257. export default ScaleItem;