<script>
import useColumns from "./columns";
import { ccdItem, editItem } from "@/api/expend/customerExpend";

export default {
  name: "customerExpendAdd",
  props: {
    dict: {
      type: Object,
    },
  },
  components: {
    ElSuperForm: () => import("@/components/super-form/index.vue"),
  },
  data() {
    const { FearchColumns } = useColumns();
    const page = this.$init.page();
    const params = this.$init.params(FearchColumns);
    const rules = this.$init.rules(FearchColumns);
    return {
      page,
      rules,
      params,
      FearchColumns,
      size: "mini",
      width: "100%",
      visible: false,
      loading: false,
      opType: "edit",
    };
  },
  computed: {
    title: {
      get() {
        let { opType } = this;
        if (opType === "edit") {
          return "编辑";
        } else {
          return "查看";
        }
      },
      set() {},
    },
  },
  methods: {
    setVisible(prop, type) {
      this.visible = prop;
      this.opType = type;
    },
    // 查询
    async fetchItem(prop) {
      try {
        this.loading = true;
        let { code, data } = await ccdItem(prop.id);
        if (code == 200) {
          this.params = data;
        }
      } catch (error) {
      } finally {
        this.loading = false;
      }
    },
    //
    onHide() {
      const { FearchColumns } = useColumns();
      this.visible = false;
      this.params = this.$init.params(FearchColumns);
      this.$emit("success");
    },
    async useSubmit() {
      try {
        this.loading = true;
        let { code, msg } = await editItem({ ...this.params });
        if (code == 200) {
          this.$notify.success(msg);
          this.onHide();
        }
      } catch (error) {
      } finally {
        this.loading = false;
      }
    },
    ccdSaleOrgChange(prop) {
      console.log(prop, "prop");
    },
  },
  created() {},
};
</script>

<template>
  <el-drawer
    :size="width"
    :title="title"
    v-bind="$attrs"
    v-on="$listeners"
    v-loading="loading"
    :show-close="false"
    :visible.sync="visible"
    append-to-body
    destroy-on-close
    @close="onHide"
  >
    <template slot="title">
      <span>{{ title }}</span>
      <el-button
        v-if="opType !== 'see'"
        type="primary"
        :size="$attrs.size"
        :loading="loading"
        @click="useSubmit('customerExpendAdd')"
      >
        确 认
      </el-button>
      <el-button :size="$attrs.size" :loading="loading" @click="onHide">
        取 消
      </el-button>
    </template>
    <el-super-form
      v-model="params"
      :dict="dict"
      :rules="rules"
      :size="$attrs.size"
      :columns="FearchColumns"
      :disabled="opType === 'see'"
      ref="customerExpendAdd"
      label-width="auto"
      label-position="right"
      style="padding: 18px"
    >
    </el-super-form>
  </el-drawer>
</template>
