sunjh 6 роки тому
батько
коміт
e4d68405f6
2 змінених файлів з 96 додано та 87 видалено
  1. 94 85
      src/components/task/TaskCreate.vue
  2. 2 2
      src/js/api.js

+ 94 - 85
src/components/task/TaskCreate.vue

@@ -66,164 +66,173 @@
 </template>
 
 <script>
-import Enum from "@/constants/enum/index";
-import provincecity from "@/components/commons/ProvinceCity";
-import provinceCityJSON from "@/constants/provinceCity.json";
+import Enum from '@/constants/enum/index'
+import provincecity from '@/components/commons/ProvinceCity'
+import provinceCityJSON from '@/constants/provinceCity.json'
+import Http from '@/js/http.js'
+import Apis from '@/js/api.js'
+
 export default {
-  name: "Task",
+  name: 'Task',
   components: {
     provincecity
   },
-  data() {
+  data () {
     return {
       projectId: 0,
       institutionArray: Enum.institution,
-      tabPosition: "top",
+      tabPosition: 'top',
       task: {
-        name: "",
-        desc: "",
-        type: "",
-        resource: "广场", //如果是广场不用管Location和institution ,定向看institution,区域看location
-        location: { provinceCode: "", cityCode: "" },
-        institution: "",
-        datetime: ""
+        name: '',
+        desc: '',
+        type: '',
+        resource: '广场', //如果是广场不用管Location和institution ,定向看institution,区域看location
+        location: {provinceCode: '', cityCode: ''},
+        institution: '',
+        datetime: ''
       },
       pickerOptions: {
         shortcuts: [
           {
-            text: "今天",
-            onClick(picker) {
-              picker.$emit("pick", new Date());
+            text: '今天',
+            onClick (picker) {
+              picker.$emit('pick', new Date())
             }
           },
           {
-            text: "昨天",
-            onClick(picker) {
-              const date = new Date();
-              date.setTime(date.getTime() - 3600 * 1000 * 24);
-              picker.$emit("pick", date);
+            text: '昨天',
+            onClick (picker) {
+              const date = new Date()
+              date.setTime(date.getTime() - 3600 * 1000 * 24)
+              picker.$emit('pick', date)
             }
           },
           {
-            text: "一周前",
-            onClick(picker) {
-              const date = new Date();
-              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
-              picker.$emit("pick", date);
+            text: '一周前',
+            onClick (picker) {
+              const date = new Date()
+              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
+              picker.$emit('pick', date)
             }
           }
         ]
       },
       rules: {
         name: [
-          { required: true, message: "请输入任务名称", trigger: "blur" }
+          {required: true, message: '请输入任务名称', trigger: 'blur'}
           // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
         ],
         datetime: [
           {
-            type: "date",
+            type: 'date',
             required: true,
-            message: "请选择截止时间",
-            trigger: "change"
+            message: '请选择截止时间',
+            trigger: 'change'
           }
         ],
         type: [
-          { required: true, message: "请选择业务类型", trigger: "change" }
+          {required: true, message: '请选择业务类型', trigger: 'change'}
         ],
-        desc: [{ required: true, message: "请填写任务描述", trigger: "blur" }]
+        desc: [{required: true, message: '请填写任务描述', trigger: 'blur'}]
       }
-    };
+    }
   },
   watch: {
-    "task.institution"() {
+    'task.institution' () {
       if (this.task.institution) {
-        this.$refs.addFormProvince.resetProviceCity();
-        this.task.location = { provinceCode: "", cityCode: "" };
+        this.$refs.addFormProvince.resetProviceCity()
+        this.task.location = {provinceCode: '', cityCode: ''}
       }
     },
-    "task.location"() {
+    'task.location' () {
       if (this.task.location.provinceCode || this.task.location.cityCode) {
-        this.task.institution = "";
+        this.task.institution = ''
       }
     },
-    "task.resource"() {
-      if (this.task.resource == "广场") {
-        this.$refs.addFormProvince.resetProviceCity();
-        this.task.institution = "";
-        this.task.location = { provinceCode: "", cityCode: "" };
+    'task.resource' () {
+      if (this.task.resource == '广场') {
+        this.$refs.addFormProvince.resetProviceCity()
+        this.task.institution = ''
+        this.task.location = {provinceCode: '', cityCode: ''}
       }
     },
     deep: true
   },
-  mounted() {
+  mounted () {
     this.$nextTick(() => {
-      this.init();
-    });
+      this.init()
+    })
   },
   methods: {
-    init() {
-      this.projectId = +this.$route.params.projectId;
+    init () {
+      this.projectId = +this.$route.params.projectId
     },
-    updateLocation(location) {
-      var provinceName = "";
-      var cityName = "";
+    updateLocation (location) {
+      var provinceName = ''
+      var cityName = ''
       for (var item of provinceCityJSON.provinces) {
         if (item.code === location.provinceCode) {
-          provinceName = item.name;
+          provinceName = item.name
           for (var city of item.cities) {
             if (city.code === location.cityCode) {
-              cityName = city.name;
-              break;
+              cityName = city.name
+              break
             }
           }
         }
       }
-      return provinceName + " / " + cityName;
+      return provinceName + ' / ' + cityName
     },
-    submitForm(formName) {
+    submitForm (formName) {
       this.$refs[formName].validate(valid => {
         if (valid) {
-          console.log(this.task);
+          console.log(this.task)
+          Http.post(Apis.TASK.CREATE_TASK_SUBMIT, this.task).then((res) => {
+            console.log(this.task)
+            console.log(res)
+          })
           //提交 task
         } else {
-          console.log("error submit!!");
-          return false;
+          console.log('error submit!!')
+          return false
         }
-      });
+      })
     },
-    resetForm(formName) {
-      this.$refs.addFormProvince.resetProviceCity();
-      this.$refs[formName].resetFields();
-      this.task.name = "";
-      this.task.desc = "";
-      this.task.type = "";
-      this.task.resource = "广场"; //如果是广场不用管Location和institution ,定向看institution,区域看location
-      (this.task.location = { provinceCode: "", cityCode: "" }),
-        (this.task.institution = "");
-      this.task.datetime = "";
+    resetForm (formName) {
+      this.$refs.addFormProvince.resetProviceCity()
+      this.$refs[formName].resetFields()
+      this.task.name = ''
+      this.task.desc = ''
+      this.task.type = ''
+      this.task.resource = '广场'; //如果是广场不用管Location和institution ,定向看institution,区域看location
+      (this.task.location = {provinceCode: '', cityCode: ''}),
+        (this.task.institution = '')
+      this.task.datetime = ''
     },
-    locationChange(provinceId, cityId) {
-      if (provinceId || cityId)
-        this.task.location = { provinceCode: provinceId, cityCode: cityId };
+    locationChange (provinceId, cityId) {
+      if (provinceId || cityId) {
+        this.task.location = {provinceCode: provinceId, cityCode: cityId}
+      }
     },
-    cancelCreate() {
+    cancelCreate () {
       if (window.history.length <= 1) {
-        this.$router.push({ path: "/" });
-        return false;
+        this.$router.push({path: '/'})
+        return false
       } else {
-        this.$router.go(-1);
+        this.$router.go(-1)
       }
     }
   }
-};
+}
 </script>
 
 <style lang="less" scoped>
-.el-radio {
-  margin: 10px 20px 10px 0;
-}
-.el-form-item /deep/.el-tabs__content {
-  max-height: 120px !important;
-  overflow: auto;
-}
+  .el-radio {
+    margin: 10px 20px 10px 0;
+  }
+
+  .el-form-item /deep/ .el-tabs__content {
+    max-height: 120px !important;
+    overflow: auto;
+  }
 </style>

+ 2 - 2
src/js/api.js

@@ -5,7 +5,8 @@ export default {
     UPDATE_PROJECT_SUBMIT: this.API + 'project/updateProject/',
   },
   TASK: {
-    GET_HOT_TASK_LIST: '/api/task/getHotTaskList/'
+    GET_HOT_TASK_LIST: '/api/task/getHotTaskList/',
+    CREATE_TASK_SUBMIT: this.API + 'task/createTask'
   },
   REPORT: {
     CREATE_REPORT_SUBMIT: this.API + 'report/createReport',
@@ -18,7 +19,6 @@ export default {
     MY_CROWD_TEST_PAGE: this.API + 'page/myCrowdTest/',
     CREATE_PROJECT_PAGE: this.API + 'page/createProject/',
     CREATE_REPORT_PAGE: this.API + 'page/createReport/',
-    CREATE_TASK_PAGE: this.API + 'page/createTask/',
     MODIFY_TASK_PAGE: this.API + 'page/modifyTask/',
     TASK_DETAIL_PAGE: this.API + 'page/taskDetail/',
     PROJECT_DETAIL_PAGE: this.API + 'page/projectDetail/',