Browse Source

创建任务和修改任务添加有效性认证

sunjh 6 years ago
parent
commit
9a206ed517

+ 4 - 4
src/components/project/Project.vue

@@ -147,7 +147,7 @@
             <a v-if="project.fileUrl!=null && project.fileUrl!=''" :href="project.fileUrl"><el-link :underline="false"
                                                                                                     type="primary"><i
               class="el-icon-document"></i>下载文件</el-link></a>
-            <i v-if="project.fileUrl==null || project.fileUrl==''" class="el-icon-document">下载文件</i>
+            <i v-if="project.fileUrl==null || project.fileUrl==''" class="el-icon-document">暂无文件</i>
           </span>
         </el-form-item>
         <el-form-item label="项目截止时间" prop="datetime">
@@ -375,12 +375,12 @@ export default {
           {required: true, message: '预算不可为空', trigger: 'blur'},
           {
             validator: (rule, value, callback) => {
-              if (value <= 0) {
-                callback(new Error('请输入于0的数'))
+              if (value < 0) {
+                callback(new Error('请输入不小于0的数'))
               } else {
                 callback()
               }
-            }, trigger: 'change'
+            }, trigger: 'blur'
           },
         ],
         resource: [

+ 3 - 3
src/components/project/ProjectCreate.vue

@@ -248,12 +248,12 @@ export default {
           {required: true, message: '预算不可为空', trigger: 'blur'},
           {
             validator: (rule, value, callback) => {
-              if(value <= 0){
-                callback(new Error('请输入于0的数'))
+              if(value < 0){
+                callback(new Error('请输入不小于0的数'))
               } else {
                 callback()
               }
-            }, trigger: 'change'
+            }, trigger: 'blur'
           },
         ],
         resource: [

+ 58 - 35
src/components/task/Task.vue

@@ -4,7 +4,7 @@
     <div class="create-body">
       <div class="title h2" v-if="!isModifyMode">基本信息</div>
       <el-form :model="task" :rules="rules" ref="task" label-width="12%" class="demo-task">
-        <el-form-item label="任务名称" prop="name">
+        <el-form-item label="任务名称" prop="title">
           <el-input size="small" v-if="isModifyMode" v-model="task.title"></el-input>
           <span v-if="!isModifyMode">{{task.title}}</span>
         </el-form-item>
@@ -76,7 +76,7 @@
             :before-remove="beforeRemove"
             :limit="1"
             :on-exceed="handleExceed"
-            :before-upload="beforeFileUpload"
+
             :http-request="uploadRequireDoc"
             :file-list="task.doc"
           >
@@ -226,24 +226,40 @@ export default {
         ]
       },
       rules: {
-        // name: [
-        //   {required: true, message: '请输入任务名称', trigger: 'blur'}
-        //   // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
-        // ],
-        // datetime: [
-        //   {
-        //     type: 'date',
-        //     required: true,
-        //     message: '请选择截止时间',
-        //     trigger: 'change'
-        //   }
-        // ],
-        // type: [
-        //   {required: true, message: '请选择业务类型', trigger: 'change'}
-        // ],
-        //desc: [{required: true, message: '请填写任务描述', trigger: 'blur'}],
-        // quotePrice: [{required: true, message: '请填写任务报价', trigger: 'blur'}],
-        //fixedPrice: [{required: true, message: '请填写任务定价', trigger: 'blur'}]
+        title: [
+          {required: true, message: '请输入任务名称', trigger: 'blur'},
+          {min: 5, max: 50, message: '任务名称长度在 5 到 50 个字符', trigger: 'blur'}
+        ],
+        type: [
+          {required: true, message: '业务类型不可为空'},
+        ],
+        desc: [{required: false, message: '请填写描述', trigger: 'blur'}],
+        //price: [{required: true, message: '请填写价格', trigger: 'blur'}],
+        quotePrice: [
+          {required: true, message: '预算不可为空', trigger: 'blur'},
+          {
+            validator: (rule, value, callback) => {
+              if (value <= 0) {
+                callback(new Error('请输入大于0的数'))
+              } else {
+                callback()
+              }
+            }, trigger: 'blur'
+          },
+        ],
+        resource: [
+          {required: true},
+          {
+            validator: (rule, value, callback) => {
+              if (value == 0 && this.task.institution.id == null) {
+                callback(new Error('定向发布至少要选择一个测评机构'))
+              } else {
+                callback()
+              }
+            }, trigger: 'change'
+          },
+        ],
+        datetime: [{required: true, message: '截止时间不可为空', trigger: 'blur'}],
       }
     }
   },
@@ -380,21 +396,28 @@ export default {
     },
     //更新任务信息
     updateTask () {
-      this.showLoading()
-      const newTask = {
-        name: this.task.title,
-        desc: this.task.description,
-        type: this.task.serviceType,
-        resource: this.task.resource,
-        location: this.task.location == null ? {} : getProvinceNameByProvinceCode(this.task.location.provinceCode, this.task.location.cityCode),
-        institution: this.task.institution.id,
-        datetime: this.task.datetime,
-        quotePrice: this.task.quotePrice,
-        fixedPrice: this.task.fixedPrice,
-        requirementFile: this.task.requireDocUrl
-      }
-      //console.log(newTask)
-      updateTask(this.projectId, this.taskId, newTask, this.updateTaskSuccess, this.updateTaskFail)
+      this.$refs['task'].validate(valid => {
+        if (valid) {
+          this.showLoading()
+          const newTask = {
+            name: this.task.title,
+            desc: this.task.description,
+            type: this.task.serviceType,
+            resource: this.task.resource,
+            location: this.task.location == null ? {} : getProvinceNameByProvinceCode(this.task.location.provinceCode, this.task.location.cityCode),
+            institution: this.task.institution.id,
+            datetime: this.task.datetime,
+            quotePrice: this.task.quotePrice,
+            fixedPrice: this.task.fixedPrice,
+            requirementFile: this.task.requireDocUrl
+          }
+          //console.log(newTask)
+          updateTask(this.projectId, this.taskId, newTask, this.updateTaskSuccess, this.updateTaskFail)
+        } else {
+          notify('error', '表单填写有误!')
+          return false
+        }
+      })
     },
     //更新任务信息成功时回调函数
     updateTaskSuccess (res) {

+ 60 - 58
src/components/task/TaskCreate.vue

@@ -155,22 +155,39 @@ export default {
       },
       rules: {
         name: [
-          {required: true, message: '请输入任务名称', trigger: 'blur'}
-          // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
+          {required: true, message: '请输入任务名称', trigger: 'blur'},
+          {min: 5, max: 50, message: '任务名称长度在 5 到 50 个字符', trigger: 'blur'}
         ],
-        datetime: [
+        type: [
+          {required: true, message: '业务类型不可为空'},
+        ],
+        desc: [{required: false, message: '请填写描述', trigger: 'blur'}],
+        //price: [{required: true, message: '请填写价格', trigger: 'blur'}],
+        quotePrice: [
+          {required: true, message: '预算不可为空', trigger: 'blur'},
           {
-            type: 'date',
-            required: true,
-            message: '请选择截止时间',
-            trigger: 'change'
-          }
+            validator: (rule, value, callback) => {
+              if (parseInt(value) < 0) {
+                callback(new Error('请输入不小于0的数'))
+              } else {
+                callback()
+              }
+            }, trigger: 'blur'
+          },
         ],
-        type: [
-          {required: true, message: '请选择业务类型', trigger: 'change'}
+        resource: [
+          {required: true},
+          {
+            validator: (rule, value, callback) => {
+              if (value == 0 && this.task.institution.id == null) {
+                callback(new Error('定向发布至少要选择一个测评机构'))
+              } else {
+                callback()
+              }
+            }, trigger: 'change'
+          },
         ],
-        desc: [{required: true, message: '请填写任务描述', trigger: 'blur'}],
-        quotePrice: [{required: true, message: '请填写任务报价', trigger: 'blur'}]
+        datetime: [{required: true, message: '截止时间不可为空', trigger: 'blur'}],
       }
     }
   },
@@ -230,50 +247,35 @@ export default {
       return provinceName + ' / ' + cityName
     },
     submitForm (formName) {
-      this.showLoading()
-      const newTask = {
-        name: this.task.name,
-        desc: this.task.desc,
-        type: this.task.type,
-        resource: this.task.resource,
-        location: getProvinceNameByProvinceCode(this.task.location.provinceCode, this.task.location.cityCode),
-        institution: this.task.institution.id,
-        datetime: this.task.datetime,
-        quotePrice: this.task.quotePrice,
-        fixedPrice: this.task.fixedPrice,
-        requirementFile: this.task.requireDocUrl
-      }
-      Http.post(Apis.TASK.CREATE_TASK.replace('{projectId}', this.projectId), newTask).then((res) => {
-        console.log(res)
-        this.hideLoading()
-        this.createTaskSuccess(res.crowdTaskVO.id)
-      }).catch((error) => {
-        console.log(error)
-        this.hideLoading()
-        notify('error', error.data)
+      this.$refs['task'].validate(valid => {
+        if (valid) {
+          this.showLoading()
+          const newTask = {
+            name: this.task.name,
+            desc: this.task.desc,
+            type: this.task.type,
+            resource: this.task.resource,
+            location: getProvinceNameByProvinceCode(this.task.location.provinceCode, this.task.location.cityCode),
+            institution: this.task.institution.id,
+            datetime: this.task.datetime,
+            quotePrice: this.task.quotePrice,
+            fixedPrice: this.task.fixedPrice,
+            requirementFile: this.task.requireDocUrl
+          }
+          Http.post(Apis.TASK.CREATE_TASK.replace('{projectId}', this.projectId), newTask).then((res) => {
+            console.log(res)
+            this.hideLoading()
+            this.createTaskSuccess(res.crowdTaskVO.id)
+          }).catch((error) => {
+            console.log(error)
+            this.hideLoading()
+            notify('error', error.data)
+          })
+        } else {
+          notify('error', '表单填写有误!')
+          return false
+        }
       })
-      // this.$refs[formName].validate(valid => {
-      //   if (valid) {
-      //     const newTask = {
-      //       name: this.task.title,
-      //       desc: this.task.description,
-      //       type: this.task.serviceType,
-      //       resource: this.task.resource,
-      //       location: this.task.location,
-      //       institution:this.task.institution,
-      //       datetime:this.task.datetime,
-      //       quotePrice: this.task.quotePrice,
-      //       fixedPrice: this.task.fixedPrice
-      //     }
-      //     Http.post(Apis.TASK.CREATE_TASK.replace('{projectId}', 'PROJECT_1'), this.task).then((res) => {
-      //       console.log(res)
-      //     })
-      //     //提交 task
-      //   } else {
-      //     console.log('error submit!!')
-      //     return false
-      //   }
-      // })
     },
     resetForm (formName) {
       this.$refs.addFormProvince.resetProviceCity()
@@ -336,12 +338,12 @@ export default {
       formData.append('file', param.file)
       Http.upload(Apis.FILE.REQUIREMENT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
         this.hideLoading()
-        notify('success','上传成功')
+        notify('success', '上传成功')
         this.task.requireDocUrl = res.data
         console.log(res.data)
-      }).catch((error)=>{
+      }).catch((error) => {
         this.hideLoading()
-        notify('error','上传失败:'+error.data)
+        notify('error', '上传失败:' + error.data)
       })
     },
     setServiceType () {