Authentication.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="create-container">
  3. <div class="create-body">
  4. <div class="title">测评机构认证</div>
  5. <el-form :model="authentication" :rules="rules" ref="authentication" label-width="12%" class="demo-report">
  6. <el-form-item label="机构名称" prop="name">
  7. <el-input v-if="isModifyMode" v-model="authentication.name"></el-input>
  8. <!--<span v-if="!isModifyMode">{{authentication.name}}</span>-->
  9. </el-form-item>
  10. <el-form-item label="机构电话" prop="name">
  11. <el-input v-if="isModifyMode" v-model="authentication.mobile"></el-input>
  12. <!--<span v-if="!isModifyMode">{{authentication.name}}</span>-->
  13. </el-form-item>
  14. <el-form-item label="银行卡账户" prop="name">
  15. <el-input v-if="isModifyMode" v-model="authentication.bankAccount"></el-input>
  16. <!--<span v-if="!isModifyMode">{{authentication.bankAccount}}</span>-->
  17. </el-form-item>
  18. <el-form-item label="地址" prop="name">
  19. <el-input v-if="isModifyMode" v-model="authentication.address"></el-input>
  20. <!--<span v-if="!isModifyMode">{{authentication.address}}</span>-->
  21. </el-form-item>
  22. <el-form-item label="测评机构能力" prop="name">
  23. <el-checkbox-group v-if="isModifyMode" v-model="authentication.ability">
  24. <span v-for="(item,index) in serviceTypes" :key="index">
  25. <el-checkbox :label="item" name="type">{{item}}&nbsp;&nbsp;&nbsp;&nbsp;</el-checkbox>
  26. </span>
  27. </el-checkbox-group>
  28. <!--<span v-if="!isModifyMode">{{authentication.ability}}</span>-->
  29. </el-form-item>
  30. <el-form-item label="测评机构资源" prop="name">
  31. <span v-for="item in authentication.resource" :key="item.id">
  32. 资源类型:&nbsp;<el-select v-model="item.type" placeholder="请选择" style="width: 150px" :value="item.type">
  33. <el-option
  34. v-for="item in resourceTypes"
  35. :key="item"
  36. :label="item"
  37. :value="item">
  38. </el-option>
  39. </el-select>
  40. 资源名称:&nbsp;<el-input v-model="item.name" style="width: 150px"></el-input>
  41. 总量:&nbsp;<el-input-number :min="0" v-model="item.totalNum"></el-input-number>
  42. 可用数量:&nbsp;<el-input-number :min="0" :max="item.totalNum" v-model="item.availableNum"></el-input-number>
  43. <el-button type="danger" icon="el-icon-delete" @click="removeAgencyResource(item.id)"></el-button>
  44. <br/>
  45. </span>
  46. <el-button type="primary" icon="el-icon-circle-plus" plain size="small" @click="addAgencyResource">添加资源
  47. </el-button>
  48. <!--<span v-if="!isModifyMode">{{authentication.resource}}</span>-->
  49. </el-form-item>
  50. <el-form-item prop="file" label="头像">
  51. <el-upload
  52. v-if="isModifyMode"
  53. drag
  54. class="upload-demo"
  55. action="https://jsonplaceholder.typicode.com/posts/"
  56. :on-remove="handleRemove"
  57. :before-remove="beforeRemove"
  58. multiple
  59. :limit="1"
  60. :show-file-list="false"
  61. :on-exceed="handleExceed"
  62. :before-upload="beforeFileUpload"
  63. :http-request="uploadFile"
  64. :file-list="authentication.photo"
  65. >
  66. <i class="el-icon-upload"></i>
  67. <div class="el-upload__text">
  68. 将文件拖到此处,或
  69. <em>点击上传</em>
  70. </div>
  71. <div class="el-upload__tip" slot="tip">请上传头像</div>
  72. </el-upload>
  73. <!--<div v-if="!isModifyMode">-->
  74. <!--<span v-if="authentication.photo==null">暂无文件</span>-->
  75. <!--<a :href="authentication.photo" v-if="authentication.photo!=null"><i class="fa fa-file-text-o"></i>-->
  76. <!--{{authentication.photo}}</a>-->
  77. <!--</div>-->
  78. </el-form-item>
  79. <!--<el-form-item v-if="!isModifyMode">-->
  80. <!--<div class="btn btn-medium btn-info" @click="modifyInfo()">修改</div>-->
  81. <!--<div class="btn btn-medium" @click="cancelModify()">返回</div>-->
  82. <!--</el-form-item>-->
  83. <el-form-item v-if="isModifyMode">
  84. <div class="btn btn-primary btn-info" @click="submitInfo()">提交</div>
  85. <!--<div class="btn btn-primary" @click="cancelModify()">取消</div>-->
  86. </el-form-item>
  87. </el-form>
  88. </div>
  89. </div>
  90. </template>
  91. <script>
  92. import Http from '@/js/http'
  93. import Apis from '@/js/api'
  94. import {notify} from '@/constants/index'
  95. import {getAllAgencyResourceTypes, getAllServiceTypes} from '@/js/index'
  96. export default {
  97. name: 'Authentication',
  98. data () {
  99. return {
  100. userId: 0,
  101. isModifyMode: true,
  102. resourceTypes: [],
  103. serviceTypes: [],
  104. authentication: {
  105. mobile: '',
  106. name: '',
  107. bankAccount: '',
  108. address: '',
  109. ability: '',
  110. resource: [],
  111. photo: [],
  112. photoUrl: '',
  113. },
  114. rules: {
  115. // name: [
  116. // {required: true, message: '请输入报告名称', trigger: 'blur'}
  117. // // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
  118. // ],
  119. // abstract: [
  120. // {
  121. // required: true,
  122. // message: '请输入摘要信息',
  123. // trigger: 'change'
  124. // }
  125. // ],
  126. // type: [
  127. // {required: true, message: '请选择报告类型', trigger: 'change'}
  128. // ],
  129. // conclusion: [
  130. // {required: true, message: '请输入报告结论', trigger: 'blur'}
  131. // ]
  132. }
  133. }
  134. },
  135. mounted () {
  136. this.$nextTick(() => {
  137. this.init()
  138. })
  139. },
  140. methods: {
  141. init () {
  142. this.setServiceTypes()
  143. this.setResourceTypes()
  144. },
  145. //加载数据
  146. loadData: function () {
  147. },
  148. modifyInfo () {
  149. this.isModifyMode = true
  150. },
  151. submitInfo () {
  152. //this.isModifyMode = false
  153. const newAuthentication = {
  154. mobile: this.authentication.mobile,
  155. evaluationAgencyName: this.authentication.name,
  156. bankAccount: this.authentication.bankAccount,
  157. address: this.authentication.address,
  158. abilities: this.authentication.ability,
  159. resources: this.authentication.resource,
  160. agencyPhoto: this.authentication.photoUrl,
  161. }
  162. Http.post(Apis.USER.AGENCY_AUTHENTICATION.replace('{userId}', 3), newAuthentication).then((res) => {
  163. console.log(res)
  164. notify('success', '测评机构成功')
  165. }).catch(error => {
  166. notify('error', error.data.msg)
  167. })
  168. },
  169. cancelModify () {
  170. this.isModifyMode = false
  171. },
  172. handleRemove (file, fileList) {
  173. console.log(file, fileList)
  174. },
  175. handleExceed (files, fileList) {
  176. this.$message.warning(
  177. `当前限制选择 1 个文件,本次选择了 ${
  178. files.length
  179. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  180. )
  181. },
  182. beforeRemove (file, fileList) {
  183. //return this.$confirm(`确定移除 ${file.name}?`)
  184. },
  185. beforeFileUpload () {
  186. },
  187. uploadFile (param) {
  188. const formData = new FormData()
  189. let config = {
  190. //添加请求头
  191. headers: {'Content-Type': 'multipart/form-data'},
  192. }
  193. formData.append('file', param.file)
  194. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', 3), formData, config).then((res) => {
  195. console.log('上传成功')
  196. this.authentication.photoUrl = res.data
  197. console.log(res.data)
  198. notify('success', '上传成功')
  199. }).catch(error => {
  200. notify('error', error.data.msg)
  201. })
  202. },
  203. setServiceTypes () {
  204. this.serviceTypes = getAllServiceTypes()
  205. },
  206. setResourceTypes () {
  207. this.resourceTypes = getAllAgencyResourceTypes()
  208. },
  209. addAgencyResource () {
  210. const tmpResource = {
  211. id: this.authentication.resource.length,
  212. type: this.resourceTypes[0],
  213. name: '',
  214. totalNum: 0,
  215. availableNum: 0,
  216. }
  217. this.authentication.resource.push(tmpResource)
  218. },
  219. removeAgencyResource (id) {
  220. this.authentication.resource.splice(id, 1)
  221. for (var i = 0; i < this.authentication.resource.length; i++) {
  222. this.authentication.resource[i].id = i
  223. }
  224. },
  225. checkAgencyResourceVaild () {
  226. if (this.authentication.resource.length === 0) {
  227. return true
  228. }
  229. for (var i = 0; i < this.authentication.resource.length; i++) {
  230. const item = this.authentication.resource[i]
  231. if (item.type === '') {
  232. notify('error', '资源类型不能为空')
  233. return false
  234. }
  235. if (item.name === '') {
  236. notify('error', '资源名称不能为空')
  237. return false
  238. }
  239. if (item.totalNum < item.availableNum) {
  240. notify('error', '资源总数量不能低于可用数量')
  241. return false
  242. }
  243. }
  244. return true
  245. }
  246. },
  247. created: function () {
  248. }
  249. }
  250. </script>
  251. <style scoped>
  252. .el-radio {
  253. margin: 10px 20px 10px 0;
  254. }
  255. .el-form-item /deep/ .el-tabs__content {
  256. max-height: 120px !important;
  257. overflow: auto;
  258. }
  259. .el-row {
  260. margin-bottom: 10px;
  261. }
  262. .el-input {
  263. width: 400px;
  264. }
  265. </style>