<template>
<div>
  
</div>
</template>

<script>
import {
  listSetting,
  delSetting,
  addSetting,
  updateSetting,
} from "@/api/customer/setting";
import { queryOilType } from "@/utils/oil";

import { listPrice } from "@/api/station/price";
export default {
  name: "Customer_Grade",
  data() {
    const validatorMemberConditEnd = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请填入会员条件"));
        return;
      }
      const start = +this.form.memberConditStart;
      const end = +value;
      if (isNaN(start) || isNaN(end)) {
        callback(new Error("请填入数字"));
        return;
      }
      if (start >= end) {
        console.log(start, end);
        callback(new Error("请检查数字逻辑有效性"));
        return;
      }
      callback();
    };
    return {
      pageStatus: 0,
      // 总条数
      total: 0,
      oilType: 0,
      settingList: [],
      //下拉油品名称
      oilNameOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        oilName: [{ required: true, message: "请填写联系人", trigger: "blur" }],
        grade: [{ required: true, message: "请填写等级名称", trigger: "blur" }],
        memberConditEnd: [
          { validator: validatorMemberConditEnd, trigger: "change" },
        ],
        discountAmt: [
          { required: true, message: "请填写优惠金额", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.setPageStatus();
    this.getList();
    listPrice().then((response) => {
      this.oilNameOptions = response.rows;

    });
  },
  methods: {
    setPageStatus() {
      this.queryPageStatus([2]).then((res) => {
        this.pageStatus = res;
      });
    },
    /** 查询客户优惠等级设置列表 */
    getList() {
      listSetting(this.queryParams).then((response) => {
        this.settingList = response.rows;
        this.total = response.total;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },

    oilNameChange(val){
      queryOilType(val).then((res) => {
        this.oilType = res;
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加客户优惠等级";
      this.form = {};
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      this.form = row;
      this.open = true;
      this.title = "修改客户优惠等级";
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateSetting(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSetting(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      this.$confirm("确认删除该条等级优惠信息?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delSetting(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
  },
};
</script>
<style>
.two {
  margin-top: 30px;
}
.settingButton {
  border: 0px;
  float: right;
}
.cutLine {
  width: 65px;
  height: 2px;
  background: #71f332;
  /*margin-top: 5px;*/
  margin-left: 5px;
  margin-bottom: 20px;
}
.textlineHeader {
  /*margin-bottom: 20px;*/
  font-family: Bahnschrift;
  /*text-shadow: #32a9f3 1px 1px 1px;*/
  /*font-size: ;*/
  color: #32a9f3;
}
</style>
