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
<template>
  <el-dialog :close-on-click-modal="false" :visible.sync="islook" width="40rem" class="add-event-dialog"
    @close="cancelMethod">
    <div slot="title" class="tac drawerHeader">{{ editRow.title }}</div>
    <div class="dialog-content-box">
      <el-form class="form-box" ref="form" :rules="rules" :model="form" label-width="120px" label-position="right">
        <el-form-item label="工种名称:" prop="workName">
          <el-input v-model="form.workName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="不达标保底:" prop="isGuaranteed">
          <el-switch
            v-model="form.isGuaranteed"
            active-color="#409EFF"
            inactive-color="#C0CCDA"
          >
          </el-switch>
        </el-form-item>
        <el-form-item label="保底工资:" prop="guaranteedWages"
        :rules="[
          {
            required:form.isGuaranteed?true: false,
            message: '请输入',
            trigger: 'blur',
          },
          {
            validator: this.validatorNum,
            trigger: 'blur',
          },
        ]">
              <el-input
                v-model.number="form.guaranteedWages"
                maxlength="20"
                style="width: calc(100% - 40px)"
                clearable
                placeholder="请输入"
              ></el-input>
              <span class="float_right">元/天</span>
            </el-form-item>
        <el-form-item label="薪资方案:" prop="salaryPlansName">
          {{ form.salaryPlansName }}
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer tac">
      <el-button type="cancel" @click="cancelMethod()">取消</el-button>
      <el-button type="primary" @click="submitForm('form')">确定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import { saveWorkTypeInfo } from "@/api/employeeManage/employeeInfo.js"
export default {
  props: {
    editRow: {
      type: Object,
    }
  },
  data() {
    return {
      islook: false,
      form: {
        workName: '',
        isGuaranteed: true,
        guaranteedWages: null,
        salaryPlansName:'',
      },
      rules: {
        workName: [
          {
            required: true,
            message: "请输入",
            trigger: ["blur", "change"],
          },
        ],
      },
      DeviceList: [],
    };
  },
  created() {
  },
  watch: {
    islook(newVal) {
      if (newVal) {
        this.formInfo()
      }
    },
    editRow() {
      this.formInfo()
    },
  },
  methods: {
    formInfo() {
      if (this.islook) {
        this.form = {
          workName: '',
          isGuaranteed: true,
          guaranteedWages: null,
          salaryPlansName:'',
        };
        this.$nextTick(()=>{
          this.$refs["form"].resetFields();
          if (this.editRow.type=='edit') {
            this.form = JSON.parse(JSON.stringify(this.editRow));
          }
        })
      }
    },
    validatorNum(rule, value, callback) {
      if (value) {
        if (value == undefined || value == null) {
          callback(new Error("请输入有效数字"));
        } else {
          var reg = /^\+?[0-9]\d*$/;
          if (!reg.test(value)) {
            callback(new Error("请填写不小于0的数字"));
          } else {
            callback();
          }
        }
      } else {
        callback();
      }
    },
    cancelMethod(val) {
      this.$refs["form"].resetFields();
      this.islook = false;
      if(val){
        this.$emit('refresh')
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let form = JSON.parse(JSON.stringify(this.form));
          form.guaranteedWages=form.guaranteedWages?form.guaranteedWages:0
            saveWorkTypeInfo(form).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: this.editRow.type == "add"?"添加成功!":"编辑成功!",
                  type: "success",
                });
                this.cancelMethod(true);
              }
            });
          
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
};
</script>
 
<style lang="scss" scoped>
.dialog-content-box {
  height: 28rem;
 
  .form-box {
    width: 90%;
    padding: 0 5%;
    height: 100%;
    overflow-y: auto;
 
  }
}
</style>