智慧农业后台管理页面
guoshilong
2022-11-08 082613d446e29e4ec1c16bfaa52345106a498b23
src/views/task/task.vue
@@ -27,10 +27,11 @@
                   @click="handleDelete">删 除
        </el-button>
      </template>
      <template slot-scope="{ type, size, row }" slot="menu">
      <template slot-scope="{ type, size, row}" slot="menu">
        <el-button
          icon="el-icon-circle-plus-outline"
          @click="chuli(row)"
          v-show="row.status"
          :size="size"
          :type="type"
        >处理
@@ -64,16 +65,30 @@
</template>
<script>
import {getList, getDetail, add, update, remove} from "@/api/task/task";
import {getList, getDetail, add, update, remove, updatechuli} from "@/api/task/task";
import {mapGetters} from "vuex";
import {getLandList} from "@/api/land/land";
import {selectStockFa} from "@/api/stockfactory/stockfactory";
export default {
  data() {
    const validateNum = (rule, value, callback) => {
      if (!/^[1-9]\d*$/.test(value)) {
        callback(new Error("请输入正整数"));
      } else {
        if (value>9999){
          callback(new Error("限制为9999以内"));
        }else {
          callback();
        }
      }
    };
    return {
      form: {},
      query: {},
      formchuli: {},
      formxq: {},
      loading: true,
      page: {
        pageSize: 10,
@@ -95,14 +110,20 @@
        selection: true,
        dialogClickModal: false,
        gradeBoxVisible: false,
        disabled:false,
        refreshBtn:false,
        columnBtn:false,
        searchShowBtn:false,
        menuWidth:300,
        column: [
          {
            label: "任务名称",
            prop: "taskName",
            maxlength:200,
            rules: [{
              required: true,
              message: "请输入任务名称",
              trigger: "blur"
              trigger: ["blur","change"]
            }]
          },
          {
@@ -118,7 +139,7 @@
            rules: [{
              required: true,
              message: "请输入地块",
              trigger: "blur"
              trigger: ["blur","change"]
            }]
          },
          {
@@ -130,7 +151,7 @@
            rules: [{
              required: true,
              message: "请输入截止时间",
              trigger: "blur"
              trigger: ["blur","change"]
            }]
          },
          {
@@ -145,7 +166,36 @@
            rules: [{
              required: true,
              message: "请输入负责人",
              trigger: "blur"
              trigger: ["blur","change"]
            }]
          },
          {
            label: "投入品",
            prop: "stockId",
            hide: true,
            type: "tree",
            dicData:[],
            // dicUrl: `/api/soldr/soldr/selectSol`,
            props: {
              label: "spn",
              value: "id"
            },
            change: function (value) {
              // console.log(value.value)
            }
          },
          {
            label: "农资量",
            prop: "stockNum",
            hide: true,
            span: 6,
            type: "number",
            // labelWidth: 110,
            display: false,
            rules:[{
              require:false,
              trigger: ["blur","change"],
              validator: validateNum
            }]
          },
          {
@@ -154,11 +204,11 @@
            span: 6,
            type: "switch",
            dicData: [{
              label: '开启',
              value: 0
            }, {
              label: '关闭',
              value: 1
              value: "1"
            }, {
              label: '开启',
              value: "0"
            }],
            mock: {
              type: 'dic'
@@ -167,20 +217,10 @@
            row: true,
          },
          {
            label: "任务说明",
            prop: "taskExplain",
            type: "textarea",
            span: 23,
            rules: [{
              required: true,
              message: "请输入任务说明",
              trigger: "blur"
            }]
          },
          {
            editDisplay: false,
            label: "任务状态",
            addDisplay: false,
            editDisplay: false,
            type: "select",
            prop: "status",
            dicData: [
              {
@@ -196,182 +236,29 @@
                value: 2
              }
            ],
            span: 23,
            span: 24
          },
          {
            label: "备注",
            hide:true,
            addDisplay: false,
            editDisplay: false,
            prop: "remark",
            label: "任务说明",
            prop: "taskExplain",
            type: "textarea",
            span: 23,
            span: 24,
            rules: [{
              required: true,
              message: "请输入任务说明",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "图片",
            hide:true,
            label: "照片",
            prop: "tp",
            addDisplay: false,
            editDisplay: false,
            rules: [{
              required: true,
              message: "请输入图片",
              trigger: "blur"
            }]
          },
          {
            label: "农事操作",
            hide:true,
            addDisplay: false,
            editDisplay: false,
            prop: "farm",
            rules: [{
              required: true,
              message: "请输入农事操作",
              trigger: "blur"
            }]
          },
        ]
      },
      optionchuli: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        column: [
          {
            label: "农资",
            prop: "stockId1",
            span: 23,
            type: "select",
            disabled: true,
            dicUrl: "/api/stockfactory/stockfactory/selectStockFa",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请输入农资",
              trigger: "blur"
            }]
          },
          {
            label: "规格",
            disabled: true,
            span: 6,
            prop: "spn",
            addDisplay: false,
          },
          {
            label: "规格",
            display: false,
            hide: true,
            prop: "specs1",
            span: 5,
            viewDisplay: false,
            rules: [{
              required: true,
              message: "请输入规格",
              trigger: "blur"
            }]
          },
          {
            label: "规格值1",
            display: false,
            hide: true,
            prop: "specsVal1",
            searchSpan: 4,
            span: 6,
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockSpecs1",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
            search: true,
          },
          {
            label: "类型",
            display: false,
            hide: true,
            prop: "stockType1",
          },
          {
            label: "规格值2",
            display: false,
            hide: true,
            prop: "specsVal2",
            searchSpan: 4,
            span: 6,
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockSpecs2",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
            search: true,
          },
          {
            label: "当前库存",
            disabled: true,
            span: 6,
            prop: "num",
          },
          {
            label: "入库数量",
            type: "number",
            span: 11,
            prop: "amount1",
          },
          {
            label: "入库类型",
            prop: "type1",
            type: "select",
            span: 12,
            searchSpan: 4,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockPurchase",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
            search: true,
            rules: [{
              required: true,
              message: "请输入入库类型",
              trigger: "blur"
            }]
          },
          {
            label: "入库时间",
            prop: "time1",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            span: 11,
            rules: [{
              required: true,
              message: "请输入入库时间",
              trigger: "blur"
            }]
          },
          {
            label: "单据、凭证照片",
            prop: "picture1",
            type: "upload",
            labelWidth: 145,
            hide: true,
            dataType: "string",
            span: 24,
            limit: 5,
            addDisplay: false,
            editDisplay: false,
            listType: "picture-card",
            tip: "建议上传手机横屏拍摄的照片,宽高比16:9,最多上传5张",
            canvasOption: {
@@ -386,13 +273,308 @@
          },
          {
            label: "备注",
            hide: true,
            addDisplay: false,
            editDisplay: false,
            prop: "remark",
            type: "textarea",
            prop: "remarks1",
            span: 24,
            maxlength:200,
          },
        ]
      },
      optionchuli: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        emptyBtn:false,
        column: [
          {
            label: "任务名称",
            prop: "taskName",
            disabled: true,
          },
          {
            label: "任务说明",
            prop: "taskExplain",
            type: "textarea",
            span: 23,
            disabled: true,
          },
          {
            label: "地块",
            prop: "landId",
            type: "tree",
            disabled: true,
            dicData: [],
            props: {
              label: "landName",
              value: "id"
            },
          },
          {
            label: "负责人",
            prop: "taskUser",
            disabled: true,
            type: "tree",
            dicUrl: `/api/blade-user/user-list`,
            props: {
              label: "account",
              value: "id"
            },
            rules: [{
              required: true,
              message: "请输入负责人",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "截止时间",
            prop: "time",
            disabled: true,
            span: 7,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            rules: [{
              required: true,
              message: "请输入截止时间",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "投入品",
            prop: "stockId",
            disabled: true,
            hide: true,
            type: "tree",
            span: 10,
            dicUrl: `/api/soldr/soldr/selectSol`,
            props: {
              label: "spn",
              value: "id"
            },
            change: function (value) {
              // console.log(value.value)
            }
          },
          {
            label: "农资量",
            prop: "stockNum",
            hide: true,
            disabled: true,
            span: 7,
            type: "number",
            labelWidth: 110,
          },
          {
            label: "拍照照片",
            prop: "type",
            span: 6,
            disabled: true,
            type: "switch",
            dicData: [{
              label: '关闭',
              value: "1"
            }, {
              label: '开启',
              value: "0"
            }],
            mock: {
              type: 'dic'
            },
            hide: true,
            row: true,
          },
          {
            label: "单据、凭证照片",
            prop: "tp",
            type: "upload",
            labelWidth: 145,
            dataType: "string",
            span: 24,
            limit: 5,
            display: false,
            listType: "picture-card",
            tip: "建议上传手机横屏拍摄的照片,宽高比16:9,最多上传5张",
            canvasOption: {
              text: "",
              ratio: 1.0,
            },
            propsHttp: {
              res: "data",
              url: "url"
            },
            action: "/api/blade-resource/oss/endpoint/put-files"
          },
          {
            label: "备注",
            hide: true,
            addDisplay: false,
            editDisplay: false,
            prop: "remark",
            type: "textarea",
            maxlength:200,
            span: 23,
          },
        ]
      },
      gradeBoxVisiblechuli:false,
      optionxq: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        column: [
          {
            label: "任务名称",
            prop: "taskName",
            maxlength:200,
            disabled: true,
          },
          {
            label: "任务说明",
            prop: "taskExplain",
            type: "textarea",
            maxlength:200,
            span: 23,
            disabled: true,
          },
          {
            label: "地块",
            prop: "landId",
            type: "tree",
            disabled: true,
            dicData: [],
            props: {
              label: "landName",
              value: "id"
            },
          },
          {
            label: "负责人",
            prop: "taskUser",
            disabled: true,
            type: "tree",
            dicUrl: `/api/blade-user/user-list`,
            props: {
              label: "account",
              value: "id"
            },
            rules: [{
              required: true,
              message: "请输入负责人",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "截止时间",
            prop: "time",
            disabled: true,
            span: 7,
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            rules: [{
              required: true,
              message: "请输入截止时间",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "投入品",
            prop: "stockId",
            disabled: true,
            hide: true,
            type: "tree",
            span: 10,
            dicUrl: `/api/soldr/soldr/selectSol`,
            props: {
              label: "spn",
              value: "stock_id1"
            },
            change: function (value) {
              // console.log(value.value)
            }
          },
          {
            label: "农资量",
            prop: "stockNum",
            hide: true,
            disabled: true,
            span: 6,
            type: "number",
            labelWidth: 110,
          },
          {
            label: "拍照照片",
            prop: "type",
            value:"1",
            span: 6,
            disabled: true,
            type: "switch",
            dicData: [{
              label: '关闭',
              value: "1"
            }, {
              label: '开启',
              value: "0"
            }],
            mock: {
              type: 'dic'
            },
            hide: true,
            row: true,
          },
          {
            label: "单据、凭证照片",
            prop: "tp",
            type: "upload",
            labelWidth: 145,
            dataType: "string",
            disabled: true,
            span: 24,
            limit: 5,
            display: false,
            listType: "picture-card",
            tip: "建议上传手机横屏拍摄的照片,宽高比16:9,最多上传5张",
            canvasOption: {
              text: "",
              ratio: 1.0,
            },
            propsHttp: {
              res: "data",
              url: "url"
            },
            action: "/api/blade-resource/oss/endpoint/put-files"
          },
          {
            label: "备注",
            disabled: true,
            hide: true,
            addDisplay: false,
            editDisplay: false,
            prop: "remark",
            type: "textarea",
            maxlength:200,
            span: 23,
          },
        ]
      },
      gradeBoxVisiblechuli: false,
      gradeBoxVisiblexq: false,
      data: []
    };
  },
@@ -400,7 +582,7 @@
    this.initData();
  },
  computed: {
    ...mapGetters(["permission", "userInfo"]),
    ...mapGetters(["permission", "userInfo","$farmId"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.task_add, false),
@@ -417,46 +599,110 @@
      return ids.join(",");
    }
  },
  watch: {
    "form.stockId": {
      handler(val) {
        var stockIdcolumn = this.findObject(this.option.column, "stockNum");
        if (val != "") {
          stockIdcolumn.display = true;
        } else {
          stockIdcolumn.display = false;
        }
      },
      immediate: true,
    },
    '$farmId':{
      handler (newName, oldName) {
          this.getLandList()
          this.getSoldrList()
          this.query={}
          this.onLoad(this.page)
      }
    }
  },
  methods: {
    //入库
    //处理
    submitR(row, done, loading) {
      that.gradeBoxVisible = false;
      // var that = this;
      // add1(row).then(
      //   () => {
      //     that.onLoad(this.page);
      //     that.$refs.formR.resetFields();
      //     that.$message({
      //       type: "success",
      //       message: "操作成功!"
      //     });
      //     that.gradeBoxVisible = false;
      //
      //     done();
      //   },
      //   error => {
      //     window.console.log(error);
      //     done();
      //   }
      // );
      var that = this;
      if(row.type == "0"){
        if(row.tp == ""){
          that.$message.warning("请上传照片")
          done()
          return
        }
      }
      updatechuli(row).then(
        () => {
          that.onLoad(this.page);
          that.$message({
            type: "success",
            message: "操作成功!"
          });
          that.gradeBoxVisiblechuli = false;
          done();
        },
        error => {
          loading();
          window.console.log(error);
          done();
        }
      );
    },
    // 处理
    chuli(row) {
      this.formchuli = {};
      this.formchuli = {
        id: row.id,
        taskName: row.taskName,
        taskExplain: row.taskExplain,
        landId: row.landId,
        taskUser: row.taskUser,
        time: row.time,
        stockId: row.stockId,
        tp: row.tp,
        remark: row.remark,
        stockNum: row.stockNum,
        type: row.type
      };
      var tp = this.findObject(this.optionchuli.column, "tp");
      if (row.type == "0") {
        tp.display = true;
      }else {
        tp.display = false
      }
      this.gradeBoxVisiblechuli = true;
    },
    initData() {
      this.getLandList()
      this.getSoldrList()
    },
    getLandList(){
      var that = this;
      //获取农地数据
      getLandList(this.userInfo.dept_id).then((res) => {
      getLandList(this.$farmId).then((res) => {
        if (res.data.code == 200) {
          var landIdcolumn = that.findObject(that.option.column, "landId");
          var landIdColumnChuli = that.findObject(that.optionchuli.column,"landId")
          that.landList = res.data.data;
          landIdcolumn.dicData = res.data.data;
          landIdColumnChuli.dicData = res.data.data
        }
      })
    },
    getSoldrList(){
      var that = this;
      //获取农资
      selectStockFa(this.$farmId).then((res) => {
        if (res.data.code == 200) {
          var stockIdcolumn = that.findObject(that.option.column, "stockId");
          stockIdcolumn.dicData = res.data.data;
        }
      });
    },
    rowSave(row, done, loading) {
      if(row.tp.length<=0){
        row.tp=""
      }
      add(row).then(() => {
        this.onLoad(this.page);
        this.$message({
@@ -470,6 +716,14 @@
      });
    },
    rowUpdate(row, index, done, loading) {
      if(row.stockNum<0){
        this.$message({
          type: "warning",
          message: "农资量不能为负数!"
        });
        done();
        return
      }
      update(row).then(() => {
        this.onLoad(this.page);
        this.$message({
@@ -522,10 +776,16 @@
        });
    },
    beforeOpen(done, type) {
      if(["add"].includes(type)){
        this.option.disabled=false
      }
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then(res => {
          this.form = res.data.data;
        });
        if(type=="edit"){
          this.form.status==0?this.option.disabled=true:this.option.disabled=false
        }
      }
      done();
    },
@@ -557,6 +817,7 @@
    },
    onLoad(page, params = {}) {
      this.loading = true;
      params["farmId"] = this.$farmId
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;