Browse Source

分时段bug

yu_ber 4 years ago
parent
commit
e327aa2031

+ 28 - 6
UI/src/pages/sellmanage/msgComponent.js

@@ -329,10 +329,8 @@ class MsgComponent extends React.Component {
         });
     }
     componentWillReceiveProps(nextProps) {
-        // console.log(nextProps,'------------');
         if(nextProps.selectKeys == nextProps.tabIndex){
             if(!this.state.tabsKes){
-               
                 if (!nextProps.type && nextProps.mediaId && nextProps.chooseKey == nextProps.cutextKey) {
                     console.log(nextProps,'nextProps');
                     this.setState({anyKes:nextProps.cutextKey,chooseKey: nextProps.chooseKey, _ID:this.state.chooseKey != "miniprogrampage" ? nextProps.mediaId : nextProps.thumbMediaId }, () => { this.loadImgs()})
@@ -343,8 +341,32 @@ class MsgComponent extends React.Component {
                         imgUrlMini:"",
                     })
                 }
+            } else {
+                switch(this.state.chooseKey){
+                    case this.state.chooseKey == "text" && nextProps.cutextKey == "text":
+                         this.setState({
+                        imgUrlNews:"",
+                        imgUrlMini:"",
+                    })
+                    break
+                    case this.state.chooseKey == "news" && nextProps.cutextKey == "news":
+                         this.setState({
+                        imgUrlText:"",
+                        imgUrlMini:"",
+                    })
+                    break
+                    case this.state.chooseKey == "miniprogrampage" && nextProps.cutextKey == "miniprogrampage":
+                         this.setState({
+                        imgUrlText:"",
+                        imgUrlNews:"",
+                    })
+                    break
+                }
             }
     }
+
+
+
         // let self = this;
         // if (!util.object.equal(nextProps.msgId, this.state.msgId)) {
         //     self.setState({ msgId: nextProps.msgId }, () => { self.loadImgs()});
@@ -430,10 +452,10 @@ class MsgComponent extends React.Component {
         this.state.faceArr.map((item, index) => {
             if (index == i) {
                 if (this.state.chooseKey == 'text') {
-                    let existContent = this.props.form.getFieldValue('content');
+                    let existContent = this.props.form.getFieldValue('content') ? this.props.form.getFieldValue('content') : "" ;
                     this.props.form.setFieldsValue({ content: existContent + "/" + item });
                 } else if (this.state.chooseKey == 'news') {
-                    let existDescription = this.props.form.getFieldValue('description');
+                    let existDescription = this.props.form.getFieldValue('description') ? this.props.form.getFieldValue('description') : "" ;
                     this.props.form.setFieldsValue({ description: existDescription + "/" + item });
                 }
             }
@@ -474,10 +496,10 @@ class MsgComponent extends React.Component {
         }
         let itemA = `<a href="${this.state.linkUrl}">${this.state.linkText}</a>`;
         if (this.state.chooseKey == 'text') {
-            let existContent = this.props.form.getFieldValue('content');
+            let existContent = this.props.form.getFieldValue('content') ?  this.props.form.getFieldValue('content'):"";
             this.props.form.setFieldsValue({ content: existContent + itemA });
         } else if (this.state.chooseKey == 'news') {
-            let existDescription = this.props.form.getFieldValue('description');
+            let existDescription = this.props.form.getFieldValue('description') ?  this.props.form.getFieldValue('description'):"";
             this.props.form.setFieldsValue({ description: existDescription + itemA });
         }
         this.setState({

+ 643 - 0
UI/src/pages/sellmanage/pushMessage/copy.js

@@ -0,0 +1,643 @@
+import React, { Component } from "react";
+import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
+import {
+  Tabs,
+  Button,
+  Switch,
+  Input,
+  Select,
+  DatePicker,
+  Icon,
+  message
+} from "antd";
+
+import { connect } from "dva";
+import PropTypes, { string } from 'prop-types'
+import styles from './index.less';
+import { deepClone, util } from "utils";
+import { Loader } from 'components';
+
+import moment from 'moment';
+import TimePicker from "../TimePicker/TimePicker";
+const { RangePicker } = DatePicker
+const dateFormat = 'MM/DD'
+
+import MsgComponent from "../msgComponent";
+import { error } from "jquery";
+const { TabPane } = Tabs;
+const { Search } = Input;
+const { TextArea } = Input;
+
+const textButtom = [
+  // "时间段(每天)",
+  "时间段(一)",
+  "时间段(二)",
+  "时间段(三)",
+  "时间段(四)",
+  "时间段(五)",
+  "时间段(六)",
+  "时间段(七)",
+]
+const week = [
+  {
+    name: "每天",
+    key: 0
+  },
+  {
+    name: "周一",
+    key: 1
+  },
+  {
+    name: "周二",
+    key: 2
+  },
+  {
+    name: "周三",
+    key: 3
+  },
+  {
+    name: "周四",
+    key: 4
+  },
+  {
+    name: "周五",
+    key: 5
+  },
+  {
+    name: "周六",
+    key: 6
+  },
+  {
+    name: "周日",
+    key: 7
+  },
+
+]
+
+
+class PushMessage extends React.Component {
+  constructor(props) {
+    super(props)
+    this.state = {
+      open: false,
+      conTrollerChecked: false,
+      selectKey: 0,
+      buttonState: 0,
+      currentState: 0,
+      newarr: [],
+      arrList: [
+        {}
+      ],
+      selectIndex: 'text',
+      disabled: false,
+      contentValueItem: "",
+      typeText: "text",
+      TimePicker: [
+        {
+          value: [],
+        },
+      ],
+      msgComponent: []
+    }
+  }
+
+
+  conTroller = (checked, key) => {
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+    // if (items) {
+    //   if (!items[key])
+    //     items[key] = {};
+    //   items[key].disable = checked ? 0 : 1;
+
+    // }
+    // initData.items = items;
+
+    const updateFromItm = this.state.msgComponent[key]
+    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+      items[key].disable = checked ? 0 : 1;
+      var chooseKey
+      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+      let messageItem = {}
+      messageItem.content = content;
+      messageItem.miniAppTitle = miniAppTitle;
+      messageItem.msgType = chooseKey;
+      messageItem.title = title;
+      messageItem.url = url;
+      messageItem.description = description;
+      messageItem.miniProgramAppId = miniProgramAppId;
+      messageItem.pagepath = pagepath;
+      items[key].message = messageItem;
+      initData.items = items;
+    }
+
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
+  }
+
+  handleChange = (value, key) => {
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+    // if (items) {
+    //   if (!items[key])
+    //     items[key] = {};
+    //   items[key].week = value;
+    // }
+    // initData.items = items;
+
+    const updateFromItm = this.state.msgComponent[key]
+    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+      items[key].week = value;
+      var chooseKey
+      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+      let messageItem = {}
+      messageItem.content = content;
+      messageItem.miniAppTitle = miniAppTitle;
+      messageItem.msgType = chooseKey;
+      messageItem.title = title;
+      messageItem.url = url;
+      messageItem.description = description;
+      messageItem.miniProgramAppId = miniProgramAppId;
+      messageItem.pagepath = pagepath;
+      items[key].message = messageItem;
+      initData.items = items;
+    }
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
+  }
+  timeReversal = val => {
+    let timeArr = []
+    for (let i = 0; i < val.length; i++) {
+      let timeList = {};
+      timeList.beginTime = val[i].value.length > 0 ? moment(val[i].value[0], 'HH:mm:ss').format('HH:mm:ss') : null
+      timeList.endTime = val[i].value.length > 0 ? moment(val[i].value[1], 'HH:mm:ss').format('HH:mm:ss') : null
+      timeArr.push(timeList);
+    }
+    return timeArr
+  }
+  add = key => {
+    var listData = this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
+      this.props.pushMessage.initData.items : undefined
+
+    if (!listData[key])
+      listData[key] = []
+
+    if (listData && listData[key] && listData[key].length < 7) {
+      let obj = {
+        value: []
+      }
+      listData[key].push(obj);
+
+      // if (items) {
+      //   if (!items[key])
+      //     items[key] = {};
+      //   initData.items = items;
+      // }
+
+      const updateFromItm = this.state.msgComponent[key]
+      var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+      var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+      var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+      var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+      var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+      var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+      var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+
+      if (items) {
+        if (!items[key])
+          items[key] = {};
+        var chooseKey
+        let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+        chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+        let messageItem = {}
+        messageItem.content = content;
+        messageItem.miniAppTitle = miniAppTitle;
+        messageItem.msgType = chooseKey;
+        messageItem.title = title;
+        messageItem.url = url;
+        messageItem.description = description;
+        messageItem.miniProgramAppId = miniProgramAppId;
+        messageItem.pagepath = pagepath;
+        items[key].message = messageItem;
+        initData.items = items;
+      }
+      this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
+    } else {
+      message.info('最多添加七个时间段');
+    }
+  }
+
+  remove = (key, key1) => {
+    var listData = this.props.pushMessage && this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
+      this.props.pushMessage.initData.items : undefined
+    if (listData && listData[key] && listData[key].length > 1) {
+      let obj = {
+        value: []
+      }
+      listData[key].splice(key1, 1);
+
+      // if (items) {
+      //   if (!items[key])
+      //     items[key] = {};
+      //   initData.items = items;
+      // }
+
+      const updateFromItm = this.state.msgComponent[key]
+      var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+      var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+      var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+      var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+      var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+      var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+      var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+      if (items) {
+        if (!items[key])
+          items[key] = {};
+        var chooseKey
+        let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+        chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+        let messageItem = {}
+        messageItem.content = content;
+        messageItem.miniAppTitle = miniAppTitle;
+        messageItem.msgType = chooseKey;
+        messageItem.title = title;
+        messageItem.url = url;
+        messageItem.description = description;
+        messageItem.miniProgramAppId = miniProgramAppId;
+        messageItem.pagepath = pagepath;
+        items[key].message = messageItem;
+        initData.items = items;
+      }
+      this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
+    } else {
+      message.info('最少保留一个时间段');
+    }
+  }
+  handleSubmit = key => {
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var appId = this.props.wxAppIdValue
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+
+      var message1 = { msgType: this.state.typeText };
+      if (this.props.pushMessage.initData.items[key] && this.props.pushMessage.initData.items[key].message) {
+        message1 = this.props.pushMessage.initData.items[key].message;
+        message1.msgType = this.props.pushMessage.initData.items[key].message.msgType ? this.props.pushMessage.initData.items[key].message.msgType : 'text'
+        message1.msgId = this.props.pushMessage.initData.items[key].message.msgId ? this.props.pushMessage.initData.items[key].message.msgId : null
+        message1.thumbMediaId = this.props.pushMessage.initData.items[key].message.mediaId ? this.props.pushMessage.initData.items[key].message.mediaId : null
+      }
+      // thumbMediaId
+      message1.content = this.state.msgComponent[key].props.form.getFieldValue('content')
+      message1.title = this.state.msgComponent[key].props.form.getFieldValue('title')
+      message1.description = this.state.msgComponent[key].props.form.getFieldValue('description')
+      message1.url = this.state.msgComponent[key].props.form.getFieldValue('url')
+      message1.miniAppTitle = this.state.msgComponent[key].props.form.getFieldValue('miniAppTitle')
+      message1.miniProgramAppId = this.state.msgComponent[key].props.form.getFieldValue('miniProgramAppId')
+      message1.pagepath = this.state.msgComponent[key].props.form.getFieldValue('pagepath')
+      items[key].message = message1;
+      initData.items = items;
+    }
+    var data = initData.items[key];
+    if (typeof (data.disable) === 'undefined')
+      data.disable = 0;
+
+    if (typeof (data.week) === 'undefined')
+      data.week = 1;
+
+    if (typeof (data.tableNo) === 'undefined')
+      data.tableNo = key;
+
+    this.props.dispatch({ type: 'pushMessage/submit', payload: { data } });
+  }
+
+  // 获取 mediaId
+  cb_mediaId = (mediaId, key, imgUrl) => {
+    console.log(mediaId, imgUrl);
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+
+      let week1 = items.week;
+
+      var message1 = { msgType: this.state.typeText }
+      if (this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[key]
+        && this.props.pushMessage.initData.items[key].message) {
+
+        message1 = this.props.pushMessage.initData.items[key].message
+      }
+
+      let check = 'text';
+      if (this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[key]
+        && this.props.pushMessage.initData.items[key].message
+        && this.props.pushMessage.initData.items[key].message.chooseKey) {
+        check = this.props.pushMessage.initData.items[key].message.chooseKey;
+      }
+
+      switch (check) {
+        case 'text':
+          message1.mediaId = mediaId;
+          break;
+        case 'news':
+          message1.mediaId = mediaId;
+          message1.thumbUrl = imgUrl;
+          break;
+
+        case 'miniprogrampage':
+          message1.thumbMediaId = mediaId;
+          break;
+      }
+
+      items[key].message = message1;
+      initData.items = items;
+    }
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
+  }
+  updateFromMessage = (value, key) => {
+    const initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    const items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+    const updateFromItm = this.state.msgComponent[key]
+    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+      var chooseKey
+      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+      let messageItem = {}
+      messageItem.content = content;
+      messageItem.miniAppTitle = miniAppTitle;
+      messageItem.msgType = chooseKey;
+      messageItem.title = title;
+      messageItem.url = url;
+      messageItem.description = description;
+      messageItem.miniProgramAppId = miniProgramAppId;
+      messageItem.pagepath = pagepath;
+      items[key].message = messageItem;
+      initData.items = items;
+    }
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
+  }
+  // text 发送消息  图文 news  小程序  miniprogrampage
+  cb_chooseKey = (chooseKey, key) => {
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
+    // console.log(chooseKey,'chooseKey');
+    this.setState({
+      typeText: chooseKey,
+    })
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+      var message1 = { msgType: this.state.typeText }
+      if (this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[key]
+        && this.props.pushMessage.initData.items[key].message) {
+        message1 = this.props.pushMessage.initData.items[key].message
+      }
+
+      if (chooseKey)
+        message1.chooseKey = chooseKey;
+      message1.msgType = chooseKey;
+      items[key].message = message1;
+      initData.items = items;
+    }
+
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
+  }
+
+  // 获取表单即文本内容
+  cb_formChange = (formdata, allData, key) => {
+
+  }
+  handleClick = (value, key1, key) => {
+    var listData = this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
+    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
+    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
+      this.props.pushMessage.initData.items : undefined
+
+    let selectTime = [];
+    if (!listData[key])
+      listData[key] = []
+
+    if (listData && listData[key] && listData[key].length > 0) {
+      for (var i in listData[key]) {
+        var seleDate = {};
+        seleDate.beginTime = moment(listData[key][i].value[0]).format('HH:mm:ss')
+        seleDate.endTime = moment(listData[key][i].value[1]).format('HH:mm:ss')
+        selectTime[i] = seleDate;
+      }
+    }
+
+    var obj = {
+      value: []
+    }
+
+    var seleDate = {};
+    if (value[0]) {
+      obj.value[0] = moment(value[0], 'HH:mm:ss');
+      seleDate.beginTime = moment(value[0], 'HH:mm:ss').format('HH:mm:ss')
+    }
+    if (value[1]) {
+      obj.value[1] = moment(value[1], 'HH:mm:ss');
+      seleDate.endTime = moment(value[1], 'HH:mm:ss').format('HH:mm:ss')
+    }
+
+    selectTime[key1] = seleDate;
+    listData[key][key1] = obj;
+    
+
+    // if (items) {
+    //   if (!items[key])
+    //     items[key] = {};
+    //   items[key].timesList = selectTime;
+    // }
+
+    const updateFromItm = this.state.msgComponent[key]
+    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
+    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
+    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
+    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
+    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
+    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
+    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
+
+
+    if (items) {
+      if (!items[key])
+        items[key] = {};
+      var chooseKey
+      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
+      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
+      let messageItem = {}
+      messageItem.content = content;
+      messageItem.miniAppTitle = miniAppTitle;
+      messageItem.msgType = chooseKey;
+      messageItem.title = title;
+      messageItem.url = url;
+      messageItem.description = description;
+      messageItem.miniProgramAppId = miniProgramAppId;
+      messageItem.pagepath = pagepath;
+      items[key].message = messageItem;
+      initData.items = items;
+      items[key].timesList = selectTime;
+    }
+    this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
+  }
+
+  onSelect = (index) => {
+    this.setState({
+      currentState: index,
+    })
+  }
+
+  render() {
+    let self = this;
+    let i = 0;
+    const { Option } = Select;
+    const format = 'HH:mm:ss';
+    return (
+      <div className={styles.segmentAutoReeply}>
+        <div className={styles.header}>
+          {
+            textButtom.map((item, key) => {
+              return <Button className={styles.buttonWidth} size="large" type={key === this.state.currentState ? "primary" : "Default"} block key={key} onClick={() => { self.onSelect(key) }}> {item}</Button>
+            })
+          }
+        </div>
+        {
+          textButtom.map((item, key) => {
+            var data = [];
+            var disable = false;
+            var weekItem = 0; //'全天'
+
+            let TimeRangePicker = [];
+            if (self.props.pushMessage && self.props.pushMessage.times && self.props.pushMessage.times[key]
+              && self.props.pushMessage.times[key].length > 0)
+              TimeRangePicker = self.props.pushMessage.times[key];
+
+            else
+              TimeRangePicker = [{ value: [] }]
+
+            if (self.props.pushMessage.initData) {
+              data = self.props.pushMessage.initData;
+              disable = data.items && data.items[key] && data.items[key].disable ? false : true;
+              weekItem = data.items && data.items[key] && typeof (data.items[key].week) !== 'undefined' ? data.items[key].week : 1;
+            }
+
+          
+
+            var chooseKey = 'text';
+            var cutextKey = "text"
+            var message1 = {};
+            if (self.props.pushMessage && self.props.pushMessage.initData && self.props.pushMessage.initData.items[self.state.currentState]
+              && self.props.pushMessage.initData.items[self.state.currentState].message
+            ) {
+              let keys = self.props.pushMessage.initData.items[self.state.currentState]
+              keys ? chooseKey = keys.message && keys.message.msgType : chooseKey = "text"
+              let item = self.props.pushMessage.selectKesData.items[self.state.currentState]
+              item ? cutextKey = item.message && item.message.msgType : cutextKey = "text"
+              message1 = self.props.pushMessage.initData.items[self.state.currentState].message;
+              message1.content = self.props.pushMessage.initData.items[self.state.currentState].message.content ?
+                self.props.pushMessage.initData.items[self.state.currentState].message.content : this.state.contentValueItem
+            }
+
+            return (
+              <div className={styles.connect} style={{ display: (key === self.state.currentState) ? "block" : "none" }}>
+                <div className={styles.Munstate}>
+                  <div>状态:</div>
+                  <Switch checked={disable} defaultChecked onChange={(v) => { self.conTroller(v, key) }} />
+                </div>
+
+                <div className={styles.TimePickers}>
+                  时间段:
+                  <Select value={weekItem} style={{ width: 120 }} className={styles.Select} onChange={(v) => { self.handleChange(v, key) }}>
+                    {
+                      week.map((item, key) => {
+                        return <Option value={item.key} key={item.key}>{item.name}</Option>
+                      })
+                    }
+                  </Select>
+
+                  <div>
+                    {TimeRangePicker && TimeRangePicker.map((item, key1) => {
+                      return <div style={{ marginBottom: "10px" }}>
+                        <TimePicker value={item.value} onChange={e => self.handleClick(e, key1, key)} format={format} style={{ marginTop: "10px" }} />
+                        <Icon type="minus-circle" size="30px" style={{ marginLeft: '30px', fontSize: '30px' }} onClick={() => { self.remove(key, key1) }}></Icon>
+                      </div>
+                    })}
+                    <Button type="dashed" size="30px" style={{ marginLeft: '30px' }} onClick={() => { self.add(key) }}>添加时间段</Button>
+                  </div>
+                </div>
+
+                <div className={styles.contentList}>
+                  <MsgComponent tabIndex={key}
+                    {...message1}
+                    chooseKey={chooseKey}
+                    cutextKey={cutextKey}
+                    selectKeys={self.state.currentState}
+                    bottomFriom={(key) => { self.handleSubmit(key) }}
+                    mediaIdChange={(v) => { self.cb_mediaId(v, key) }}
+                    onChange={(v, av) => { self.cb_formChange(v, av, key) }}
+                    chooseKeyChange={(v) => { self.cb_chooseKey(v, key) }}
+                    updateFrom={(v) => { self.updateFromMessage(v, key) }}
+                    className={styles.from}
+                    wrappedComponentRef={ref => { (self.state.msgComponent[key]) = ref }}
+                  />
+                </div>
+                <Button className={styles.bthRight} size="large" type="primary" onClick={() => { self.handleSubmit(key) }}>保存</Button>
+              </div>
+            )
+          })
+        }
+      </div>
+    );
+  }
+}
+
+PushMessage.propTypes = {
+  dispatch: PropTypes.func,
+  loading: PropTypes.object,
+  state: PropTypes.string
+}
+export default connect(({ loading, dispatch, sellmanage: { wxAppIdValue }, pushMessage }) => ({ wxAppIdValue, loading, dispatch, pushMessage }))(PushMessage)

+ 58 - 224
UI/src/pages/sellmanage/pushMessage/index.js

@@ -100,89 +100,48 @@ class PushMessage extends React.Component {
       msgComponent: []
     }
   }
-
-
-  conTroller = (checked, key) => {
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
-    // if (items) {
-    //   if (!items[key])
-    //     items[key] = {};
-    //   items[key].disable = checked ? 0 : 1;
-
-    // }
-    // initData.items = items;
-
-    const updateFromItm = this.state.msgComponent[key]
-    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
-
+  getFormModel = (key) => {
+    const { initData } = this.props.pushMessage;
+    let selectTimeList = initData.items[key];
+    // 获取表单信息
+    const FormModelItem = this.state.msgComponent[key]
+    let pushMessageItem = {}
+    pushMessageItem.content = FormModelItem.props.form.getFieldValue('content')
+    pushMessageItem.miniAppTitle = FormModelItem.props.form.getFieldValue('miniAppTitle')
+    pushMessageItem.title = FormModelItem.props.form.getFieldValue('title')
+    pushMessageItem.url = FormModelItem.props.form.getFieldValue('url')
+    pushMessageItem.description = FormModelItem.props.form.getFieldValue('description')
+    pushMessageItem.miniProgramAppId = FormModelItem.props.form.getFieldValue('miniProgramAppId')
+    pushMessageItem.pagepath = FormModelItem.props.form.getFieldValue('pagepath')
+    // 获取素材id
+    pushMessageItem.msgId = initData.items[key].message && initData.items[key].message.msgId ? initData.items[key].message.msgId : null
+    pushMessageItem.mediaId = initData.items[key].message && initData.items[key].message.mediaId ? initData.items[key].message.mediaId : null
+    pushMessageItem.thumbMediaId = initData.items[key].message && initData.items[key].message.thumbMediaId ? initData.items[key].message.thumbMediaId : null
+    // 获取默认选中msgType choosekey
+    pushMessageItem.msgType = selectTimeList.message && selectTimeList.message.msgType ? selectTimeList.message.msgType : 'text';
+    pushMessageItem.chooseKey = selectTimeList.message && selectTimeList.message.msgType ? selectTimeList.message.msgType : 'text';
+    console.log(pushMessageItem, 'pushMessageItem');
+    return pushMessageItem
+  }
+  getSwitchStatus = (checked, key) => {
+    const { initData, initData: { items } } = this.props.pushMessage;
     if (items) {
       if (!items[key])
         items[key] = {};
       items[key].disable = checked ? 0 : 1;
-      var chooseKey
-      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-      let messageItem = {}
-      messageItem.content = content;
-      messageItem.miniAppTitle = miniAppTitle;
-      messageItem.msgType = chooseKey;
-      messageItem.title = title;
-      messageItem.url = url;
-      messageItem.description = description;
-      messageItem.miniProgramAppId = miniProgramAppId;
-      messageItem.pagepath = pagepath;
-      items[key].message = messageItem;
+      items[key].message = this.getFormModel(key);
       initData.items = items;
     }
-
     this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
   }
 
   handleChange = (value, key) => {
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
-    // if (items) {
-    //   if (!items[key])
-    //     items[key] = {};
-    //   items[key].week = value;
-    // }
-    // initData.items = items;
-
-    const updateFromItm = this.state.msgComponent[key]
-    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
-
+    const { initData, initData: { items } } = this.props.pushMessage;
     if (items) {
       if (!items[key])
         items[key] = {};
       items[key].week = value;
-      var chooseKey
-      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-      let messageItem = {}
-      messageItem.content = content;
-      messageItem.miniAppTitle = miniAppTitle;
-      messageItem.msgType = chooseKey;
-      messageItem.title = title;
-      messageItem.url = url;
-      messageItem.description = description;
-      messageItem.miniProgramAppId = miniProgramAppId;
-      messageItem.pagepath = pagepath;
-      items[key].message = messageItem;
+      items[key].message = this.getFormModel(key);
       initData.items = items;
     }
     this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
@@ -198,11 +157,8 @@ class PushMessage extends React.Component {
     return timeArr
   }
   add = key => {
-    var listData = this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
-      this.props.pushMessage.initData.items : undefined
-
+    var listData = this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }  //  初始数据源
+    const { initData, initData: { items } } = this.props.pushMessage
     if (!listData[key])
       listData[key] = []
 
@@ -212,38 +168,10 @@ class PushMessage extends React.Component {
       }
       listData[key].push(obj);
 
-      // if (items) {
-      //   if (!items[key])
-      //     items[key] = {};
-      //   initData.items = items;
-      // }
-
-      const updateFromItm = this.state.msgComponent[key]
-      var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-      var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-      var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-      var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-      var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-      var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-      var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
-
       if (items) {
         if (!items[key])
           items[key] = {};
-        var chooseKey
-        let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-        chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-        let messageItem = {}
-        messageItem.content = content;
-        messageItem.miniAppTitle = miniAppTitle;
-        messageItem.msgType = chooseKey;
-        messageItem.title = title;
-        messageItem.url = url;
-        messageItem.description = description;
-        messageItem.miniProgramAppId = miniProgramAppId;
-        messageItem.pagepath = pagepath;
-        items[key].message = messageItem;
+        items[key].message = this.getFormModel(key);
         initData.items = items;
       }
       this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
@@ -254,46 +182,17 @@ class PushMessage extends React.Component {
 
   remove = (key, key1) => {
     var listData = this.props.pushMessage && this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
-      this.props.pushMessage.initData.items : undefined
+    const { initData, initData: { items } } = this.props.pushMessage
     if (listData && listData[key] && listData[key].length > 1) {
       let obj = {
         value: []
       }
       listData[key].splice(key1, 1);
 
-      // if (items) {
-      //   if (!items[key])
-      //     items[key] = {};
-      //   initData.items = items;
-      // }
-
-      const updateFromItm = this.state.msgComponent[key]
-      var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-      var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-      var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-      var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-      var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-      var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-      var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
       if (items) {
         if (!items[key])
           items[key] = {};
-        var chooseKey
-        let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-        chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-        let messageItem = {}
-        messageItem.content = content;
-        messageItem.miniAppTitle = miniAppTitle;
-        messageItem.msgType = chooseKey;
-        messageItem.title = title;
-        messageItem.url = url;
-        messageItem.description = description;
-        messageItem.miniProgramAppId = miniProgramAppId;
-        messageItem.pagepath = pagepath;
-        items[key].message = messageItem;
+        items[key].message = this.getFormModel(key);
         initData.items = items;
       }
       this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
@@ -302,32 +201,15 @@ class PushMessage extends React.Component {
     }
   }
   handleSubmit = key => {
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var appId = this.props.wxAppIdValue
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
-
+    const { initData, initData: { items } } = this.props.pushMessage
+    console.log(items,'............................');
     if (items) {
       if (!items[key])
         items[key] = {};
-
-      var message1 = { msgType: this.state.typeText };
-      if (this.props.pushMessage.initData.items[key] && this.props.pushMessage.initData.items[key].message) {
-        message1 = this.props.pushMessage.initData.items[key].message;
-        message1.msgType = this.props.pushMessage.initData.items[key].message.msgType ? this.props.pushMessage.initData.items[key].message.msgType : 'text'
-        message1.msgId = this.props.pushMessage.initData.items[key].message.msgId ? this.props.pushMessage.initData.items[key].message.msgId : null
-        message1.thumbMediaId = this.props.pushMessage.initData.items[key].message.mediaId ? this.props.pushMessage.initData.items[key].message.mediaId : null
-      }
-      // thumbMediaId
-      message1.content = this.state.msgComponent[key].props.form.getFieldValue('content')
-      message1.title = this.state.msgComponent[key].props.form.getFieldValue('title')
-      message1.description = this.state.msgComponent[key].props.form.getFieldValue('description')
-      message1.url = this.state.msgComponent[key].props.form.getFieldValue('url')
-      message1.miniAppTitle = this.state.msgComponent[key].props.form.getFieldValue('miniAppTitle')
-      message1.miniProgramAppId = this.state.msgComponent[key].props.form.getFieldValue('miniProgramAppId')
-      message1.pagepath = this.state.msgComponent[key].props.form.getFieldValue('pagepath')
-      items[key].message = message1;
+      items[key].message = this.getFormModel(key);
       initData.items = items;
     }
+   
     var data = initData.items[key];
     if (typeof (data.disable) === 'undefined')
       data.disable = 0;
@@ -338,12 +220,25 @@ class PushMessage extends React.Component {
     if (typeof (data.tableNo) === 'undefined')
       data.tableNo = key;
 
+     const seleckey  =  initData.items[key] && initData.items[key].message && initData.items[key].message.msgType
+     const Validator = this.getFormModel(key)
+    //  console.log(seleckey,Validator,'Validator');
+    //  if(seleckey == 'news'){
+    //  }
+      // pushMessageItem.content = FormModelItem.props.form.getFieldValue('content')
+      // pushMessageItem.miniAppTitle = FormModelItem.props.form.getFieldValue('miniAppTitle')
+      // pushMessageItem.title = FormModelItem.props.form.getFieldValue('title')
+      // pushMessageItem.url = FormModelItem.props.form.getFieldValue('url')
+      // pushMessageItem.description = FormModelItem.props.form.getFieldValue('description')
+      // pushMessageItem.miniProgramAppId = FormModelItem.props.form.getFieldValue('miniProgramAppId')
+      // pushMessageItem.pagepath = FormModelItem.props.form.getFieldValue('pagepath')
+
+    
     this.props.dispatch({ type: 'pushMessage/submit', payload: { data } });
   }
 
   // 获取 mediaId
   cb_mediaId = (mediaId, key, imgUrl) => {
-    console.log(mediaId, imgUrl);
     var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
     var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
 
@@ -351,12 +246,9 @@ class PushMessage extends React.Component {
       if (!items[key])
         items[key] = {};
 
-      let week1 = items.week;
-
       var message1 = { msgType: this.state.typeText }
       if (this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[key]
         && this.props.pushMessage.initData.items[key].message) {
-
         message1 = this.props.pushMessage.initData.items[key].message
       }
 
@@ -387,34 +279,11 @@ class PushMessage extends React.Component {
     this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
   }
   updateFromMessage = (value, key) => {
-    const initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    const items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
-    const updateFromItm = this.state.msgComponent[key]
-    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
-
+    const { initData,initData:{ items } } = this.props.pushMessage
     if (items) {
       if (!items[key])
         items[key] = {};
-      var chooseKey
-      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-      let messageItem = {}
-      messageItem.content = content;
-      messageItem.miniAppTitle = miniAppTitle;
-      messageItem.msgType = chooseKey;
-      messageItem.title = title;
-      messageItem.url = url;
-      messageItem.description = description;
-      messageItem.miniProgramAppId = miniProgramAppId;
-      messageItem.pagepath = pagepath;
-      items[key].message = messageItem;
+      items[key].message = this.getFormModel(key);
       initData.items = items;
     }
     this.props.dispatch({ type: 'pushMessage/updateState', payload: { initData: initData } });
@@ -423,7 +292,6 @@ class PushMessage extends React.Component {
   cb_chooseKey = (chooseKey, key) => {
     var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
     var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ? this.props.pushMessage.initData.items : undefined
-    // console.log(chooseKey,'chooseKey');
     this.setState({
       typeText: chooseKey,
     })
@@ -452,9 +320,8 @@ class PushMessage extends React.Component {
   }
   handleClick = (value, key1, key) => {
     var listData = this.props.pushMessage.times ? this.props.pushMessage.times : { key: [] }
-    var initData = this.props.pushMessage && this.props.pushMessage.initData ? this.props.pushMessage.initData : undefined;
-    var items = this.props.pushMessage && this.props.pushMessage.initData && this.props.pushMessage.initData.items ?
-      this.props.pushMessage.initData.items : undefined
+
+    const { initData, initData: { items } } = this.props.pushMessage
 
     let selectTime = [];
     if (!listData[key])
@@ -486,39 +353,10 @@ class PushMessage extends React.Component {
     selectTime[key1] = seleDate;
     listData[key][key1] = obj;
 
-    // if (items) {
-    //   if (!items[key])
-    //     items[key] = {};
-    //   items[key].timesList = selectTime;
-    // }
-
-    const updateFromItm = this.state.msgComponent[key]
-    var content = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('content') : ""
-    var miniAppTitle = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniAppTitle') : ""
-    var title = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('title') : ""
-    var url = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('url') : ""
-    var description = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('description') : ""
-    var miniProgramAppId = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('miniProgramAppId') : ""
-    var pagepath = updateFromItm && updateFromItm.props.form ? updateFromItm.props.form.getFieldValue('pagepath') : ""
-
-
     if (items) {
       if (!items[key])
         items[key] = {};
-      var chooseKey
-      let keys = this.props.pushMessage.initData && this.props.pushMessage.initData.items && this.props.pushMessage.initData.items[this.state.currentState]
-      chooseKey = keys && keys.message && keys.message.msgType ? keys.message.msgType : 'text';
-      let messageItem = {}
-      messageItem.content = content;
-      messageItem.miniAppTitle = miniAppTitle;
-      messageItem.msgType = chooseKey;
-      messageItem.title = title;
-      messageItem.url = url;
-      messageItem.description = description;
-      messageItem.miniProgramAppId = miniProgramAppId;
-      messageItem.pagepath = pagepath;
-      items[key].message = messageItem;
-      initData.items = items;
+      items[key].message = this.getFormModel(key);
       items[key].timesList = selectTime;
     }
     this.props.dispatch({ type: 'pushMessage/updateState', payload: { times: listData, initData: initData } });
@@ -549,12 +387,10 @@ class PushMessage extends React.Component {
             var data = [];
             var disable = false;
             var weekItem = 0; //'全天'
-
             let TimeRangePicker = [];
             if (self.props.pushMessage && self.props.pushMessage.times && self.props.pushMessage.times[key]
               && self.props.pushMessage.times[key].length > 0)
               TimeRangePicker = self.props.pushMessage.times[key];
-
             else
               TimeRangePicker = [{ value: [] }]
 
@@ -564,8 +400,6 @@ class PushMessage extends React.Component {
               weekItem = data.items && data.items[key] && typeof (data.items[key].week) !== 'undefined' ? data.items[key].week : 1;
             }
 
-          
-
             var chooseKey = 'text';
             var cutextKey = "text"
             var message1 = {};
@@ -578,14 +412,14 @@ class PushMessage extends React.Component {
               item ? cutextKey = item.message && item.message.msgType : cutextKey = "text"
               message1 = self.props.pushMessage.initData.items[self.state.currentState].message;
               message1.content = self.props.pushMessage.initData.items[self.state.currentState].message.content ?
-                self.props.pushMessage.initData.items[self.state.currentState].message.content : this.state.contentValueItem
+              self.props.pushMessage.initData.items[self.state.currentState].message.content : this.state.contentValueItem
             }
 
             return (
               <div className={styles.connect} style={{ display: (key === self.state.currentState) ? "block" : "none" }}>
                 <div className={styles.Munstate}>
                   <div>状态:</div>
-                  <Switch checked={disable} defaultChecked onChange={(v) => { self.conTroller(v, key) }} />
+                  <Switch checked={disable} defaultChecked onChange={(v) => { self.getSwitchStatus(v, key) }} />
                 </div>
 
                 <div className={styles.TimePickers}>

+ 14 - 1
UI/src/pages/sellmanage/pushMessage/model.js

@@ -81,8 +81,21 @@ export default {
     }, { put, call, select }) {
       try{
         const { wxAppIdValue } = yield select(_ => _.sellmanage);
+        const { initData } = yield select(_ => _.pushMessage);
         const data = yield call(submit,{payload,appId:wxAppIdValue})
-       
+        // var modelData = []
+        // for(let i =0;i<initData.items.length;i++){
+        //   if(data.result.tableNo == initData.items[i].tableNo){
+        //     modelData = initData.items[i].message.msgId = data.result.message.msgId
+        //   }
+        // }
+        // yield put({
+        //   type: 'updateState',
+        //   payload: {
+        //     initData:modelData,
+        //   },
+        // })
+      
         if(data.success)
         message.success(data.message);
         else{

+ 8 - 1
UI/src/pages/sellmanage/templateMessage/index.js

@@ -4,6 +4,7 @@ import { connect } from "dva";
 import { config, request } from "utils";
 import { SketchPicker } from 'react-color'
 import PropTypes, { string } from 'prop-types'
+import { routerRedux } from 'dva/router'
 import moment from 'moment';
 import { Modal, Radio, Badge, Form, Input, Button, message, Popover, DatePicker, Tabs } from "antd";
 const {  WXMpAPI } = config;
@@ -503,7 +504,13 @@ class TemplateMessage extends React.Component {
             },
             {
               name: '编辑', onClick: function (data) {
-                // console.log(JSON.parse(data.contentValue));
+
+                // self.props.dispatch(routerRedux.push({
+                //   pathname: '/ingproduct/add_product',
+                //   query: {},
+                //   })
+                // );
+                // return
                 self.setState({
                   pushValueItem: data.theme,
                   templateId: "",