AgencyAuthenticationCreate.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. <!--<span v-if="!isModifyMode">{{authentication.bankAccount}}</span>-->
  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. ],
  128. address: [
  129. {required: true, message: '请输入地址', trigger: 'blur'}
  130. ],
  131. evaluationAgencyAbilityList: [
  132. {
  133. type: 'array',
  134. required: true,
  135. message: '请至少选择一种服务类型',
  136. trigger: 'change'
  137. }
  138. ],
  139. evaluationAgencyResourceList: [
  140. {
  141. validator: (rule, value, callback) => {
  142. var isError = false
  143. if (value == null || value.length == 0){
  144. callback(new Error('机构资源不可为空'))
  145. } else {
  146. for (var i = 0; i < value.length; i++) {
  147. if (value[i].name == '') {
  148. isError = true
  149. break
  150. }
  151. }
  152. }
  153. if (isError) {
  154. callback(new Error('资源名称不可为空'))
  155. } else {
  156. callback()
  157. }
  158. }, trigger: 'blur'
  159. },
  160. ],
  161. }
  162. }
  163. },
  164. mounted () {
  165. this.$nextTick(() => {
  166. this.init()
  167. })
  168. },
  169. methods: {
  170. //初始化数据
  171. init () {
  172. this.setServiceTypes()
  173. this.setResourceTypes()
  174. this.setUserInfo()
  175. },
  176. //加载数据
  177. loadData: function () {
  178. },
  179. //表单进入可编辑状态,可修改表单,不再使用
  180. modifyInfo () {
  181. this.isModifyMode = true
  182. },
  183. //提交认证信息
  184. submitInfo () {
  185. //this.isModifyMode = false
  186. this.$refs['authentication'].validate(valid => {
  187. if (valid) {
  188. this.showLoading()
  189. const newAuthentication = {
  190. userId: this.user.userVO.id,
  191. evaluationAgencyName: this.authentication.evaluationAgencyName,
  192. bankAccount: this.authentication.bankAccount,
  193. address: this.authentication.address,
  194. evaluationAgencyAbilityList: this.authentication.evaluationAgencyAbilityList,
  195. evaluationAgencyResourceList: this.authentication.evaluationAgencyResourceList,
  196. agencyPhoto: this.authentication.agencyPhoto,
  197. }
  198. console.log(newAuthentication)
  199. uploadAgencyAuthenticationInfo(this.user.userVO.id, newAuthentication, this.submitInfoSuccess, this.submitInfoFail)
  200. } else {
  201. notify('error', '表单填写错误!')
  202. return false
  203. }
  204. })
  205. },
  206. submitInfoSuccess (res) {
  207. console.log(res)
  208. getCurrentUser().then(res => {
  209. storageSave('user', res)
  210. this.user = res
  211. this.sendBusMessage()
  212. //this.rolesPermissions = getRolesPermissions(res.roleList)
  213. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  214. this.hideLoading()
  215. this.$confirm('认证信息提交成功,将于10个工作日内审核完成')
  216. .then(_ => {
  217. //done()
  218. this.$router.push({
  219. name: 'AgencyAuthentication',
  220. params: {userId: this.user.userVO.id}
  221. })
  222. })
  223. .catch(_ => {
  224. this.$router.push({
  225. name: 'AgencyAuthentication',
  226. params: {userId: this.user.userVO.id}
  227. })
  228. })
  229. }).catch((error) => {
  230. this.hideLoading()
  231. notify('error', '重新获取用户信息失败:' + error.data)
  232. })
  233. },
  234. submitInfoFail (error) {
  235. this.hideLoading()
  236. notify('error', error.data)
  237. },
  238. //取消修改表单,表单进入不可编辑状态,不再使用
  239. cancelModify () {
  240. this.isModifyMode = false
  241. },
  242. //上传文件时移除文件的响应函数
  243. handleRemove (file, fileList) {
  244. console.log(file, fileList)
  245. },
  246. //添加文件时的响应函数
  247. handleExceed (files, fileList) {
  248. this.$message.warning(
  249. `当前限制选择 1 个文件,本次选择了 ${
  250. files.length
  251. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  252. )
  253. },
  254. //移除文件前的响应函数
  255. beforeRemove (file, fileList) {
  256. //return this.$confirm(`确定移除 ${file.name}?`)
  257. },
  258. //文件上传前的响应函数
  259. beforeFileUpload () {
  260. },
  261. //上传文件,此处为上传图片
  262. uploadFile (param) {
  263. const formData = new FormData()
  264. let config = {
  265. //添加请求头
  266. headers: {'Content-Type': 'multipart/form-data'},
  267. }
  268. formData.append('file', param.file)
  269. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  270. console.log('上传成功')
  271. this.authentication.agencyPhoto = res.data
  272. console.log(res.data)
  273. notify('success', '上传成功')
  274. }).catch(error => {
  275. notify('error', error.data.msg)
  276. })
  277. },
  278. //设置服务类型
  279. setServiceTypes () {
  280. getAllServiceTypes().then((res) => {
  281. this.serviceTypes = res
  282. }).catch((error) => {
  283. notify('error', '机构能力加载失败')
  284. })
  285. },
  286. //设置机构资源类型
  287. setResourceTypes () {
  288. this.resourceTypes = getAllAgencyResourceTypes()
  289. },
  290. //添加一项测评机构资源
  291. addAgencyResource () {
  292. const tmpResource = {
  293. id: this.authentication.evaluationAgencyResourceList.length,
  294. type: this.resourceTypes[0],
  295. name: '',
  296. totalNum: 0,
  297. availableNum: 0,
  298. }
  299. this.authentication.evaluationAgencyResourceList.push(tmpResource)
  300. },
  301. //删除一项测评机构资源
  302. removeAgencyResource (id) {
  303. this.authentication.evaluationAgencyResourceList.splice(id, 1)
  304. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  305. this.authentication.evaluationAgencyResourceList[i].id = i
  306. }
  307. },
  308. //检测测评机构资源填写是否有效
  309. checkAgencyResourceVaild () {
  310. if (this.authentication.evaluationAgencyResourceList.length === 0) {
  311. return true
  312. }
  313. for (var i = 0; i < this.authentication.evaluationAgencyResourceList.length; i++) {
  314. const item = this.authentication.evaluationAgencyResourceList[i]
  315. if (item.type === '') {
  316. notify('error', '资源类型不能为空')
  317. return false
  318. }
  319. if (item.name === '') {
  320. notify('error', '资源名称不能为空')
  321. return false
  322. }
  323. if (item.totalNum < item.availableNum) {
  324. notify('error', '资源总数量不能低于可用数量')
  325. return false
  326. }
  327. }
  328. return true
  329. },
  330. //
  331. setUserInfo () {
  332. this.user = storageGet('user')
  333. },
  334. //
  335. showLoading () {
  336. this.loading = true
  337. },
  338. hideLoading () {
  339. this.loading = false
  340. },
  341. submitSuccess () {
  342. },
  343. sendBusMessage () {
  344. this.$root.$emit('user', this.user)
  345. }
  346. },
  347. created: function () {
  348. }
  349. }
  350. </script>
  351. <style scoped>
  352. .el-radio {
  353. margin: 10px 20px 10px 0;
  354. }
  355. .el-form-item /deep/ .el-tabs__content {
  356. max-height: 120px !important;
  357. overflow: auto;
  358. }
  359. .el-row {
  360. margin-bottom: 10px;
  361. }
  362. .el-input {
  363. width: 400px;
  364. }
  365. .avatar-uploader .el-upload {
  366. border: 1px dashed #d9d9d9;
  367. border-radius: 6px;
  368. cursor: pointer;
  369. position: relative;
  370. overflow: hidden;
  371. }
  372. .avatar-uploader .el-upload:hover {
  373. border-color: #409EFF;
  374. }
  375. .avatar-uploader-icon {
  376. border: 1px dashed #d9d9d9;
  377. border-radius: 6px;
  378. font-size: 28px;
  379. color: #8c939d;
  380. width: 176px;
  381. height: 178px;
  382. line-height: 178px;
  383. text-align: center;
  384. }
  385. .avatar-uploader-icon:hover {
  386. border-color: #409EFF;
  387. }
  388. .avatar {
  389. width: 178px;
  390. height: 178px;
  391. display: block;
  392. }
  393. </style>