Sunny Feng 2 лет назад
Родитель
Сommit
36e9cef6e3

+ 7 - 4
src/components/BillForm/BillForm.vue

xqd xqd xqd xqd
@@ -211,6 +211,7 @@
         <!-- 删除汇票 -->
         <el-col :span="24" style="text-align:right">
           <el-button
+            v-if="showDel"
             type="primary"
             @click="onDelete(index)"
           >删除汇票</el-button>
@@ -227,6 +228,7 @@
 import { maxLoanAmount, serviceCharge, interest } from '@/utils/calc'
 import DrawerSelect from '@/components/DrawerSelect/DrawerSelect.vue'
 import AcceptorSelect from '@/components/AcceptorSelect/AcceptorSelect.vue'
+
 export default {
   name: 'BillForm',
   props: {
@@ -235,6 +237,10 @@ export default {
       default: () => {
         return []
       },
+    },
+    showDel: {
+      type: Boolean,
+      default: true
     }
   },
   components: {
@@ -281,15 +287,12 @@ export default {
   },
   watch:{
     value(val, old) {
-      console.log('billform=', val)
+      console.log('BillForm=', val)
       if(val){
         this.contractDrafts = val
       }
     }
   },
-  mounted() {
-    //this.$set(this.contractDrafts, 'picUrls', this.contractDrafts.picList)
-  },
   methods: {
     addDrawer() {
       this.$router.push({

+ 0 - 271
src/components/FileUpload/FileUpload.vue

xqd
@@ -1,271 +0,0 @@
-<template>
-  <div>
-    <el-upload
-      :action="action"
-      :file-list="fileList"
-      list-type="picture-card"
-      :http-request="uploadFile"
-      :headers="headers"
-      :limit="limit"
-      :accept="accept"
-      :data="data"
-      :class="hideUpload || uploading ? 'hideUpload' : ''"
-      :on-error="handleError"
-      :before-upload="beforeUpload"
-      drag
-      multiple
-    >
-      <i slot="default" class="el-icon-plus"></i>
-      <div slot="file" slot-scope="{ file }">
-        <div class="text-center p-2">
-        <img
-        class="el-upload-list__item-thumbnail"
-        :src="file.file_type ? (file.file_type === 'image' ? file.url : '/images/file/' + file.file_type + '.png') : '/images/file/pdf.png'"
-        alt="" />
-
-        <span
-          v-if="file.status === 'success'"
-          class="el-upload-list__item-actions"
-        >
-          <span
-            v-if="preview"
-            class="el-upload-list__item-preview"
-            @click="handlePreview(file)"
-          >
-            <i class="el-icon-zoom-in"></i>
-          </span>
-          <span
-            v-if="download"
-            class="el-upload-list__item-delete"
-            @click="handleDownload(file)"
-          >
-            <i class="el-icon-download"></i>
-          </span>
-          <span
-            v-if="deleted"
-            class="el-upload-list__item-delete"
-            @click="handleRemove(file)"
-          >
-            <i class="el-icon-delete"></i>
-          </span>
-        </span>
-        <span
-          v-else
-          :class="[
-            uploading ? 'uploading' : '',
-            'el-upload-list__item-actions',
-          ]"
-        >
-          <i class="el-icon-loading" /><i style="font-size: 14px">上传中</i>
-        </span>
-
-        <div style="word-break: break-all;
-         text-overflow: ellipsis;
-         display: -webkit-box;
-         -webkit-box-orient: vertical;
-         -webkit-line-clamp: 2;
-         overflow: hidden;">{{ file.created_at.substr(0,10) + '-' + file.name+'.'+file.ext }}</div>
-      </div>
-
-      </div>
-    </el-upload>
-
-    <el-dialog :visible.sync="previewVisible">
-      <img width="100%" :src="previewImgUrl" alt="" />
-    </el-dialog>
-  </div>
-</template>
-
-<script>
-
-export default {
-  name: 'FileUpload',
-  props: {
-    type: {
-      type: String,
-      default: () => {
-        return ''
-      },
-    },
-    data: {
-      type: Object,
-      default: () => {
-        return {}
-      },
-    },
-    // 上传的地址
-    action: {
-      type: String,
-      default: '#',
-    },
-    // 设置上传的请求头部
-    headers: {
-      type: Object,
-      default: () => {
-        return {}
-      },
-    },
-    // 上传文件大小限制, 默认 50M,单位M
-    size: {
-      type: [Number, String],
-      default: 50,
-    },
-    // 文件上传格式, 默认jpeg, png,jpg
-    accept: {
-      type: String,
-      default: 'image/jpeg,image/png',
-    },
-    // 是否显示删除操作按钮
-    deleted: {
-      type: Boolean,
-      default: true,
-    },
-    // 是否显示预览操作按钮
-    preview: {
-      type: Boolean,
-      default: false,
-    },
-    // 是否显示下载操作按钮
-    download: {
-      type: Boolean,
-      default: true,
-    },
-    // 上传文件个数限制,默认0 不限制
-    limit: {
-      type: [Number, String],
-      default: 0,
-    },
-  },
-  data() {
-    return {
-      fileList: [], // 默认文件列表
-      hideUpload: false, // 超出限制掩藏上传按钮
-      uploading: false, // 是否上传中,上传时隐藏上传按钮
-      previewImgUrl: '', // 预览图片地址
-      previewVisible: false, // 是否显示预览
-      get_url: '',
-      save_url:'',
-      del_url: '',
-    }
-  },
-  mounted() {
-    if(this.type == 'apply'){
-      this.get_url = `user/folder/${this.data.folder_id}/file/list`
-      this.save_url = `user/folder/${this.data.folder_id}/file`,
-      this.del_url = `user/folder/file`
-    } else {
-      this.get_url = `user/${this.data.user_id}/file/list?type=${this.data.type}`
-      this.save_url = `user/file`
-      this.del_url = `user/file`
-    }
-    this.getData()
-  },
-  methods: {
-    async getData() {
-      const res = await this.$axios.$get(
-        this.get_url
-      )
-      if(res){
-        this.fileList = res.files
-        console.log(this.fileList)
-        this.handleChange()
-      }
-    },
-    async uploadFile(data){
-      var formData = new FormData();
-      formData.append("file", data.file);
-      if(data.data.type){
-        formData.append("type", data.data.type);
-      }
-      formData.append("user_id", data.data.user_id);
-      try{
-        let res = await this.$axios.$post(
-          this.save_url,
-          formData
-        )
-        this.fileList.push(res)
-        console.log(this.fileList)
-      } catch (e) {
-        if (!e.response) return
-        const { data, status } = e.response
-        this.$message.error(`(${status}) ${this.$helper.extractError(data)}`)
-      } finally {
-        this.handleChange()
-      }
-    },
-    // 上传前文件大小判断
-    beforeUpload(file) {
-      const { size } = this
-      const overSize = size > 0 && file.size < 1024 * 1024 * size
-      if (!overSize) this.$message.error(`上传文件大小不能超过 ${size}MB!`)
-      this.uploading = overSize // 是否上传中
-      return overSize
-    },
-    // 上传出错返回
-    handleError(event, file, fileList) {
-      console.log(event, file, fileList, 'error')
-      this.$message.error('服务出错,上传失败!')
-      this.handleChange()
-    },
-    // 删除图片
-    async handleRemove(file) {
-      this.$confirm(`确认删除 ${file.name+'.'+file.ext} 文件?`, '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(async () => {
-        const { fileList } = this
-        this.fileList = fileList.filter((item) => item.uid !== file.uid)
-        let res = await this.$axios.$delete(
-          this.del_url + '/' + file.id
-        )
-        this.handleChange()
-      }).catch(()=>{})
-    },
-    // 图片预览
-    handlePreview(file) {
-        window.open(file.url, "_blank");
-      /*
-        this.previewImgUrl = file.url
-        this.previewVisible = true
-      */
-    },
-    handleChange(file, list) {
-      const { limit, fileList } = this
-      if (limit > 0 && fileList.length >= limit) this.hideUpload = true
-      else this.hideUpload = false
-      this.uploading = false
-    },
-    handleDownload(file) {
-      window.open(file.url, "_blank");
-      /*const a = document.createElement('a')
-      a.href = file.url
-      a.click() // 模拟点击事件,实现图片文件的同源下载
-      */
-    },
-  },
-}
-</script>
-
-<style>
-.hideUpload .el-upload--picture-card {
-  display: none;
-}
-.el-upload-list--picture-card .uploading.el-upload-list__item-actions {
-  opacity: 1;
-}
-/*添加、删除文件时去掉动画过渡*/
-.el-upload-list__item {
-  transition: none !important;
-}
-.el-upload-list--picture-card .el-upload-list__item-thumbnail {
-    width: 108px;
-    height: 128px;
-}
-.el-upload-list--picture-card .el-upload-list__item {
-    background-color: inherit;
-    border: none;
-    width: 158px;
-    height: 208px;
-}
-</style>

+ 16 - 12
src/components/upload/FileUpload.vue

xqd
@@ -142,18 +142,22 @@ export default {
     }
   },
   watch:{
-    value(val, old) {
-      console.log('value=', val)
-      if(val){
-        this.files = val
-        this.fileList = [] // 先清空
-        for(var i=0; i<val.length;i++){
-          this.fileList.push({
-            url: val[i] // 转化
-          })
-        }
-        this.handleChange()
-      }
+    value: {
+        handler(val, old){
+          console.log('FileUpload=', val)
+          if(val){
+            this.files = val
+            this.fileList = [] // 先清空
+            for(var i=0; i<val.length;i++){
+              this.fileList.push({
+                url: val[i] // 转化
+              })
+            }
+            this.handleChange()
+          }
+      },
+      deep: true,
+      immediate: true // 避免在子组件中监听失效
     }
   },
   methods: {

+ 30 - 4
src/views/contracts/addnewbill.vue

xqd xqd xqd xqd
@@ -5,12 +5,16 @@
       <!-- 汇票编辑 -->
       <el-form ref="form" :model="form" label-width="110px" label-position="right" class="form-container">
         <BillForm
+        :showDel="showDel"
         v-model="form.contractDrafts"
         />
       </el-form>
 
       <!-- 新增汇票 -->
       <div class="commit">
+        <div class="addnew" v-if="showDel">
+          <el-button type="success" @click.stop="onAdd">新增汇票</el-button>
+        </div>
         <div class="addall">
           <el-button
             type="warning"
@@ -34,6 +38,7 @@ export default {
   },
   data() {
     return {
+      showDel: true,
       form: {
         /* 汇票的数据 */
         contractDrafts: []
@@ -48,8 +53,8 @@ export default {
     getDetail() {
       const id = this.$route.query.id
       if(!id){
-        // 合同ID 没有汇票id 新增汇票
-        this.form.contractDrafts.push({
+        // 合同ID 没有汇票id 新增多条汇票
+        this.form.contractDrafts = [{
             name: '', // 汇票名称
             draftNo: '', // 汇票号码
             acceptorId: '', // 承兑人id
@@ -69,16 +74,37 @@ export default {
             // limitTime: '', //
             // acceptDateTime: '', //
             // expectDiscountDateTime: ''//
-          })
+          }]
 
           return
       }
 
-      // 有汇票ID 修改汇票
+      // 有汇票ID 修改一条汇票
       contractsDraftDetailApi(id).then((res) => {
+        this.showDel = false
+        res.data.picUrls = res.data.picList
         this.form.contractDrafts = [res.data]
       });
     },
+    onAdd() {
+      this.form.contractDrafts.push({
+        name: '', // 汇票名称
+        draftNo: '', // 汇票号码
+        acceptorId: '', // 承兑人id
+        drawersId: '', // 出票人
+        money: '', // 金额
+        acceptDate: '', // 出票日期
+        loanLimit: '', // 最高贷款额度
+        serviceRate: '', // 服务费率
+        serviceMoney: '', // 服务费
+        interestRate: '', // 利率
+        interest: '', // 利息
+        picUrls: [], // 汇票名称
+        expectDiscountDate: '', // 预计贴现日
+        issueDate: '', // 承兑日期
+        expireDate: '' // 到期日期
+      })
+    },
     onSubmit(o) {
       this.$refs.form.validate((valid) => {
         if (valid) {

+ 23 - 21
src/views/contracts/new_file.vue

xqd xqd xqd
@@ -67,7 +67,7 @@
       <!-- 新增汇票 -->
       <div class="commit">
         <div class="addnew">
-          <el-button type="primary" @click.stop="onAdd">新增汇票</el-button>
+          <el-button type="success" @click.stop="onAdd">新增汇票</el-button>
         </div>
         <div class="addall">
           <el-button
@@ -101,26 +101,7 @@ export default {
         tradePics: [], // 贸易合同
         supplierId: 2, // 不知道干啥的
         /* 汇票的数据 */
-        contractDrafts: [{
-            name: '', // 汇票名称
-            draftNo: '', // 汇票号码
-            acceptorId: '', // 承兑人id
-            drawersId: '', // 出票人
-            money: '', // 金额
-            acceptDate: '', // 出票日期
-            loanLimit: '', // 最高贷款额度
-            serviceRate: '', // 服务费率
-            serviceMoney: '', // 服务费
-            interestRate: '', // 利率
-            interest: '', // 利息
-            picUrls: [], // 汇票名称
-            expectDiscountDate: '', // 预计贴现日
-            issueDate: '', // 承兑日期
-            expireDate: '' // 到期日期
-            // limitTime: '', //
-            // acceptDateTime: '', //
-            // expectDiscountDateTime: ''//
-          }]
+        contractDrafts: []
       },
     }
   },
@@ -132,6 +113,27 @@ export default {
     getDetail() {
       const id = this.$route.query.id
       if(!id){
+        // 新增合同
+        this.form.contractDrafts = [{
+          name: '', // 汇票名称
+          draftNo: '', // 汇票号码
+          acceptorId: '', // 承兑人id
+          drawersId: '', // 出票人
+          money: '', // 金额
+          acceptDate: '', // 出票日期
+          loanLimit: '', // 最高贷款额度
+          serviceRate: '', // 服务费率
+          serviceMoney: '', // 服务费
+          interestRate: '', // 利率
+          interest: '', // 利息
+          picUrls: [], // 汇票名称
+          expectDiscountDate: '', // 预计贴现日
+          issueDate: '', // 承兑日期
+          expireDate: '' // 到期日期
+          // limitTime: '', //
+          // acceptDateTime: '', //
+          // expectDiscountDateTime: ''//
+        }]
         return
       }
       contractsDetailApi(id).then((res) => {