移动端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

301 行
9.2 KiB

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