移动端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

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