From d3edd6d592db12fbec67e2700d168e07546aed29 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 15 十一月 2019 09:46:00 +0800
Subject: [PATCH] 2019-11-15

---
 src/components/sidemenu/editthdmenu/index.jsx |  528 ++++++++++++++++++++++++++--------------------------------
 1 files changed, 240 insertions(+), 288 deletions(-)

diff --git a/src/components/sidemenu/editthdmenu/index.jsx b/src/components/sidemenu/editthdmenu/index.jsx
index 2b7f5cf..3e1e65d 100644
--- a/src/components/sidemenu/editthdmenu/index.jsx
+++ b/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 = () => {
     // 涓夌骇鑿滃崟瑙i櫎鍐荤粨
@@ -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> */}
         {/* 瑙e喕鑿滃崟妯℃�佹 */}
         <Modal
           title={this.state.dict['header.thawmenu']}

--
Gitblit v1.8.0