123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="'设置毛利率'"
- :center="true"
- align="left"
- top="12vh"
- width="600px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- @close="showModelThis = false"
- >
- <el-card style="margin: -20px 0 0 0">
- <el-row :gutter="0">
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- :size="'small'"
- :rules="rulesThis"
- label-width="110px"
- class="demo-ruleForm"
- >
- <el-form-item label="分类名称" prop="cat_name">
- <el-input
- v-model="ruleForm.cat_name"
- disabled
- placeholder="分类名称"
- maxlength="20"
- ><template slot="prepend" v-if="pid_name">{{
- pid_name
- }}</template></el-input
- >
- </el-form-item>
- <el-form-item label="财务核算码" prop="fund_code">
- <el-input
- v-model="ruleForm.fund_code"
- disabled
- placeholder="财务核算码"
- maxlength="50"
- />
- </el-form-item>
- <el-form-item label="预算→成本" prop="order_rate">
- <digital-input
- :values="ruleForm.order_rate"
- :placeholder="'预算→成本'"
- :min="0"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'order_rate')"
- />
- </el-form-item>
- <el-form-item label="成本→售价" prop="sale_rate">
- <digital-input
- :values="ruleForm.sale_rate"
- :placeholder="'成本→售价'"
- :min="-100"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'sale_rate')"
- />
- </el-form-item>
- <el-form-item label="主管利率" prop="rate">
- <digital-input
- :values="ruleForm.rate"
- :placeholder="'主管利率'"
- :min="-100"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'rate')"
- />
- </el-form-item>
- <el-form-item label="财务利率" prop="money_rate">
- <digital-input
- :values="ruleForm.money_rate"
- :placeholder="'财务利率'"
- :min="-100"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'money_rate')"
- />
- </el-form-item>
- <el-form-item label="项目最低毛利" prop="low_rate">
- <digital-input
- :values="ruleForm.low_rate"
- :placeholder="'项目最低毛利'"
- :min="-100"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'low_rate')"
- />
- </el-form-item>
- <!-- <el-form-item label="BOSS毛利率" prop="lower_rate">
- <digital-input
- :values="ruleForm.lower_rate"
- :placeholder="'BOSS毛利率'"
- :min="-100"
- :max="100000000000"
- :position="'right'"
- :precision="2"
- :size="'mini'"
- :controls="false"
- :append="'%'"
- @reschange="rate_change($event, 'lower_rate')"
- />
- </el-form-item>-->
- </el-form>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-button
- v-if="id !== '007'"
- type="primary"
- :size="'small'"
- @click="submitForm"
- >保 存
- </el-button>
- <el-button :size="'small'" @click="showModelThis = false">{{
- id == "007" ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/goodStore/sort";
- import resToken from "@/mixins/resToken";
- export default {
- name: "sort",
- props: ["showModel", "id", "sitem", "titleList"],
- mixins: [resToken],
- data() {
- const validate_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("主管利率毛利率不能为空!"));
- } else {
- callback();
- }
- };
- const validate_order_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("预算→成本毛利率不能为空!"));
- } else {
- callback();
- }
- };
- const validate_sale_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("成本→售价毛利率不能为空!"));
- } else {
- callback();
- }
- };
- const validate_lower_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("BOSS毛利率不能为空!"));
- } else {
- callback();
- }
- };
- const validate_low_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("项目最低毛利率不能为空!"));
- } else {
- callback();
- }
- };
- const validate_money_rate = (rule, value, callback) => {
- const { required } = rule;
- if (value === "" && required) {
- callback(new Error("财务毛利率不能为空!"));
- } else {
- callback();
- }
- };
- return {
- loading: false,
- showModelThis: this.showModel,
- pid_name: "",
- ruleForm: {
- id: "",
- cat_name: "",
- order_rate: "0",
- sale_rate: "0",
- lower_rate: "0",
- rate: "0",
- low_rate: "0",
- money_rate: "0",
- },
- rulesThis: this.rules,
- rules: {
- order_rate: [
- { required: true, validator: validate_order_rate, trigger: "blur" },
- ],
- sale_rate: [
- { required: true, validator: validate_sale_rate, trigger: "blur" },
- ],
- lower_rate: [
- { required: false, validator: validate_lower_rate, trigger: "blur" },
- ],
- rate: [{ required: true, validator: validate_rate, trigger: "blur" }],
- low_rate: [
- { required: true, validator: validate_low_rate, trigger: "blur" },
- ],
- money_rate: [
- { required: true, validator: validate_money_rate, trigger: "blur" },
- ],
- },
- };
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.$emit("cancel");
- }
- },
- },
- methods: {
- async initForm() {
- this.loading = true;
- this.pid_name = "";
- this.titleList.forEach((e, i) => {
- this.pid_name += i !== 0 ? `${e.titleName}/` : "";
- });
- this.rulesThis = this.rules;
- await this.resetForm();
- await this.initData();
- this.loading = false;
- },
- async resetForm() {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- const {
- pid,
- id,
- cat_name,
- order_rate,
- sale_rate,
- lower_rate,
- rate,
- fund_code,
- low_rate,
- money_rate,
- } = this.sitem;
- this.ruleForm = {
- pid: pid || "",
- id: id || "",
- cat_name: cat_name || "",
- fund_code: fund_code || "",
- order_rate: order_rate || "0",
- sale_rate: sale_rate || "0",
- lower_rate: lower_rate || "0",
- rate: rate || "0",
- low_rate: low_rate || "0",
- money_rate: money_rate || "0",
- };
- }
- });
- },
- rate_change(e, key) {
- this.ruleForm[key] = e + "";
- this.$refs.ruleForm.validateField(key);
- },
- async initData() {
- const { code, data, message } = await asyncRequest.detail({
- id: this.sitem.id,
- });
- if (code === 0) {
- const {
- pid,
- id,
- cat_name,
- order_rate,
- sale_rate,
- lower_rate,
- rate,
- fund_code,
- low_rate,
- money_rate,
- } = data;
- this.ruleForm = {
- pid: pid || "",
- id: id || "",
- cat_name: cat_name || "",
- fund_code: fund_code || "",
- order_rate: order_rate || "0",
- sale_rate: sale_rate || "0",
- lower_rate: lower_rate || "0",
- rate: rate || "0",
- low_rate: low_rate || "0",
- money_rate: money_rate || "0",
- };
- } else if (code >= 100 && code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(message);
- }
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- if (!this.loading) {
- this.loading = true;
- let model = JSON.parse(JSON.stringify(this.ruleForm));
- delete model["cat_name"];
- delete model["pid"];
- delete model["fund_code"];
- let res = await asyncRequest.editRate(model);
- this.loading = false;
- if (res && res.code === 0) {
- this.$notify.success({
- title: "毛利率设置成功!",
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- this.$emit("refresh");
- } 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>
- .sort {
- }
- </style>
|