表单键值对

很久的代码,能看着找找灵感就行。

<template>
  <div class="one">
    <el-form :model="form" class="dadada">
      <el-card>
        <!-- er -->
        <el-form-item label="佣金类型:">
          <el-select
            clearable
            class="ele-block"
            v-model="form.lv"
            placeholder="请选择"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="内容:">
          <el-input
            v-if="form.lv == 1"
            v-model="listinfio.percentage"
            placeholder="请输入拿推广用户收益百分比"
          />
          <el-input
            v-if="form.lv == 2"
            v-model="listinfio2.percentage"
            placeholder="请输入拿推广用户收益百分比"
            clearable
          />
          <el-input
            v-if="form.lv == 3"
            v-model="listinfio23.percentage"
            placeholder="请输入拿推广用户收益百分比"
            clearable
          />
          <!--
          <el-input
            v-if="form.lv == 3"
            v-model="form.list[2].percentage"
            placeholder="请输入拿推广用户收益百分比"
            clearable
          /> -->
        </el-form-item>
        <!-- 提交 -->
        <el-form-item>
          <el-button type="primary" @click="submit" class="tj">
            提交
          </el-button>
        </el-form-item>
      </el-card>
    </el-form>
  </div>
</template>

<script>
import qs from "qs";
export default {
  data() {
    return {
      options: [
        {
          value: "1",
          label: "直推佣金"
        },
        {
          value: "2",
          label: "二级佣金"
        },
        {
          value: "3",
          label: "三级佣金"
        }
      ],
      upinof: [],
      quertlistall: {},
      // 表单数据
      form: {
        lv: "1"
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      listinfio: {
        percentage: ""
      },
      listinfio2: {
        percentage: ""
      },
      listinfio23: {
        percentage: ""
      },
      info: {}
    };
  },
  mounted() {
    this.queryinfo();
  },
  methods: {
    /* 提交 */
    submit() {
      if (this.form.lv == 1) {
        this.info["lv_percentage"] = {
          [this.form.lv]: this.listinfio.percentage
        };
        let param = new URLSearchParams();
        param.append(
          "lv_percentage",
          JSON.stringify({ "1": this.listinfio.percentage })
        );
        this.$http
          .post("admin-api/commission-config/update", param)
          .then(res => {
            console.log(res);
            if (res.data.status === 1) {
              this.$message({ type: "success", message: "成功" });
              // this.queryinfo();
            } else {
              this.$message.error(res.error);
            }
          });
      } else if (this.form.lv == 2) {
        this.info["lv_percentage"] = {
          [this.form.lv]: this.listinfio.percentage
        };
        let param = new URLSearchParams();
        param.append(
          "lv_percentage",
          JSON.stringify({ "2": this.listinfio.percentage })
        );
        this.$http
          .post("admin-api/commission-config/update", param)
          .then(res => {
            console.log(res);
            if (res.data.status === 1) {
              this.$message({ type: "success", message: "成功" });
              this.queryinfo();
            } else {
              this.$message.error(res.error);
            }
          });
      } else {
        this.info["lv_percentage"] = {
          [this.form.lv]: this.listinfio.percentage
        };
        let param = new URLSearchParams();
        param.append(
          "lv_percentage",
          JSON.stringify({ "3": this.listinfio.percentage })
        );
        this.$http
          .post("admin-api/commission-config/update", param)
          .then(res => {
            console.log(res);
            if (res.data.status === 1) {
              this.$message({ type: "success", message: "成功" });
              this.queryinfo();
            } else {
              this.$message.error(res.error);
            }
          });
      }
    },

    // 查询信息
    queryinfo() {
      this.$http.get("admin-api/commission-config/get", {}).then(res => {
        console.log(res, "佣金设置");
        if (res.data.status === 1) {
          this.listinfio = res.data.result[0];
          this.listinfio2 = res.data.result[1];
          this.listinfio23 = res.data.result[2];
        }
      });
    }
  },
};
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值