edit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="hui-flex hui-dialog">
  3. <div class="hui-flex-box hui-dialog-content">
  4. <el-form ref="projectForm" label-position="top" :model="projectForm">
  5. <el-form-item label="项目名称" prop="name" :rules="[{required: true, message: '请输入项目名称'}]">
  6. <el-input type="text" v-model="projectForm.name" placeholder="请输入项目名称"></el-input>
  7. </el-form-item>
  8. <el-form-item label="项目区域" prop="address" :rules="[{required: true, message: '请选择项目区域'}]">
  9. <city v-model="projectForm.address"></city>
  10. </el-form-item>
  11. <el-form-item label="具体地点">
  12. <el-input type="text" v-model="specific" placeholder="请输入具体地点">
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item label="项目描述" class="hui-textarea">
  16. <el-input type="textarea" v-model="projectForm.comment" placeholder="请输入项目描述" resize="none">
  17. </el-input>
  18. </el-form-item>
  19. <el-form-item label="项目配图" class="hui-textarea">
  20. <upload ref="upload" :list="responsibility" type="insert"></upload>
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. <div class="hui-dialog-submit">
  25. <el-button size="medium" @click="$emit('callback')">取 消</el-button>
  26. <el-button size="medium" type="primary" @click="submit">保 存</el-button>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import {
  32. insertProject,
  33. getProjectDetailById,
  34. updateProject
  35. } from '@/httpApi/work'
  36. import upload from '@/components/common/upload'
  37. import city from '@/components/common/city'
  38. export default {
  39. props: ['isUpdate', 'detailId'],
  40. data() {
  41. return {
  42. projectForm: {
  43. name: '', //项目名称
  44. address: [],
  45. comment: '',
  46. data: '',
  47. organizationId: '',
  48. picture: '',
  49. tagId: ''
  50. },
  51. specific: '',
  52. responsibility: []
  53. }
  54. },
  55. created() {
  56. this.projectForm['organizationId'] = this.$store.getters.user.organization.id;
  57. if (this.isUpdate) {
  58. console.log(this.detailId);
  59. getProjectDetailById(this.detailId).then(res => {
  60. if (res.state) {
  61. this.projectForm = res.data;
  62. this.projectForm.address = JSON.parse(this.projectForm.address);
  63. if (this.projectForm.picture) this.responsibility = JSON.parse(this.projectForm.picture);
  64. if (this.projectForm.data) {
  65. let data = JSON.parse(this.projectForm.data);
  66. this.specific = data.specific;
  67. }
  68. }
  69. })
  70. }
  71. },
  72. methods: {
  73. submit() {
  74. this.$refs.projectForm.validate((valid) => {
  75. if (valid) {
  76. let postData = JSON.parse(JSON.stringify(this.projectForm));
  77. postData.data = JSON.stringify({
  78. specific: this.specific
  79. });
  80. postData['picture'] = JSON.stringify(this.$refs.upload.fileList);
  81. postData['address'] = JSON.stringify(this.projectForm.address);
  82. if (this.isUpdate) {
  83. updateProject(postData).then(this.successFunc);
  84. } else {
  85. insertProject(postData).then(this.successFunc);
  86. }
  87. } else {
  88. return false;
  89. }
  90. });
  91. },
  92. successFunc(res) {
  93. if (res.state) {
  94. this.$message.success('操作成功');
  95. this.$emit('callback', 'init');
  96. }
  97. }
  98. },
  99. components: {
  100. city,
  101. upload
  102. },
  103. }
  104. </script>
  105. <style lang="scss"></style>