<template>
  <div id="notice_create">
    <admin-frame topType="2" @back="back" :rightArrow="false" :usePage="false" :useNav="false">
      <template v-slot:info>
        <notice-form :form="form" @onSubmit="onSubmit"></notice-form>
      </template>
    </admin-frame>
  </div>
</template>

<script>
import noticeForm from './parts/form-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentnotice } = createNamespacedHelpers('patentnotice');
export default {
  name: 'detail',
  props: {},
  components: {
    adminFrame,
    noticeForm,
  },
  data: function () {
    return {
      form: {},
    };
  },
  async created() {
    this.search();
  },
  methods: {
    ...patentnotice(['create']),
    search() {
      let data = { send_id: this.user.id, send_name: this.user.name, to_type: '3' };
      this.$set(this, `form`, data);
    },
    async onSubmit(data) {
      let res = await this.create(data);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `发送通知成功` });
        this.back();
      } else {
        this.$toast({ type: `success`, message: `${res.errmsg}` });
      }
    },
    // 返回
    back() {
      this.$router.push({ path: '/patent/mech/message/notice' });
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.one {
  .one_1 {
    text-align: center;
    .van-button {
      margin: 0 5px 10px 5px;
    }
  }
}
</style>
