newPolicy.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <el-dialog
  3. title="政策信息"
  4. :visible.sync="dialogVisible"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. @close="handleClose"
  8. width="1200px"
  9. height="800px"
  10. >
  11. <el-form
  12. ref="baseForm"
  13. class="base-form"
  14. label-position="right"
  15. label-width="130px"
  16. :model="baseForm"
  17. :rules="rules"
  18. size="small"
  19. >
  20. <el-row>
  21. <el-form-item label="标题:" prop="subsidypolicyTitle">
  22. <el-input
  23. placeholder="请输入"
  24. maxlength="50"
  25. v-model="baseForm.subsidypolicyTitle">
  26. </el-input>
  27. </el-form-item>
  28. </el-row>
  29. <el-row>
  30. <el-form-item label="图片:" prop="src">
  31. <el-upload
  32. ref="uploader"
  33. class="avatar-uploader"
  34. :action="uploadUrl"
  35. :show-file-list="false"
  36. :on-success="handleAvatarSuccess"
  37. :on-error="handleUploadError"
  38. name="file"
  39. :headers="headers"
  40. :before-upload="beforeAvatarUpload">
  41. <img v-if="baseForm.src" :src="baseForm.src" class="avatar">
  42. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  43. </el-upload>
  44. </el-form-item>
  45. </el-row>
  46. <el-row style="height: 200px;">
  47. <el-form-item label="内容:" prop="subsidypolicyContent">
  48. <Editor
  49. style="height: 150px"
  50. v-model="baseForm.subsidypolicyContent"
  51. :mode="mode"
  52. @onCreated="onCreated"
  53. />
  54. </el-form-item>
  55. </el-row>
  56. </el-form>
  57. <div style="text-align: right;margin-top:20px;" class="button-container">
  58. <el-button type="info" plain @click="resetForm('baseForm')"
  59. >取消</el-button
  60. >
  61. <el-button
  62. type="primary"
  63. style="margin-left:16px;"
  64. @click="submitForm('baseForm')"
  65. :disabled="dialogSubmitLoading"
  66. :loading="dialogSubmitLoading"
  67. >确定</el-button
  68. >
  69. </div>
  70. </el-dialog>
  71. </template>
  72. <script>
  73. import { addSubsidyPolicy, editSubsidyPolicy } from '@/api/subsidypolicy/index.js'
  74. import { getToken } from "@/utils/auth";
  75. import { Message } from 'element-ui'
  76. import { assign } from 'lodash-es';
  77. export default {
  78. name:'newPolicy',
  79. props: {
  80. data: {
  81. default() {
  82. return {};
  83. }
  84. },
  85. visible: {
  86. type: Boolean,
  87. default: false
  88. },
  89. editRow: {
  90. type: Object,
  91. default: () => { }
  92. },
  93. areaId: {
  94. type: String
  95. },
  96. policyType: {
  97. type: String
  98. }
  99. },
  100. data() {
  101. return {
  102. uploadUrl: process.env.VUE_APP_BASE_API + "/wpr/subsidypolicy/preview/upload", // 上传的图片服务器地址
  103. headers: {
  104. Authorization: "Bearer " + getToken()
  105. },
  106. textarea: '',
  107. editor: null,
  108. decisionContent:"",
  109. mode: 'default',
  110. dialogSubmitLoading: false,
  111. dialogVisible: false,
  112. src: '',
  113. baseForm: {
  114. subsidypolicyTitle: '',
  115. src: '',
  116. subsidypolicyContent: ''
  117. },
  118. resId: '',
  119. hasFetched: false,
  120. rules: {
  121. subsidypolicyTitle: [
  122. { required: true, message: '请输入您的标题', trigger: 'blur' }
  123. ],
  124. src: [
  125. { required: true, message: '请选择您的图片', trigger: 'change' }
  126. ],
  127. subsidypolicyContent: [
  128. { required: true, message: '请输入内容', trigger: 'change' }
  129. ]
  130. }
  131. };
  132. },
  133. watch: {
  134. visible(val) {
  135. if (val !== this.dialogVisible) {
  136. this.dialogVisible = val;
  137. if (val) {
  138. assign(this.baseForm, this.data);
  139. }
  140. }
  141. },
  142. data: {
  143. deep: true,
  144. handler(val) {
  145. assign(this.baseForm, val);
  146. }
  147. },
  148. editRow: {
  149. handler(val) {
  150. this.baseForm = { ...this.editRow }
  151. },
  152. deep: true
  153. },
  154. baseForm: {
  155. handler(val) {
  156. const { src, subsidypolicyContent } = val
  157. const uploader = this.$refs.uploader
  158. const errorUploadText = uploader
  159. console.log(errorUploadText,'uploaderuploaderuploader')
  160. },
  161. deep: true
  162. }
  163. },
  164. methods: {
  165. onCreated(editor) {
  166. this.editor = Object.seal(editor)
  167. },
  168. handleAvatarSuccess(res, file) {
  169. this.resId = res?.data?.resId
  170. this.baseForm.src = URL.createObjectURL(file.raw);
  171. },
  172. handleUploadError() {
  173. Message.error("图片插入失败");
  174. },
  175. beforeAvatarUpload(file) {
  176. const isJPG = file.type === 'image/jpeg';
  177. const isLt2M = file.size / 1024 / 1024 < 2;
  178. if (!isLt2M) {
  179. Message({
  180. type: 'error',
  181. message: '上传头像图片大小不能超过 2MB!'
  182. })
  183. }
  184. return isJPG && isLt2M;
  185. },
  186. resetForm() {
  187. this.dialogVisible = false;
  188. this.resetFormData()
  189. },
  190. resetFormData() {
  191. this.baseForm = {
  192. subsidypolicyTitle: '',
  193. src: '',
  194. subsidypolicyContent: ''
  195. };
  196. },
  197. async addSubsidyPolicyHandler() {
  198. if (this.policyType == 'add') {
  199. const params = {
  200. areaIds: this.areaId,
  201. resIds: this.resId,
  202. subsidypolicyContent: this.baseForm.subsidypolicyContent,
  203. subsidypolicyTitle: this.baseForm.subsidypolicyTitle
  204. }
  205. await addSubsidyPolicy(params)
  206. } else {
  207. const params = {
  208. areaIds: this.areaId,
  209. resIds: this.resId,
  210. subsidypolicyContent: this.baseForm.subsidypolicyContent,
  211. subsidypolicyTitle: this.baseForm.subsidypolicyTitle,
  212. subsidypolicyId: this.baseForm.subsidypolicyId
  213. }
  214. await editSubsidyPolicy(params)
  215. }
  216. this.handleClose()
  217. this.$emit('addSuccess')
  218. },
  219. submitForm(formName) {
  220. this.$refs[formName].validate((valid) => {
  221. valid && this.addSubsidyPolicyHandler()
  222. })
  223. },
  224. handleClose() {
  225. this.$emit('update:visible', false);
  226. this.resetForm('baseForm');
  227. },
  228. }
  229. };
  230. </script>
  231. <style lang="scss" scoped>
  232. ::v-deep.avatar-uploader .el-upload {
  233. border: 1px dashed #d9d9d9;
  234. border-radius: 6px;
  235. cursor: pointer;
  236. position: relative;
  237. overflow: hidden;
  238. }
  239. ::v-deep.avatar-uploader .el-upload:hover {
  240. border-color: #409EFF;
  241. }
  242. ::v-deep.avatar-uploader-icon {
  243. font-size: 28px;
  244. color: #8c939d;
  245. width: 100px;
  246. height: 100px;
  247. line-height: 100px;
  248. text-align: center;
  249. }
  250. ::v-deep.avatar {
  251. width: 100px;
  252. height: 100px;
  253. display: block;
  254. }
  255. .input-number {
  256. width: 100%;
  257. }
  258. .base-form {
  259. max-height: 70vh;
  260. overflow-y: auto;
  261. overflow-x: hidden;
  262. padding: 0 20px;
  263. }
  264. </style>
  265. <style lang="css" scoped>
  266. ::v-deep .el-dialog__header {
  267. border-bottom: 1px solid #ebeef5;
  268. }
  269. </style>