智慧农业后台管理页面
guoshilong
2022-11-08 082613d446e29e4ec1c16bfaa52345106a498b23
src/views/farmplant/detection.vue
@@ -1,308 +1,306 @@
<template>
  <div>
    <el-dialog
      title="检测报告"
      :modal-append-to-body="false"
      :append-to-body="true"
      :close-on-click-modal="false"
      @close="close"
      width="60%"
      :visible.sync="visible"
      center
    >
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
    >
      <template slot="menuLeft">
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          @click="handleDelete"
          >删 除
        </el-button>
      </template>
    </avue-crud>
  </el-dialog>
</div>
    <div>
        <el-dialog
            title="检测报告"
            :modal-append-to-body="false"
            :append-to-body="true"
            :close-on-click-modal="false"
            @close="close"
            width="60%"
            :visible.sync="visible"
            center
        >
            <avue-crud
                :option="option"
                :table-loading="loading"
                :data="data"
                :page.sync="page"
                :permission="permissionList"
                :before-open="beforeOpen"
                v-model="form"
                ref="crud"
                @row-update="rowUpdate"
                @row-save="rowSave"
                @row-del="rowDel"
                @search-change="searchChange"
                @search-reset="searchReset"
                @selection-change="selectionChange"
                @current-change="currentChange"
                @size-change="sizeChange"
                @refresh-change="refreshChange"
            >
                <template slot="menuLeft">
                    <el-button
                        type="danger"
                        size="small"
                        icon="el-icon-delete"
                        plain
                        @click="handleDelete"
                    >删 除</el-button>
                </template>
            </avue-crud>
        </el-dialog>
    </div>
</template>
<script>
import { getDetail, getList, update, remove, save } from "@/api/farm/farmPaper";
import { mapGetters } from "vuex";
import { getDetail, getList, update, remove, save } from "@/api/farm/farmPaper"
import { mapGetters } from "vuex"
export default {
  props: ["farmId"],
  data() {
    return {
      farmPlantId:null,
      visible: true,
      form: {},
      query: {},
      loading: true,
      excelBox: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        tip: false,
        searchSize: "mini",
        searchMenuSpan: 8,
        height: "400",
        editBtn: true,
        delBtn: true,
        viewBtn: true,
        menuWidth: 200,
        menuAlign: "center",
        align: "center",
        selection: true,
        column: [
          {
            label: "检测项目",
            prop: "name",
            rules: [
              {
                required: true,
                message: "请输入检测项目",
                trigger: "blur",
              },
            ],
          },
          {
            label: "检测机构",
            prop: "organName",
            rules: [
              {
                required: true,
                message: "请输入检测机构",
                trigger: "blur",
              },
            ],
          },
          {
            label: "报告编号",
            prop: "code",
            rules: [
              {
                required: true,
                message: "请输入报告编号",
                trigger: "blur",
              },
            ],
          },
          {
            label: "颁发日期",
            prop: "time",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            rules: [
              {
                required: true,
                message: "请选择颁发日期",
                trigger: "blur",
              },
            ],
          },
          {
            label: "报告图片",
            prop: "pictures",
            type: "upload",
            dataType: "string",
            span: 24,
            limit: 3,
            listType: "picture-card",
            tip: "只能上传jpg/png文件,最多上传3张",
            propsHttp: {
              res: "data",
              url: "url"
    props: ["farmId"],
    data () {
        return {
            farmPlantId: null,
            visible: true,
            form: {},
            query: {},
            loading: true,
            excelBox: false,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            action: "/api/blade-resource/oss/endpoint/put-files"
          },
        ],
      },
      data: [],
    };
  },
  created() {
  },
  computed: {
    ...mapGetters(["permission", "userInfo"]),
    // permissionList() {
    //   return {
    //     addBtn: this.vaildData(this.permission.social_add, true),
    //     viewBtn: this.vaildData(this.permission.social_view, false),
    //     delBtn: this.vaildData(this.permission.social_delete, false),
    //     editBtn: this.vaildData(this.permission.social_edit, false),
    //   };
    // },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  mounted() {
   },
  methods: {
    init(id) {
      this.visible = true;
      this.farmPlantId = id;
      this.onLoad(this.page);
    },
    //新增
    rowSave(row, done, loading) {
      row["farmId"] = this.farmPlantId;
      //种养品
      row["type"] = 3;
      save(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
            selectionList: [],
            option: {
                tip: false,
                searchSize: "mini",
                searchMenuSpan: 8,
                height: "400",
                editBtn: true,
                delBtn: true,
                viewBtn: true,
                menuWidth: 200,
                menuAlign: "center",
                align: "center",
                selection: true,
                column: [
                    {
                        label: "检测项目",
                        prop: "name",
                        rules: [
                            {
                                required: true,
                                message: "请输入检测项目",
                                trigger: "blur",
                            },
                        ],
                    },
                    {
                        label: "检测机构",
                        prop: "organName",
                        rules: [
                            {
                                required: true,
                                message: "请输入检测机构",
                                trigger: "blur",
                            },
                        ],
                    },
                    {
                        label: "报告编号",
                        prop: "code",
                        rules: [
                            {
                                required: true,
                                message: "请输入报告编号",
                                trigger: "blur",
                            },
                        ],
                    },
                    {
                        label: "颁发日期",
                        prop: "time",
                        type: "date",
                        format: "yyyy-MM-dd",
                        valueFormat: "yyyy-MM-dd",
                        rules: [
                            {
                                required: true,
                                message: "请选择颁发日期",
                                trigger: "blur",
                            },
                        ],
                    },
                    {
                        label: "报告图片",
                        prop: "pictures",
                        type: "upload",
                        dataType: "string",
                        span: 24,
                        limit: 3,
                        listType: "picture-card",
                        tip: "只能上传jpg/png文件,最多上传3张",
                        propsHttp: {
                            res: "data",
                            url: "url"
                        },
                        action: "/api/blade-resource/oss/endpoint/put-files"
                    },
                ],
            },
            data: [],
        }
      );
    },
    //修改
    rowUpdate(row, index, done, loading) {
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
    created () {
    },
    computed: {
        ...mapGetters(["permission", "userInfo"]),
        // permissionList() {
        //   return {
        //     addBtn: this.vaildData(this.permission.social_add, true),
        //     viewBtn: this.vaildData(this.permission.social_view, false),
        //     delBtn: this.vaildData(this.permission.social_delete, false),
        //     editBtn: this.vaildData(this.permission.social_edit, false),
        //   };
        // },
        ids () {
            let ids = []
            this.selectionList.forEach((ele) => {
                ids.push(ele.id)
            })
            return ids.join(",")
        },
        (error) => {
          loading();
          console.log(error);
        }
      );
    },
    //删除
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    mounted () {
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    methods: {
        init (id) {
            this.visible = true
            this.farmPlantId = id
            this.onLoad(this.page)
        },
        //新增
        rowSave (row, done, loading) {
            row["farmId"] = this.farmPlantId
            //种养品
            row["type"] = 3
            save(row).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                    done()
                },
                (error) => {
                    loading()
                    window.console.log(error)
                }
            )
        },
        //修改
        rowUpdate (row, index, done, loading) {
            update(row).then(
                () => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                    done()
                },
                (error) => {
                    loading()
                    console.log(error)
                }
            )
        },
        //删除
        rowDel (row) {
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    return remove(row.id)
                })
                .then(() => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                })
        },
        handleDelete () {
            if (this.selectionList.length === 0) {
                this.$message.warning("请选择至少一条数据")
                return
            }
            this.$confirm("确定将选择数据删除?", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    return remove(this.ids)
                })
                .then(() => {
                    this.onLoad(this.page)
                    this.$message({
                        type: "success",
                        message: "操作成功!",
                    })
                    this.$refs.crud.toggleSelection()
                })
        },
        beforeOpen (done, type) {
            if (["edit", "view"].includes(type)) {
                getDetail(this.form.id).then((res) => {
                    this.form = res.data.data
                })
            }
            done()
        },
        searchReset () {
            this.query = {}
            this.onLoad(this.page)
        },
        searchChange (params, done) {
            this.query = params
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            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
            params['type'] = 3
            params['farmId'] = this.farmPlantId
            getList(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
                this.selectionClear()
            })
        },
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      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;
      params['type'] = 3;
      params['farmId'] = this.farmPlantId;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>
<style>
</style>
</style>