addFileTransmit.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view>
  3. <view class="bg-white default_title">
  4. <u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
  5. ref="inputForm">
  6. <u-form-item label="年度" borderBottom prop="yearNum">
  7. <u--input v-model="inputForm.yearNum" placeholder="输入年度" border="none"></u--input>
  8. </u-form-item>
  9. <u-form-item label="卡号" borderBottom prop="cardNum">
  10. <u--input v-model="inputForm.cardNum" placeholder="输入卡号" border="none"></u--input>
  11. </u-form-item>
  12. </u--form>
  13. </view>
  14. <view class="bg-white margin-top main_info">
  15. <u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
  16. ref="inputForm">
  17. <u-form-item label="来文机关" borderBottom prop="sendingAgency">
  18. <u--input v-model="inputForm.sendingAgency" placeholder="请输入来文机关" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item label="来文字号" borderBottom prop="docFontSize">
  21. <u--input v-model="inputForm.docFontSize" placeholder="请输入来文字号" border="none"></u--input>
  22. </u-form-item>
  23. <u-form-item label="文件来源" borderBottom prop="fileSource">
  24. <u--input v-model="inputForm.fileSource" placeholder="请输入文件来源" border="none"></u--input>
  25. </u-form-item>
  26. <u-form-item label="成文时间" borderBottom prop="writtenTime">
  27. <jp-datetime-picker v-model="inputForm.writtenTime" placeholder="选择成文时间"
  28. mode="datetime"></jp-datetime-picker>
  29. </u-form-item>
  30. <u-form-item label="收文时间" borderBottom prop="receivingTime">
  31. <jp-datetime-picker v-model="inputForm.receivingTime" placeholder="选择收文时间"
  32. mode="datetime"></jp-datetime-picker>
  33. </u-form-item>
  34. <u-form-item label="内容摘要" borderBottom prop="contentSummary">
  35. <u--textarea v-model="inputForm.contentSummary" placeholder="请输入内容摘要" border="none"></u--textarea>
  36. </u-form-item>
  37. <u-form-item label="来文附件" prop="attachedDocumentId" labelPosition="top">
  38. <u-upload :fileList="fileLists" @afterRead="afterRead" multiple :maxCount="9" width="250"
  39. height="150" accept="file" :previewImage="false">
  40. <view class="addfile flex"> <u-icon size="20" bold name="plus"></u-icon></view>
  41. </u-upload>
  42. </u-form-item>
  43. <view class="other_info">
  44. <view class="other_pdf">
  45. <u-cell-group>
  46. <u-cell v-for="item in fileList" :title="item.name">
  47. <u-icon slot="right-icon" size="28" name="trash-fill"
  48. @click="deleteFile(item)"></u-icon>
  49. </u-cell>
  50. </u-cell-group>
  51. </view>
  52. </view>
  53. <u-upload :fileList="imgList" @delete="deletePic" multiple :maxCount="imgList.length"
  54. :previewFullImage="true"></u-upload>
  55. <u--text size="12" type="error" text="请确保上传图片内容清晰可见,所有涉密敏感信息不得上传"></u--text>
  56. <view class="submit_btn flex">
  57. <u-button v-if="!loading" type="primary" text="提交新增" @click="formSubmit"></u-button>
  58. <u-button v-if="loading" :loading="loading" type="primary" text="加载中"></u-button>
  59. </view>
  60. </u--form>
  61. </view>
  62. <u-toast ref="uToast"></u-toast>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. isImageFormat
  68. } from "@/common/util.js"
  69. import BASE_URL from '@/config.js'
  70. import * as $auth from "@/common/auth.js"
  71. import fileService from '@/api/file/fileService.js'
  72. import gwCirculationCard2Service from '@/api/circulation/gwCirculationCard2.js'
  73. export default {
  74. data() {
  75. return {
  76. loading: false,
  77. fileLists: [],
  78. fileList: [],
  79. imgList: [],
  80. inputForm: {
  81. id: '',
  82. yearNum: '',
  83. cardNum: '',
  84. sendingAgency: '',
  85. docFontSize: '',
  86. fileSource: '',
  87. writtenTime: '',
  88. receivingTime: '',
  89. contentSummary: '',
  90. attachedDocumentId: '',
  91. remark: '',
  92. state: '1'
  93. },
  94. }
  95. },
  96. methods: {
  97. showToast(params) {
  98. this.$refs.uToast.show({
  99. ...params,
  100. complete() {
  101. params.url && uni.navigateTo({
  102. url: params.url
  103. })
  104. }
  105. })
  106. },
  107. // 删除文件
  108. deleteFile(item) {
  109. let that = this
  110. uni.showModal({
  111. title: '提示',
  112. content: '确认删除该文件',
  113. success: function(res) {
  114. if (res.confirm) {
  115. console.log("this.fileLists====", that.fileLists);
  116. that.fileLists = that.fileLists.filter(i => !(i.url == item.url))
  117. that.fileList = that.fileList.filter(i => !(i.url == item.url))
  118. } else if (res.cancel) {
  119. console.log('用户点击取消');
  120. }
  121. }
  122. });
  123. },
  124. // 删除图片
  125. deletePic(event) {
  126. this[`imgList${event.name}`].splice(event.index, 1)
  127. this[`fileLists${event.name}`].splice(event.index, 1)
  128. },
  129. // 新增图片
  130. async afterRead(event) {
  131. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  132. let lists = [].concat(event.file)
  133. let fileListLen = this.fileLists.length
  134. lists.map((item) => {
  135. this.fileLists.push({
  136. ...item,
  137. status: 'uploading',
  138. message: '上传中'
  139. })
  140. })
  141. for (let i = 0; i < lists.length; i++) {
  142. const result = await this.uploadFilePromise(lists[i])
  143. let item = this.fileLists[fileListLen]
  144. this.fileLists.splice(fileListLen, 1, Object.assign(item, {
  145. status: 'success',
  146. message: '',
  147. url: result
  148. }))
  149. fileListLen++
  150. if (isImageFormat(item.url)) {
  151. item.url = BASE_URL + item.url
  152. this.imgList.push(item)
  153. } else {
  154. const fileName = item.url.split(/[/\\=]/).pop();
  155. let a = {
  156. name: fileName,
  157. url: item.url
  158. }
  159. this.fileList.push(a)
  160. }
  161. }
  162. },
  163. uploadFilePromise(param) {
  164. return new Promise((resolve, reject) => {
  165. let a = uni.uploadFile({
  166. url: this.BASE_URL + '/file/upload?uploadPath=filtransmit',
  167. filePath: param.url,
  168. name: 'file',
  169. header: {
  170. "token": $auth.getUserToken()
  171. },
  172. formData: param,
  173. success: (res) => {
  174. setTimeout(() => {
  175. resolve(res.data)
  176. }, 1000)
  177. }
  178. })
  179. });
  180. },
  181. // 下载文件
  182. download(param) {
  183. fileService.download(param).then(data)
  184. },
  185. // 表单提交
  186. formSubmit() {
  187. this.loading = true
  188. let files = []
  189. this.fileLists.forEach(item => {
  190. files.push(item.url)
  191. })
  192. this.inputForm.attachedDocumentId = files.join(",");
  193. // this.$refs['inputForm'].validate((valid) => {
  194. // if (valid) {
  195. gwCirculationCard2Service.save(this.inputForm).then((data) => {
  196. let param = {
  197. type: 'success',
  198. message: data,
  199. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
  200. }
  201. this.showToast(param);
  202. setTimeout(() => {
  203. uni.redirectTo({
  204. url: '/pages/fileTransmit/addFileTransmit'
  205. });
  206. }, 500)
  207. }).catch(() => {
  208. let param = {
  209. type: 'error',
  210. message: data,
  211. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png',
  212. }
  213. this.showToast(param);
  214. })
  215. // }
  216. // })
  217. }
  218. }
  219. }
  220. </script>
  221. <style>
  222. .default_title {
  223. padding-top: 0px;
  224. }
  225. .main_info {
  226. margin-top: 15px;
  227. /* height: 80vh; */
  228. }
  229. .submit_btn {
  230. background-color: #fefefe;
  231. margin-top: 20px;
  232. box-shadow: none;
  233. margin-bottom: 20px;
  234. }
  235. .submit_btn button {
  236. height: 40px;
  237. width: 80%;
  238. border-radius: 30px;
  239. }
  240. .addfile {
  241. width: 80px;
  242. height: 80px;
  243. background-color: #eee;
  244. padding-left: 30%;
  245. /* padding-left: 18%; */
  246. margin: 10px;
  247. }
  248. .other_info {
  249. width: 100%;
  250. }
  251. </style>