智慧农业后台管理页面
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
<template>
  <el-dialog
    :title="title"
    :modal-append-to-body="false"
    :append-to-body="true"
    :close-on-click-modal="false"
    width="60%"
    :visible.sync="visible"
  >
    <avue-form ref="form" v-model="form" :option="option" @submit="submit">
    </avue-form>
  </el-dialog>
</template>
 
<script>
 
import { mapState } from "vuex";
import { add } from "@/api/stock/stock";
import {limitNumInt} from "@/util/validate";
 
export default {
  data() {
    return {
      title:"农资入库",
      form: {},
      option: {
        emptyBtn: false,
        submitText: "保存",
        gutter: 30,
        column: [
          {
            label: "农资",
            prop: "stockId",
            span: 24,
            type: "select",
            dicUrl: "/api/stockfactory/stockfactory/selectStockFa",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请输入农资",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "规格",
            type: "number",
            prop: "specs",
            span: 7,
            rules: [{
              required: true,
              // message: "请输入规格",
              trigger: ["blur","change"],
              validator: limitNumInt
            }]
          },
          {
            label: "规格值1",
            prop: "specsValue1",
            span: 6,
            value:"0",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockSpecs1",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
          },
          {
            label: "规格值2",
            prop: "specsValue2",
            value:"0",
            span: 6,
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockSpecs2",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
          },
          {
            label: "入库数量",
            span: 6,
            type: "number",
            prop: "amount",
            rules: [{
              required: true,
              message: "请输入入库数量",
              trigger: ["blur","change"],
              validator: limitNumInt
            }]
          },
          {
            label: "入库类型",
            prop: "type",
            type: "select",
            value:"0",
            span: 12,
            searchSpan: 4,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=stockPurchase",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
            rules: [{
              required: true,
              message: "请输入入库类型",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "入库时间",
            prop: "time",
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            span: 12,
            rules: [{
              required: true,
              message: "请输入入库时间",
              trigger: ["blur","change"]
            }]
          },
          {
            label: "单据、凭证照片",
            prop: "picture",
            type: "upload",
            labelWidth: 120,
            dataType: "string",
            span: 24,
            limit: 5,
            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: "备注",
            type: "textarea",
            prop: "remarks",
            maxlength:200,
            span: 24,
          },
        ]
      },
      visible: false,
    };
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
      $farmId: state =>state.user.$farmId
    }),
  },
  methods: {
    //计算当前时间
    getNowTime(){
        var date = new Date();
        //年 getFullYear():四位数字返回年份
        var year = date.getFullYear();  //getFullYear()代替getYear()
        //月 getMonth():0 ~ 11
        var month = date.getMonth() + 1;
        //日 getDate():(1 ~ 31)
        var day = date.getDate();
        //时 getHours():(0 ~ 23)
        var hour = date.getHours();
        //分 getMinutes(): (0 ~ 59)
        var minute = date.getMinutes();
        //秒 getSeconds():(0 ~ 59)
        var second = date.getSeconds();
        //赋值
        this.form['time'] = year + '-'
                          + this.addZero(month) + '-'
                          + this.addZero(day) + ' '
                          + this.addZero(hour);
    },
    //小于10的拼接上0字符串
    addZero(s) {
      return s < 10 ? ('0' + s) : s;
    },
    //初始化
    init() {
      this.visible = true;
      if (this.$refs.form){
        this.$refs.form.resetForm()
      }
      //计算当前时间
      this.getNowTime();
    },
    // 表单提交
    submit(row,done) {
      var that = this;
      row['tenantId'] = this.userInfo.tenant_id;
      row['deptId'] = this.$farmId;
      add(row).then(
        () => {
          that.$refs.form.resetFields();
          that.visible = false;
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          that.$emit("refreshOnLoad")
          done();
        },
        (error) => {
          done();
          window.console.log(error);
        }
      );
    },
  },
};
</script>