FormResult.vue 2.7 KB
Newer Older
aaronchen2k2k's avatar
aaronchen2k2k 已提交
1 2 3 4 5 6 7 8 9
<template>
  <ZModal
    :showModal="showModalRef"
    @onCancel="close"
    @onOk="submit"
    :title="t('submit_result_to_zentao')"
  >
    <Form labelCol="6" wrapperCol="16">
      <FormItem name="taskId" :label="t('task')">
Z
zhaoke 已提交
10
        <select name="taskId" v-model="modelRef.taskId">
aaronchen2k2k's avatar
aaronchen2k2k 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
          <option value="0"></option>
          <option v-for="item in tasks" :key="item.id" :value="item.id">
            {{ item.name }}
          </option>
        </select>
      </FormItem>
    </Form>
  </ZModal>
</template>

<script setup lang="ts">
import { useI18n } from "vue-i18n";
import { useStore } from "vuex";
import { ZentaoData } from "@/store/zentao";
import { ScriptData } from "@/views/script/store";
import { unitTestTypesDef, ztfTestTypesDef } from "@/utils/const";
import {
  computed,
  defineExpose,
  onMounted,
  withDefaults,
  ref,
  defineProps,
  defineEmits, reactive, PropType,
} from "vue";
import { useForm } from "@/utils/form";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
37 38
import Form from "@/components/Form.vue";
import FormItem from "@/components/FormItem.vue";
aaronchen2k2k's avatar
aaronchen2k2k 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
import {queryTask} from "@/services/zentao";
import {submitResultToZentao} from "@/views/result/service";
import {notification} from "ant-design-vue";

export interface FormWorkspaceProps {
  data?: any;
  show?: boolean;
  finish?: Function;
}
const { t } = useI18n();
const props = withDefaults(defineProps<FormWorkspaceProps>(), {
  data: {},
  show: false,
});

const showModalRef = computed(() => {
  return props.show;
});
const testTypes = ref([...ztfTestTypesDef, ...unitTestTypesDef]);
const store = useStore<{ Zentao: ZentaoData }>();
const currProduct = computed<any>(() => store.state.Zentao.currProduct);

const modelRef = ref({taskId: 0});
const rulesRef = ref({});

let tasks = ref([])
const listTask = () => {
  queryTask(currProduct.value.id).then((jsn) => {
    tasks.value = jsn.data
  })
}
listTask()

const { validate, reset, validateInfos } = useForm(modelRef, rulesRef);

const submit = () => {
  console.log('submitResultForm', modelRef.value)

  if (!validate()) {
    return
  }

  const data = Object.assign({
    workspaceId: props.data.workspaceId,
    seq: props.data.seq,
  }, modelRef.value)
  data.taskId = parseInt(data.taskId)

  console.log('data', data)

  submitResultToZentao(data).then((json) => {
    console.log('json', json)
    if (json.code === 0) {
      notification.success({
        message: t('submit_success'),
      });
      close()
    } else {
      notification.error({
        message: t('submit_failed'),
        description: json.msg,
      });
    }
  })
}
const close = () => {
  props.finish()
};

const clearFormData = () => {
  modelRef.value = {};
};

defineExpose({
  clearFormData,
});
</script>

<style lang="less" scoped>
aaronchen2k2k's avatar
aaronchen2k2k 已提交
118

aaronchen2k2k's avatar
aaronchen2k2k 已提交
119
</style>