main-navbar-update-sign.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <el-dialog
  3. title="修改个人签名"
  4. :visible.sync="visible"
  5. :append-to-body="true">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
  7. <upload-component :title="'个人签名'" :accept="'.png,.jpeg,.jpg'" :file-obj-list="fileList" @uploadSuccess="uploadSuccess"/>
  8. </el-form>
  9. <span slot="footer">
  10. <el-button @click="visible = false">取消</el-button>
  11. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  12. </span>
  13. </el-dialog>
  14. </template>
  15. <script>
  16. import { getMyInfo } from '@/api/my'
  17. import UploadComponent from './modules/common/upload-component'
  18. export default {
  19. components: {
  20. UploadComponent
  21. },
  22. data () {
  23. return {
  24. visible: false,
  25. fileList: [],
  26. dataForm: {},
  27. dataRule: {
  28. }
  29. }
  30. },
  31. computed: {
  32. userName: {
  33. get () { return this.$store.state.user.name }
  34. },
  35. mainTabs: {
  36. get () { return this.$store.state.common.mainTabs },
  37. set (val) { this.$store.commit('common/updateMainTabs', val) }
  38. }
  39. },
  40. methods: {
  41. // 初始化
  42. init () {
  43. // 获取用户信息
  44. getMyInfo().then(({data}) => {
  45. if (data && data.code === '200' && data.data) {
  46. this.dataForm = data.data
  47. this.fileList = []
  48. data.data.attachList.forEach((item) => {
  49. this.fileList.push({
  50. name: item.fileName,
  51. url: item.url,
  52. id: item.url
  53. })
  54. })
  55. }
  56. })
  57. this.visible = true
  58. this.$nextTick(() => {
  59. this.$refs['dataForm'].resetFields()
  60. })
  61. },
  62. // 表单提交
  63. dataFormSubmit () {
  64. let fList = this.fileList
  65. if (!fList || fList.length === 0) {
  66. this.$message.error('请上传文件')
  67. return
  68. }
  69. if (fList.length > 1) {
  70. this.$message.error('只能上传一个附件')
  71. return
  72. } else {
  73. this.dataForm.attachList = []
  74. for (let i = 0; i < fList.length; i++) {
  75. this.dataForm.attachList.push({
  76. fileName: fList[i].name,
  77. url: fList[i].url
  78. })
  79. }
  80. }
  81. this.$refs['dataForm'].validate((valid) => {
  82. if (valid) {
  83. this.$http({
  84. url: this.$http.adornUrl('/biz-service/personal/setSignInfo'),
  85. method: 'post',
  86. data: this.dataForm
  87. }).then(({data}) => {
  88. if (data && data.code === '200') {
  89. this.$message({
  90. message: '操作成功',
  91. type: 'success',
  92. duration: 1500,
  93. onClose: () => {
  94. this.visible = false
  95. }
  96. })
  97. } else {
  98. this.$message.error(data.msg)
  99. }
  100. })
  101. }
  102. })
  103. },
  104. uploadSuccess (fileList) {
  105. this.fileList = fileList
  106. }
  107. }
  108. }
  109. </script>