智慧农业后台管理页面
guoshilong
2022-11-08 082613d446e29e4ec1c16bfaa52345106a498b23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<template>
    <basic-container>
        <avue-crud
            :option="option"
            :table-loading="loading"
            :data="data"
            :page.sync="page"
            :summary-method="getSummaries"
            v-model="form"
            ref="crud"
            :search.sync="search"
            @search-change="searchChange"
            @search-reset="searchReset"
            @selection-change="selectionChange"
            @current-change="currentChange"
            @size-change="sizeChange"
            @refresh-change="refreshChange"
        ></avue-crud>
    </basic-container>
</template>
 
<script>
import { getFarmPlantStatistics } from "@/api/farmplant/farmplant"
import { getStrainList } from "@/api/farmplant/strain"
import { mapGetters } from "vuex"
export default {
    data () {
        return {
            visible: true,
            form: {},
            farm:{},
            query: {},
            search: {},
            loading: true,
            excelBox: false,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            selectionList: [],
            option: {
                tip: false,
                searchShow: true,
                searchMenuSpan: 6,
                height: 520,
                editBtn: false,
                addBtn: false,
                delBtn: true,
                viewBtn: true,
                menuWidth: 200,
                menuAlign: "center",
                align: "center",
                selection: false,
                showSummary: true,
                indexFixed: false,
                selectionFixed: false,
                expandFixed: false,
                menuFixed: false,
                menu: false,
                header:false,
                sumColumnList: [
                    {
                        label: "合计",
                        name: "strainId",
                    },
                    {
                        name: "areas",
                        type: "sum",
                    },
                ],
                column: [
                    {
                        label: "作物",
                        prop: "strainId",
                        span: 12,
                        searchLabelWidth: 100,
                        type: "tree",
                        dicData: [],
                        props: {
                            label: "strainName",
                            value: "id",
                        },
                        labelWidth: 145,
                        rules: [
                            {
                                required: true,
                                message: "请输入作物",
                                trigger: ["blur","change"],
                            },
                        ],
                        disabled: true,
                    },
                    {
                        label: "播种面积(亩)",
                        prop: "areas",
                        span: 12,
                        labelWidth: 145,
                        controls: false,
                        type: "number",
                        rules: [
                            {
                                required: true,
                                message: "请输入库存重量 公斤",
                                trigger: "click",
                            },
                        ],
                    },
                    {
                        label: "筛选时间段",
                        prop: "releaseTimeRange",
                        span: 12,
                        hide: true,
                        search: true,
                        searchSpan: 7,
                        searchLabelWidth: 110,
                        searchRange: true,
                        searchValue: [this.getStartTime(), this.getEndTime()],
                        type: "date",
                        format: "yyyy-MM-dd",
                        valueFormat: "yyyy-MM-dd",
                        rules: [
                            {
                                required: true,
                                message: "请选择采收时间",
                                trigger: "click",
                            },
                        ],
                    },
                ],
            },
            data: [],
        }
    },
    created () {
        this.initData()
        this.farm.id = this.$farmId
    },
      watch: {
    '$farmId':{
      handler (newName, oldName) {
        this.farm.id = newName
        this.onLoad(this.page)
      }
    }
  },
    computed: {
        ...mapGetters(["permission", "userInfo","$farmId"]),
        ids () {
            let ids = []
            this.selectionList.forEach((ele) => {
                ids.push(ele.id)
            })
            return ids.join(",")
        },
    },
    mounted () {
        var params = {
            startTime: this.getStartTime(),
            endTime: this.getEndTime()
        }
        this.onLoad(this.page, params)
    },
    methods: {
        //合计计算
        getSummaries (param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计"
                    return
                }
                if (index === 1) {
                    const values = data.map((item) => Number(item[column.property]))
                    if (!values.every((value) => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr)
                            if (!isNaN(value)) {
                                return prev + curr
                            } else {
                                return prev
                            }
                        }, 0)
                        sums[index] = sums[index].toFixed(3)
                        sums[index] += " 亩"
                    } else {
                        sums[index] = "N/A"
                    }
                }
            })
            return sums
        },
        getStartTime () {
            var myDate = new Date()
            var year = myDate.getFullYear()
            //获取当前月份(0-11,0代表1月,所以要加1);
            var month = myDate.getMonth() + 1
            //获取当前日(1-31)
            var day = myDate.getDate()
            if (month < 10) {
                month = "0" + month
            }
            if (day >= 0 && day <= 9) {
                day = "0" + day
            }
            var firstDay = year + "-" + month + "-01"
            // this.query['startTime'] = firstDay;
            return firstDay
        },
        getEndTime () {
            var myDate = new Date()
            var year = myDate.getFullYear()
            //获取当前月份(0-11,0代表1月,所以要加1);
            var month = myDate.getMonth() + 1
            //获取当前日(1-31)
            var day = myDate.getDate()
            if (month < 10) {
                month = "0" + month
            }
            if (day >= 0 && day <= 9) {
                day = "0" + day
            }
            var thisDay = year + "-" + month + "-" + day
            // this.query['endTime'] = thisDay;
            return thisDay
        },
        initData () {
            var that = this
            //获取农产品数据
            getStrainList(0).then((res) => {
                if (res.data.code == 200) {
                    var strainId = that.findObject(that.option.column, "strainId")
                    strainId.dicData = res.data.data
                }
            })
        },
        searchReset () {
            this.query = {}
            this.onLoad(this.page)
        },
        searchChange (params, done) {
            this.query = params
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            this.query = {}
            done()
        },
        selectionChange (list) {
            this.selectionList = list
        },
        selectionClear () {
            this.selectionList = []
            this.$refs.crud.toggleSelection()
        },
        currentChange (currentPage) {
            this.page.currentPage = currentPage
        },
        sizeChange (pageSize) {
            this.page.pageSize = pageSize
        },
        refreshChange () {
            this.onLoad(this.page, this.query)
        },
        onLoad (page, params = {}) {
            this.loading = true
            const { releaseTimeRange } = this.query
            params['tenantId'] = this.userInfo.tenant_id
            params['deptId'] = this.farm.id
            let values = {
                ...params,
            }
            if (releaseTimeRange) {
                values = {
                    ...params,
                    startTime: releaseTimeRange[0],
                    endTime: releaseTimeRange[1],
                    ...this.query,
                }
                values.releaseTimeRange = null
                values.farmId = this.$farmId
            }
            getFarmPlantStatistics(page.currentPage, page.pageSize, values).then(
                (res) => {
                    const data = res.data.data
                    this.page.total = data.total
                    this.data = data.records
                    this.loading = false
                    this.selectionClear()
                }
            )
        },
    },
};
</script>
 
<style>
</style>