移动端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

HomeApplyUploadComp.vue 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div v-if="this.attachmentList.length !== 0">
  3. <p class="main_title">当前节点所需上传文件</p>
  4. <van-steps direction="vertical" :active="active">
  5. <van-step
  6. v-for="(item, index) in attachmentList"
  7. :key="index">
  8. <van-collapse :accordion="true" v-model="item.collapse">
  9. <van-collapse-item :title="item.fileTypeName + '(' + item.fileList.length + ')'" :name="0">
  10. <van-uploader
  11. v-model="item.fileList"
  12. :after-read="(file, detail) => { handleUploadSuccess(file, detail, item); }"
  13. :readonly="disabled || !item.current"
  14. :show-upload="!disabled && item.current"
  15. :before-delete="handleRemove"
  16. :deletable="!disabled && item.current"
  17. accept=".jpg,.png,.gif,.pdf,.doc,.docx,.xlsx,.xls"
  18. :before-read="checkFile"
  19. >
  20. <!-- accept=".jpg,.png,.gif,.pdf,.doc,.docx,.xlsx,.xls" 设置了无法拉起相机/下载
  21. :disabled="disabled || !item.current"
  22. -->
  23. </van-uploader>
  24. </van-collapse-item>
  25. </van-collapse>
  26. </van-step>
  27. </van-steps>
  28. </div>
  29. </template>
  30. <script>
  31. import {
  32. treeSingleProcessView,
  33. attach,
  34. removeFile,
  35. getAttachmentConfigTree,
  36. attachmentFind
  37. } from "@/api/sunVillage_info/homestead/application";
  38. import {getToken} from "@/utils/auth";
  39. import request from '@/utils/request'
  40. import {Notify} from "vant";
  41. /** 导入JS方法 */
  42. export default {
  43. name: "houseApplyUploadComp",
  44. components: {},
  45. props: ["businessType", "proposerId", "houseApplyStatus", "processKey", "tableName", "readonly", 'full', "userName"],
  46. data() {
  47. return {
  48. disabled: this.readonly,
  49. loading: false,
  50. attachmentList: [],
  51. uploadImg: {
  52. //上传图片配置
  53. uploadImgUrl: "/open/home/mobile/common/attach",
  54. },
  55. newAttachments: [],
  56. fileTypeList:[],
  57. active: -1,
  58. has: false,
  59. }
  60. },
  61. watch: {
  62. proposerId: function (newVal, oldVal) {
  63. this.showAttachmentComp(this.businessType, newVal, this.houseApplyStatus, this.processKey, this.tableName, this.full);
  64. },
  65. readonly: function (newVal, oldVal) {
  66. this.disabled = newVal;
  67. },
  68. },
  69. created() {
  70. if (this.businessType !== null && this.proposerId == -1) {
  71. this.showAttachmentComp(this.businessType, this.proposerId, this.houseApplyStatus, this.processKey, this.tableName, this.full)
  72. }
  73. },
  74. methods: {
  75. handleUploadSuccess(file, detail, item) {
  76. this.setFileStatus(file, 'uploading', '文件上传中...');
  77. let formData = new FormData;
  78. formData.set('file', file.file);
  79. this.$set(item.postData, 'userName', this.userName);
  80. request({
  81. url: this.uploadImg.uploadImgUrl,
  82. method: "post",
  83. params: item.postData,
  84. data: formData,
  85. }).then((resp) => {
  86. if (resp.code === 200) {
  87. file.response = resp;
  88. file.fileList = item.fileList;
  89. this.onFileListChanged("ADD", resp);
  90. this.setFileStatus(file, 'done', '文件上传成功');
  91. this.$emit('onUploadSuccess', file);
  92. } else
  93. this.setFileStatus(file, 'fail', '文件上传失败!');
  94. }).catch((e) => {
  95. this.setFileStatus(file, 'fail', '文件上传失败!');
  96. });
  97. return true;
  98. },
  99. //获取ip
  100. getPath() {
  101. // 获取当前页面的URL
  102. const url = window.location.href;
  103. // 使用正则表达式解析URL以获取IP和端口
  104. const ipAndPortRegex = /^(?:https?:\/\/)?(?:([^\s:@\/]+)(?::([^\s:@\/]+))?@)?([\da-z\.-]+)(?::(\d+))?(?:\/([^\?#]+))?(?:\?([^#]+))?(?:#(.+))?$/;
  105. const match = url.match(ipAndPortRegex);
  106. // 提取IP和端口
  107. const ip = match[3];
  108. const port = match[4];
  109. return "http://"+ip + ":" + port + "/api"
  110. },
  111. handleRemove(file, detail) {
  112. console.log(file);
  113. this.setFileStatus(file, 'uploading', '文件删除中...');
  114. let id = file.id || file.response.id;
  115. this.onFileListChanged("REMOVE", id);
  116. removeFile(id).then(resp => {
  117. if (this.proposerId != -1 && false) // 不刷新
  118. this.showAttachmentComp(this.businessType, this.proposerId, this.houseApplyStatus, this.processKey, this.tableName, this.full)
  119. /* else // 新增时
  120. {
  121. let fileList = file.fileList;
  122. //console.log(fileList);
  123. fileList.splice(fileList.indexOf(file), 1);
  124. }*/
  125. this.setFileStatus(file, 'done', '文件删除成功');
  126. }).catch((e) => {
  127. this.setFileStatus(file, 'fail', '文件删除失败!');
  128. }).finally(() => {
  129. //loading.close();
  130. });
  131. return true;
  132. },
  133. showAttachmentComp(businessType, proposerId, houseApplyStatus, processKey, tableName, full) {
  134. this.attachmentList = [];
  135. this.active = -1;
  136. this.has = false;
  137. if (!full && 0) {
  138. this.getCurrentFiles(businessType, proposerId, houseApplyStatus, processKey, tableName);
  139. } else {
  140. this.getHistoryFiles(businessType, proposerId, houseApplyStatus, processKey, tableName);
  141. }
  142. },
  143. formatFile(list) {
  144. if (list !== null && list !== undefined) {
  145. let baseImgUrl = this.$store.getters.baseRoutingUrl;
  146. if (baseImgUrl === "") {
  147. baseImgUrl = this.getPath();
  148. }
  149. let UfileList = []; //上传图片列表
  150. list.forEach((value, index) => {
  151. UfileList.push({
  152. name: value.fileName,
  153. fileUrl: value.fileUrl,
  154. url: baseImgUrl + value.fileUrl,
  155. id: value.id,
  156. fileList: UfileList,
  157. });
  158. if(list.length > 0){
  159. this.newAttachments.push(value);
  160. this.fileTypeList.push(value.fileType)
  161. }
  162. });
  163. return UfileList;
  164. }
  165. },
  166. onFileListChanged(type, data) {
  167. console.info(data);
  168. if(type === "ADD")
  169. {
  170. this.newAttachments.push(data);
  171. this.fileTypeList.push(data.fileType);
  172. }
  173. else if(type === "REMOVE")
  174. {
  175. this.fileTypeList = [];
  176. this.newAttachments = this.newAttachments.filter((item)=>{
  177. return item.id !== data;
  178. });
  179. this.newAttachments.forEach((item)=>{
  180. this.fileTypeList.push(item.fileType);
  181. });
  182. }
  183. console.log(this.newAttachments);
  184. this.$emit('uploadFinished', this.newAttachments,this.fileTypeList);
  185. },
  186. getCurrentFiles(businessType, proposerId, houseApplyStatus, processKey, tableName) {
  187. this.loading = true;
  188. treeSingleProcessView({
  189. businessType: businessType,
  190. houseApplyStatus: houseApplyStatus,
  191. processKey: processKey,
  192. tableName: tableName,
  193. }).then(res => {
  194. this.handleResponse(res.rows, proposerId, houseApplyStatus, tableName);
  195. if (this.attachmentList.length === 0) {
  196. this.disabled = true;
  197. this.getHistoryFiles(businessType, proposerId, houseApplyStatus, processKey, tableName);
  198. }
  199. }).finally(() => {
  200. this.loading = false;
  201. });
  202. },
  203. getHistoryFiles(businessType, proposerId, houseApplyStatus, processKey, tableName) {
  204. this.loading = true;
  205. getAttachmentConfigTree({
  206. businessType: businessType,
  207. nodeStatus: houseApplyStatus,
  208. processKey: processKey,
  209. dictTypeSort: 'home_stage_status',
  210. nodeStatusSort: '',
  211. tableId: proposerId,
  212. }).then(resp => {
  213. //console.log(resp);
  214. try {
  215. if (!resp.data || resp.data.length === 0)
  216. return;
  217. let rows = resp.data[0].children;
  218. rows.forEach((value, index) => {
  219. if (!value.children)
  220. return;
  221. this.handleResponse(value.children, proposerId, houseApplyStatus, tableName);
  222. });
  223. } catch (e) {
  224. console.error(e);
  225. }
  226. }).finally(() => {
  227. this.loading = false;
  228. });
  229. },
  230. handleResponse(rows, proposerId, houseApplyStatus, tableName) {
  231. rows.forEach((value, index) => {
  232. let obj = {
  233. fileTypeName: value.fileTypeName,
  234. tableId: proposerId,
  235. tableName: tableName,
  236. fileList: [],
  237. fileType: value.fileType,
  238. postData: {
  239. tableId: proposerId,
  240. tableName: tableName,
  241. bizPath: tableName,
  242. fileType: value.fileType,
  243. },
  244. current: value.nodeStatus == houseApplyStatus,
  245. collapse: this.disabled || value.nodeStatus == houseApplyStatus ? 0 : '',
  246. };
  247. if (value.nodeStatus != houseApplyStatus && !this.has)
  248. this.active++;
  249. if (value.nodeStatus == houseApplyStatus) {
  250. if (!this.has)
  251. this.active++;
  252. this.has = true;
  253. }
  254. if(value.attachmentList != null){
  255. if(value.attachmentList.length > 0){
  256. let list = this.formatFile( value.attachmentList);
  257. this.$set(obj, "fileList", list);
  258. }
  259. }
  260. this.attachmentList.push(obj);
  261. console.info(this.attachmentList);
  262. });
  263. if (proposerId !== -1) {
  264. this.$emit('uploadFinished',this.newAttachments,this.fileTypeList);
  265. }
  266. },
  267. setFileStatus(file, status, message) {
  268. file.status = status;
  269. file.message = message;
  270. },
  271. checkFile(file) {
  272. let mime = file.type;
  273. if ([
  274. "image/png",
  275. "image/jpeg",
  276. "image/gif",
  277. "image/bmp",
  278. ].indexOf(mime) === -1) {
  279. this.notify('请上传jpg/png/gif/bmp等格式图片!', 'danger');
  280. return false;
  281. }
  282. return true;
  283. },
  284. notify(message, type) {
  285. Notify.clear();
  286. Notify({type: type || 'primary', message: message});
  287. },
  288. }
  289. };
  290. </script>
  291. <style scoped>
  292. .my_class >>> .el-upload--picture-card {
  293. width: 72px;
  294. height: 72px;
  295. line-height: 78px;
  296. }
  297. .my_class >>> .el-upload-list__item {
  298. width: 72px;
  299. height: 72px;
  300. }
  301. .my_class >>> .el-upload-list__item-preview {
  302. width: 20px;
  303. }
  304. .my_class >>> .el-upload-list__item-delete {
  305. width: 20px;
  306. }
  307. .main_title {
  308. font-size: 0.4rem;
  309. color: #1D6FE9;
  310. margin: 0.2rem 6%;
  311. position: relative;
  312. }
  313. </style>