<template>
  <div class="subject">
    <syDialogInput
      class="w-full"
      v-model:value="name"
      placeholder="请输入存证名称"
    ></syDialogInput>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import { ElMessage } from "element-plus";
import { GO_URLS, syDialogInput } from "cqk-sy-ui";
import { $ajax } from "@/service";

export default defineComponent({
  components: {
    syDialogInput,
  },
  props: ["navigate"],
  expose: ["determine"],
  data() {
    return {
      name: "",
      isactive: false,
    };
  },
  methods: {
    // 确认按钮
    async determine() {
      if (!this.name) {
        ElMessage("请输入名称");
        return false;
      }
      if (this.isactive) {
        return false;
      }
      this.isactive = true;
      const res = await $ajax({
        type: "post",
        url: GO_URLS.add,
        params: {
          name: this.name,
          note: JSON.stringify({
            version: 1,
            evidenceName: this.name,
            stepName: "",
            banners: [],
          }),
          detail: JSON.stringify([
            {
              label: "ext",
              key: "",
              type: 3,
              data: [
                {
                  data: {
                    type: "text",
                    format: "string",
                    value: this.name,
                  },
                  type: 0,
                  key: "存证名称",
                  label: "存证名称",
                },
                {
                  data: {
                    type: "text",
                    format: "hash",
                    value: "null",
                  },
                  type: 0,
                  key: "basehash",
                  label: "basehash",
                },
                {
                  data: {
                    type: "text",
                    format: "hash",
                    value: "null",
                  },
                  type: 0,
                  key: "prehash",
                  label: "prehash",
                },
                {
                  data: {
                    type: "text",
                    format: "string",
                    value: null,
                  },
                  type: 0,
                  key: "存证类型",
                  label: "存证类型",
                },
              ],
            },
            {},
          ]),
        },
      });
      if (res) {
        ElMessage({
          message: "添加成功",
          type: "success",
        });
        this.isactive = false;
        this.navigate({
          path: "/tracingDetail",
          query: {
            id: res.data.id,
          },
        });
        return true;
      }
    },
  },
});
</script>
<style scoped lang="scss">
.subject {
  width: 100%;
  background: rgba(255, 255, 255, 1);
  box-sizing: content-box;
}
h1 {
  padding-top: 34px;
  padding-bottom: 42px;
  font-size: 22px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: rgba(53, 53, 53, 1);
}
input {
  height: 44px;
  width: 100%;
  border: 1px solid rgba(226, 226, 226, 1);
  font-size: 18px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: black;
  line-height: 25px;
  text-indent: 26px;
  &::-webkit-input-placeholder {
    /* WebKit browsers */
    color: #b6b5ba;
  }
  &:-moz-placeholder {
    color: #b6b5ba;
  }
  &::-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #b6b5ba;
  }

  &:-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #b6b5ba;
  }
}
input:focus {
  outline: none;
  border: 1px solid rgba(226, 226, 226, 1);
}
.btn-box {
  overflow: hidden;
  padding-top: 40px;
  float: right;
}
.btn {
  float: left;
  width: 120px;
  height: 40px;
  border-radius: 4px;
  text-align: center;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  line-height: 40px;
  cursor: pointer;
}
.btn-cancel {
  color: rgba(92, 100, 118, 1);
}
.btn-determine {
  background: var(--sy-blue);
  color: white;
}
</style>
