index.jsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. }
  48. componentDidMount(){
  49. // const height = getWindowInnerHeight()-160;
  50. // this.$cont.current.style.height = height+"px";
  51. }
  52. /**
  53. *
  54. * @param {tab组件切换id} id
  55. */
  56. handleActiveClick(id) {
  57. if(id == '1'){
  58. store.dispatch(initItemList());
  59. }
  60. store.dispatch(tabChange(id))
  61. }
  62. /**
  63. * 引用模板id
  64. * @param {模板id} id
  65. */
  66. handleContentClick(id) {
  67. this.setState({
  68. message:this.content(),
  69. type:4,
  70. id:id,
  71. okText:'引用',
  72. okBorderColor:'#3B9ED0',
  73. okColor:'#fff',
  74. oKBg:'#3B9ED0'
  75. },()=>{
  76. store.dispatch(changeVisible(true))
  77. })
  78. }
  79. content(){
  80. return <p className={style['center']}>确认引用该模板?</p>
  81. }
  82. /**
  83. * 删除模板
  84. * @param {模板id} id
  85. */
  86. handleTemplateDel(id) {
  87. this.setState({
  88. message:this.delDiv(),
  89. type:1,
  90. id:id,
  91. okText:'删除',
  92. okBorderColor:'red',
  93. okColor:'red',
  94. oKBg:'#fff'
  95. },()=>{
  96. store.dispatch(changeVisible(true))
  97. })
  98. }
  99. delDiv(){
  100. return <p className={style['center']}>确认删除模板?</p>
  101. }
  102. onchange(value){
  103. this.setState({
  104. title: value
  105. },()=>{
  106. this.setState({
  107. message:this.changeTitle(),
  108. })
  109. })
  110. }
  111. keypress(event){
  112. let e = event?event:window.event;
  113. if(e.keyCode == 13) {
  114. this.makeSure()
  115. // store.dispatch(changeVisible(false))
  116. }
  117. }
  118. handleInput(e){
  119. let val = e.target.value
  120. if(e.target.value.length > 30){
  121. e.target.value = val.substring(0,30)
  122. this.onchange(val.substring(0,30))
  123. }else{
  124. this.onchange(e.target.value)
  125. }
  126. }
  127. changeTitle(){
  128. return <div className={style['box']}>
  129. <input className={style['ipt']}
  130. placeholder="请输入模板名称"
  131. type="text"
  132. value={this.state.title}
  133. maxLength='30'
  134. onInput={(e) => {
  135. this.handleInput(e)
  136. }}
  137. onPropertyChange={(e) => { // 兼容ie
  138. this.handleInput(e)
  139. }}
  140. onKeyPress={e=>this.keypress(e)}
  141. />
  142. <div className={style['line']}></div>
  143. </div>
  144. }
  145. /**
  146. * 改变模板标题
  147. * @param {模板id和模板title} obj
  148. */
  149. handleTitleChange(obj) {
  150. store.dispatch(changeVisible(true))
  151. this.setState({
  152. type:3,
  153. obj:obj,
  154. title:obj.text,
  155. okText:'保存',
  156. okBorderColor:'#3B9ED0',
  157. okColor:'#fff',
  158. oKBg:'#3B9ED0'
  159. },()=>{
  160. this.setState({
  161. message:this.changeTitle(),
  162. })
  163. })
  164. }
  165. handleAllCheckbox(){ //全.反选
  166. let tmpFlg = this.props.allChecked;
  167. if(this.props.checkItems.length < this.props.items.length && this.props.allChecked){
  168. tmpFlg = false;
  169. }else if(this.props.checkItems.length == this.props.items.length && !this.props.allChecked){
  170. tmpFlg = true;
  171. } //两种特殊情况处理
  172. store.dispatch(allChecked(!tmpFlg))
  173. }
  174. handleMangerTemplate(){ //管理
  175. let tmpFlg = this.props.allCheckShow;
  176. store.dispatch(allChecked(false))
  177. store.dispatch(allCheckedShow(!tmpFlg))
  178. }
  179. handleDelList(){ //批量删除
  180. this.setState({
  181. type:2,
  182. message:this.delDiv(),
  183. okText:'删除',
  184. okBorderColor:'red',
  185. okColor:'red',
  186. oKBg:'#fff'
  187. })
  188. store.dispatch(changeVisible(true))
  189. }
  190. makeSure(){
  191. if(this.state.type == 1) {
  192. store.dispatch(delItem(this.state.id))
  193. }else if(this.state.type == 2){
  194. store.dispatch(delBatchItem(this.props.checkItems))
  195. }else if(this.state.type == 3){
  196. if(this.state.title == this.state.obj.text){
  197. store.dispatch(changeVisible(false))
  198. Notify.success('标题修改成功');
  199. return;
  200. }
  201. let tempObj = {
  202. id:this.state.obj.id,
  203. title:this.state.title
  204. }
  205. store.dispatch(changeTitleAsync(tempObj))
  206. }else if(this.state.type == 4){ //模板引入
  207. const {items} = this.props;
  208. items && items.map((part)=>{
  209. if(this.state.id == part.id){
  210. let typeConfig = part.type;
  211. store.dispatch(keepPushData(part,'part')) //引用数据的存储,用于保存模板是判断数据是否变化
  212. pushAllDataList(typeConfig,'push',part,'template') //引用
  213. }
  214. })
  215. }
  216. store.dispatch(changeVisible(false))
  217. }
  218. render() {
  219. const {activeId,checkItems,visible,showMsg,items,allCheckShow} = this.props;
  220. return <div className={style["container"]} ref={this.$cont} >
  221. <Tab tabs={this.state.tabs}
  222. activeId={activeId}
  223. handleActiveClick={this.handleActiveClick}
  224. >
  225. <TemplateContainer activeId={activeId}>
  226. <PushItemsContainer></PushItemsContainer>
  227. <TemplateItems
  228. items={items}
  229. checkItems={checkItems}
  230. allCheckShow={allCheckShow}
  231. handleContentClick={this.handleContentClick}
  232. handleTemplateDel={this.handleTemplateDel}
  233. handleTitleChange={this.handleTitleChange}
  234. handleDelList={this.handleDelList}
  235. handleMangerTemplate={this.handleMangerTemplate}
  236. handleAllCheckbox={this.handleAllCheckbox}
  237. ></TemplateItems>
  238. </TemplateContainer>
  239. </Tab>
  240. <ConfirmModal
  241. visible={visible}
  242. confirm={()=>{this.makeSure()}}
  243. close={()=>{store.dispatch(changeVisible(false))}}
  244. cancel={()=>{store.dispatch(changeVisible(false))}}
  245. okText={this.state.okText}
  246. okBorderColor={this.state.okBorderColor}
  247. okColor={this.state.okColor}
  248. oKBg={this.state.oKBg}
  249. >
  250. {this.state.message}
  251. </ConfirmModal>
  252. <CopyRightContainer />
  253. </div>
  254. }
  255. }
  256. const mapStateToProps = (state) => {
  257. return {
  258. items: state.tabTemplate.items,
  259. activeId:state.tabTemplate.activeId,
  260. checkItems:state.tabTemplate.checkItems,
  261. allChecked:state.tabTemplate.allChecked,
  262. visible:state.tabTemplate.visible,
  263. showMsg:state.tabTemplate.showMsg,
  264. allCheckShow:state.tabTemplate.allCheckShow,
  265. }
  266. }
  267. export default connect(mapStateToProps, null)(PushContainer);