TaskCreate.vue 17 KB

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