index.vue 2.82 KB
<template>
  <div>
    <el-dialog
      title="添加人群包客户"
      :visible.sync="shows"
      :show-close="!1"
      :close-on-click-modal="!1"
      width="600px"
    >
      <!-- 操作区域 -->
      <el-form ref="form" :rules="rules" :model="queryParams" label-width="100px">
        <el-form-item label="选择客户" prop="customerId">
          <el-select v-model="queryParams.customerId" clearable size="small" style="width: 240px">
            <el-option
              v-for="(item,index) in customerOptions"
              :key="index"
              :label="item.name"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="预付金额" prop="prepaidAmount">
          <el-input
            v-model="queryParams.prepaidAmount"
            placeholder="请输入预付金额"
            clearable
            size="small"
            style="width: 240px"
          />
        </el-form-item>
      </el-form>
      <!-- 底部区域 -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确认</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import bus from "../bus";
import { getPackOption, addCustomer } from "@/api/system/pack";
export default {
  data() {
    return {
      // 表单校验
      rules: {
        customerId: [
          { required: true, message: "选项不能为空", trigger: "blur" }
        ],
        prepaidAmount: [
          { required: true, message: "预付金额不能为空", trigger: "blur" }
        ]
      },
      queryParams: {
        customerId: null,
        prepaidAmount: null
      },
      shows: false,
      customerOptions: []
    };
  },
  created() {
    this.getOptions();
  },
  mounted() {
    // 响应组件状态
    bus.$on("shows", va => {
      this.shows = va;
    });
  },
  methods: {
    // 清空
    clear() {
      this.queryParams = {
        customerId: null,
        prepaidAmount: null
      };
    },
    // 获取客户下拉
    getOptions() {
      getPackOption()
        .then(res => {
          this.customerOptions = res.data;
        })
        .catch(console.log);
    },
    // 添加-确认
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addCustomer(this.queryParams)
            .then(res => {
              res.success
                ? this.msgSuccess("添加人群包客户成功")
                : this.msgError("异常错误");
              this.clear();
              this.shows = false;
              this.$emit("refresh", true);
            })
            .catch(console.log);
        }
      });
    },
    // 添加-取消
    cancel() {
      this.shows = false;
      this.clear();
    }
  }
};
</script>

<style>
</style>