From 3c5a7ee5c39b9681bfd3e7a3a8ae573c47277564 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Mon, 23 May 2022 10:31:06 +0800
Subject: [PATCH] 溯源码溯源绑定

---
 src/views/traceability/addTraceability.vue |  228 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 177 insertions(+), 51 deletions(-)

diff --git a/src/views/traceability/addTraceability.vue b/src/views/traceability/addTraceability.vue
index c113bf7..797def5 100644
--- a/src/views/traceability/addTraceability.vue
+++ b/src/views/traceability/addTraceability.vue
@@ -4,6 +4,7 @@
     :modal-append-to-body="false"
     :append-to-body="true"
     :close-on-click-modal="false"
+    @close="close"
     width="60%"
     :visible.sync="visible"
     center
@@ -78,7 +79,13 @@
               </div>
               <div class="input">
                 <div class="left">重量/数量:</div>
-                <div class="rigth">{{ formLabelAlign.weight==''?'':formLabelAlign.weight+"公斤" }}</div>
+                <div class="rigth">
+                  {{
+                    formLabelAlign.weight == ""
+                      ? ""
+                      : formLabelAlign.weight + "公斤"
+                  }}
+                </div>
               </div>
               <div class="input">
                 <div class="left">产地:</div>
@@ -135,11 +142,30 @@
               <el-input v-model="formLabelAlign.certificationCode"></el-input>
             </el-form-item>
             <el-form-item label="承诺依据" prop="according">
-              <el-checkbox-group v-model="formLabelAlign.according" @change="changeCheckBox">
-                <el-checkbox label="委托检测" name="type" @change="wtChange"></el-checkbox>
-                <el-checkbox label="自我检测" name="type" @change="zwChange"></el-checkbox>
-                <el-checkbox label="内部质量控制" name="type" @change="nbChange"></el-checkbox>
-                <el-checkbox label="自我承诺" name="type" @change="cnChange"></el-checkbox>
+              <el-checkbox-group
+                v-model="formLabelAlign.according"
+                @change="changeCheckBox"
+              >
+                <el-checkbox
+                  label="委托检测"
+                  name="type"
+                  @change="wtChange"
+                ></el-checkbox>
+                <el-checkbox
+                  label="自我检测"
+                  name="type"
+                  @change="zwChange"
+                ></el-checkbox>
+                <el-checkbox
+                  label="内部质量控制"
+                  name="type"
+                  @change="nbChange"
+                ></el-checkbox>
+                <el-checkbox
+                  label="自我承诺"
+                  name="type"
+                  @change="cnChange"
+                ></el-checkbox>
               </el-checkbox-group>
             </el-form-item>
             <el-form-item label="是否绑定溯源" prop="bind">
@@ -151,39 +177,46 @@
       </div>
     </div>
     <div class="traceablility-table" v-if="isShow">
-        <avue-crud
-      :option="option"
-      :table-loading="loading"
-      :data="data"
-      :page.sync="page"
-      v-model="form"
-      ref="crud"
-      @search-change="searchChange"
-      @search-reset="searchReset"
-      @selection-change="selectionChange"
-      @current-change="currentChange"
-      @size-change="sizeChange"
-      @refresh-change="refreshChange"
-      @on-load="onLoad"
-    ></avue-crud>
+      <avue-crud
+        :option="option"
+        :table-loading="loading"
+        :data="data"
+        :page.sync="page"
+        v-model="form"
+        ref="crud"
+        @search-change="searchChange"
+        @search-reset="searchReset"
+        @selection-change="selectionChange"
+        @current-change="currentChange"
+        @size-change="sizeChange"
+        @refresh-change="refreshChange"
+        @on-load="onLoad"
+      ></avue-crud>
     </div>
     <div class="traceability-btn">
-        <el-button type="primary" @click="next" v-if="isBind">{{tip}}</el-button>
-        <el-button type="primary" @click="submit">提 交</el-button>
-      </div>
+      <el-button type="primary" @click="next" v-if="isBind">{{
+        tip
+      }}</el-button>
+      <el-button type="primary" @click="submit" v-if="isBtn">提 交</el-button>
+      <el-button type="primary" @click="submits" v-if="!isBtn">提 交</el-button>
+    </div>
   </el-dialog>
 </template>
 
 <script>
 import { mapState } from "vuex";
 import { save } from "@/api/traceability/traceability";
-import { getList} from "@/api/farmplant/recovery";
+import { getList } from "@/api/farmplant/recovery";
+import { getStrainList } from "@/api/farmplant/strain";
+import { getLandList } from "@/api/land/land";
 export default {
   data() {
     return {
-      tip:"下一步",
+      selectionList: [],
+      tip: "下一步",
       isShow: false,
       isBind: false,
+      isBtn: true,
       wtjc: false,
       zwjc: true,
       nbjc: false,
@@ -240,6 +273,11 @@
           { required: true, message: "请输入合格证编号", trigger: "blur" },
         ],
       },
+      page: {
+        pageSize: 10,
+        currentPage: 1,
+        total: 0,
+      },
       option: {
         tip: false,
         height: 400,
@@ -247,10 +285,10 @@
         delBtn: false,
         viewBtn: false,
         addBtn: false,
-        menuWidth: 200,
+        menu: false,
         menuAlign: "center",
         align: "center",
-        selection: false,
+        selection: true,
         searchShow: true,
         searchMenuSpan: 6,
         column: [
@@ -365,7 +403,6 @@
     }),
   },
   methods: {
-    changeCheckBox(data) {},
     //委托检测
     wtChange(data) {
       this.wtjc = data;
@@ -385,37 +422,39 @@
     //创建溯源码
     submit() {
       var that = this;
-      if(this.isBind){
-        this.formLabelAlign['bind'] = "0";
-      }else{
-        this.formLabelAlign['bind'] = "1";
+      if (this.isBind) {
+        this.formLabelAlign["bind"] = "0";
+      } else {
+        this.formLabelAlign["bind"] = "1";
       }
-      
+
       this.$refs["formLabelAlign"].validate((valid) => {
         if (valid) {
-          that.formLabelAlign.createTime = that.formLabelAlign.createTime+" 00:00:00";
+          that.formLabelAlign.createTime =
+            that.formLabelAlign.createTime + " 00:00:00";
           var according = [];
           //承诺依据 数据格式转换
-          that.formLabelAlign.according.forEach((item)=>{
-            if(item=="委托检测"){
+          that.formLabelAlign.according.forEach((item) => {
+            if (item == "委托检测") {
               according.push(0);
             }
-            if(item=="自我检测"){
+            if (item == "自我检测") {
               according.push(1);
             }
-            if(item=="内部质量控制"){
+            if (item == "内部质量控制") {
               according.push(2);
             }
-            if(item=="自我承诺"){
+            if (item == "自我承诺") {
               according.push(3);
             }
-          })
+          });
           that.formLabelAlign.according = according.join(",");
           //新增
           save(that.formLabelAlign).then(
             () => {
               that.$emit("refreshOnLoad");
               that.$refs.formLabelAlign.resetFields();
+              that.close();
               that.visible = false;
               this.$message({
                 type: "success",
@@ -432,17 +471,109 @@
         }
       });
     },
+    //创建溯源码
+    submits() {
+      var that = this;
+      if (this.selectionList.length > 0 && this.selectionList.length > 1) {
+        this.$message.warning("只能绑定一个溯源");
+        return;
+      }
+      if (this.selectionList.length ==1) {
+        that.formLabelAlign['code'] = this.selectionList[0].code;
+      }
+      //新增
+      save(that.formLabelAlign).then(
+        () => {
+          that.$emit("refreshOnLoad");
+          that.visible = false;
+          that.close();
+          this.$message({
+            type: "success",
+            message: "操作成功!",
+          });
+        },
+        (error) => {
+          window.console.log(error);
+        }
+      );
+    },
+    //关闭弹窗
+    close() {
+      //清除数据,状态回归
+      this.isShow = false;
+      this.isBind = false;
+      this.isBtn = true;
+      this.wtjc = false;
+      this.zwjc = true;
+      this.nbjc = false;
+      this.zwcn = false;
+      this.formLabelAlign = {
+        productName: "",
+        createTime: "",
+        according: ["自我检测"],
+        weight: "",
+        phone: "",
+        space: "",
+        certificationCode: "",
+        code: "",
+      };
+    },
     //下一步
     next() {
+      var that = this;
       this.$refs["formLabelAlign"].validate((valid) => {
         if (valid) {
+          this.formLabelAlign["bind"] = "0";
+          //设置时间
+          that.formLabelAlign.createTime =
+            that.formLabelAlign.createTime + " 00:00:00";
+          var according = [];
+          //承诺依据 数据格式转换
+          that.formLabelAlign.according.forEach((item) => {
+            if (item == "委托检测") {
+              according.push(0);
+            }
+            if (item == "自我检测") {
+              according.push(1);
+            }
+            if (item == "内部质量控制") {
+              according.push(2);
+            }
+            if (item == "自我承诺") {
+              according.push(3);
+            }
+          });
+          that.formLabelAlign.according = according.join(",");
+          //修改按钮状态
           this.isShow = true;
           this.isBind = false;
+          this.isBtn = false;
+          //initFormData
+          that.initFormData();
         } else {
           console.log("error submit!!");
           return false;
         }
       });
+    },
+    //初始化表格数据
+    initFormData(){
+      var that = this;
+      //获取农地数据
+      getLandList(this.userInfo.user_id).then((res)=>{
+          if(res.data.code==200){
+              var landIdcolumn = that.findObject(that.option.column,"landId");
+              that.landList = res.data.data;
+              landIdcolumn.dicData = res.data.data;
+          }
+      })
+      //获取农产品数据
+      getStrainList(0).then((res)=>{
+          if(res.data.code==200){
+              var strainId = that.findObject(that.option.column,"strainId");
+              strainId.dicData = res.data.data;
+          }
+      })
     },
     //计算当前时间
     getNowTime() {
@@ -455,11 +586,7 @@
       var day = date.getDate();
       //赋值
       this.formLabelAlign.createTime =
-        year +
-        "-" +
-        this.addZero(month) +
-        "-" +
-        this.addZero(day);
+        year + "-" + this.addZero(month) + "-" + this.addZero(day);
     },
     //小于10的拼接上0字符串
     addZero(s) {
@@ -483,6 +610,7 @@
     },
     selectionChange(list) {
       this.selectionList = list;
+      console.log(this.selectionList, 123456789);
     },
     selectionClear() {
       this.selectionList = [];
@@ -561,12 +689,10 @@
       padding-top: 10px;
     }
   }
-
-  
 }
 
 .traceability-btn {
-    text-align: center;
-    margin-top: 30px;
-  }
+  text-align: center;
+  margin-top: 30px;
+}
 </style>

--
Gitblit v1.9.3