From 0cb01027a7115273746496a8fc20aa3e7d2ff682 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 09 Aug 2022 14:01:25 +0800
Subject: [PATCH] 首页种养结束添加批量结束种养

---
 src/api/farmplant/farmplant.js    |    7 +
 src/views/wel/index.vue           |    4 
 src/views/farmplant/farmplant.vue |    2 
 src/views/wel/over.vue            |  212 ++++++++++++++++++++++++++++++++++++----------------
 4 files changed, 155 insertions(+), 70 deletions(-)

diff --git a/src/api/farmplant/farmplant.js b/src/api/farmplant/farmplant.js
index 7ecbe5a..e46b041 100644
--- a/src/api/farmplant/farmplant.js
+++ b/src/api/farmplant/farmplant.js
@@ -47,6 +47,13 @@
         data: row
     })
 }
+export const overAll = (params)=>{
+    return request({
+        url: '/api/farmPlant/overAll',
+        method: 'post',
+        data:params
+    })
+}
 
 export const getDetail = (id) => {
     return request({
diff --git a/src/views/farmplant/farmplant.vue b/src/views/farmplant/farmplant.vue
index e583381..3aa41ab 100644
--- a/src/views/farmplant/farmplant.vue
+++ b/src/views/farmplant/farmplant.vue
@@ -35,7 +35,7 @@
               <el-button icon="el-icon-error" :size="size" :type="type" @click="getData(row)">结 束</el-button>
 
                 <el-dialog
-                    title="确认结束种养"
+                    title="结束种养时间"
                     :visible.sync="overVisible"
                     width="30%"
                     append-to-body="true">
diff --git a/src/views/wel/index.vue b/src/views/wel/index.vue
index 16a1134..bf366e8 100644
--- a/src/views/wel/index.vue
+++ b/src/views/wel/index.vue
@@ -170,7 +170,7 @@
         <!-- 弹窗, 采收 -->
         <recovery v-if="recoveryVisible" ref="recovery" :farmDetail="farm"></recovery>
         <!-- 弹窗,结束种养-->
-        <over v-if="overVisible" ref="over" :farmDetail="farm"></over>
+        <over v-if="overVisible" ref="over"></over>
         <!-- 圈地 -->
         <land v-if="landVisible" ref="land"></land>
         <!-- 种养品 -->
@@ -331,7 +331,7 @@
         over(data) {
             this.overVisible = true
             this.$nextTick(() => {
-                this.$refs.over.initData(data)
+                this.$refs.over.initData(data,this.farm.id)
             })
         },
         //结束种植
diff --git a/src/views/wel/over.vue b/src/views/wel/over.vue
index 7695e8a..38ebb25 100644
--- a/src/views/wel/over.vue
+++ b/src/views/wel/over.vue
@@ -7,7 +7,8 @@
             :modal-append-to-body="false"
             :append-to-body="true"
             :close-on-click-modal="false"
-            destroy-on-close="true">
+            destroy-on-close="true"
+            @close="close">
                     
         <avue-crud
             :option="option"
@@ -25,10 +26,33 @@
             @size-change="sizeChange"
             @refresh-change="refreshChange"   
         >
-            <template slot-scope="{ type, size, row }" slot="menu">
-              <el-button icon="el-icon-error" :size="size" :type="type" @click="getData(row)">结 束</el-button>
+            <template slot="menuLeft" slot-scope="{size}">
+                <el-button type="primary" :size="large" @click="overAllVisible = true">批量结束种养</el-button>
                 <el-dialog
-                    title="确认结束种养"
+                    title="批量结束种养时间"
+                    :visible.sync="overAllVisible"
+                    width="30%"
+                    append-to-body="true">
+                    <div class="block">
+                        <span class="demonstration">结束时间</span>
+                        <el-date-picker
+                        v-model="endPlantTime"
+                        type="date"
+                        placeholder="选择日期"
+                        value-format="yyyy-MM-dd"
+                        align="center">
+                        </el-date-picker>
+                    </div>
+                    <span slot="footer" class="dialog-footer">
+                        <el-button @click="overAllVisible = false">取 消</el-button>
+                        <el-button type="primary" @click="overAll">确 定</el-button>
+                    </span>
+                </el-dialog>
+            </template>
+            <template slot-scope="{ type, size, row }" slot="menu">
+              <el-button icon="el-icon-error" :size="size" :type="type" @click="getData(row)">结束种养</el-button>
+                <el-dialog
+                    title="结束种养时间"
                     :visible.sync="overVisible"
                     width="30%"
                     append-to-body="true">
@@ -53,7 +77,7 @@
 </template>
 
 <script>
-import { getDetail, getList, update, remove, save } from "@/api/farmplant/farmplant"
+import { getDetail, getList, update, remove, save,overAll } from "@/api/farmplant/farmplant"
 import { getStrainList } from "@/api/farmplant/strain"
 import { getLandList } from "@/api/land/land"
 import { mapGetters } from "vuex"
@@ -64,17 +88,20 @@
         recovery,
         detection
     },
-    props: {
-        farmDetail:{
-            type:Object
-        }
-    },
+    // props: {
+    //     farmDetail:{
+    //         type:Object
+    //     }
+    // },
     data () {
         return {
             visible: true,
             overVisible:false,
+            overAllVisible:false,
             form: {},
-            query: {},
+            query: {
+                status:1
+            },
             loading: true,
             excelBox: false,
             page: {
@@ -91,7 +118,7 @@
                 editBtn: false,
                 delBtn: false,
                 viewBtn: false,
-                header:false,
+                // header:false,
                 menuWidth: 100,
                 menuAlign: "center",
                 align: "center",
@@ -102,6 +129,10 @@
                 selectionFixed: false,
                 expandFixed: false,
                 menuFixed: false,
+                addBtn:false,
+                refreshBtn:false,
+                columnBtn:false,
+                searchShowBtn:false,
                 column: [
                     {
                         label: "种养品",
@@ -433,9 +464,11 @@
             //结束种养时的传输数据
             overData:"",
             strainId:"",
+            farmId:"",
         }
     },
     created () {
+        this.endPlantTime = new Date()
         // this.initData()
     },
     computed: {
@@ -458,29 +491,32 @@
     },
     methods: {
         //初始化数据
-        initData(data){
+        initData(data,farmId){
             var that = this
+            this.farmId = farmId
+            this.query.strainId = data.strainId
+            this.query.farmId = farmId
             this.strainId = data.strainId
             that.visible = true;
             var params={
                 status:"1"
             }
             this.onLoad(this.page,params)
-            //获取农地数据
-            getLandList(that.userInfo.dept_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
-                }
-            })
+            // //获取农地数据
+            // getLandList(that.userInfo.dept_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
+            //     }
+            // })
             
         },
         searchReset () {
@@ -488,14 +524,16 @@
             this.onLoad(this.page)
         },
         searchChange (params, done) {
-            if(params.transplanTimeStart !=""){
+            if(params.transplanTimeStart !="" && params.transplanTimeStart !=null){
                 params['transplanTimeEnd']=this.getEndDate(params.transplanTimeStart,1)
             }
             this.query = params
-            console.log(this.query)
             this.page.currentPage = 1
             this.onLoad(this.page, params)
-            this.query = {}
+            this.query.status = 1
+            this.query.transplanTimeStart = ""
+            this.query.strainName = ""
+            this.query.strainId = ""
             done()
         },
         selectionChange (list) {
@@ -522,7 +560,7 @@
             }
             params['tenantId'] = this.userInfo.tenant_id
             params['deptId'] = this.userInfo.dept_id
-            params['farmId'] = this.farmDetail.id
+            params['farmId'] = this.farmId
             params['strainId'] = this.strainId
             this.loading = true
             getList(
@@ -537,43 +575,27 @@
                 this.selectionClear()
             })
         },
-        // 结束种植
-        // over(id) {
-        //     var that = this
-        //     that.$confirm("确定结束当前种植的农产品?", {
-        //       confirmButtonText: "确定",
-        //       cancelButtonText: "取消",
-        //       type: "warning",
-        //     })
-        //     .then(() => {
-        //         const data = {
-        //           id: id,
-        //           status: 2,
-        //         }
-        //         return update(data)
-        //     })
-        //     .then(() => {
-        //         that.onLoad(this.page, this.query)
-        //         that.$message({
-        //           type: "success",
-        //           message: "操作成功!",
-        //         })
-        //     })
-        // },
         //结束种植
         over(){
-            this.overData.endPlantTime = this.endPlantTime
-            const data = {
-                id:this.overData.id,
-                status:2,
-                endPlantTime:this.overData.endPlantTime
-            }
-            update(data).then((res)=>{
-                if(res.data.code == 200){
-                    this.onLoad(this.page, this.query)
+            if(this.endPlantTime == ""){
+                this.$message({
+                    type: "error",
+                    message: "请选择结束种养日期!",
+                })
+            }else{
+                this.overData.endPlantTime = this.endPlantTime
+                const data = {
+                    id:this.overData.id,
+                    status:2,
+                    endPlantTime:this.overData.endPlantTime
                 }
-            })
-            this.overVisible = false
+                update(data).then((res)=>{
+                    if(res.data.code == 200){
+                        this.onLoad(this.page, this.query)
+                    }
+                })
+                this.overVisible = false
+            }
         },
         getData(row){
             this.overVisible = true
@@ -583,7 +605,63 @@
             var array = date.split('-')
             array[2]=array[2]-0+num
             return array[0]+"-"+array[1]+"-"+array[2]
-        }
+        },
+        close(){
+            this.query.strainId=""
+            this.$parent.onLoad()
+        },
+        overAll(){
+            if(this.selectionList == 0){
+                this.$message({
+                    type: "error",
+                    message: "请至少选择一项!",
+                })
+            }else{
+                if(this.endPlantTime == ""){
+                    this.$message({
+                        type: "error",
+                        message: "请选择结束种养时间!",
+                    })
+                }else{
+                    // this.selectionList.forEach((e)=>{
+                    //     const data = {
+                    //         id:e.id,
+                    //         status:2,
+                    //         endPlantTime:this.endPlantTime
+                    //     }
+                    //     update(data).then((res)=>{
+                            
+                    //     })
+                    // })
+                    // for(let i=0;i<this.selectionList.length;i++){
+                    //     const data = {
+                    //         id:this.selectionList[i].id,
+                    //         status:2,
+                    //         endPlantTime:this.endPlantTime
+                    //     }
+                    //     update(data).then((res)=>{
+   
+                    //     })
+                    //     this.onLoad(this.page, this.query)
+                    //     this.overAllVisible = false
+                    // }
+
+                    var ids = []
+                    this.selectionList.forEach((e)=>{
+                        ids.push(e.id)
+                    })
+                    var params={
+                        ids:ids,
+                        endPlantTime:this.endPlantTime
+                    }
+                    overAll(params).then((res)=>{
+                        this.onLoad(this.page, this.query)
+                        this.overAllVisible = false
+                    })
+                }
+            }
+
+        },
     },
 };
 </script>

--
Gitblit v1.9.3