智慧农业后台管理页面
Administrator
2022-05-13 20f2ac4345f1c5db7d781da19da4c530be86a93e
农产品页面新增
1 files modified
2 files added
380 ■■■■■ changed files
src/api/farmplant/strain.js 48 ●●●●● patch | view | raw | blame | history
src/views/farmplant/farmplant.vue 33 ●●●●● patch | view | raw | blame | history
src/views/farmplant/strain.vue 299 ●●●●● patch | view | raw | blame | history
src/api/farmplant/strain.js
New file
@@ -0,0 +1,48 @@
import request from '@/router/axios';
export const getList = (current, size, params) => {
    return request({
        url: '/api/strain/page',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}
export const remove = (ids) => {
    return request({
        url: '/api/strain/remove',
        method: 'post',
        params: {
            ids,
        }
    })
}
export const save = (row) => {
    return request({
        url: '/api/strain/save',
        method: 'post',
        data: row
    })
}
export const update = (row) => {
    return request({
        url: '/api/strain/update',
        method: 'post',
        data: row
    })
}
export const getDetail = (id) => {
    return request({
        url: '/api/strain/detail',
        method: 'get',
        params: {
            id
        }
    })
}
src/views/farmplant/farmplant.vue
@@ -1,5 +1,5 @@
<template>
  <basic-container class="paper">
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
@@ -55,7 +55,6 @@
      landList:[],
      option: {
        tip: false,
        searchMenuSpan: 8,
        height: "auto",
        editBtn: true,
        delBtn: true,
@@ -64,6 +63,8 @@
        menuAlign: "center",
        align: "center",
        selection: true,
        searchShow: true,
        searchMenuSpan: 6,
        column: [
          {
            label: "类型",
@@ -124,8 +125,8 @@
          {
            label: "品种",
            prop: "varieties",
            search:true,
            searchSpan:5,
            // search:true,
            // searchSpan:5,
            labelWidth:110,
            rules: [
              {
@@ -135,21 +136,27 @@
              },
            ],
          },
          // {
          //   label: "种养品图片",
          //   prop: "url",
          //   type: "upload",
          //   listType: "picture-img",
          //   width: 100,
          //   labelWidth:110,
          //   addDisplay:false,
          // },
          {
            label: "种养品图片",
            prop: "url",
            type: "upload",
            listType: "picture-img",
            width: 100,
            labelWidth:110,
            display:false,
          },
          {
            label: "所属地块",
            prop: "landName",
            display:false,
          },
          {
            label: "所属地块",
            prop: "landId",
            searchSpan:4,
            search:true,
            type:"tree",
            hide:true,
            dicData: [],
            props: {
              label: "landName",
src/views/farmplant/strain.vue
New file
@@ -0,0 +1,299 @@
<template>
  <basic-container>
    <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"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          @click="handleDelete"
          >删 除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import {
  getDetail,
  getList,
  update,
  remove,
  save,
} from "@/api/farmplant/strain";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      visible: true,
      form: {},
      query: {},
      loading: true,
      excelBox: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        height: "auto",
        editBtn: true,
        delBtn: true,
        viewBtn: true,
        menuWidth: 200,
        menuAlign: "center",
        align: "center",
        selection: true,
        column: [
          {
            label: "农产品名称",
            prop: "strainName",
            searchLabelWidth: 110,
            labelWidth: 110,
            search: true,
            searchSpan: 5,
            rules: [
              {
                required: true,
                message: "请输入农产品名称",
                trigger: "blur",
              },
            ],
          },
          {
            label: "类型",
            prop: "strainType",
            type: "select",
            labelWidth: 110,
            search: true,
            searchSpan: 4,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=strainType",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            rules: [
              {
                required: true,
                message: "请输入类型",
                trigger: "blur",
              },
            ],
          },
          {
            label: "别名",
            prop: "alias",
            labelWidth: 110,
            rules: [
              {
                required: false,
                message: "请输入别名",
                trigger: "blur",
              },
            ],
          },
          {
            label: "图片",
            type: "upload",
            listType: "picture-img",
            propsHttp: {
              res: "data",
              url: "url",
            },
            canvasOption: {
              text: " ",
              ratio: 1.0,
            },
            action: "/api/blade-resource/oss/endpoint/put-files",
            tip: "",
            span: 24,
            labelWidth: 110,
            prop: "url",
            rules: [
              {
                required: true,
                message: "请上传农产品图片",
                trigger: "blur",
              },
            ],
          },
        ],
      },
      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: {
    //新增
    rowSave(row, done, loading) {
      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;
      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>