AgencyAuthentication.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <div class="create-container">
  3. <div class="create-body" v-loading="loading" style="width: 100%">
  4. <div class="title">测评机构认证</div>
  5. <el-form :model="authentication" :rules="rules" ref="authentication" label-width="12%" class="demo-report">
  6. <el-form-item prop="agencyPhoto" label="机构logo">
  7. <el-upload
  8. v-if="isModifyMode"
  9. class="avatar-uploader"
  10. action=""
  11. :show-file-list="false"
  12. :http-request="uploadFile"
  13. :before-upload="beforeFileUpload">
  14. <img v-if="authentication.agencyPhoto" :src="authentication.agencyPhoto" class="avatar">
  15. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  16. </el-upload>
  17. <span v-if="!isModifyMode">
  18. <el-image
  19. style="width: 100px;"
  20. :src="authentication.agencyPhoto"
  21. fit="scale-down"></el-image>
  22. </span>
  23. </el-form-item>
  24. <el-form-item label="机构名称" prop="evaluationAgencyName">
  25. <el-input v-if="isModifyMode" v-model="authentication.evaluationAgencyName"></el-input>
  26. <span v-if="!isModifyMode">{{authentication.evaluationAgencyName}}</span>
  27. </el-form-item>
  28. <!--<el-form-item label="机构电话" prop="name">-->
  29. <!--<el-input v-if="isModifyMode" v-model="authentication.mobile"></el-input>-->
  30. <!--&lt;!&ndash;<span v-if="!isModifyMode">{{authentication.name}}</span>&ndash;&gt;-->
  31. <!--</el-form-item>-->
  32. <el-form-item v-if="!isModifyMode" label="认证状态" prop="name">
  33. <el-tag :type="authentication.authStatus.style">{{authentication.authStatus.text}}</el-tag>
  34. </el-form-item>
  35. <el-form-item v-if="!isModifyMode && authentication.authStatus.text == '认证失败'" label="失败原因" prop="name">
  36. <el-link v-if="authentication.explain!=null&&authentication.explain!=''" type="danger" disabled>
  37. {{authentication.explain}}
  38. </el-link>
  39. <el-link v-if="authentication.explain==null || authentication.explain==''" type="danger" disabled>管理员未填写
  40. </el-link>
  41. </el-form-item>
  42. <el-form-item label="对公账户" prop="bankAccount">
  43. <el-input v-if="isModifyMode" v-model="authentication.bankAccount"></el-input>
  44. <span v-if="!isModifyMode">{{authentication.bankAccount}}</span>
  45. </el-form-item>
  46. <el-form-item label="地址" prop="address">
  47. <el-input v-if="isModifyMode" v-model="authentication.address"></el-input>
  48. <span v-if="!isModifyMode">{{authentication.address}}</span>
  49. </el-form-item>
  50. <el-form-item label="测评机构能力" prop="evaluationAgencyAbilityList">
  51. <el-checkbox-group v-if="isModifyMode" v-model="authentication.evaluationAgencyAbilityList">
  52. <span v-for="(item,index) in serviceTypes" :key="index">
  53. <el-checkbox :label="item" name="type">{{item}}&nbsp;&nbsp;&nbsp;&nbsp;</el-checkbox>
  54. </span>
  55. </el-checkbox-group>
  56. <span v-if="!isModifyMode" v-for="(item,index) in authentication.evaluationAgencyAbilityList"
  57. :key="index"><span class="badge">{{item}}</span></span>
  58. </el-form-item>
  59. <el-form-item label="测评机构资源" prop="evaluationAgencyResourceList">
  60. <span v-if="isModifyMode" v-for="item in authentication.evaluationAgencyResourceList" :key="item.id"
  61. style="width: 2000px">
  62. 资源类型:&nbsp;<el-select v-model="item.type" placeholder="请选择" style="width: 15%;margin-bottom: 10px"
  63. :value="item.type">
  64. <el-option
  65. v-for="item in resourceTypes"
  66. :key="item"
  67. :label="item"
  68. :value="item">
  69. </el-option>
  70. </el-select>
  71. 资源名称:&nbsp;<el-input v-model="item.name" style="width: 15%"></el-input>
  72. 总量:&nbsp;<el-input-number :min="0" v-model="item.totalNum" style="width: 15%"></el-input-number>
  73. 可用数量:&nbsp;<el-input-number :min="0" :max="item.totalNum" style="width: 15%"
  74. v-model="item.availableNum"></el-input-number>
  75. <el-button type="danger" icon="el-icon-delete" @click="removeAgencyResource(item.id)"></el-button>
  76. <br/>
  77. </span>
  78. <el-button v-if="isModifyMode" type="primary" icon="el-icon-circle-plus" plain size="small"
  79. @click="addAgencyResource">添加资源
  80. </el-button>
  81. <span v-if="!isModifyMode" v-for="item in authentication.evaluationAgencyResourceList" :key="item.id">
  82. 资源类型:{{item.type}};&nbsp;&nbsp;资源名称:{{item.name}};&nbsp;&nbsp;资源总量:{{item.totalNum}};&nbsp;&nbsp;可用资源:{{item.availableNum}}<br/>
  83. </span>
  84. </el-form-item>
  85. <el-form-item v-if="!isModifyMode">
  86. <div class="btn btn-medium btn-info" @click="modifyInfo()">修改</div>
  87. </el-form-item>
  88. <el-form-item v-if="isModifyMode">
  89. <div class="btn btn-primary btn-info" @click="updateAuthInfo()">提交</div>
  90. <div class="btn btn-primary" @click="cancelModify()">取消</div>
  91. </el-form-item>
  92. </el-form>
  93. </div>
  94. </div>
  95. </template>
  96. <script>
  97. import Http from '@/js/http'
  98. import Apis from '@/js/api'
  99. import {notify} from '@/constants/index'
  100. import {
  101. defaultValue,
  102. getAllAgencyResourceTypes,
  103. getAllServiceTypes,
  104. getCurrentAgencyAuthInfo,
  105. getCurrentAuthenInfo,
  106. getCurrentUser,
  107. getRolesPermissions,
  108. storageGet,
  109. storageSave,
  110. updateAgencyAuthInfo
  111. } from '@/js/index'
  112. export default {
  113. name: 'AgencyAuthentication',
  114. data () {
  115. return {
  116. userId: 0,
  117. user: {},
  118. loading: false,
  119. isModifyMode: false,
  120. resourceTypes: [],
  121. serviceTypes: [],
  122. authentication: {
  123. mobile: '',
  124. evaluationAgencyName: '',
  125. bankAccount: '',
  126. address: '',
  127. evaluationAgencyAbilityList: [],
  128. evaluationAgencyResourceList: [],
  129. photo: [],
  130. authStatus: {},
  131. agencyPhoto: defaultValue.image,
  132. explain: ''
  133. },
  134. rules: {
  135. // agencyPhoto: [
  136. // {required: true, message: '请输入机构名称', trigger: 'blur'},
  137. // { min: 3, max: 50, message: "机构名称长度在 3 到 50 个字符", trigger: "blur" }
  138. // ],
  139. evaluationAgencyName: [
  140. {required: true, message: '请输入机构名称', trigger: 'blur'},
  141. {min: 3, max: 50, message: '机构名称长度在 3 到 50 个字符', trigger: 'blur'}
  142. ],
  143. bankAccount: [
  144. {required: true, message: '请输入银行卡账户', trigger: 'blur'},
  145. {
  146. validator: (rule, value, callback) => {
  147. if (!this.checkNumber(value)) {
  148. callback(new Error('银行卡账户输入有误'))
  149. } else {
  150. callback()
  151. }
  152. }, trigger: 'blur'
  153. },
  154. ],
  155. address: [
  156. {required: true, message: '请输入地址', trigger: 'blur'}
  157. ],
  158. evaluationAgencyAbilityList: [
  159. {
  160. type: 'array',
  161. required: true,
  162. message: '请至少选择一种服务类型',
  163. trigger: 'change'
  164. }
  165. ],
  166. evaluationAgencyResourceList: [
  167. {
  168. validator: (rule, value, callback) => {
  169. var isError = false
  170. if (value == null || value.length == 0) {
  171. callback(new Error('机构资源不可为空'))
  172. } else {
  173. for (var i = 0; i < value.length; i++) {
  174. if (value[i].name == '') {
  175. isError = true
  176. break
  177. }
  178. }
  179. }
  180. if (isError) {
  181. callback(new Error('资源名称不可为空'))
  182. } else {
  183. callback()
  184. }
  185. }, trigger: 'blur'
  186. },
  187. ],
  188. }
  189. }
  190. },
  191. mounted () {
  192. this.$nextTick(() => {
  193. this.init()
  194. })
  195. },
  196. methods: {
  197. //初始化数据
  198. init () {
  199. this.setServiceTypes()
  200. this.setResourceTypes()
  201. this.setUserInfo()
  202. this.getAuthInfo()
  203. },
  204. //加载数据
  205. getAuthInfo () {
  206. this.showLoading()
  207. getCurrentAgencyAuthInfo(this.user.userVO.id, this.getAuthInfoSuccess, this.getAuthInfoFail)
  208. },
  209. getAuthInfoSuccess (res) {
  210. this.hideLoading()
  211. this.authentication.agencyPhoto = res.agencyPhoto == null ? defaultValue.image : res.agencyPhoto
  212. this.authentication.evaluationAgencyName = res.evaluationAgencyName == null ? '暂未填写' : res.evaluationAgencyName
  213. this.authentication.evaluationAgencyAbilityList = res.evaluationAgencyAbilityList == null ? [] : res.evaluationAgencyAbilityList
  214. this.authentication.evaluationAgencyResourceList = res.evaluationAgencyResourceList == null ? [] : res.evaluationAgencyResourceList
  215. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  216. this.authentication.address = res.address == null ? '暂未填写' : res.address
  217. this.authentication.authStatus = res.authStatus
  218. this.authentication.explain = res.explain
  219. console.log(this.authentication)
  220. },
  221. getAuthInfoFail (error) {
  222. this.hideLoading()
  223. notify('error', '加载认证信息失败:' + error.data)
  224. },
  225. //表单进入可编辑状态,可修改表单,不再使用
  226. modifyInfo () {
  227. this.isModifyMode = true
  228. },
  229. //提交认证信息
  230. updateAuthInfo () {
  231. //this.isModifyMode = false
  232. this.$refs['authentication'].validate(valid => {
  233. if (valid) {
  234. this.showLoading()
  235. const newAuthentication = {
  236. userId: this.user.userVO.id,
  237. evaluationAgencyName: this.authentication.evaluationAgencyName,
  238. bankAccount: this.authentication.bankAccount,
  239. address: this.authentication.address,
  240. evaluationAgencyAbilityList: this.authentication.evaluationAgencyAbilityList,
  241. evaluationAgencyResourceList: this.authentication.evaluationAgencyResourceList,
  242. agencyPhoto: this.authentication.agencyPhoto,
  243. }
  244. //console.log(newAuthentication)
  245. updateAgencyAuthInfo(this.user.userVO.id, newAuthentication, this.updateAuthInfoSuccess, this.updateAuthInfoFail)
  246. } else {
  247. notify('error', '表单填写错误!')
  248. return false
  249. }
  250. })
  251. },
  252. updateAuthInfoSuccess (res) {
  253. console.log(res)
  254. this.hideLoading()
  255. this.cancelModify()
  256. notify('success', '认证信息修改成功,正在为您刷新用户信息')
  257. getCurrentUser().then(res => {
  258. storageSave('user', res)
  259. this.user = res
  260. this.sendBusMessage()
  261. //this.rolesPermissions = getRolesPermissions(res.roleList)
  262. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  263. this.hideLoading()
  264. notify('success', '用户信息刷新成功')
  265. }).catch((error) => {
  266. this.hideLoading()
  267. notify('error', '重新获取用户信息失败:' + error.data)
  268. })
  269. },
  270. updateAuthInfoFail (error) {
  271. this.hideLoading()
  272. notify('error', error.data)
  273. },
  274. //取消修改表单,表单进入不可编辑状态,不再使用
  275. cancelModify () {
  276. this.isModifyMode = false
  277. this.getAuthInfo()
  278. },
  279. //上传文件时移除文件的响应函数
  280. handleRemove (file, fileList) {
  281. console.log(file, fileList)
  282. },
  283. //添加文件时的响应函数
  284. handleExceed (files, fileList) {
  285. this.$message.warning(
  286. `当前限制选择 1 个文件,本次选择了 ${
  287. files.length
  288. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  289. )
  290. },
  291. //移除文件前的响应函数
  292. beforeRemove (file, fileList) {
  293. //return this.$confirm(`确定移除 ${file.name}?`)
  294. },
  295. //文件上传前的响应函数
  296. beforeFileUpload () {
  297. },
  298. //上传文件,此处为上传图片
  299. uploadFile (param) {
  300. const formData = new FormData()
  301. let config = {
  302. //添加请求头
  303. headers: {'Content-Type': 'multipart/form-data'},
  304. }
  305. formData.append('file', param.file)
  306. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  307. console.log('上传成功')
  308. this.authentication.agencyPhoto = res.data
  309. console.log(res.data)
  310. notify('success', '上传成功')
  311. }).catch(error => {
  312. notify('error', error.data.msg)
  313. })
  314. },
  315. //设置服务类型
  316. setServiceTypes () {
  317. getAllServiceTypes().then((res) => {
  318. this.serviceTypes = res
  319. }).catch((error) => {
  320. notify('error', '机构能力加载失败')
  321. })
  322. },
  323. //设置机构资源类型
  324. setResourceTypes () {
  325. this.resourceTypes = getAllAgencyResourceTypes()
  326. },
  327. //添加一项测评机构资源
  328. addAgencyResource () {
  329. const tmpResource = {
  330. id: this.authentication.evaluationAgencyResourceList.length,
  331. type: this.resourceTypes[0],
  332. name: '',
  333. totalNum: 0,
  334. availableNum: 0,
  335. }
  336. this.authentication.evaluationAgencyResourceList.push(tmpResource)
  337. },
  338. //删除一项测评机构资源
  339. removeAgencyResource (id) {
  340. this.authentication.evaluationAgencyResourceList.splice(id, 1)
  341. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  342. this.authentication.evaluationAgencyResourceList[i].id = i
  343. }
  344. },
  345. //检测测评机构资源填写是否有效
  346. checkAgencyResourceVaild () {
  347. if (this.authentication.evaluationAgencyResourceList.length === 0) {
  348. return true
  349. }
  350. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  351. const item = this.authentication.evaluationAgencyResourceList[i]
  352. if (item.type === '') {
  353. notify('error', '资源类型不能为空')
  354. return false
  355. }
  356. if (item.name === '') {
  357. notify('error', '资源名称不能为空')
  358. return false
  359. }
  360. if (item.totalNum < item.availableNum) {
  361. notify('error', '资源总数量不能低于可用数量')
  362. return false
  363. }
  364. }
  365. return true
  366. },
  367. //
  368. setUserInfo () {
  369. this.user = storageGet('user')
  370. },
  371. //
  372. showLoading () {
  373. this.loading = true
  374. },
  375. hideLoading () {
  376. this.loading = false
  377. },
  378. submitSuccess () {
  379. },
  380. sendBusMessage () {
  381. this.$root.$emit('user', this.user)
  382. },
  383. checkNumber (value) {
  384. return /^\d+$/.test(value)
  385. },
  386. },
  387. created: function () {
  388. }
  389. }
  390. </script>
  391. <style scoped>
  392. .el-radio {
  393. margin: 10px 20px 10px 0;
  394. }
  395. .el-form-item /deep/ .el-tabs__content {
  396. max-height: 120px !important;
  397. overflow: auto;
  398. }
  399. .el-row {
  400. margin-bottom: 10px;
  401. }
  402. .el-input {
  403. width: 400px;
  404. }
  405. .avatar-uploader .el-upload {
  406. border: 1px dashed #d9d9d9;
  407. border-radius: 6px;
  408. cursor: pointer;
  409. position: relative;
  410. overflow: hidden;
  411. }
  412. .avatar-uploader .el-upload:hover {
  413. border-color: #409EFF;
  414. }
  415. .avatar-uploader-icon {
  416. border: 1px dashed #d9d9d9;
  417. border-radius: 6px;
  418. font-size: 28px;
  419. color: #8c939d;
  420. width: 176px;
  421. height: 178px;
  422. line-height: 178px;
  423. text-align: center;
  424. }
  425. .avatar-uploader-icon:hover {
  426. border-color: #409EFF;
  427. }
  428. .avatar {
  429. width: 178px;
  430. height: 178px;
  431. display: block;
  432. }
  433. </style>