index.jsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import React, { Component } from 'react';
  2. import style from './index.less';
  3. import { Tab ,ConfirmModal,Notify } from '@commonComp';
  4. import { tabChange,allChecked,changeVisible,keepPushData,allCheckedShow} from '@store/actions/tabTemplate';
  5. import { initItemList,delItem,delBatchItem,changeTitleAsync,saveTemplateDetail } from '@store/async-actions/tabTemplate';
  6. import { CHANGE_TYPE } from "@store/types/typeConfig";
  7. import { connect } from "react-redux";
  8. import store from '@store';
  9. import TemplateContainer from '@components/TemplateContainer';
  10. import TemplateItems from '@components/TemplateItems';
  11. import {getWindowInnerHeight} from '@common/js/func';
  12. import PushItemsContainer from '@containers/PushItemsContainer';
  13. import { pushAllDataList } from '@utils/tools';
  14. import CopyRightContainer from "@containers/CopyRightContainer";
  15. class PushContainer extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. data: null,
  20. tabs: [{
  21. title: '辅助信息',
  22. disabled: true
  23. }, {
  24. title: '模板',
  25. }],
  26. visible:false,
  27. message:'', //提示的内容
  28. type:'', //1:删除模板 2:批量删除 3.修改标题 4.引用
  29. id:'', //单个删除
  30. obj:{}, //修改模板标题
  31. title:'', //修改后的标题
  32. okText:'确定', //确认按钮
  33. okBorderColor:'red',
  34. oKBg:'',
  35. okColor:'red',
  36. num:0, //计数
  37. }
  38. this.$cont = React.createRef();
  39. this.itemList = null;
  40. this.handleActiveClick = this.handleActiveClick.bind(this)
  41. this.handleContentClick = this.handleContentClick.bind(this)
  42. this.handleTemplateDel = this.handleTemplateDel.bind(this)
  43. this.handleTitleChange = this.handleTitleChange.bind(this)
  44. this.handleAllCheckbox=this.handleAllCheckbox.bind(this)
  45. this.handleMangerTemplate=this.handleMangerTemplate.bind(this)
  46. this.handleDelList=this.handleDelList.bind(this)
  47. this.makeSure=this.makeSure.bind(this)
  48. this.handleClose = this.handleClose.bind(this);
  49. }
  50. componentDidMount(){
  51. // const height = getWindowInnerHeight()-160;
  52. // this.$cont.current.style.height = height+"px";
  53. }
  54. /**
  55. *
  56. * @param {tab组件切换id} id
  57. */
  58. handleActiveClick(id) {
  59. if(id == '1'){
  60. store.dispatch(initItemList());
  61. }
  62. store.dispatch(tabChange(id))
  63. }
  64. /**
  65. * 引用模板id
  66. * @param {模板id} id
  67. */
  68. handleContentClick(id,sex) {
  69. let baseSex = store.getState().patInfo.message.sex
  70. this.setState({
  71. message:this.content(sex,baseSex),
  72. type:4,
  73. id:id,
  74. okText:'引用',
  75. okBorderColor:'#3B9ED0',
  76. okColor:'#fff',
  77. oKBg:'#3B9ED0'
  78. },()=>{
  79. store.dispatch(changeVisible(true))
  80. })
  81. }
  82. content(sex,baseSex){
  83. if(sex != 3 && sex != baseSex){
  84. return <p className={style['center']}>确认引用该模板?<p style={{fontSize:'12px',color:'#6b6969',marginTop:'10px'}}>引用该模版可能显示有误</p></p>
  85. }else{
  86. return <p className={style['center']}>确认引用该模板?</p>
  87. }
  88. }
  89. /**
  90. * 删除模板
  91. * @param {模板id} id
  92. */
  93. handleTemplateDel(id) {
  94. this.setState({
  95. message:this.delDiv(),
  96. type:1,
  97. id:id,
  98. okText:'删除',
  99. okBorderColor:'red',
  100. okColor:'red',
  101. oKBg:'#fff'
  102. },()=>{
  103. store.dispatch(changeVisible(true))
  104. })
  105. }
  106. delDiv(){
  107. return <p className={style['center']}>确认删除模板?</p>
  108. }
  109. onchange(value){
  110. this.setState({
  111. title: value
  112. },()=>{
  113. this.setState({
  114. message:this.changeTitle(),
  115. })
  116. })
  117. }
  118. keypress(event){
  119. let e = event?event:window.event;
  120. if(e.keyCode == 13) {
  121. this.makeSure()
  122. }
  123. }
  124. handleInput(e){
  125. let val = e.target.value
  126. if(e.target.value.length > 30){
  127. e.target.value = val.substring(0,30)
  128. this.onchange(val.substring(0,30))
  129. }else{
  130. this.onchange(e.target.value)
  131. }
  132. }
  133. changeTitle(){
  134. return <div className={style['box']}>
  135. <input className={style['ipt']}
  136. placeholder="请输入模板名称"
  137. type="text"
  138. value={this.state.title}
  139. maxLength='30'
  140. onInput={(e) => {
  141. this.handleInput(e)
  142. }}
  143. onPropertyChange={(e) => { // 兼容ie
  144. this.handleInput(e)
  145. }}
  146. onKeyPress={e=>this.keypress(e)}
  147. />
  148. <div className={style['line']}></div>
  149. </div>
  150. }
  151. /**
  152. * 改变模板标题
  153. * @param {模板id和模板title} obj
  154. */
  155. handleTitleChange(id,text) {
  156. store.dispatch(changeVisible(true))
  157. this.setState({
  158. type:3,
  159. currId:id,
  160. title:text,
  161. text:text,
  162. okText:'保存',
  163. okBorderColor:'#3B9ED0',
  164. okColor:'#fff',
  165. oKBg:'#3B9ED0'
  166. },()=>{
  167. this.setState({
  168. message:this.changeTitle(),
  169. })
  170. })
  171. }
  172. handleAllCheckbox(){ //全.反选
  173. let tmpFlg = this.props.allChecked;
  174. if(this.props.checkItems.length < this.props.items.length && this.props.allChecked){
  175. tmpFlg = false;
  176. }else if(this.props.checkItems.length == this.props.items.length && !this.props.allChecked){
  177. tmpFlg = true;
  178. } //两种特殊情况处理
  179. store.dispatch(allChecked(!tmpFlg))
  180. }
  181. handleMangerTemplate(){ //管理
  182. let tmpFlg = this.props.allCheckShow;
  183. store.dispatch(allChecked(false))
  184. store.dispatch(allCheckedShow(!tmpFlg))
  185. }
  186. handleDelList(){ //批量删除
  187. this.setState({
  188. type:2,
  189. message:this.delDiv(),
  190. okText:'删除',
  191. okBorderColor:'red',
  192. okColor:'red',
  193. oKBg:'#fff'
  194. })
  195. store.dispatch(changeVisible(true))
  196. }
  197. makeSure(){
  198. if(this.state.type == 1) {
  199. store.dispatch(delItem(this.state.id))
  200. store.dispatch(changeVisible(false))
  201. }else if(this.state.type == 2){
  202. store.dispatch(delBatchItem(this.props.checkItems))
  203. store.dispatch(changeVisible(false))
  204. }else if(this.state.type == 3){
  205. if(this.state.title == this.state.text){
  206. store.dispatch(changeVisible(false))
  207. Notify.success('标题修改成功');
  208. return;
  209. }
  210. let tempObj = {
  211. id:this.state.currId,
  212. title:this.state.title
  213. }
  214. store.dispatch(changeTitleAsync(tempObj))
  215. }else if(this.state.type == 4){ //模板引入
  216. const {items} = this.props;
  217. items && items.map((part)=>{
  218. if(this.state.id == part.id){
  219. let typeConfig = part.type;
  220. store.dispatch(keepPushData(part,'part')) //引用数据的存储,用于保存模板是判断数据是否变化
  221. pushAllDataList(typeConfig,'push',part,'template') //引用
  222. }
  223. })
  224. store.dispatch(changeVisible(false))
  225. }
  226. }
  227. handleClose(){
  228. store.dispatch(changeVisible(false));
  229. }
  230. render() {
  231. const {activeId,checkItems,visible,showMsg,items,allCheckShow} = this.props;
  232. return <div className={style["container"]} ref={this.$cont} >
  233. <Tab tabs={this.state.tabs}
  234. activeId={activeId}
  235. handleActiveClick={this.handleActiveClick}
  236. >
  237. <TemplateContainer activeId={activeId}>
  238. <PushItemsContainer></PushItemsContainer>
  239. <TemplateItems
  240. items={items}
  241. checkItems={checkItems}
  242. allCheckShow={allCheckShow}
  243. handleContentClick={this.handleContentClick}
  244. handleTemplateDel={this.handleTemplateDel}
  245. handleTitleChange={this.handleTitleChange}
  246. handleDelList={this.handleDelList}
  247. handleMangerTemplate={this.handleMangerTemplate}
  248. handleAllCheckbox={this.handleAllCheckbox}
  249. ></TemplateItems>
  250. </TemplateContainer>
  251. </Tab>
  252. <ConfirmModal
  253. visible={visible}
  254. confirm={this.makeSure}
  255. close={this.handleClose}
  256. cancel={this.handleClose}
  257. okText={this.state.okText}
  258. okBorderColor={this.state.okBorderColor}
  259. okColor={this.state.okColor}
  260. oKBg={this.state.oKBg}
  261. >
  262. {this.state.message}
  263. </ConfirmModal>
  264. <CopyRightContainer />
  265. </div>
  266. }
  267. }
  268. const mapStateToProps = (state) => {
  269. return {
  270. items: state.tabTemplate.items,
  271. activeId:state.tabTemplate.activeId,
  272. checkItems:state.tabTemplate.checkItems,
  273. allChecked:state.tabTemplate.allChecked,
  274. visible:state.tabTemplate.visible,
  275. showMsg:state.tabTemplate.showMsg,
  276. allCheckShow:state.tabTemplate.allCheckShow,
  277. }
  278. }
  279. export default connect(mapStateToProps, null)(PushContainer);