|
|
@@ -93,6 +93,16 @@
|
|
|
v-hasPermi="['live:task:export']"
|
|
|
>导出</el-button>
|
|
|
</el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="success"
|
|
|
+ plain
|
|
|
+ icon="el-icon-upload2"
|
|
|
+ size="mini"
|
|
|
+ @click="handleImportCoupon"
|
|
|
+ v-hasPermi="['live:task:export']"
|
|
|
+ >导入优惠券</el-button>
|
|
|
+ </el-col>
|
|
|
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
</el-row>
|
|
|
|
|
|
@@ -289,6 +299,32 @@
|
|
|
<el-button @click="cancel">取 消</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
+
|
|
|
+ <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
|
|
|
+ <el-upload
|
|
|
+ ref="upload"
|
|
|
+ :limit="1"
|
|
|
+ accept=".xlsx, .xls"
|
|
|
+ :headers="upload.headers"
|
|
|
+ :action="upload.url"
|
|
|
+ :disabled="upload.isUploading"
|
|
|
+ :on-progress="handleFileUploadProgress"
|
|
|
+ :on-success="handleFileSuccess"
|
|
|
+ :auto-upload="false"
|
|
|
+ drag
|
|
|
+ >
|
|
|
+ <i class="el-icon-upload"></i>
|
|
|
+ <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
+ <div class="el-upload__tip" slot="tip">
|
|
|
+ <el-link type="info" style="font-size:12px;float:right" @click="importCouponTemplateDownload">下载模板</el-link>
|
|
|
+ </div>
|
|
|
+ <div class="el-upload__tip" style="color:red" slot="tip">提示:填写优惠券名称(需已关联本直播间),仅允许 xls/xlsx 格式!</div>
|
|
|
+ </el-upload>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitFileForm">确 定</el-button>
|
|
|
+ <el-button @click="upload.open = false">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -299,6 +335,9 @@ import {listLiveGoods} from "@/api/live/liveGoods";
|
|
|
import {listLiveRedConfOn} from "@/api/live/liveRedConf";
|
|
|
import {listLiveLotteryConfOn} from "@/api/live/liveLotteryConf";
|
|
|
import {listLiveCouponOn} from "@/api/live/liveCoupon";
|
|
|
+import { getToken } from "@/utils/auth";
|
|
|
+import request from "@/utils/request";
|
|
|
+import axios from "axios";
|
|
|
|
|
|
|
|
|
export default {
|
|
|
@@ -428,6 +467,13 @@ export default {
|
|
|
{ required: true, message: "更新时间不能为空", trigger: "blur" }
|
|
|
]
|
|
|
},
|
|
|
+ upload: {
|
|
|
+ open: false,
|
|
|
+ title: "",
|
|
|
+ isUploading: false,
|
|
|
+ headers: { Authorization: "Bearer " + getToken() },
|
|
|
+ url: process.env.VUE_APP_BASE_API + "/live/task/importCouponData",
|
|
|
+ },
|
|
|
liveId: null,
|
|
|
listParams: {
|
|
|
pageNum: 1,
|
|
|
@@ -456,6 +502,7 @@ export default {
|
|
|
return;
|
|
|
}
|
|
|
this.queryParams.liveId = this.liveId;
|
|
|
+ this.upload.url = process.env.VUE_APP_BASE_API + "/live/task/importCouponData?liveId=" + this.liveId;
|
|
|
this.getList();
|
|
|
},
|
|
|
// 初始化时立即执行一次
|
|
|
@@ -1093,6 +1140,72 @@ export default {
|
|
|
this.exportLoading = false;
|
|
|
}).catch(() => {});
|
|
|
},
|
|
|
+ /** 导入优惠券任务 */
|
|
|
+ handleImportCoupon() {
|
|
|
+ if (!this.liveId) {
|
|
|
+ this.$message.error("错误直播间,请联系管理员处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.upload.title = "导入定时优惠券任务";
|
|
|
+ this.upload.open = true;
|
|
|
+ },
|
|
|
+ handleFileUploadProgress() {
|
|
|
+ this.upload.isUploading = true;
|
|
|
+ },
|
|
|
+ handleFileSuccess(response) {
|
|
|
+ this.upload.open = false;
|
|
|
+ this.upload.isUploading = false;
|
|
|
+ this.$refs.upload.clearFiles();
|
|
|
+ this.$alert(response.msg || "导入完成", "导入结果", { dangerouslyUseHTMLString: true });
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+ submitFileForm() {
|
|
|
+ if (!this.liveId) {
|
|
|
+ this.$message.error("错误直播间,请联系管理员处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$refs.upload.submit();
|
|
|
+ },
|
|
|
+ importCouponTemplateDownload() {
|
|
|
+ request({
|
|
|
+ url: '/live/task/importCouponTemplate',
|
|
|
+ method: 'get'
|
|
|
+ }).then((response) => {
|
|
|
+ return this.downloadFileWithAuth(response.msg);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /** 带 Token 下载,避免 /common/download 401(参考 liveCouponUser) */
|
|
|
+ downloadFileWithAuth(fileName) {
|
|
|
+ if (!fileName) {
|
|
|
+ this.msgError("下载失败,未获取到文件名");
|
|
|
+ return Promise.reject("empty fileName");
|
|
|
+ }
|
|
|
+ return axios({
|
|
|
+ method: "get",
|
|
|
+ url: process.env.VUE_APP_BASE_API + "/common/download",
|
|
|
+ params: { fileName: fileName, delete: false },
|
|
|
+ responseType: "blob",
|
|
|
+ headers: {
|
|
|
+ Authorization: "Bearer " + getToken(),
|
|
|
+ "X-Frontend-Type": "admin"
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ const disposition = res.headers["content-disposition"] || "";
|
|
|
+ let downloadName = fileName.indexOf("_") > -1 ? fileName.substring(fileName.indexOf("_") + 1) : fileName;
|
|
|
+ const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(disposition);
|
|
|
+ if (match && match[1]) {
|
|
|
+ downloadName = decodeURIComponent(match[1].replace(/['"]/g, ""));
|
|
|
+ }
|
|
|
+ const blob = new Blob([res.data]);
|
|
|
+ const link = document.createElement("a");
|
|
|
+ link.href = window.URL.createObjectURL(blob);
|
|
|
+ link.setAttribute("download", downloadName);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+ window.URL.revokeObjectURL(link.href);
|
|
|
+ });
|
|
|
+ },
|
|
|
}
|
|
|
};
|
|
|
</script>
|