TaskCreate.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <div class="create-container" v-loading="loading">
  3. <div class="title h1">创建任务</div>
  4. <div class="create-body">
  5. <el-form :model="task" :rules="rules" ref="task" label-width="120px" class="demo-task" style="margin:0 100px">
  6. <el-form-item label="任务名称" prop="name" style="width:700px;">
  7. <el-input size="small" v-model="task.name"></el-input>
  8. </el-form-item>
  9. <el-form-item label="任务描述" prop="desc" style="width:700px;">
  10. <el-input autosize type="textarea" style="width: 400px" v-model="task.desc"></el-input>
  11. </el-form-item>
  12. <el-form-item label="任务报价" prop="quotePrice" style="width:700px;">
  13. <el-input size="small" type="number" v-model="task.quotePrice">
  14. <template slot="append">¥</template>
  15. </el-input>
  16. </el-form-item>
  17. <!--<el-form-item type="number" label="任务定价" prop="fixedPrice">-->
  18. <!--<el-input v-model="task.fixedPrice">-->
  19. <!--<template slot="append">¥</template>-->
  20. <!--</el-input>-->
  21. <!--</el-form-item>-->
  22. <el-form-item label="测试类型" prop="type">
  23. <el-radio-group v-model="task.type" @change="handleTestTypeChange">
  24. <span v-for="(item,index) in serviceType" :key="index">
  25. <el-radio :label="item.code" name="type">{{item.name}}</el-radio>
  26. </span>
  27. </el-radio-group>
  28. </el-form-item>
  29. <el-form-item label="服务序列号" prop="endPoint" style="width:700px;" v-if="currType.type==1"
  30. >
  31. <el-input v-model="task.endPoint.serverCode" label="serverCode"></el-input>
  32. </el-form-item>
  33. <el-form-item label="任务可见性" prop="resource" style="width:700px;" v-if="currType.type==0">
  34. <el-tabs :tab-position="tabPosition" v-model="task.resource" style="width: 800px">
  35. <el-tab-pane :label="resourceType[0]" name="0">
  36. <!-- <el-radio-group v-model="task.institution">-->
  37. <!-- <el-radio-->
  38. <!-- :label="item"-->
  39. <!-- name="type"-->
  40. <!-- v-for="item,index in institutionArray"-->
  41. <!-- :key="index"-->
  42. <!-- >{{item.evaluationAgencyName}}-->
  43. <!-- </el-radio>-->
  44. <!-- </el-radio-group>-->
  45. <el-select v-model="task.institution" filterable placeholder="请选择">
  46. <el-option
  47. v-for="item in institutionArray"
  48. :key="item.id"
  49. :label="item.name"
  50. :value="item.id">
  51. </el-option>
  52. </el-select>
  53. <br/>
  54. <el-button type="primary" size="mini" @click="instituationEvaluate()">
  55. 机构评估
  56. </el-button>
  57. <el-button type="primary" size="mini" @click="peopleEvaluate()">
  58. 人员评估
  59. </el-button>
  60. </el-tab-pane>
  61. <!--<el-tab-pane :label="resourceType[1]" name="1">-->
  62. <!--<provincecity-->
  63. <!--ref="addFormProvince"-->
  64. <!--@selectChange="locationChange"-->
  65. <!--:provinceCode="task.location.provinceCode"-->
  66. <!--:cityCode="task.location.cityCode"-->
  67. <!--&gt;</provincecity>-->
  68. <!--</el-tab-pane>-->
  69. <el-tab-pane :label="resourceType[2]" name="2"></el-tab-pane>
  70. </el-tabs>
  71. </el-form-item>
  72. <el-form-item label="任务可见性" prop="resource" style="width:700px;"
  73. v-if="currType.type ==1"
  74. required>
  75. <el-tabs :tab-position="tabPosition" v-model="task.resource" value='2' style="width: 800px">
  76. <el-tab-pane :label="resourceType[2]" name="2"></el-tab-pane>
  77. </el-tabs>
  78. </el-form-item>
  79. <el-form-item label="领取人数" prop="contactPhone" v-if="task.resource !== '0' && currType.type===0">
  80. <el-input-number v-model="task.participantCount" :min="1" :max="1000" label="领取人数"></el-input-number>
  81. </el-form-item>
  82. <el-form-item label="领取人数" prop="contactPhone" v-if="task.resource !== '0' && currType.type===1">
  83. <el-input-number v-model="task.participantCount" :min="2" :max="1000" label="领取人数"></el-input-number>
  84. </el-form-item>
  85. <el-form-item label="Go平台" prop="goPlatform">
  86. <el-radio-group v-model="task.goPlatform">
  87. <el-radio :label="0">不使用</el-radio>
  88. <el-radio :label="1">使用</el-radio>
  89. </el-radio-group>
  90. </el-form-item>
  91. <el-form-item label="需求文档" prop="doc">
  92. <el-upload
  93. drag
  94. style="width: 400px"
  95. class="upload-demo"
  96. action=""
  97. :on-remove="handleRemove"
  98. :before-remove="beforeRemove"
  99. :limit="1"
  100. :on-exceed="handleExceed"
  101. :before-upload="beforeFileUpload"
  102. :http-request="uploadRequireDoc"
  103. :file-list="task.doc"
  104. >
  105. <i class="el-icon-upload"></i>
  106. <div class="el-upload__text">
  107. 将文件拖到此处,或
  108. <em>点击上传</em>
  109. </div>
  110. </el-upload>
  111. </el-form-item>
  112. <el-form-item size="small" label="任务截止时间" prop="datetime">
  113. <div class="block">
  114. <el-date-picker
  115. v-model="task.datetime"
  116. type="datetime"
  117. placeholder="选择截止时间"
  118. align="right"
  119. :picker-options="pickerOptions"
  120. ></el-date-picker>
  121. </div>
  122. </el-form-item>
  123. <el-form-item>
  124. <div class="btn btn-medium btn-info" @click="submitForm('task')">立即创建</div>
  125. <!--<div class="btn btn-medium" @click="resetForm('task')">重置</div>-->
  126. <div class="btn btn-medium" @click="cancelCreate('task')">取消</div>
  127. </el-form-item>
  128. </el-form>
  129. </div>
  130. </div>
  131. </template>
  132. <script>
  133. import provincecity from '@/components/commons/ProvinceCity'
  134. import provinceCityJSON from '@/constants/provinceCity.json'
  135. import Http from '@/js/http.js'
  136. import Apis from '@/js/api.js'
  137. import ResourceType from '@/constants/enum/resource-type.js'
  138. import {notify} from '@/constants/index'
  139. import {getAllInstitutions, getAllServiceTypes, getProvinceNameByProvinceCode, storageGet} from '@/js/index'
  140. export default {
  141. name: 'Task',
  142. components: {
  143. provincecity
  144. },
  145. data() {
  146. return {
  147. currType: {},
  148. user: {},
  149. projectId: 0,
  150. institutionArray: [],
  151. tabPosition: 'top',
  152. resourceType: ResourceType,
  153. loading: false,
  154. serviceType: [],
  155. task: {
  156. name: '',
  157. desc: '',
  158. type: '',
  159. resource: '', //如果是广场不用管Location和institution ,定向看institution,区域看location
  160. // location: {provinceCode: '3200', cityCode: '3201'},
  161. institution: null,
  162. datetime: '',
  163. quotePrice: '',
  164. fixedPrice: '',
  165. doc: [],
  166. requireDocUrl: '',
  167. participantCount: 1,
  168. goPlatform: 0,
  169. endPoint: {
  170. serverCode: '',
  171. }
  172. },
  173. pickerOptions: {
  174. shortcuts: [
  175. {
  176. text: '今天',
  177. onClick(picker) {
  178. picker.$emit('pick', new Date())
  179. }
  180. },
  181. {
  182. text: '昨天',
  183. onClick(picker) {
  184. const date = new Date()
  185. date.setTime(date.getTime() - 3600 * 1000 * 24)
  186. picker.$emit('pick', date)
  187. }
  188. },
  189. {
  190. text: '一周前',
  191. onClick(picker) {
  192. const date = new Date()
  193. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
  194. picker.$emit('pick', date)
  195. }
  196. }
  197. ]
  198. },
  199. rules: {
  200. name: [
  201. {required: true, message: '请输入任务名称', trigger: 'blur'},
  202. {min: 5, max: 50, message: '任务名称长度在 5 到 50 个字符', trigger: 'blur'}
  203. ],
  204. type: [
  205. {required: true, message: '测试类型不可为空'},
  206. ],
  207. desc: [{required: true, message: '请填写描述', trigger: 'blur'}],
  208. //price: [{required: true, message: '请填写价格', trigger: 'blur'}],
  209. quotePrice: [
  210. {required: true, message: '预算不可为空', trigger: 'blur'},
  211. {
  212. validator: (rule, value, callback) => {
  213. if (parseInt(value) < 0) {
  214. callback(new Error('请输入不小于0的数'))
  215. } else {
  216. callback()
  217. }
  218. }, trigger: 'blur'
  219. },
  220. ],
  221. resource: [
  222. {required: true},
  223. {
  224. validator: (rule, value, callback) => {
  225. if (value == 0 && !this.task.institution) {
  226. callback(new Error('定向发布至少要选择一个测评机构'))
  227. } else {
  228. callback()
  229. }
  230. }, trigger: 'change'
  231. },
  232. ],
  233. endPoint: [
  234. {
  235. validator: (rule, value, callback) => {
  236. if (this.currType.type === 1 && this.task.endPoint.serverCode === '') {
  237. callback(new Error('请填写对应得服务序列号'))
  238. } else {
  239. callback()
  240. }
  241. }, trigger: ['change','blur']
  242. },
  243. ],
  244. datetime: [{required: true, message: '截止时间不可为空', trigger: 'blur'}],
  245. }
  246. }
  247. },
  248. watch: {
  249. serviceType(val) {
  250. this.serviceType = val
  251. },
  252. institution(val) {
  253. this.institution = val
  254. },
  255. // 'task.institution' () {
  256. // if (this.task.institution) {
  257. // this.$refs.addFormProvince.resetProviceCity()
  258. // this.task.location = {provinceCode: '', cityCode: ''}
  259. // }
  260. // },
  261. // 'task.location' () {
  262. // if (this.task.location.provinceCode || this.task.location.cityCode) {
  263. // this.task.institution = ''
  264. // }
  265. // },
  266. // 'task.resource' () {
  267. // if (this.task.resource == '广场') {
  268. // this.$refs.addFormProvince.resetProviceCity()
  269. // this.task.institution = ''
  270. // this.task.location = {provinceCode: '', cityCode: ''}
  271. // }
  272. // },
  273. deep: true
  274. },
  275. mounted() {
  276. this.$nextTick(() => {
  277. this.init()
  278. })
  279. },
  280. methods: {
  281. instituationEvaluate(){
  282. let turl ='http://8.134.39.104:8088/#/enter/';
  283. window.open(turl,'_blank');
  284. },
  285. peopleEvaluate(){
  286. let turl ='http://8.134.39.104:7477/#/evaluate/evaevaall';
  287. window.open(turl,'_blank');
  288. },
  289. handleTestTypeChange(val) {
  290. let type = this.serviceType.filter((item) => {
  291. return item.code === val;
  292. });
  293. this.currType = type[0] ? type[0] : {};
  294. if (this.currType.type === 0) {
  295. this.$refs.task.clearValidate('endPoint');
  296. }else{
  297. this.task.resource = '2'
  298. }
  299. },
  300. init() {
  301. this.projectId = this.$route.params.projectId
  302. this.setServiceType()
  303. this.setInstitutions()
  304. this.setUserInfo()
  305. },
  306. updateLocation(location) {
  307. var provinceName = ''
  308. var cityName = ''
  309. for (var item of provinceCityJSON.provinces) {
  310. if (item.code === location.provinceCode) {
  311. provinceName = item.name
  312. for (var city of item.cities) {
  313. if (city.code === location.cityCode) {
  314. cityName = city.name
  315. break
  316. }
  317. }
  318. }
  319. }
  320. return provinceName + ' / ' + cityName
  321. },
  322. submitForm(formName) {
  323. this.$refs['task'].validate(valid => {
  324. if (valid) {
  325. this.showLoading()
  326. const newTask = {
  327. name: this.task.name,
  328. desc: this.task.desc,
  329. type: this.task.type,
  330. resource: this.task.resource,
  331. // location: this.task.resource == '0' ? getProvinceNameByProvinceCode(this.task.location.provinceCode, this.task.location.cityCode):null,
  332. institution: this.task.resource === '0' ? this.task.institution : null,
  333. datetime: this.task.datetime,
  334. quotePrice: this.task.quotePrice,
  335. fixedPrice: this.task.fixedPrice,
  336. requirementFile: this.task.requireDocUrl,
  337. participantCount: this.task.participantCount,
  338. goPlatform: this.task.goPlatform,
  339. endPoint: this.task.endPoint
  340. }
  341. Http.post(Apis.TASK.CREATE_TASK.replace('{projectId}', this.projectId), newTask).then((res) => {
  342. console.log(res)
  343. this.hideLoading()
  344. this.createTaskSuccess(res.crowdTaskVO.id)
  345. }).catch((error) => {
  346. console.log(error)
  347. this.hideLoading()
  348. notify('error', error.data)
  349. })
  350. } else {
  351. notify('error', '表单填写有误!')
  352. return false
  353. }
  354. })
  355. },
  356. resetForm(formName) {
  357. this.$refs.addFormProvince.resetProviceCity()
  358. this.$refs[formName].resetFields()
  359. this.task.name = ''
  360. this.task.desc = ''
  361. this.task.type = ''
  362. this.task.resource = '广场'; //如果是广场不用管Location和institution ,定向看institution,区域看location
  363. this.task.location = {provinceCode: '', cityCode: ''}
  364. this.task.institution = null
  365. this.task.datetime = ''
  366. this.task.participantCount = 1
  367. this.task.goPlatform = 0
  368. },
  369. locationChange(provinceId, cityId) {
  370. if (provinceId || cityId) {
  371. this.task.location = {provinceCode: provinceId, cityCode: cityId}
  372. }
  373. },
  374. cancelCreate() {
  375. if (window.history.length <= 1) {
  376. this.$router.push({path: '/'})
  377. return false
  378. } else {
  379. this.$router.go(-1)
  380. }
  381. },
  382. handleRemove(file, fileList) {
  383. console.log(file, fileList)
  384. },
  385. handleExceed(files, fileList) {
  386. this.$message.warning(
  387. `当前限制选择 1 个文件,本次选择了 ${
  388. files.length
  389. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  390. )
  391. },
  392. beforeRemove(file, fileList) {
  393. //return this.$confirm(`确定移除 ${file.name}?`)
  394. },
  395. // RAR文件获取不到ContentType
  396. beforeFileUpload(file) {
  397. const isPDF = file.type === 'application/pdf'
  398. const isDOC = file.type === 'application/msword'
  399. const isDOCX = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  400. const isEXCEL = file.type === 'application/vnd.ms-excel'
  401. const isXLS = file.type === 'application/x-xls'
  402. const isTXT = file.type === 'text/plain'
  403. const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  404. const isZIP = file.type === 'application/x-zip-compressed'
  405. //console.log(file)
  406. if (!(isDOC || isDOCX || isEXCEL || isPDF || isTXT || isXLS || isXLSX || isZIP)) {
  407. this.$message.error('上传文件只能是 PDF、DOC、DOCX、XLS、TXT、XLSX、ZIP!')
  408. }
  409. return isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX || isZIP
  410. },
  411. uploadRequireDoc(param) {
  412. this.showLoading()
  413. const formData = new FormData()
  414. let config = {
  415. //添加请求头
  416. headers: {'Content-Type': 'multipart/form-data'},
  417. }
  418. formData.append('file', param.file)
  419. Http.upload(Apis.FILE.REQUIREMENT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  420. this.hideLoading()
  421. notify('success', '上传成功')
  422. this.task.requireDocUrl = res.data
  423. console.log(res.data)
  424. }).catch((error) => {
  425. this.hideLoading()
  426. notify('error', '上传失败:' + error.data)
  427. })
  428. },
  429. setServiceType() {
  430. getAllServiceTypes().then((res) => {
  431. this.serviceType = res
  432. })
  433. },
  434. setInstitutions() {
  435. getAllInstitutions().then((res) => {
  436. this.institutionArray = res
  437. }).catch((error) => {
  438. notify('error', '测评机构加载失败')
  439. })
  440. },
  441. setUserInfo() {
  442. this.user = storageGet('user')
  443. },
  444. createTaskSuccess(taskId) {
  445. this.$alert('任务创建成功', '创建成功', {
  446. confirmButtonText: '确定',
  447. callback: action => {
  448. this.$router.push({
  449. name: 'Task',
  450. params: {projectId: this.projectId, taskId: taskId}
  451. })
  452. }
  453. })
  454. },
  455. showLoading() {
  456. this.loading = true
  457. },
  458. hideLoading() {
  459. this.loading = false
  460. }
  461. }
  462. }
  463. </script>
  464. <style lang="scss" scoped>
  465. .el-radio {
  466. margin: 10px 20px 10px 0;
  467. }
  468. .el-input {
  469. width: 400px;
  470. }
  471. .el-form-item /deep/ .el-tabs__content {
  472. /*max-height: 120px !important;*/
  473. overflow: auto;
  474. }
  475. </style>