Преглед изворни кода

Merge http://39.104.94.153:3000/yf_zy/MingGao_vue

zhangyun пре 4 година
родитељ
комит
3f2654e5d9
2 измењених фајлова са 80 додато и 153 уклоњено
  1. 1 1
      minggao/config/index.js
  2. 79 152
      minggao/src/page/commandCenter/laboratory.vue

+ 1 - 1
minggao/config/index.js

@@ -22,7 +22,7 @@ module.exports = {
     },
 
     // Various Dev Server settings
-    host: '192.168.1.29', // can be overwritten by process.env.HOST
+    host: '192.168.137.1', // can be overwritten by process.env.HOST
     port: 8888, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
     autoOpenBrowser: false,
     errorOverlay: true,

+ 79 - 152
minggao/src/page/commandCenter/laboratory.vue

@@ -239,7 +239,6 @@
             <el-input
               placeholder="请输入内容"
               size="mini"
-              @change="compileInsect($event, item, index)"
               v-model="item.num"
               clearable
               type="number"
@@ -289,6 +288,11 @@
           >
         </li>
       </ul>
+
+      <span slot="footer" class="dialog-footer">
+        <el-button @click="dialogVisible = false">取 消</el-button>
+        <el-button type="primary" @click="confirmAxios">确 定</el-button>
+      </span>
     </el-dialog>
   </div>
 </template>
@@ -593,54 +597,25 @@ export default {
     addInsect() {
       if (this.insectVal !== "" && this.numVal !== "") {
         var array = [];
-        for (var i = 0; i < this.fillList.length; i++) {
-          var obj = {};
-          obj["pest_name"] = this.fillList[i].label;
-          obj["pest_number"] = this.fillList[i].num;
-          array.push(obj);
+        var arr = [];
+        for (var i = 0; i < this.options2.length; i++) {
+          if (this.options2[i].label == this.insectVal) {
+            var obj = {};
+            obj["value"] = this.options2[i].id;
+            obj["label"] = this.options2[i].label;
+            obj["num"] = Number(this.numVal);
+            arr = [obj, ...this.fillList];
+            this.models = [obj.value, ...this.models];
+          }
         }
-        var obj1 = {};
-        obj1["pest_name"] = this.insectVal;
-        obj1["pest_number"] = Number(this.numVal);
-        array = [...array, obj1];
-
-        this.$confirm("此操作将新增有害生物, 是否继续?", "提示", {
-          confirmButtonText: "确定",
-          cancelButtonText: "取消",
-          type: "warning"
-        })
-          .then(() => {
-            this.$axios({
-              method: "POST",
-              url: "/api/api_gateway?method=control_center.task.discern_add",
-              data: this.qs.stringify({
-                record_id: this.examineObj.id, // 任务id
-                pest_list: JSON.stringify(array) // 害虫数组
-              })
-            })
-              .then(res => {
-                if (res.data.message == "") {
-                  this.$message({
-                    type: "success",
-                    message: "添加成功!",
-                    duration: 1500
-                  });
-                  this.examine(this.examineObj);
-                }
-                this.insectVal = "";
-                this.numVal = "";
-              })
-              .catch(err => {
-                console.log(err);
-              });
-          })
-          .catch(() => {
-            this.$message({
-              type: "info",
-              message: "已取消添加",
-              duration: 1500
-            });
-          });
+        // 修改原数据
+        this.fillList = [];
+        this.insectVal = "";
+        this.numVal = "";
+        arr.forEach((item, index) => {
+          item.ind = index;
+          this.fillList.push(item);
+        });
       } else {
         this.$message({
           type: "info",
@@ -652,116 +627,68 @@ export default {
 
     // 删除有害生物
     delInsect(data) {
-      this.$confirm("此操作将永久删除该有害生物, 是否继续?", "提示", {
-        confirmButtonText: "确定",
-        cancelButtonText: "取消",
-        type: "warning"
+      this.$delete(this.fillList, data.ind); // 删除渲染列表对应数据
+      this.$delete(this.models, data.ind); // 删除对应双向绑定数据
+      var list = [];
+      this.fillList.forEach((item, index) => {
+        item.ind = index;
+        list.push(item);
+      });
+      this.fillList = [];
+      this.fillList = list;
+    },
+
+    // 添加、删除确定事件
+    confirmAxios() {
+      var array = [];
+      for (var i = 0; i < this.fillList.length; i++) {
+        var obj = {};
+        obj["pest_name"] = this.fillList[i].label;
+        obj["pest_number"] = this.fillList[i].num;
+        array.push(obj);
+      }
+      this.$axios({
+        method: "POST",
+        url: "/api/api_gateway?method=control_center.task.discern_add",
+        data: this.qs.stringify({
+          record_id: this.examineObj.id, // 任务id
+          pest_list: JSON.stringify(array) // 害虫数组
+        })
       })
-        .then(() => {
-          this.loading1 = true;
-          var list = this.fillList;
-          list.splice(data.ind, 1);
-          var arr = [];
-          list.forEach(item => {
-            var obj = {};
-            obj["pest_name"] = item.label;
-            obj["pest_number"] = item.num;
-            arr.push(obj);
-          });
-          this.$axios({
-            method: "POST",
-            url: "/api/api_gateway?method=control_center.task.discern_add",
-            data: this.qs.stringify({
-              record_id: this.examineObj.id, // 任务id
-              pest_list: JSON.stringify(arr) // 害虫数组
-            })
-          })
-            .then(res => {
-              if (res.data.message == "") {
-                this.$message({
-                  type: "success",
-                  message: "删除成功!",
-                  duration: 1500
-                });
-                this.examine(this.examineObj);
-              }
-              this.loading1 = false;
-            })
-            .catch(err => {
-              this.loading1 = false;
+        .then(res => {
+          if (res.data.message == "") {
+            this.$message({
+              type: "success",
+              message: "成功!",
+              duration: 1500
             });
+            this.fillList = [];
+            this.models = [];
+            this.dialogVisible = false;
+          }
+          this.insectVal = "";
+          this.numVal = "";
         })
-        .catch(() => {
-          this.$message({
-            type: "info",
-            message: "已取消删除",
-            duration: 1500
-          });
+        .catch(err => {
+          console.log(err);
         });
     },
 
     // 编辑有害生物
     compileInsect(e, data, index) {
-      this.$confirm("此操作将编辑该有害生物, 是否继续?", "提示", {
-        confirmButtonText: "确定",
-        cancelButtonText: "取消",
-        type: "warning"
-      })
-        .then(() => {
-          this.$set(this.models, index, e);
-          var list = this.spareData;
-          var newList = [];
-          // 下拉框数据改变处理
-          for (var i = 0; i < list.length; i++) {
-            var obj = {};
-            if (e == list[i].value) {
-              obj["pest_name"] = list[i].label;
-              obj["pest_number"] = data.num;
-              newList.push(obj);
-            }
-          }
-          // 修改数据为可发送到后端接口数据
-          var arr = [];
-          var list = this.fillList;
-          list.forEach(item => {
-            var obj = {};
-            obj["pest_name"] = item.label;
-            obj["pest_number"] = item.num;
-            arr.push(obj);
-          });
-          arr.splice(index, 1, ...newList);
-          this.$axios({
-            method: "POST",
-            url: "/api/api_gateway?method=control_center.task.discern_add",
-            data: this.qs.stringify({
-              record_id: this.examineObj.id, // 任务id
-              pest_list: JSON.stringify(arr) // 害虫数组
-            })
-          })
-            .then(res => {
-              if (res.data.message == "") {
-                this.$message({
-                  type: "success",
-                  message: "编辑成功!",
-                  duration: 1500
-                });
-                this.examine(this.examineObj);
-              }
-              this.insectVal = "";
-              this.numVal = "";
-            })
-            .catch(err => {
-              console.log(err);
-            });
-        })
-        .catch(() => {
-          this.loading1 = false;
-          this.$set(this.models, index, this.fillList[index].value);
-          this.$message({
-            type: "info",
-            message: "已取消编辑"
-          });
-        });
+      var list = this.spareData;
+      var newList = [];
+      // 下拉框数据改变处理
+      var name = "";
+      for (var i = 0; i < list.length; i++) {
+        var obj = {};
+        if (e == list[i].value) {
+          name = list[i].label;
+        }
+      }
+      this.$set(this.models, index, e);
+      this.fillList[index].label = name;
+      this.fillList[index].value = e;
     },
 
     getBit(value, bit) {
@@ -890,9 +817,9 @@ export default {
 /deep/ input[type="number"] {
   -moz-appearance: textfield !important;
 }
-/deep/.el-date-editor{
+/deep/.el-date-editor {
   cursor: pointer;
-  .el-range-input{
+  .el-range-input {
     cursor: pointer;
   }
 }