king
2019-11-15 d3edd6d592db12fbec67e2700d168e07546aed29
src/components/sidemenu/editthdmenu/index.jsx
@@ -8,7 +8,7 @@
import TransferForm from '@/components/transferform'
import Utils from '@/utils/utils.js'
import DragElement from '../menuelement'
import MenuForm from '../menuform'
// import MenuForm from '../menuform'
import ComTableConfig from '../comtableconfig'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/header.js'
@@ -51,11 +51,8 @@
    baseTemplates: [{
      title: '基础表格',
      type: 'CommonTable',
      url: illust['CommonTable']
    }, {
      title: '数据表格',
      type: 'datatable',
      url: illust['CommonTable']
      url: illust['CommonTable'],
      baseconfig: ''
    }]
  }
@@ -106,52 +103,33 @@
      }
      Api.getSystemConfig(param).then(res => {
        if (res.status) {
          let _LongParam = window.atob(res.LongParam)
          try {
            _LongParam = JSON.parse(_LongParam)
          } catch (e) {
            _LongParam = {
              type: 'system',
              search: [],
              action: [],
              columns: []
            }
          }
          _menu.LongParam = _LongParam
          console.log(_menu)
          // 检测模板是否存在
          let _Template = this.state.baseTemplates.filter(temp => temp.type === _menu.PageParam.Template)
          this.setState({
            editMvisible: true,
            title: this.state.dict['header.menu.editTitle'],
            type: 'edit',
            editMenu: {..._menu, LongParam: res.LongParam},
            formlist: [
              {
                type: 'select',
                key: 'parentId',
                label: this.state.dict['header.menu.supMenu'],
                initVal: this.props.supMenu.MenuID,
                required: true,
                options: this.props.supMenuList
              },
              {
                type: 'text',
                key: 'menuName',
                label: this.state.dict['header.menu.menuName'],
                initVal: menu.card.text,
                required: true,
                readonly: false
              },
              {
                type: 'text',
                key: 'menuNo',
                label: this.state.dict['header.menu.menuNo'],
                initVal: menu.card.MenuNo,
                required: true,
                readonly: false
              },
              {
                type: 'select',
                key: 'opentype',
                label: '打开方式',
                initVal: menu.card.PageParam.OpenType || 'newtab',
                required: true,
                options: [{
                  MenuID: 'newtab',
                  text: '新标签页'
                }, {
                  MenuID: 'newpage',
                  text: '新页面'
                }]
              }
            ]
            editMenu: _menu,
            tabview: _Template.length > 0 ? _menu.PageParam.Template : 'template'
          })
          if (_Template.length === 0) {
            notification.warning({
              top: 92,
              message: this.state.dict['header.menu.template.empty'],
              duration: 10
            })
          }
        } else {
          notification.warning({
            top: 92,
@@ -231,94 +209,94 @@
    }
  }
  memuHandleSubmit = () => {
    if (this.state.type === 'add') {
      // 新建菜单:提交
      this.menuFormRef.handleConfirm().then(values => {
        let param = {
          func: 'sPC_TrdMenu_Add',
          ParentID: this.props.supMenu.MenuID,
          MenuID: Utils.getuuid(),
          MenuNo: values.menuNo,
          Template: this.state.selectTemp.type,
          MenuName: values.menuName,
          Sort: (this.props.menulist.length + 1) * 10,
          PageParam: JSON.stringify({
            OpenType: values.opentype,
            Template: this.state.selectTemp.type
          }),
          LongParam: window.btoa(JSON.stringify(this.state.selectTemp.baseconfig))
        }
        this.setState({
          confirmLoading: true
        })
        Api.getSystemConfig(param).then(res => {
          if (res.status) {
            this.setState({
              confirmLoading: false,
              tabview: '',
              visible: false
            })
            this.props.reload()
            this.resetFormlist()
          } else {
            this.setState({
              confirmLoading: false
            })
            notification.warning({
              top: 92,
              message: res.message,
              duration: 10
            })
          }
        })
      }, () => {})
    } else if (this.state.type === 'edit') {
      // 编辑菜单:提交
      this.menuFormRef.handleConfirm().then(values => {
        let param = {
          func: 'sPC_TrdMenu_Upt',
          ParentID: values.parentId,
          MenuID: this.state.editMenu.MenuID,
          MenuNo: values.menuNo,
          Template: this.state.editMenu.PageParam.Template || '',
          MenuName: values.menuName,
          PageParam: JSON.stringify(this.state.editMenu.PageParam),
          LongParam: this.state.editMenu.LongParam ? window.btoa(this.state.editMenu.LongParam) : ''
        }
        this.setState({
          confirmLoading: true
        })
        Api.getSystemConfig(param).then(res => {
          if (res.status) {
            this.setState({
              confirmLoading: false,
              editMvisible: false
            })
            this.props.reload()
            this.resetFormlist()
          } else {
            this.setState({
              confirmLoading: false
            })
            notification.warning({
              top: 92,
              message: res.message,
              duration: 10
            })
          }
        })
      }, () => {})
    }
  }
  // memuHandleSubmit = () => {
  //   if (this.state.type === 'add') {
  //     // 新建菜单:提交
  //     this.menuFormRef.handleConfirm().then(values => {
  //       let param = {
  //         func: 'sPC_TrdMenu_Add',
  //         ParentID: this.props.supMenu.MenuID,
  //         MenuID: Utils.getuuid(),
  //         MenuNo: values.menuNo,
  //         Template: this.state.selectTemp.type,
  //         MenuName: values.menuName,
  //         Sort: (this.props.menulist.length + 1) * 10,
  //         PageParam: JSON.stringify({
  //           OpenType: values.opentype,
  //           Template: this.state.selectTemp.type
  //         }),
  //         LongParam: window.btoa(JSON.stringify(this.state.selectTemp.baseconfig))
  //       }
  //       this.setState({
  //         confirmLoading: true
  //       })
  //       Api.getSystemConfig(param).then(res => {
  //         if (res.status) {
  //           this.setState({
  //             confirmLoading: false,
  //             tabview: '',
  //             visible: false
  //           })
  //           this.props.reload()
  //           this.resetFormlist()
  //         } else {
  //           this.setState({
  //             confirmLoading: false
  //           })
  //           notification.warning({
  //             top: 92,
  //             message: res.message,
  //             duration: 10
  //           })
  //         }
  //       })
  //     }, () => {})
  //   } else if (this.state.type === 'edit') {
  //     // 编辑菜单:提交
  //     this.menuFormRef.handleConfirm().then(values => {
  //       let param = {
  //         func: 'sPC_TrdMenu_Upt',
  //         ParentID: values.parentId,
  //         MenuID: this.state.editMenu.MenuID,
  //         MenuNo: values.menuNo,
  //         Template: this.state.editMenu.PageParam.Template || '',
  //         MenuName: values.menuName,
  //         PageParam: JSON.stringify(this.state.editMenu.PageParam),
  //         LongParam: this.state.editMenu.LongParam ? window.btoa(this.state.editMenu.LongParam) : ''
  //       }
  //       this.setState({
  //         confirmLoading: true
  //       })
  //       Api.getSystemConfig(param).then(res => {
  //         if (res.status) {
  //           this.setState({
  //             confirmLoading: false,
  //             editMvisible: false
  //           })
  //           this.props.reload()
  //           this.resetFormlist()
  //         } else {
  //           this.setState({
  //             confirmLoading: false
  //           })
  //           notification.warning({
  //             top: 92,
  //             message: res.message,
  //             duration: 10
  //           })
  //         }
  //       })
  //     }, () => {})
  //   }
  // }
  memuHandleCancel = () => {
    this.setState({
      editMvisible: false,
      visible: false
    })
    this.resetFormlist()
  }
  // memuHandleCancel = () => {
  //   this.setState({
  //     editMvisible: false,
  //     visible: false
  //   })
  //   this.resetFormlist()
  // }
  thawMemuSubmit = () => {
    // 三级菜单解除冻结
@@ -389,164 +367,133 @@
  }
  useTemplate = (template) => {
    const { type, editMenu } = this.state
    // 选择模板:添加菜单时
    if (this.state.type === 'add') {
    if (type === 'add') {
      this.setState({
        tabview: template.type,
        menuConfig: template.baseconfig
        editMenu: {
          MenuID: Utils.getuuid(),
          MenuName: '',
          MenuNo: '',
          id: this.props.menulist.length,
          src: '',
          text: '',
          type: template.type,
          PageParam: {OpenType: "newtab", Template: template.type},
          LongParam: ''
        }
      })
      // this.setState({
      //   visible: true,
      //   title: this.state.dict['header.menu.addtitle'],
      //   selectTemp: template,
      //   formlist: [
      //     {
      //       type: 'text',
      //       key: 'parentId',
      //       label: this.state.dict['header.menu.supMenu'],
      //       initVal: this.props.supMenu.text,
      //       required: true,
      //       readonly: true
      //     },
      //     {
      //       type: 'text',
      //       key: 'menuName',
      //       label: this.state.dict['header.menu.menuName'],
      //       initVal: '',
      //       required: true,
      //       readonly: false
      //     },
      //     {
      //       type: 'text',
      //       key: 'menuNo',
      //       label: this.state.dict['header.menu.menuNo'],
      //       initVal: '',
      //       required: true,
      //       readonly: false
      //     },
      //     {
      //       type: 'select',
      //       key: 'opentype',
      //       label: '打开方式',
      //       initVal: 'newtab',
      //       required: true,
      //       options: [{
      //         MenuID: 'newtab',
      //         text: '新标签页'
      //       }, {
      //         MenuID: 'newpage',
      //         text: '新页面'
      //       }]
      //     }
      //   ]
      // })
    } else {
      // this.setState({
      //   tabview: this.state.selectTemp.type
      // })
    }
  }
      let _PageParam = {OpenType: editMenu.PageParam.OpenType, Template: template.type}
  submitMenuConfig = () => {
    if (this.state.type !== 'edit') {
      this.setState({
        visible: true,
        title: this.state.dict['header.menu.addtitle'],
        formlist: [
          {
            type: 'text',
            key: 'parentId',
            label: this.state.dict['header.menu.supMenu'],
            initVal: this.props.supMenu.text,
            required: true,
            readonly: true
          },
          {
            type: 'text',
            key: 'menuName',
            label: this.state.dict['header.menu.menuName'],
            initVal: '',
            required: true,
            readonly: false
          },
          {
            type: 'text',
            key: 'menuNo',
            label: this.state.dict['header.menu.menuNo'],
            initVal: '',
            required: true,
            readonly: false
          },
          {
            type: 'select',
            key: 'opentype',
            label: '打开方式',
            initVal: 'newtab',
            required: true,
            options: [{
              MenuID: 'newtab',
              text: '新标签页'
            }, {
              MenuID: 'newpage',
              text: '新页面'
            }]
          }
        ]
      })
    } else {
      console.log(this.state.editMenu)
      // confirm({
      //   title: this.state.dict['header.menu.update'].replace('@M', menu.card.text),
      //   content: '',
      //   okText: this.state.dict['header.confirm'],
      //   cancelText: this.state.dict['header.cancel'],
      //   onOk() {
      //     let param = {
      //       func: 'sPC_MainMenu_Del',
      //       MenuID: menu.card.MenuID
      //     }
      //     return Api.getSystemConfig(param).then(res => {
      //       if (res.status) {
      //         _this.props.reload()
      //       } else {
      //         notification.warning({
      //           top: 92,
      //           message: res.message,
      //           duration: 10
      //         })
      //       }
      //     })
      //   },
      //   onCancel() {}
      // })
      this.setState({
        tabview: this.state.selectTemp.type
        tabview: template.type,
        editMenu: {...editMenu, ...{LongParam: template.baseconfig, PageParam: _PageParam, type: template.type}}
      })
    }
  }
  changeTemp = () => {
    this.setState({
      editMvisible: false,
      tabview: 'template'
    })
    this.resetFormlist()
  }
  // submitMenuConfig = () => {
  //   if (this.state.type !== 'edit') {
  //     this.setState({
  //       visible: true,
  //       title: this.state.dict['header.menu.addtitle'],
  //       formlist: [
  //         {
  //           type: 'text',
  //           key: 'parentId',
  //           label: this.state.dict['header.menu.supMenu'],
  //           initVal: this.props.supMenu.text,
  //           required: true,
  //           readonly: true
  //         },
  //         {
  //           type: 'text',
  //           key: 'menuName',
  //           label: this.state.dict['header.menu.menuName'],
  //           initVal: '',
  //           required: true,
  //           readonly: false
  //         },
  //         {
  //           type: 'text',
  //           key: 'menuNo',
  //           label: this.state.dict['header.menu.menuNo'],
  //           initVal: '',
  //           required: true,
  //           readonly: false
  //         },
  //         {
  //           type: 'select',
  //           key: 'opentype',
  //           label: '打开方式',
  //           initVal: 'newtab',
  //           required: true,
  //           options: [{
  //             MenuID: 'newtab',
  //             text: '新标签页'
  //           }, {
  //             MenuID: 'newpage',
  //             text: '新页面'
  //           }]
  //         }
  //       ]
  //     })
  //   } else {
  //     console.log(this.state.editMenu)
  //     // confirm({
  //     //   title: this.state.dict['header.menu.update'].replace('@M', menu.card.text),
  //     //   content: '',
  //     //   okText: this.state.dict['header.confirm'],
  //     //   cancelText: this.state.dict['header.cancel'],
  //     //   onOk() {
  //     //     let param = {
  //     //       func: 'sPC_MainMenu_Del',
  //     //       MenuID: menu.card.MenuID
  //     //     }
  //     //     return Api.getSystemConfig(param).then(res => {
  //     //       if (res.status) {
  //     //         _this.props.reload()
  //     //       } else {
  //     //         notification.warning({
  //     //           top: 92,
  //     //           message: res.message,
  //     //           duration: 10
  //     //         })
  //     //       }
  //     //     })
  //     //   },
  //     //   onCancel() {}
  //     // })
  //     this.setState({
  //       tabview: this.state.selectTemp.type
  //     })
  //   }
  // }
  changeConfig = () => {
    this.setState({
      editMvisible: false,
      tabview: this.state.editMenu.PageParam.Template,
      menuConfig: window.atob(this.state.editMenu.LongParam)
    })
    this.resetFormlist()
  }
  // changeTemp = () => {
  //   this.setState({
  //     editMvisible: false,
  //     tabview: 'template'
  //   })
  //   this.resetFormlist()
  // }
  // changeConfig = () => {
  //   this.setState({
  //     editMvisible: false,
  //     tabview: this.state.editMenu.PageParam.Template,
  //     menuConfig: window.atob(this.state.editMenu.LongParam)
  //   })
  //   this.resetFormlist()
  // }
  
  resetFormlist = () => {
    setTimeout(() => {
      this.setState({formlist: null})
    }, 300)
  }
  // resetFormlist = () => {
  //   setTimeout(() => {
  //     this.setState({formlist: null})
  //   }, 300)
  // }
  getUsedTemplate = () => {
    Api.getSystemConfig({func: 'sPC_Get_UserTemp'}).then(res => {
@@ -576,8 +523,8 @@
    this.setState({tabview: ''})
  }
  handleConfig = () => {
    this.setState({tabview: ''})
  handleConfig = (type) => {
    this.setState({tabview: type})
  }
  UNSAFE_componentWillMount () {
@@ -662,12 +609,17 @@
          </div>
        </div>}
        {this.state.tabview === 'CommonTable' &&
          <ComTableConfig config={this.state.menuConfig} handleConfig={this.handleConfig} />
          <ComTableConfig
            menu={this.state.editMenu}
            supMenu={this.props.supMenu}
            supMenuList={this.props.supMenuList}
            handleConfig={this.handleConfig}
          />
        }
        {/* 图片预览 */}
        <Preview cancel={this.cancelPrePicture} preview={this.state.preview}/>
        {/* 添加模态框 */}
        <Modal
        {/* <Modal
          title={this.state.title}
          okText={this.state.dict['header.confirm']}
          cancelText={this.state.dict['header.cancel']}
@@ -681,9 +633,9 @@
            formlist={this.state.formlist}
            wrappedComponentRef={(inst) => this.menuFormRef = inst}
          />}
        </Modal>
        </Modal> */}
        {/* 编辑模态框 */}
        <Modal
        {/* <Modal
          title={this.state.title}
          visible={this.state.editMvisible}
          footer={null}
@@ -700,7 +652,7 @@
            <Button onClick={this.memuHandleCancel}>{this.state.dict['header.cancel']}</Button>
            <Button type="primary" onClick={this.memuHandleSubmit} loading={this.state.confirmLoading}>{this.state.dict['header.confirm']}</Button>
          </div>
        </Modal>
        </Modal> */}
        {/* 解冻菜单模态框 */}
        <Modal
          title={this.state.dict['header.thawmenu']}