浏览代码

合并 work-jyf 代码

jiayufei 3 年之前
父节点
当前提交
2f06109185
共有 1 个文件被更改,包括 72 次插入113 次删除
  1. 72 113
      src/views/modules/settlement-account/settlement-account.vue

+ 72 - 113
src/views/modules/settlement-account/settlement-account.vue

@@ -117,7 +117,7 @@
                 <span slot="action" slot-scope="text, record">
                     <a @click="handleSettleDel(record)">删除</a>
                     <a-divider type="vertical"/>
-                    <a>更多</a>
+                    <a disabled>更多</a>
                 </span>
             </a-table>
             <a-pagination
@@ -131,7 +131,7 @@
                 @showSizeChange="onShowSizeChange"
             />
         </div>
-        <!-- 新增、编辑政策 -->
+        <!-- 上传账户数据 -->
         <a-modal
             v-if="policyOperationStatus"
             title="账户上传"
@@ -214,14 +214,14 @@
                     <a-form-model-item label="附件上传">
                         <a-upload
                             name="file"
-                            :file-list="fileList"
-                            :before-upload="beforeUpload"
-                            @change="handleChange"
+                            :file-list="policyOperationForm.fileList"
+                            :customRequest="handleCustomRequest"
+                            :remove="handleRemoveUpload"
                         >
-                            <a-button><a-icon type="upload" />文件上传</a-button>
+                            <a-button><a-icon type="upload"/>文件上传</a-button>
                         </a-upload>
                         <a class="file-down-title" @click="handleFileDownTitle">文件格式下载</a>
-                        <p class="upload-txt-rules">支持扩展名:.xlxs</p>
+                        <p class="upload-txt-rules">支持扩展名:.xlsx、.xls</p>
                     </a-form-model-item>
                 </a-form-model>
             </div>
@@ -230,17 +230,9 @@
 </template>
 <script>
 import {mapGetters} from 'vuex';
-import {getAction, postAction} from '@/api/manage';
+import {getAction, postFileAction} from '@/api/manage';
 import {urlAcount} from './settlement-account-server.js';
 
-
-import BMF from 'browser-md5-file';
-let COS = require('cos-js-sdk-v5');
-let cos = new COS({
-    SecretId: 'AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets',
-    SecretKey: 'tXzuwMfplTTK3c9GFUyETilasvQfePu9'
-});
-
 export default {
     name: 'settlement-account',
     data() {
@@ -250,7 +242,6 @@ export default {
             allProductListOption: [],
             controlLoading: false,
             allSaleListOption: [],
-            fileList: [],
             labelCol: {span: 7},
             wrapperCol: {span: 14},
             policyOperationForm: {
@@ -258,7 +249,8 @@ export default {
                 productId: undefined,
                 projectId: undefined,
                 mediaId: 1,
-                operateType: 1
+                operateType: 1,
+                fileList: []
             },
             policyOperationRules: {
                 advertiserId: [{required: true, message: '请选择广告主公司名称', trigger: 'change'}],
@@ -466,110 +458,79 @@ export default {
         },
         // 文件格式下载
         handleFileDownTitle() {
-            console.log('文件格式下载');
-        },
-        beforeUpload(file) {
-            this.cosUpload(file);
+            const {mediaId} = this.policyOperationForm;
+            if (mediaId === 1) {
+                window.location.href = 'http://media-1301855440.cos.ap-chongqing.myqcloud.com/undefined/2021-08-17/%E5%A4%B4%E6%9D%A1%E8%B4%A6%E6%88%B7%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF-1629185054420.xlsx';
+            }
+            else if (mediaId === 2) {
+                window.location.href = 'http://media-1301855440.cos.ap-chongqing.myqcloud.com/undefined/2021-08-17/%E5%BF%AB%E6%89%8B%E8%B4%A6%E6%88%B7%E4%B8%8A%E4%BC%A0%E6%A8%A1%E6%9D%BF-1629185318124.xlsx';
+            }
         },
-        handleMd5(file) {
-            let bmf = new BMF();
-            let that = this;
-            return new Promise(function (resolve, reject) {
-                bmf.md5(file, (err, md5) => {
-                    console.log(md5, 'md5');
-                    // getAction('kuaishouPopulationPackage/checkPopulationPackage', {signature: md5}).then(result => {
-                    //     if (result.code === 200) {
-                    //         that.personNameDisabled = false;
-                    //         that.personResourceDisabled = false;
-                    //         resolve();
-                    //     }
-                    //     else if (result.code === 201) {
-                    //         that.$message.error(result.message);
-                    //         that.personForm.name = result.result.orientationName;
-                    //         that.personForm.resource = result.result.type;
-                    //         that.personNameDisabled = true;
-                    //         that.personResourceDisabled = true;
-                    //         reject();
-                    //     }
-                    // }).catch(error => {
-                    //     console.log(error, 'eeee');
-                    //     reject();
-                    // });
-                });
+        handleCustomRequest(info) {
+            const isZip = info.file.name.indexOf('xlsx') !== -1 || info.file.name.indexOf('xls') !== -1;
+            if (!isZip) {
+                this.$message.error('上传模板只能是 xls、xlsx格式!');
+                return;
+            }
+            this.policyOperationForm.fileList = [];
+            this.$nextTick(() => {
+                this.policyOperationForm.fileList.push(info.file);
             });
         },
-        handleChange(info) {
-            this.fileList = info.fileList;
+        handleRemoveUpload(data) {
+            let index = this.policyOperationForm.fileList.indexOf(data);
+            let newUploadFile = this.policyOperationForm.fileList;
+            newUploadFile.splice(index, 1);
+            this.policyOperationForm.fileList = newUploadFile;
         },
-        cosUpload(file) {
-            let that = this;
-            let date = new Date();
-            let y = date.getFullYear();
-            let MM = date.getMonth() + 1;
-            MM = MM < 10 ? '0' + MM : MM;
-            let d = date.getDate();
-            d = d < 10 ? '0' + d : d;
-            let timeElse = new Date().getTime();
-            let arr = file.name.split('.');
-            let str = '';
-            for (let i = 0; i < arr.length; i++) {
-                if (i === arr.length - 1) {
-                }
-                else {
-                    if (i === arr.length - 2) {
-                        str += arr[i];
-                    }
-                    else {
-                        str += arr[i] + '.';
-                    }
-                }
-            }
-            cos.putObject(
-                {
-                    Bucket: 'media-1301855440',
-                    Region: 'ap-chongqing',
-                    // 存储桶所在地域,必须字段
-                    Key: that.uploadType + '/' + y + '-' + MM + '-' + d + '/' + str + '-' + timeElse + '.' + arr[arr.length - 1],
-                    StorageClass: 'STANDARD',
-                    Body: file // 上传文件对象
-                },
-                function (err, data) {
-                    if (err) {
-                        that.$message.error('上传失败!!!' + err);
+        // 上传确定按钮操作
+        handlePolicyOperationSure() {
+            const {advertiserId, productId, projectId, mediaId, operateType, fileList} = this.policyOperationForm;
+            this.$refs.policyOperationForm.validate(valid => {
+                if (valid) {
+                    if (!fileList.length) {
+                        this.$message.error('请上传文件');
                         return;
                     }
-                    that.loadingElse = false;
-                    that.fileList.push({
-                        uid: file.name,
-                        name: file.name,
-                        status: 'done',
-                        url: '//' + data.Location
+                    let paramsData = new FormData();
+                    paramsData.append('advertiserId', advertiserId);
+                    paramsData.append('productId', productId);
+                    paramsData.append('projectId', projectId);
+                    paramsData.append('mediaId', mediaId);
+                    paramsData.append('operateType', operateType);
+                    paramsData.append('file', fileList[0]);
+                    postFileAction(urlAcount + '/finance/settLementController/settlementAccountImport', paramsData, {
+                        headers: {
+                            'Content-Type': 'multipart/form-data'
+                        }
+                    }).then(result => {
+                        if (result.code === 0) {
+                            this.$message.success(result.message);
+                            this.handlePolicyOperationCancel();
+                            this.handleInitTable();
+                        }
+                        else {
+                            this.$message.error(result.message);
+                        }
+                    }).catch(error => {
+                        console.log(error, 'eeee');
                     });
-                    console.log(data.Location, 'data.Location');
-                    if (that.fileList.length > 1) {
-                        that.fileList = that.fileList.slice(-1);
-                    }
-                    const isZip = file.type.includes('xlxs');
-                    const fileOvesize = file.size > (1024 * 1024 * 1024);
-                    // if (!isZip) {
-                    //     that.$message.error('只能上传xlxs格式的文件');
-                    //     return;
-                    // }
-                    // if (fileOvesize) {
-                    //     that.$message.error('文件大小不能超过1G');
-                    //     return;
-                    // }
-                    that.handleMd5(file);
                 }
-            );
-        },
-        // 上传确定按钮操作
-        handlePolicyOperationSure() {
-            console.log('上传确定按钮操作');
+                else {
+                    return false;
+                }
+            });
         },
         // 上传取消按钮操作
         handlePolicyOperationCancel() {
-            console.log('上传取消按钮操作');
+            this.policyOperationForm = {
+                advertiserId: undefined,
+                productId: undefined,
+                projectId: undefined,
+                mediaId: 1,
+                operateType: 1,
+                fileList: []
+            };
             this.policyOperationStatus = false;
         },
         // 删除操作
@@ -621,12 +582,10 @@ export default {
         },
         // 账户上传按钮
         handleUploadAccount() {
-            console.log('上传账户数据');
             this.policyOperationStatus = true;
         },
         // 查询的按钮
         handleQueryList() {
-            console.log(this.configForm, '搜索的按钮');
             this.tablePag = {
                 page: 1,
                 size: 10