info_create.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div id="info_create">
  3. <admin-frame topType="2" @back="back" :rightArrow="false" :usePage="false" :useNav="false">
  4. <template v-slot:info>
  5. <detail-1 :form="form" @onSubmit="onSubmit"></detail-1>
  6. </template>
  7. </admin-frame>
  8. </div>
  9. </template>
  10. <script>
  11. import detail1 from './info/detail-1.vue';
  12. import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
  13. import { mapState, createNamespacedHelpers } from 'vuex';
  14. const { mapActions: patentinfo } = createNamespacedHelpers('patentinfo');
  15. export default {
  16. name: 'info_create',
  17. props: {},
  18. components: {
  19. adminFrame,
  20. detail1,
  21. },
  22. data: function () {
  23. return {
  24. form: { inventor: [] },
  25. };
  26. },
  27. async created() {
  28. if (this.id) await this.search();
  29. },
  30. methods: {
  31. ...patentinfo(['fetch', 'create', 'update']),
  32. async search() {
  33. let res = await this.fetch(this.id);
  34. if (this.$checkRes(res)) {
  35. this.$set(this, `form`, res.data);
  36. }
  37. },
  38. async onSubmit() {
  39. let data = this.form;
  40. if (data.id) {
  41. let res = await this.update(data);
  42. if (this.$checkRes(res)) {
  43. this.$toast({ type: `success`, message: `修改成功` });
  44. this.back();
  45. } else {
  46. this.$toast({ type: `fail`, message: `${res.errmsg}` });
  47. }
  48. } else {
  49. data.trans_status = '0';
  50. let res = await this.create(data);
  51. if (this.$checkRes(res)) {
  52. this.$toast({ type: `success`, message: `添加成功` });
  53. this.back();
  54. } else {
  55. this.$toast({ type: `fail`, message: `${res.errmsg}` });
  56. }
  57. }
  58. },
  59. // 返回
  60. back() {
  61. this.$router.push({ path: '/patent/admin/patent/info' });
  62. },
  63. },
  64. computed: {
  65. ...mapState(['user']),
  66. id() {
  67. return this.$route.query.id;
  68. },
  69. },
  70. metaInfo() {
  71. return { title: this.$route.meta.title };
  72. },
  73. watch: {
  74. test: {
  75. deep: true,
  76. immediate: true,
  77. handler(val) {},
  78. },
  79. },
  80. };
  81. </script>
  82. <style lang="less" scoped></style>