index.vue 3.59 KB
Newer Older
1 2 3
<template>
  <div class="eContainer">
    <c-page :title="title">
hewei committed
4
      <el-form ref="modelForm" label-width="120px" size="small" label-position="right" :model="model" :rules="rules" :disabled="isDisabled">
nanrui committed
5 6 7
        <c-content>
          <m-cur-info :model="model" />
        </c-content>
8 9 10 11 12 13 14 15 16 17 18 19 20 21
      </el-form>
      <div style="text-align: center">
        <c-button type="primary" style="margin-right: 10px" @click="commitAdd" v-if="type === 'add'">提 交</c-button>
        <c-button type="primary" style="margin-right: 10px" @click="commitEdit" v-if="type === 'edit'">提 交</c-button>
        <c-button type="primary" style="margin-right: 10px" @click="commitDelete" v-if="type === 'delete'">提 交
        </c-button>
        <c-button type="primary" @click="goBack">返 回</c-button>
      </div>
    </c-page>
  </div>
</template>

<script>
import Utils from "~/utils";
nanrui committed
22
import Cur, { Pattern } from "../Infcur/Cur.js";
23

nanrui committed
24
import Currency from "./Currency.vue";
25

nanrui committed
26
import { curInfo, add, edit, deleteById } from "~/service/test/cur.js";
27 28 29 30

export default {
  name: "StaticsDbicur",
  components: {
nanrui committed
31
    "m-cur-info": Currency,
32 33 34 35 36 37 38 39 40 41 42 43 44
  },
  provide() {
    return {
      root: this,
    };
  },
  props: {
    type: {
      type: String,
      default: "info"
    },
    title: {
      type: String,
hewei committed
45
      default: "dbicur"
46 47 48 49 50
    }
  },
  data() {
    return {
      model: new Cur().data,
hewei committed
51
      tabVal: "cur",
52 53 54 55 56 57 58 59 60 61 62
      rules: Pattern,
    };
  },
  computed: {
    isDisabled() {
      return this.type === "info" || this.type === "delete";
    },
  },
  created() {
    if (this.type !== "add") {
      const inr = this.$route.params.inr;
nanrui committed
63
      curInfo(inr).then((res) => {
64
        if (res.inr) {
nanrui committed
65
          console.log(res);
66 67 68 69 70 71
          this.model = res;
        } else {
          this.$message.error("客户不存在")
        }
      });
    }
nanrui committed
72
    
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
  },
  methods: {
    commitAdd() {
      this.$refs.modelForm.validate((validated) => {
        if (validated) {
          add(this.model)
            .then((res) => {
              this.$message.success("保存成功!");
              this.goBack(true)
            })
            .catch((err) => {
              this.$message.error("保存失败!");
            });
        } else {
          Utils.formValidateTips(this.$refs.modelForm.fields)
        }
      });
    },
    commitEdit() {
      this.$refs.modelForm.validate((validated) => {
        if (validated) {
          edit(this.model)
            .then((res) => {
              this.$message.success("保存成功!");
hewei committed
97
              this.goBack(true)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
            })
            .catch((err) => {
              this.$message.error("保存失败!");
            });
        } else {
          Utils.formValidateTips(this.$refs.modelForm.fields)
        }
      });
    },
    commitDelete() {
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteById(this.model.inr)
            .then((res) => {
              this.$message.success("删除成功!");
              this.goBack(true)
            })
            .catch((err) => {
              this.$message.error("删除失败!");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /**
     * update 是否更新infpty的查询列表
     */
    goBack(update) {
      this.$store.dispatch("TagsView/delView", this.$route);
nanrui committed
135
      this.$router.push({ name: "StaticsInfcur", params: { update } });
136 137 138 139 140 141 142 143 144
    },

  },
};
</script>

<style>

</style>