123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <template>
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- :size="'mini'"
- :rules="rulesThis"
- label-width="112px"
- >
- <el-row>
- <el-col :span="12">
- <el-form-item label="项目毛利率" prop="rate">
- <digital-input
- :values="ruleForm.rate"
- :placeholder="'项目毛利率'"
- :min="0"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :disabled="
- (status === '5' || status === '6') &&
- powers &&
- powers.length > 0 &&
- powers.some((item) => item == '060')
- "
- :controls="false"
- :append="'%'"
- @reschange="rate_change"
- />
- </el-form-item>
- </el-col>
- <el-col
- :span="12"
- style="text-align: right"
- v-if="
- (status !== '5' || status !== '6') &&
- powers &&
- powers.length > 0 &&
- powers.some((item) => item == '060')
- "
- >
- <el-button type="primary" :size="'mini'" @click="submitForm"
- >保 存
- </el-button>
- </el-col>
- </el-row>
- </el-form>
- </template>
- <script>
- import asyncRequest from "@/apis/service/sellOut/project";
- import resToken from "@/mixins/resToken";
- export default {
- name: "Account",
- props: ["showModel", "sitem", "id", "type"],
- mixins: [resToken],
- computed: {
- powers() {
- let tran =
- this.$store.getters.btnList.find(
- (item) => item.menu_route == "projectDetail"
- ) || {};
- if (tran && tran.action && tran.action.length > 0) {
- return tran.action;
- } else {
- return [];
- }
- },
- },
- watch: {
- // showModel: function (val) {
- // this.showModelThis = val;
- // if (val) {
- // this.initForm();
- // }
- // },
- // showModelThis(val) {
- // if (!val) {
- // this.$emit("cancel");
- // }
- // },
- },
- data() {
- const validate_sale_price = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("项目毛利率不能为空!"));
- } else if (
- value === "0" ||
- value === "0." ||
- value === "0.0" ||
- value === "0.00"
- ) {
- callback(new Error("项目毛利率不能为零!"));
- } else {
- callback();
- }
- };
- return {
- loading: false,
- ruleForm: {
- projectNo: "",
- rate: "0",
- },
- rulesThis: this.rules,
- rules: {
- rate: [
- {
- required: true,
- validator: validate_sale_price,
- trigger: "blur",
- },
- ],
- },
- };
- },
- mounted() {
- this.initForm();
- },
- methods: {
- //项目毛利率编辑
- rate_change(e) {
- this.ruleForm.rate = e + "";
- this.$refs.ruleForm.validateField("rate");
- },
- //初始化整个组件
- async initForm() {
- this.loading = true;
- this.company = "";
- this.ruleForm = {
- projectNo: "",
- rate: "0",
- };
- this.rulesThis = this.rules;
- await this.resetForm();
- this.loading = false;
- },
- //初始化整个表单
- async resetForm() {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- const { low_rate, projectNo, status } = this.sitem;
- this.status = status || "";
- this.ruleForm = {
- projectNo: projectNo || "",
- rate: low_rate || "0",
- };
- }
- });
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- this.loading = true;
- let model = JSON.parse(JSON.stringify(this.ruleForm));
- let res = await asyncRequest.rateEdit(model);
- this.loading = false;
- if (res && res.code === 0) {
- this.$notify.success({
- title: "设置成功!",
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- this.$emit("refresh", res.data);
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .account {
- }
- </style>
|