AgencyAuthenticationCreate.vue 15 KB

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