AgencyAuthentication.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. {min: 16, max: 19, message: '银行卡账户输入有误', trigger: 'blur'},
  146. {
  147. validator: (rule, value, callback) => {
  148. if (!this.checkNumber(value)) {
  149. callback(new Error('银行卡账户输入有误'))
  150. } else {
  151. callback()
  152. }
  153. }, trigger: 'blur'
  154. },
  155. ],
  156. address: [
  157. {required: true, message: '请输入地址', trigger: 'blur'}
  158. ],
  159. evaluationAgencyAbilityList: [
  160. {
  161. type: 'array',
  162. required: true,
  163. message: '请至少选择一种服务类型',
  164. trigger: 'change'
  165. }
  166. ],
  167. evaluationAgencyResourceList: [
  168. {
  169. validator: (rule, value, callback) => {
  170. var isError = false
  171. if (value == null || value.length == 0) {
  172. callback(new Error('机构资源不可为空'))
  173. } else {
  174. for (var i = 0; i < value.length; i++) {
  175. if (value[i].name == '') {
  176. isError = true
  177. break
  178. }
  179. }
  180. }
  181. if (isError) {
  182. callback(new Error('资源名称不可为空'))
  183. } else {
  184. callback()
  185. }
  186. }, trigger: 'blur'
  187. },
  188. ],
  189. agencyPhoto: [
  190. {
  191. validator: (rule, value, callback) => {
  192. if (value == null || value == '') {
  193. callback(new Error('机构logo不可为空'))
  194. } else {
  195. callback()
  196. }
  197. }, trigger: 'blur'
  198. },
  199. ]
  200. }
  201. }
  202. },
  203. mounted () {
  204. this.$nextTick(() => {
  205. this.init()
  206. })
  207. },
  208. methods: {
  209. //初始化数据
  210. init () {
  211. this.setServiceTypes()
  212. this.setResourceTypes()
  213. this.setUserInfo()
  214. this.getAuthInfo()
  215. },
  216. //加载数据
  217. getAuthInfo () {
  218. this.showLoading()
  219. getCurrentAgencyAuthInfo(this.user.userVO.id, this.getAuthInfoSuccess, this.getAuthInfoFail)
  220. },
  221. getAuthInfoSuccess (res) {
  222. this.hideLoading()
  223. this.authentication.agencyPhoto = res.agencyPhoto == null ? defaultValue.image : res.agencyPhoto
  224. this.authentication.evaluationAgencyName = res.evaluationAgencyName == null ? '暂未填写' : res.evaluationAgencyName
  225. this.authentication.evaluationAgencyAbilityList = res.evaluationAgencyAbilityList == null ? [] : res.evaluationAgencyAbilityList
  226. this.authentication.evaluationAgencyResourceList = res.evaluationAgencyResourceList == null ? [] : res.evaluationAgencyResourceList
  227. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  228. this.authentication.address = res.address == null ? '暂未填写' : res.address
  229. this.authentication.authStatus = res.authStatus
  230. this.authentication.explain = res.explain
  231. console.log(this.authentication)
  232. },
  233. getAuthInfoFail (error) {
  234. this.hideLoading()
  235. notify('error', '加载认证信息失败:' + error.data)
  236. },
  237. //表单进入可编辑状态,可修改表单,不再使用
  238. modifyInfo () {
  239. this.isModifyMode = true
  240. },
  241. //提交认证信息
  242. updateAuthInfo () {
  243. //this.isModifyMode = false
  244. this.$refs['authentication'].validate(valid => {
  245. if (valid) {
  246. this.showLoading()
  247. const newAuthentication = {
  248. userId: this.user.userVO.id,
  249. evaluationAgencyName: this.authentication.evaluationAgencyName,
  250. bankAccount: this.authentication.bankAccount,
  251. address: this.authentication.address,
  252. evaluationAgencyAbilityList: this.authentication.evaluationAgencyAbilityList,
  253. evaluationAgencyResourceList: this.authentication.evaluationAgencyResourceList,
  254. agencyPhoto: this.authentication.agencyPhoto,
  255. }
  256. //console.log(newAuthentication)
  257. updateAgencyAuthInfo(this.user.userVO.id, newAuthentication, this.updateAuthInfoSuccess, this.updateAuthInfoFail)
  258. } else {
  259. notify('error', '表单填写错误!')
  260. return false
  261. }
  262. })
  263. },
  264. updateAuthInfoSuccess (res) {
  265. console.log(res)
  266. this.hideLoading()
  267. this.cancelModify()
  268. notify('success', '认证信息修改成功,正在为您刷新用户信息')
  269. getCurrentUser().then(res => {
  270. storageSave('user', res)
  271. this.user = res
  272. this.sendBusMessage()
  273. //this.rolesPermissions = getRolesPermissions(res.roleList)
  274. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  275. this.hideLoading()
  276. notify('success', '用户信息刷新成功')
  277. }).catch((error) => {
  278. this.hideLoading()
  279. notify('error', '重新获取用户信息失败:' + error.data)
  280. })
  281. },
  282. updateAuthInfoFail (error) {
  283. this.hideLoading()
  284. notify('error', error.data)
  285. },
  286. //取消修改表单,表单进入不可编辑状态,不再使用
  287. cancelModify () {
  288. this.isModifyMode = false
  289. this.getAuthInfo()
  290. },
  291. //上传文件时移除文件的响应函数
  292. handleRemove (file, fileList) {
  293. console.log(file, fileList)
  294. },
  295. //添加文件时的响应函数
  296. handleExceed (files, fileList) {
  297. this.$message.warning(
  298. `当前限制选择 1 个文件,本次选择了 ${
  299. files.length
  300. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  301. )
  302. },
  303. //移除文件前的响应函数
  304. beforeRemove (file, fileList) {
  305. //return this.$confirm(`确定移除 ${file.name}?`)
  306. },
  307. //文件上传前的响应函数
  308. beforeFileUpload (file) {
  309. // 文件大小不能超过10M
  310. if (file.size > 10 * 1000 * 1000){
  311. notify('error', '单个文件大小不能超过10M')
  312. return false;
  313. }
  314. let fileName = file.name
  315. let index = fileName.lastIndexOf('.');
  316. // 文件不能没有后缀
  317. if (index <= 0){
  318. notify('error', '只能上传png/jpg格式的文件')
  319. return false;
  320. }
  321. let fileSuffix = fileName.substr(index)
  322. // 文件后缀必须是.png或者.jpg
  323. if (fileSuffix !== '.jpg' && fileSuffix !== '.png') {
  324. notify('error', '只能上传png/jpg格式的文件')
  325. return false;
  326. }
  327. },
  328. //上传文件,此处为上传图片
  329. uploadFile (param) {
  330. const formData = new FormData()
  331. let config = {
  332. //添加请求头
  333. headers: {'Content-Type': 'multipart/form-data'},
  334. }
  335. formData.append('file', param.file)
  336. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  337. this.hideLoading()
  338. this.authentication.agencyPhoto = res.data
  339. console.log(res.data)
  340. notify('success', '上传成功')
  341. this.$refs['authentication'].validateField('agencyPhoto');
  342. }).catch(error => {
  343. this.hideLoading()
  344. try {
  345. if (error.response.status === 413){
  346. notify('error', '文件过大,请选择小于20M的图片')
  347. }else if (error.response.status === 500){
  348. notify('error', '上传文件发生错误,请稍后重试')
  349. }
  350. }catch (e) {
  351. notify('error', error.data)
  352. }
  353. })
  354. },
  355. //设置服务类型
  356. setServiceTypes () {
  357. getAllServiceTypes().then((res) => {
  358. this.serviceTypes = res
  359. }).catch((error) => {
  360. notify('error', '机构能力加载失败')
  361. })
  362. },
  363. //设置机构资源类型
  364. setResourceTypes () {
  365. this.resourceTypes = getAllAgencyResourceTypes()
  366. },
  367. //添加一项测评机构资源
  368. addAgencyResource () {
  369. const tmpResource = {
  370. id: this.authentication.evaluationAgencyResourceList.length,
  371. type: this.resourceTypes[0],
  372. name: '',
  373. totalNum: 0,
  374. availableNum: 0,
  375. }
  376. this.authentication.evaluationAgencyResourceList.push(tmpResource)
  377. },
  378. //删除一项测评机构资源
  379. removeAgencyResource (id) {
  380. this.authentication.evaluationAgencyResourceList.splice(id, 1)
  381. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  382. this.authentication.evaluationAgencyResourceList[i].id = i
  383. }
  384. },
  385. //检测测评机构资源填写是否有效
  386. checkAgencyResourceVaild () {
  387. if (this.authentication.evaluationAgencyResourceList.length === 0) {
  388. return true
  389. }
  390. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  391. const item = this.authentication.evaluationAgencyResourceList[i]
  392. if (item.type === '') {
  393. notify('error', '资源类型不能为空')
  394. return false
  395. }
  396. if (item.name === '') {
  397. notify('error', '资源名称不能为空')
  398. return false
  399. }
  400. if (item.totalNum < item.availableNum) {
  401. notify('error', '资源总数量不能低于可用数量')
  402. return false
  403. }
  404. }
  405. return true
  406. },
  407. //
  408. setUserInfo () {
  409. this.user = storageGet('user')
  410. },
  411. //
  412. showLoading () {
  413. this.loading = true
  414. },
  415. hideLoading () {
  416. this.loading = false
  417. },
  418. submitSuccess () {
  419. },
  420. sendBusMessage () {
  421. this.$root.$emit('user', this.user)
  422. },
  423. checkNumber (value) {
  424. return /^\d+$/.test(value)
  425. },
  426. },
  427. created: function () {
  428. }
  429. }
  430. </script>
  431. <style scoped>
  432. .el-radio {
  433. margin: 10px 20px 10px 0;
  434. }
  435. .el-form-item /deep/ .el-tabs__content {
  436. max-height: 120px !important;
  437. overflow: auto;
  438. }
  439. .el-row {
  440. margin-bottom: 10px;
  441. }
  442. .el-input {
  443. width: 400px;
  444. }
  445. .avatar-uploader .el-upload {
  446. border: 1px dashed #d9d9d9;
  447. border-radius: 6px;
  448. cursor: pointer;
  449. position: relative;
  450. overflow: hidden;
  451. }
  452. .avatar-uploader .el-upload:hover {
  453. border-color: #409EFF;
  454. }
  455. .avatar-uploader-icon {
  456. border: 1px dashed #d9d9d9;
  457. border-radius: 6px;
  458. font-size: 28px;
  459. color: #8c939d;
  460. width: 176px;
  461. height: 178px;
  462. line-height: 178px;
  463. text-align: center;
  464. }
  465. .avatar-uploader-icon:hover {
  466. border-color: #409EFF;
  467. }
  468. .avatar {
  469. width: 178px;
  470. height: 178px;
  471. display: block;
  472. }
  473. </style>