<template>
  <div>
    <BaseDialog
      width="500px"
      :isShow.sync="isShow"
      title="成本支付"
      @submit="submitForm"
      @close="close"
      confirmName="确定支付"
    >
      <div class="box" v-for="(item, index) in formList" :key="index">
        <div class="title">{{ item.label ? item.label + "：" : "" }}</div>
        <template v-if="item.scope === 'select'">
          <template v-for="(items, indexs) in item.options">
            <div v-if="formData[item.value] == items.value" class="text">
              {{ items.label }}
            </div>
          </template>
        </template>
        <div
          class="text"
          v-else-if="item.scope === 'money'"
          style="color: red; font-size: 16px"
        >
          ￥{{ formData[item.value] }}
        </div>
        <div v-else class="text">{{ formData[item.value] }}</div>
      </div>
    </BaseDialog>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    activeData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      formList: [
        {
          label: "添加时间",
          value: "title",
        },
        {
          label: "结算方式",
          value: "settleType",
          scope: "select",
          options: [
            {
              label: "数量结算",
              value: 1,
            },
            {
              label: "时间结算",
              value: 2,
            },
          ],
        },
        {
          label: "成本分类",
          value: "costCatName",
        },
        {
          label: "教育类型",
          value: "educationName",
        },
        {
          label: "培训项目",
          value: "businessName",
        },
        {
          label: "结算金额",
          value: "settleMoney",
          scope: "money",
        },
        {
          label: "供应商",
          value: "instName",
        },
        {
          label: "收款信息",
          value: "bankName",
        },
        {
          label: "",
          value: "bank",
        },
        {
          label: "",
          value: "bankAccount",
        },
      ],
      formData: {},
    };
  },
  methods: {
    init() {
      this.$api.settlepayinfodata(this.activeData.settleId).then((res) => {
        this.formData = res.data;
      });
    },
    close() {},
    submitForm() {
      this.$confirm("是否支付?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .settlepay({ settleId: this.formData.settleId })
            .then((res) => {
              this.$message({
                type: "success",
                message: "支付成功",
              });
              this.isShow = false;
              this.$emit("search");
            });
        })
        .catch(() => {});
    },
  },
  computed: {
    isShow: {
      get() {
        if (this.dialogVisible) {
          this.init();
        }
        return this.dialogVisible;
      },
      set(val) {
        this.$emit("update:dialogVisible", false);
      },
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
  .title {
    width: 100px;
    text-align: end;
  }
  .text {
    flex: 1;
    font-weight: bold;
  }
}
</style>
