瀏覽代碼

去sessionStorage为store并优化代码(上一版本是并存的代码)

yuhan 1 年之前
父節點
當前提交
52c2075931

+ 3 - 24
itdmWeb/src/views/module-iTDM/weituo/modules/ItdmWeituoInfoForm.vue

@@ -87,14 +87,11 @@ export default {
       }
 
     },
-
     prevStep() {
       if (this.currentTab > 0) {
         this.currentTab -= 1
       }
-
     },
-
     add() {
       this.model = Object.assign({}, this.modelDefault)
       this.visible = true
@@ -105,15 +102,9 @@ export default {
       getAction(this.url.queryById, select).then((res) => {
         if (res.success) {
           this.model.id = res.result.id
-
-          // sessionStorage.setItem('data', JSON.stringify(res.result.data))
-          // sessionStorage.setItem('yangpin', JSON.stringify(res.result.yangpins))
-          // sessionStorage.setItem('yangpinkz', JSON.stringify(res.result.pinShiYans))
           this.$store.commit('SET_BASEINFO', res.result.data);
           this.$store.commit('SET_YANGPININFO', res.result.yangpins);
           this.$store.commit('SET_SHIYANINFO', res.result.pinShiYans);
-          this.$store.commit('SET_COUNTYP', res.result.yangpins.length>0?res.result.yangpins.length>0:1);
-          this.$store.commit('SET_COUNTSY', res.result.pinShiYans.length>0?res.result.pinShiYans.length>0:1);
           this.$refs.data001.init()
 
         } else {
@@ -122,38 +113,26 @@ export default {
       })
       this.visible = true
     },
-
+    // 提交
     submitForm() {
       const that = this
       // 触发表单验证
-      // this.weituomodel = JSON.parse(sessionStorage.getItem('data'))
-      // this.weituomodel.yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
-      // this.weituomodel.pinShiYans = JSON.parse(sessionStorage.getItem('yangpinkz'))
-      // console.log(JSON.parse(sessionStorage.getItem('yangpinkz')))
-      // var pinShiYans = JSON.parse(sessionStorage.getItem('yangpinkz'))
       this.weituomodel = this.baseInfos
       this.weituomodel.yangpins = this.yangpinInfos
-      this.weituomodel.pinShiYans = this.shiyanInfos.map(item => {
-        item.standardRequirement = item.standardRequirementQ.join(',')
-        return item
-      })
+      this.weituomodel.pinShiYans = this.shiyanInfos
       
-
       that.confirmLoading = true
       let httpurl = ''
       let method = ''
       if (!this.model.id) {
         httpurl += this.url.add
         method = 'post'
-
       } else {
         httpurl += this.url.edit
         method = 'put'
         this.weituomodel.id = this.model.id
-
       }
-
-      console.log(this.weituomodel)
+      // console.log(this.weituomodel)
       httpAction(httpurl, this.weituomodel, method).then((res) => {
         if (res.success) {
           that.$message.success(res.message)

+ 7 - 34
itdmWeb/src/views/module-iTDM/weituo/modules/ItdmWeituoInfoModal.vue

@@ -42,75 +42,47 @@ import { postAction  } from '@api/manage'
       },
     },
     methods: {
-      add () {
-
-        sessionStorage.removeItem("data")
-        sessionStorage.removeItem("yangpin")
-        sessionStorage.removeItem("yangpinkz")
-
-        sessionStorage.removeItem("count")
-        sessionStorage.removeItem("count1")
-
+      initStore(){
         this.$store.commit('SET_BASEINFO', {});
         this.$store.commit('SET_YANGPININFO', []);
         this.$store.commit('SET_SHIYANINFO', []);
-
-
+      },
+      add () {
+        this.initStore()
         this.visible=true
         this.$nextTick(()=>{
           this.$refs.realForm.add();
         })
       },
       edit (record) {
-        sessionStorage.removeItem("data")
-        sessionStorage.removeItem("yangpin")
-        sessionStorage.removeItem("yangpinkz")
-        sessionStorage.removeItem("count")
-        sessionStorage.removeItem("count1")
-        this.$store.commit('SET_BASEINFO', {});
-        this.$store.commit('SET_YANGPININFO', []);
-        this.$store.commit('SET_SHIYANINFO', []);
+        this.initStore()
         this.visible=true
         this.$nextTick(()=>{
           this.$refs.realForm.edit(record);
         })
       },
       close () {
-        // sessionStorage.removeItem("data")
-        // sessionStorage.removeItem("yangpin")
-        // sessionStorage.removeItem("yangpinkz")
-        // sessionStorage.removeItem("count")
-        // sessionStorage.removeItem("count1")
-        this.$store.commit('SET_BASEINFO', {});
-        this.$store.commit('SET_YANGPININFO', []);
-        this.$store.commit('SET_SHIYANINFO', []);
+        this.initStore()
         this.$emit('close');
         this.visible = false;
       },
       // 临时保存
       temporarySave () {
         var weituoInfo = {}
-        // console.log(this.$refs.realForm.model.id)
         var weituoId = this.$refs.realForm.model.id
 
         switch (this.$refs.realForm.currentTab) {
           case 0:
-            // console.log(this.$refs.realForm.$refs.data001.model)
             weituoInfo = this.$refs.realForm.$refs.data001.model
             weituoInfo.yangpins = this.yangpinInfos
             weituoInfo.pinShiYans = this.shiyanInfos
             break;
           case 1:
-            // console.log(this.$refs.realForm.$refs.ypxx.model)
-            // weituoInfo = JSON.parse(sessionStorage.getItem('data'))
             weituoInfo = this.baseInfos
             weituoInfo.yangpins = this.$refs.realForm.$refs.ypxx.model.data
             weituoInfo.pinShiYans = this.shiyanInfos
             break;
           case 2:
-            // console.log(this.$refs.realForm.$refs.syxx.model)
-            // weituoInfo = JSON.parse(sessionStorage.getItem('data'))
-            // weituoInfo.yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
             weituoInfo = this.baseInfos
             weituoInfo.yangpins = this.yangpinInfos
             var pinShiYans = this.$refs.realForm.$refs.syxx.model.list
@@ -138,6 +110,7 @@ import { postAction  } from '@api/manage'
           // that.confirmLoading = false
         })
       },
+      // 
       submitCallback(){
         this.$emit('ok');
         this.visible = false;

+ 18 - 35
itdmWeb/src/views/module-iTDM/weituo/modules/step/Step2.vue

@@ -180,31 +180,26 @@ export default {
     yangpinInfos() {
       return this.$store.getters.yangpinInfos
     },
-    countYp() {
-      return this.$store.getters.countYp
-    },
   },
   created() {
-    // this.count = this.countYp
-    // console.log(this.count)
-    // const data = JSON.parse(sessionStorage.getItem('yangpin'))
-    if (this.yangpinInfos.length > 0) {
-      this.model.data = this.yangpinInfos.map((item, index) => {
-        item.key = (index+1) + ''
-        item.editable = true
-        return item
-      })
-      // this.count++
-      this.count = this.yangpinInfos.length + 1
-      console.log(this.model.data)
-    } else {
-      this.model.data = []
-      this.newMember()
-    }
-    // this.count = sessionStorage.getItem('count') != null ? Number(sessionStorage.getItem('count')) : 1
-
+    this.setInitData()
   },
   methods: {
+    // 设置初始数据
+    setInitData(){
+      if (this.yangpinInfos.length > 0) {
+        this.model.data = this.yangpinInfos.map((item, index) => {
+          item.key = (index+1) + ''
+          item.editable = true
+          return item
+        })
+        this.count = this.yangpinInfos.length + 1
+        // console.log(this.model.data)
+      } else {
+        this.model.data = []
+        this.newMember()
+      }
+    },
     // 新增样品
     newMember() {
       console.log(this.count)
@@ -218,10 +213,6 @@ export default {
         isNew: true
       })
       this.count++
-      // sessionStorage.setItem('count', this.count)
-      
-      
-
     },
     // 删除
     remove(key) {
@@ -234,9 +225,7 @@ export default {
     //   let target = this.data.filter(item => item.key === key)[0]
     //   target.editable = false
     //   target.isNew = false
-
     // },
-
     handleChange(value, key, column) {
       const newData = [...this.model.data]
       const target = newData.filter(item => key === item.key)[0]
@@ -247,25 +236,19 @@ export default {
     },
     // 下一步
     nextStep() {
-
-      console.log(11111,this.model.data)
+      // console.log(11111,this.model.data)
       this.$refs.form.validate(valid => {
         if (valid) {
-          // sessionStorage.setItem('yangpin', JSON.stringify(this.model.data))
           this.$store.commit('SET_YANGPININFO', this.model.data);
-          // this.$store.commit('SET_COUNTYP', this.count);
           this.$emit('nextStep')
         }
       })
-      
     },
+    // 上一步
     prevStep() {
-      // sessionStorage.setItem('yangpin', JSON.stringify(this.model.data))
       this.$store.commit('SET_YANGPININFO', this.model.data);
-      // this.$store.commit('SET_COUNTYP', this.count);
       this.$emit('prevStep')
     },
-
   }
 }
 </script>

+ 37 - 61
itdmWeb/src/views/module-iTDM/weituo/modules/step/Step3.vue

@@ -227,42 +227,10 @@ export default {
     shiyanInfos() {
       return this.$store.getters.shiyanInfos
     },
-    // count() {
-    //   return this.$store.getters.countSy
-    // },
   },
   created() {
     this.getYijuLists()
-    // console.log(JSON.parse(sessionStorage.getItem('yangpin')))
-    // console.log(JSON.parse(sessionStorage.getItem('yangpinkz')))
-    // const data = JSON.parse(sessionStorage.getItem('yangpinkz'))
-    if (this.shiyanInfos.length > 0) {
-      this.model.list = this.shiyanInfos.map((item, index) => {
-        // console.log(!item.standardRequirement)
-        // console.log(item.standardRequirement)
-        if(!item.standardRequirement){
-          item.standardRequirementQ = []
-        } else {
-          item.standardRequirementQ = item.standardRequirement.split(',')
-        }
-        item.key = (index+1) + ''
-        item.editable = true
-        return item
-      })
-      this.count = this.shiyanInfos.length + 1
-      console.log(this.model.list)
-      
-    }else{
-      this.newMember()
-    }
-
-    // console.log(2323,sessionStorage.getItem('yangpin'))
-    // const yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
-
-    this.yangpins = this.yangpinInfos
-
-    // this.count = sessionStorage.getItem('count1') != null ? Number(sessionStorage.getItem('count1')) : 1
-
+    this.setInitData()
   },
   methods: {
     // 获取所有依据列表
@@ -272,6 +240,26 @@ export default {
         this.yijuLists = res.result
       })
     },
+    // 设置初始数据-主要是依据
+    setInitData(){
+      if (this.shiyanInfos.length > 0) {
+        this.model.list = this.shiyanInfos.map((item, index) => {
+          if(!item.standardRequirement){
+            item.standardRequirementQ = []
+          } else {
+            item.standardRequirementQ = item.standardRequirement.split(',')
+          }
+          item.key = (index+1) + ''
+          item.editable = true
+          return item
+        })
+        this.count = this.shiyanInfos.length + 1
+        // console.log(this.model.list)
+      }else{
+        this.newMember()
+      }
+      this.yangpins = this.yangpinInfos
+    },
     // 获取当前点击行是哪儿一行
     clickThenCheck(record, index){
       return {
@@ -283,8 +271,7 @@ export default {
         }
       }
     },
-
-    // 获得选中项信息
+    // 选中样品改变时输入规格型号
     handleChange(value,optipn) {
       console.log(777,value,optipn);
       if(value){
@@ -295,8 +282,7 @@ export default {
         this.$set(this.model.list[this.clickIndex], 'yangpinKeyId', a.sampleName )
       }
     },
-
-    // 多选依据
+    // 多选检测依据
     handleDescCate(value,optipn) {
       // console.log(value, optipn)
       // 这里用$set不好使
@@ -307,7 +293,7 @@ export default {
       target.standardRequirementQ = value;
       this.model.list = newData;
     },
-
+    // 创建一条新数据
     newMember() {
       this.model.list.push({
         key: this.count + '',
@@ -321,46 +307,36 @@ export default {
         editable: true,
         isNew: true
       })
-
       this.count++
-      // sessionStorage.setItem('count1', this.count)
-
     },
+    // 删除
     remove(key) {
       const newData = this.model.list.filter(item => item.key !== key)
       this.model.list = newData
     },
-    // saveRow(key) {
-    //   let target = this.model.list.filter(item => item.key === key)[0]
-    //   target.editable = false
-    //   target.isNew = false
-    // },
-
+    // 提交
     submitForm() {
-      // sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
-      this.$store.commit('SET_SHIYANINFO', this.model.list);
       
+      this.$store.commit('SET_SHIYANINFO', this.changeJcyj());
       this.$refs.form.validate(valid => {
         if (valid) {  
           this.$emit('submitForm')
         }
       })
     },
+    // 上一步
     prevStep() {
-      // sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
-      // var newData = this.model.list.map(item => {
-      //   item.standardRequirement = item.standardRequirementQ.toString()
-      //   return item
-      // })
-      // this.model.list = newData
-      for (let i = 0; i < this.model.list.length; i++) {
-        const element = this.model.list[i];
-        element.standardRequirement = element.standardRequirementQ.join(',')
-      }
-      this.$store.commit('SET_SHIYANINFO', this.model.list);
-
+      this.$store.commit('SET_SHIYANINFO', this.changeJcyj());
       this.$emit('prevStep')
     },
+    // 修改数据格式
+    changeJcyj(){
+      var saveData = this.model.list.map(item => {
+        item.standardRequirement = item.standardRequirementQ.join(',')
+        return item
+      })
+      return saveData
+    }
   }
 }
 </script>