addFileTransmit.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.redirectTo({
  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. that.fileLists = that.fileLists.filter(i => !(i.url == item.url))
  116. that.fileList = that.fileList.filter(i => !(i.url == item.url))
  117. } else if (res.cancel) {
  118. console.log('用户点击取消');
  119. }
  120. }
  121. });
  122. },
  123. // 删除图片
  124. deletePic(event) {
  125. this[`imgList${event.name}`].splice(event.index, 1)
  126. this[`fileLists${event.name}`].splice(event.index, 1)
  127. },
  128. // 新增图片
  129. async afterRead(event) {
  130. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  131. let lists = [].concat(event.file)
  132. let fileListLen = this.fileLists.length
  133. lists.map((item) => {
  134. this.fileLists.push({
  135. ...item,
  136. status: 'uploading',
  137. message: '上传中'
  138. })
  139. })
  140. for (let i = 0; i < lists.length; i++) {
  141. const result = await this.uploadFilePromise(lists[i])
  142. let item = this.fileLists[fileListLen]
  143. this.fileLists.splice(fileListLen, 1, Object.assign(item, {
  144. status: 'success',
  145. message: '',
  146. url: result
  147. }))
  148. fileListLen++
  149. if (isImageFormat(item.url)) {
  150. let item1 = {
  151. url:BASE_URL + result
  152. }
  153. this.imgList.push(item1)
  154. } else {
  155. const fileName = item.url.split(/[/\\=]/).pop();
  156. let a = {
  157. name: fileName,
  158. url: item.url
  159. }
  160. this.fileList.push(a)
  161. }
  162. }
  163. },
  164. uploadFilePromise(param) {
  165. return new Promise((resolve, reject) => {
  166. let a = uni.uploadFile({
  167. url: this.BASE_URL + '/gwfile/upload?uploadPath=filtransmit',
  168. filePath: param.url,
  169. name: 'file',
  170. header: {
  171. "token": $auth.getUserToken()
  172. },
  173. formData: param,
  174. success: (res) => {
  175. setTimeout(() => {
  176. resolve(res.data)
  177. }, 1000)
  178. }
  179. })
  180. });
  181. },
  182. // 下载文件
  183. download(param) {
  184. fileService.download(param).then(data)
  185. },
  186. // 表单提交
  187. formSubmit() {
  188. this.loading = true
  189. let files = []
  190. this.fileLists.forEach(item => {
  191. files.push(item.url)
  192. })
  193. this.inputForm.attachedDocumentId = files.join(",");
  194. // this.$refs['inputForm'].validate((valid) => {
  195. // if (valid) {
  196. gwCirculationCard2Service.save(this.inputForm).then((data) => {
  197. let param = {
  198. type: 'success',
  199. message: data,
  200. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
  201. url:"/pages/fileTransmit/addFileTransmit"
  202. }
  203. this.showToast(param);
  204. // setTimeout(() => {
  205. // uni.redirectTo({
  206. // url: '/pages/fileTransmit/addFileTransmit'
  207. // });
  208. // }, 500)
  209. }).catch(() => {
  210. let param = {
  211. type: 'error',
  212. message: data,
  213. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png',
  214. }
  215. this.showToast(param);
  216. })
  217. // }
  218. // })
  219. }
  220. }
  221. }
  222. </script>
  223. <style>
  224. .default_title {
  225. padding-top: 0px;
  226. }
  227. .main_info {
  228. margin-top: 15px;
  229. /* height: 80vh; */
  230. }
  231. .submit_btn {
  232. background-color: #fefefe;
  233. margin-top: 20px;
  234. box-shadow: none;
  235. margin-bottom: 20px;
  236. }
  237. .submit_btn button {
  238. height: 40px;
  239. width: 80%;
  240. border-radius: 30px;
  241. }
  242. .addfile {
  243. width: 80px;
  244. height: 80px;
  245. background-color: #eee;
  246. padding-left: 30%;
  247. /* padding-left: 18%; */
  248. margin: 10px;
  249. }
  250. .other_info {
  251. width: 100%;
  252. }
  253. </style>