123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <template>
- <view>
- <view class="bg-white default_title">
- <u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
- ref="inputForm">
- <u-form-item label="年度" borderBottom prop="yearNum">
- <u--input v-model="inputForm.yearNum" placeholder="输入年度" border="none"></u--input>
- </u-form-item>
- <u-form-item label="卡号" borderBottom prop="cardNum">
- <u--input v-model="inputForm.cardNum" placeholder="输入卡号" border="none"></u--input>
- </u-form-item>
- </u--form>
- </view>
- <view class="bg-white margin-top main_info">
- <u--form :model="inputForm" labelWidth="130px" class="u-form default_title" labelPosition="left"
- ref="inputForm">
- <u-form-item label="来文机关" borderBottom prop="sendingAgency">
- <u--input v-model="inputForm.sendingAgency" placeholder="请输入来文机关" border="none"></u--input>
- </u-form-item>
- <u-form-item label="来文字号" borderBottom prop="docFontSize">
- <u--input v-model="inputForm.docFontSize" placeholder="请输入来文字号" border="none"></u--input>
- </u-form-item>
- <u-form-item label="文件来源" borderBottom prop="fileSource">
- <u--input v-model="inputForm.fileSource" placeholder="请输入文件来源" border="none"></u--input>
- </u-form-item>
- <u-form-item label="成文时间" borderBottom prop="writtenTime">
- <jp-datetime-picker v-model="inputForm.writtenTime" placeholder="选择成文时间"
- mode="datetime"></jp-datetime-picker>
- </u-form-item>
- <u-form-item label="收文时间" borderBottom prop="receivingTime">
- <jp-datetime-picker v-model="inputForm.receivingTime" placeholder="选择收文时间"
- mode="datetime"></jp-datetime-picker>
- </u-form-item>
- <u-form-item label="内容摘要" borderBottom prop="contentSummary">
- <u--textarea v-model="inputForm.contentSummary" placeholder="请输入内容摘要" border="none"></u--textarea>
- </u-form-item>
- <u-form-item label="来文附件" prop="attachedDocumentId" labelPosition="top">
- <u-upload :fileList="fileLists" @afterRead="afterRead" multiple :maxCount="9" width="250"
- height="150" accept="file" :previewImage="false">
- <view class="addfile flex"> <u-icon size="20" bold name="plus"></u-icon></view>
- </u-upload>
- </u-form-item>
- <view class="other_info">
- <view class="other_pdf">
- <u-cell-group>
- <u-cell v-for="item in fileList" :title="item.name">
- <u-icon slot="right-icon" size="28" name="trash-fill"
- @click="deleteFile(item)"></u-icon>
- </u-cell>
- </u-cell-group>
- </view>
- </view>
- <u-upload :fileList="imgList" @delete="deletePic" multiple :maxCount="imgList.length"
- :previewFullImage="true"></u-upload>
- <u--text size="12" type="error" text="请确保上传图片内容清晰可见,所有涉密敏感信息不得上传"></u--text>
- <view class="submit_btn flex">
- <u-button v-if="!loading" type="primary" text="提交新增" @click="formSubmit"></u-button>
- <u-button v-if="loading" :loading="loading" type="primary" text="加载中"></u-button>
- </view>
- </u--form>
- </view>
- <u-toast ref="uToast"></u-toast>
- </view>
- </template>
- <script>
- import {
- isImageFormat
- } from "@/common/util.js"
- import BASE_URL from '@/config.js'
- import * as $auth from "@/common/auth.js"
- import fileService from '@/api/file/fileService.js'
- import gwCirculationCard2Service from '@/api/circulation/gwCirculationCard2.js'
- export default {
- data() {
- return {
- loading: false,
- fileLists: [],
- fileList: [],
- imgList: [],
- inputForm: {
- id: '',
- yearNum: '',
- cardNum: '',
- sendingAgency: '',
- docFontSize: '',
- fileSource: '',
- writtenTime: '',
- receivingTime: '',
- contentSummary: '',
- attachedDocumentId: '',
- remark: '',
- state: '1'
- },
- }
- },
- methods: {
- showToast(params) {
- this.$refs.uToast.show({
- ...params,
- complete() {
- params.url && uni.redirectTo({
- url: params.url
- })
- }
- })
- },
- // 删除文件
- deleteFile(item) {
- let that = this
- uni.showModal({
- title: '提示',
- content: '确认删除该文件',
- success: function(res) {
- if (res.confirm) {
- that.fileLists = that.fileLists.filter(i => !(i.url == item.url))
- that.fileList = that.fileList.filter(i => !(i.url == item.url))
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- },
- // 删除图片
- deletePic(event) {
- this[`imgList${event.name}`].splice(event.index, 1)
- this[`fileLists${event.name}`].splice(event.index, 1)
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file)
- let fileListLen = this.fileLists.length
- lists.map((item) => {
- this.fileLists.push({
- ...item,
- status: 'uploading',
- message: '上传中'
- })
- })
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i])
- let item = this.fileLists[fileListLen]
-
- this.fileLists.splice(fileListLen, 1, Object.assign(item, {
- status: 'success',
- message: '',
- url: result
- }))
- fileListLen++
- if (isImageFormat(item.url)) {
- let item1 = {
- url:BASE_URL + result
- }
- this.imgList.push(item1)
- } else {
- const fileName = item.url.split(/[/\\=]/).pop();
- let a = {
- name: fileName,
- url: item.url
- }
- this.fileList.push(a)
- }
- }
- },
- uploadFilePromise(param) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- url: this.BASE_URL + '/gwfile/upload?uploadPath=filtransmit',
- filePath: param.url,
- name: 'file',
- header: {
- "token": $auth.getUserToken()
- },
- formData: param,
- success: (res) => {
- setTimeout(() => {
- resolve(res.data)
- }, 1000)
- }
- })
- });
- },
- // 下载文件
- download(param) {
- fileService.download(param).then(data)
- },
- // 表单提交
- formSubmit() {
- this.loading = true
- let files = []
- this.fileLists.forEach(item => {
- files.push(item.url)
- })
- this.inputForm.attachedDocumentId = files.join(",");
- // this.$refs['inputForm'].validate((valid) => {
- // if (valid) {
- gwCirculationCard2Service.save(this.inputForm).then((data) => {
- let param = {
- type: 'success',
- message: data,
- iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
- url:"/pages/fileTransmit/addFileTransmit"
- }
- this.showToast(param);
- // setTimeout(() => {
- // uni.redirectTo({
- // url: '/pages/fileTransmit/addFileTransmit'
- // });
- // }, 500)
- }).catch(() => {
- let param = {
- type: 'error',
- message: data,
- iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png',
- }
- this.showToast(param);
- })
- // }
- // })
- }
- }
- }
- </script>
- <style>
- .default_title {
- padding-top: 0px;
- }
- .main_info {
- margin-top: 15px;
- /* height: 80vh; */
- }
- .submit_btn {
- background-color: #fefefe;
- margin-top: 20px;
- box-shadow: none;
- margin-bottom: 20px;
- }
- .submit_btn button {
- height: 40px;
- width: 80%;
- border-radius: 30px;
- }
- .addfile {
- width: 80px;
- height: 80px;
- background-color: #eee;
- padding-left: 30%;
- /* padding-left: 18%; */
- margin: 10px;
- }
- .other_info {
- width: 100%;
- }
- </style>
|