Merge branch 'ymf' of https://newgitea.sxczgkj.cn/czg_team/cashier_app into new_gyq
This commit is contained in:
commit
97feb2c588
|
|
@ -495,7 +495,7 @@
|
|||
right: 0;
|
||||
bottom: 0;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
z-index: 9999;
|
||||
background-color: rgba(51, 51, 51, .5);
|
||||
|
||||
.item {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
import http from "@/http/http.js";
|
||||
const request = http.request;
|
||||
const urlType = "market";
|
||||
|
||||
export function enable(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption/enable`,
|
||||
method: "PUT",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function status(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption/enable/status`,
|
||||
method: "get",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function couponRedemption(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption`,
|
||||
method: "get",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function couponRedemptionList(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption/list`,
|
||||
method: "get",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function add(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption`,
|
||||
method: "POST",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function edit(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption`,
|
||||
method: "PUT",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function codeList(params) {
|
||||
return request({
|
||||
url: urlType + `/admin/couponRedemption/code/list`,
|
||||
method: "GET",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
export function codeExport(params) {
|
||||
return http.download({
|
||||
url: urlType + `/admin/couponRedemption/code/export`,
|
||||
method: "GET",
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
}
|
||||
407
http/http.js
407
http/http.js
|
|
@ -1,26 +1,26 @@
|
|||
/**
|
||||
* HTTP的封装, 基于uni.request
|
||||
* 包括: 通用响应结果的处理 和 业务的增删改查函数
|
||||
*
|
||||
*
|
||||
* @author terrfly
|
||||
* @site https://www.jeequan.com
|
||||
* @date 2021/12/16 18:35
|
||||
*/
|
||||
// 设置env配置文件
|
||||
import envConfig from '@/env/config.js'
|
||||
import envConfig from "@/env/config.js";
|
||||
// 导入全局属性
|
||||
import appConfig from '@/config/appConfig.js'
|
||||
import storageManage from '@/commons/utils/storageManage.js'
|
||||
import infoBox from "@/commons/utils/infoBox.js"
|
||||
import go from '@/commons/utils/go.js';
|
||||
import { reject } from 'lodash';
|
||||
import appConfig from "@/config/appConfig.js";
|
||||
import storageManage from "@/commons/utils/storageManage.js";
|
||||
import infoBox from "@/commons/utils/infoBox.js";
|
||||
import go from "@/commons/utils/go.js";
|
||||
import { reject } from "lodash";
|
||||
// 设置node环境
|
||||
// envConfig.changeEnv(storageManage.env('production'))
|
||||
envConfig.changeEnv(storageManage.env('development'))
|
||||
envConfig.changeEnv(storageManage.env("development"));
|
||||
|
||||
// 测试服
|
||||
// #ifdef H5
|
||||
let baseUrl = '/api/'
|
||||
let baseUrl = "/api/";
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
// let baseUrl = 'https://tapi.cashier.sxczgkj.cn/'
|
||||
|
|
@ -29,207 +29,248 @@ let baseUrl = '/api/'
|
|||
|
||||
//正式
|
||||
// let baseUrl = 'https://cashier.sxczgkj.com/'
|
||||
let baseUrl = appConfig.env.JEEPAY_BASE_URL
|
||||
let baseUrl = appConfig.env.JEEPAY_BASE_URL;
|
||||
// #endif
|
||||
|
||||
const loadingShowTime = 200
|
||||
const loadingShowTime = 200;
|
||||
|
||||
function getHeader(){
|
||||
const headerObject={}
|
||||
headerObject["token"] = storageManage.token()
|
||||
headerObject["shopId"] = uni.getStorageSync("shopInfo").id
|
||||
headerObject["platformType"] = 'APP'
|
||||
|
||||
return headerObject
|
||||
function getHeader() {
|
||||
const headerObject = {};
|
||||
headerObject["token"] = storageManage.token();
|
||||
headerObject["shopId"] = uni.getStorageSync("shopInfo").id;
|
||||
headerObject["platformType"] = "APP";
|
||||
|
||||
return headerObject;
|
||||
}
|
||||
|
||||
// 通用处理逻辑
|
||||
// 通用处理逻辑
|
||||
function commonsProcess(showLoading, httpReqCallback) {
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = "ing";
|
||||
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = 'ing'
|
||||
// 是否已经提示的错误信息
|
||||
let isShowErrorToast = false;
|
||||
|
||||
// 是否已经提示的错误信息
|
||||
let isShowErrorToast = false
|
||||
// 请求完成, 需要处理的动作
|
||||
let reqFinishFunc = () => {
|
||||
if (reqState == "ingLoading") {
|
||||
// 关闭loading弹层
|
||||
infoBox.hideLoading();
|
||||
}
|
||||
reqState = "finish"; // 请求完毕
|
||||
};
|
||||
|
||||
// 明确显示loading
|
||||
if (showLoading) {
|
||||
// xx ms内响应完成,不提示loading
|
||||
setTimeout(() => {
|
||||
if (reqState == "ing") {
|
||||
reqState = "ingLoading";
|
||||
infoBox.showLoading();
|
||||
}
|
||||
}, loadingShowTime);
|
||||
}
|
||||
|
||||
// 请求完成, 需要处理的动作
|
||||
let reqFinishFunc = () => {
|
||||
return httpReqCallback()
|
||||
.then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let { statusCode, data } = httpData;
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data;
|
||||
if (statusCode == 500) {
|
||||
isShowErrorToast = true;
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
if (statusCode == 501) {
|
||||
// storageManage.token(null, true)
|
||||
// 提示信息
|
||||
isShowErrorToast = true;
|
||||
// infoBox.showErrorToast('请登录').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
// http响应码不正确
|
||||
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
|
||||
isShowErrorToast = true;
|
||||
bodyData.msg =
|
||||
bodyData.msg == "Bad credentials" ? "用户名或密码错误" : bodyData.msg;
|
||||
infoBox.showToast(bodyData.msg || "服务器异常");
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
|
||||
if (reqState == 'ingLoading') { // 关闭loading弹层
|
||||
infoBox.hideLoading()
|
||||
}
|
||||
reqState = 'finish' // 请求完毕
|
||||
}
|
||||
// // 业务响应异常
|
||||
if (bodyData.hasOwnProperty("code") && bodyData.code != 200) {
|
||||
isShowErrorToast = true;
|
||||
infoBox.showToast(bodyData.msg);
|
||||
// if (bodyData.code == 5005) { // 密码已过期, 直接跳转到更改密码页面
|
||||
// uni.reLaunch({
|
||||
// url: '/pageUser/setting/updatePwd'
|
||||
// })
|
||||
// }
|
||||
// if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
|
||||
// uni.redirectTo({url: '/pages/login/index'})
|
||||
// }
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
|
||||
// 明确显示loading
|
||||
if (showLoading) {
|
||||
// xx ms内响应完成,不提示loading
|
||||
setTimeout(() => {
|
||||
if (reqState == 'ing') {
|
||||
reqState = 'ingLoading'
|
||||
infoBox.showLoading()
|
||||
}
|
||||
}, loadingShowTime)
|
||||
}
|
||||
// 构造请求成功的响应数据
|
||||
return Promise.resolve(bodyData.data);
|
||||
})
|
||||
.catch((res) => {
|
||||
console.log(res);
|
||||
if (res.code == 501) {
|
||||
storageManage.token(null, true);
|
||||
infoBox.showToast("登录过期,请重新登录").then(() => {
|
||||
uni.redirectTo({ url: "/pages/login/index" });
|
||||
reject();
|
||||
});
|
||||
}
|
||||
// if(res.status==400){
|
||||
// storageManage.token(null, true)
|
||||
// infoBox.showErrorToast('').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
// }
|
||||
if (res.code == 500) {
|
||||
infoBox.showToast(res.msg || "服务器异常").then(() => {});
|
||||
}
|
||||
// if(res&&res.msg){
|
||||
// infoBox.showErrorToast(res.msg)
|
||||
// }
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
return httpReqCallback().then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let {
|
||||
statusCode,
|
||||
data
|
||||
} = httpData
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data
|
||||
if (statusCode == 500) {
|
||||
isShowErrorToast = true
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
if (statusCode == 501) {
|
||||
// storageManage.token(null, true)
|
||||
// 提示信息
|
||||
isShowErrorToast = true
|
||||
// infoBox.showErrorToast('请登录').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
// http响应码不正确
|
||||
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
|
||||
isShowErrorToast = true
|
||||
bodyData.msg=bodyData.msg=='Bad credentials'?'用户名或密码错误':bodyData.msg
|
||||
infoBox.showToast(bodyData.msg || '服务器异常')
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
|
||||
// // 业务响应异常
|
||||
if (bodyData.hasOwnProperty('code') && bodyData.code != 200) {
|
||||
isShowErrorToast = true
|
||||
infoBox.showToast(bodyData.msg)
|
||||
// if (bodyData.code == 5005) { // 密码已过期, 直接跳转到更改密码页面
|
||||
// uni.reLaunch({
|
||||
// url: '/pageUser/setting/updatePwd'
|
||||
// })
|
||||
// }
|
||||
// if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
|
||||
// uni.redirectTo({url: '/pages/login/index'})
|
||||
// }
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
|
||||
// 构造请求成功的响应数据
|
||||
return Promise.resolve(bodyData.data)
|
||||
|
||||
}).catch(res => {
|
||||
console.log(res)
|
||||
if(res.code==501){
|
||||
storageManage.token(null, true)
|
||||
infoBox.showToast('登录过期,请重新登录').then(() => {
|
||||
uni.redirectTo({url: '/pages/login/index'})
|
||||
reject()
|
||||
})
|
||||
}
|
||||
// if(res.status==400){
|
||||
// storageManage.token(null, true)
|
||||
// infoBox.showErrorToast('').then(() => {
|
||||
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
|
||||
// })
|
||||
// }
|
||||
if(res.code==500){
|
||||
infoBox.showToast(res.msg||'服务器异常').then(() => {})
|
||||
}
|
||||
// if(res&&res.msg){
|
||||
// infoBox.showErrorToast(res.msg)
|
||||
// }
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
if (!isShowErrorToast) {
|
||||
infoBox.showToast(`请求网络异常`)
|
||||
}
|
||||
|
||||
return Promise.reject(res)
|
||||
|
||||
}).finally(() => { // finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
|
||||
|
||||
});
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
if (!isShowErrorToast) {
|
||||
infoBox.showToast(`请求网络异常`);
|
||||
}
|
||||
|
||||
return Promise.reject(res);
|
||||
})
|
||||
.finally(() => {
|
||||
// finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
url: baseUrl + uri,
|
||||
data: data,
|
||||
method: method,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
)
|
||||
})
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + uri,
|
||||
data: data,
|
||||
method: method,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function request(args) {
|
||||
const {
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {}
|
||||
} = args
|
||||
let headerObject = {}
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
url: baseUrl + url,
|
||||
data: params||data,
|
||||
method: method,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
|
||||
)
|
||||
})
|
||||
const {
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {},
|
||||
} = args;
|
||||
let headerObject = {};
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + url,
|
||||
data: params || data,
|
||||
method: method,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 上传
|
||||
function upload(uri, data, file, showLoading = true, extParams = {}) {
|
||||
// 放置token
|
||||
let headerObject = {}
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
// 放置token
|
||||
let headerObject = {};
|
||||
// headerObject[appConfig.tokenKey] = storageManage.token()
|
||||
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.uploadFile(
|
||||
Object.assign({
|
||||
url: baseUrl + uri,
|
||||
formData: data,
|
||||
name: "file",
|
||||
filePath: file.path||file.url,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
).then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data)
|
||||
return Promise.resolve(httpData)
|
||||
}).catch(err=>{
|
||||
uni.hideLoading()
|
||||
infoBox.showErrorToast(`上传失败`)
|
||||
})
|
||||
})
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni
|
||||
.uploadFile(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + uri,
|
||||
formData: data,
|
||||
name: "file",
|
||||
filePath: file.path || file.url,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
)
|
||||
.then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data);
|
||||
return Promise.resolve(httpData);
|
||||
})
|
||||
.catch((err) => {
|
||||
uni.hideLoading();
|
||||
infoBox.showErrorToast(`上传失败`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function returnParams(params) {
|
||||
let returnStr = "";
|
||||
if (params) {
|
||||
returnStr = "?";
|
||||
for (let key in params) {
|
||||
returnStr += `${key}=${params[key]}&`;
|
||||
}
|
||||
returnStr = returnStr.substring(0, returnStr.length - 1);
|
||||
}
|
||||
return returnStr;
|
||||
}
|
||||
// 下载文件
|
||||
function download(args) {
|
||||
const {
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {},
|
||||
} = args;
|
||||
let headerObject = {};
|
||||
return uni
|
||||
.downloadFile({
|
||||
url: baseUrl + url + returnParams(params),
|
||||
|
||||
header: getHeader(),
|
||||
})
|
||||
.then((httpData) => {
|
||||
return Promise.resolve(httpData);
|
||||
})
|
||||
.catch((err) => {
|
||||
uni.hideLoading();
|
||||
infoBox.showErrorToast(`下载失败`);
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
req: req,
|
||||
request,
|
||||
upload: upload
|
||||
}
|
||||
req: req,
|
||||
request,
|
||||
upload: upload,
|
||||
download,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"] // 适配 uni-app 的 @ 路径别名(关键,避免导入路径报错)
|
||||
},
|
||||
"jsx": "preserve",
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"pages.json",
|
||||
"uni.pages.json" // 包含 uni-app 配置文件,让 Vetur 识别页面结构
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"unpackage" // 排除编译产物和依赖目录
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
<template>
|
||||
<view class="">
|
||||
<up-popup :show="show" mode="bottom">
|
||||
<view class="">
|
||||
<view class="top u-flex u-row-between">
|
||||
<text class="font-bold u-font-32 color-333">{{ title }}</text>
|
||||
<up-icon size="18" name="close" @click="show = false"></up-icon>
|
||||
</view>
|
||||
<scroll-view
|
||||
ref="couponScroll"
|
||||
:scroll-y="true"
|
||||
style="max-height: 50vh"
|
||||
@scroll="scroll"
|
||||
:scroll-top="scrollTop"
|
||||
>
|
||||
<view
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
class="item"
|
||||
@click="itemClick(item)"
|
||||
:class="[selGoods && selGoods.id == item.id ? 'selected' : '']"
|
||||
>
|
||||
<view class="u-flex u-row-between">
|
||||
<view class="u-flex gap-20">
|
||||
<!-- <view class="u-flex" @click.stop="preview(item)">
|
||||
<up-image
|
||||
:src="item.coverImg"
|
||||
width="80rpx"
|
||||
height="80rpx"
|
||||
></up-image>
|
||||
</view> -->
|
||||
|
||||
<text class="u-font-32 color-333">{{ item.title }}</text>
|
||||
</view>
|
||||
<text class="u-font-32 color-red u-p-l-30"
|
||||
></text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<up-empty v-if="list.length == 0" class="u-p-30" text="暂无数据"></up-empty>
|
||||
</scroll-view>
|
||||
<view class="bottom">
|
||||
<view class="btn cancel" @click="close">{{ cancelText }}</view>
|
||||
<view class="btn success" @click="confirm">{{ confirmText }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</up-popup>
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, onMounted, watch } from "vue";
|
||||
const modelValue = defineModel({
|
||||
type: String,
|
||||
default: "",
|
||||
});
|
||||
const show = defineModel("show", {
|
||||
type: String,
|
||||
default: "",
|
||||
});
|
||||
const couponName = defineModel("couponName", {
|
||||
type: String,
|
||||
default: "",
|
||||
});
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "选择优惠券",
|
||||
},
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: "确认",
|
||||
},
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: "取消",
|
||||
},
|
||||
list: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const selGoods = ref("");
|
||||
function itemClick(item) {
|
||||
if (selGoods.value && selGoods.value.id == item.id) {
|
||||
selGoods.value = "";
|
||||
return;
|
||||
}
|
||||
selGoods.value = item;
|
||||
}
|
||||
|
||||
const scrollTop = ref(0);
|
||||
function scroll(e) {
|
||||
scrollTop.value = e.detail.scrollTop;
|
||||
}
|
||||
function preview(item) {
|
||||
uni.previewImage({
|
||||
urls: item.images || [item.coverImg],
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => modelValue.value,
|
||||
(newVal, oldVal) => {
|
||||
console.log(newVal, oldVal);
|
||||
selGoods.value = props.list.find((item) => item.id == newVal);
|
||||
console.log(selGoods.value);
|
||||
if (selGoods.value) {
|
||||
couponName.value = selGoods.value.title;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.list.length,
|
||||
(newVal, oldVal) => {
|
||||
selGoods.value = props.list.find((item) => item.id == modelValue.value);
|
||||
console.log(selGoods.value);
|
||||
if (selGoods.value) {
|
||||
modelValue.value = selGoods.value.id;
|
||||
couponName.value = selGoods.value.title;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function close() {
|
||||
show.value = false;
|
||||
}
|
||||
|
||||
const emit = defineEmits(["confirm"]);
|
||||
function confirm() {
|
||||
if (!selGoods.value) {
|
||||
uni.showToast({
|
||||
title: "请选择优惠券",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
modelValue.value = selGoods.value.id;
|
||||
show.value = false;
|
||||
emit("confirm", selGoods.value);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.popup-content {
|
||||
background: #fff;
|
||||
width: 640rpx;
|
||||
border-radius: 18rpx;
|
||||
}
|
||||
.top {
|
||||
padding: 40rpx 48rpx;
|
||||
border-bottom: 1px solid #d9d9d9;
|
||||
}
|
||||
.bottom {
|
||||
padding: 48rpx 52rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
border-top: 1px solid #d9d9d9;
|
||||
gap: 50rpx;
|
||||
.btn {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 18rpx 60rpx;
|
||||
border-radius: 100rpx;
|
||||
font-size: 32rpx;
|
||||
border: 2rpx solid transparent;
|
||||
&.success {
|
||||
background-color: $my-main-color;
|
||||
color: #fff;
|
||||
}
|
||||
&.cancel {
|
||||
border-color: #d9d9d9;
|
||||
box-shadow: 0 4rpx 0 0 #00000005;
|
||||
}
|
||||
}
|
||||
}
|
||||
.item {
|
||||
padding: 10rpx 30rpx;
|
||||
border: 1px solid #d9d9d9;
|
||||
margin: 10rpx;
|
||||
border-radius: 8rpx;
|
||||
transition: all 0.3s ease-in-out;
|
||||
box-shadow: 0 0 10px transparent;
|
||||
&.selected {
|
||||
border-color: $my-main-color;
|
||||
box-shadow: 0 0 10px $my-main-color;
|
||||
}
|
||||
}
|
||||
.choose-goods {
|
||||
display: flex;
|
||||
padding: 24rpx;
|
||||
align-items: center;
|
||||
border-radius: 8rpx;
|
||||
border: 2rpx solid #d9d9d9;
|
||||
background: #fff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<template>
|
||||
<view>
|
||||
<view
|
||||
class="u-flex u-row-between u-m-b-24"
|
||||
style="gap: 40rpx"
|
||||
v-for="(item, index) in modelValue"
|
||||
:key="index"
|
||||
>
|
||||
<view
|
||||
class="choose-coupon u-flex-1 u-flex u-row-between"
|
||||
@click="showCoupon(item, index)"
|
||||
>
|
||||
<template v-if="item.title">
|
||||
<text>{{ item.title }}</text>
|
||||
<view class="u-flex" @click.stop="item.title = ''">
|
||||
<up-icon name="close" size="14"></up-icon>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<text class="color-999">选择赠送券</text>
|
||||
<up-icon name="arrow-down" size="14"></up-icon>
|
||||
</template>
|
||||
</view>
|
||||
<view class="u-flex-1 u-flex">
|
||||
<view class="u-flex-1 choose-coupon u-flex">
|
||||
<input
|
||||
class="u-flex-1"
|
||||
placeholder=""
|
||||
type="number"
|
||||
v-model="item.num"
|
||||
placeholder-class="color-999 u-font-28"
|
||||
/>
|
||||
<text class="no-wrap color-999">张/1个码</text>
|
||||
</view>
|
||||
<view class="u-m-l-20">
|
||||
<up-icon name="minus-circle-fill" color="#EB4F4F" size="18" @click="removeCoupon(index)"></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<chooseCoupon
|
||||
v-model="chooseCouponData.couponId"
|
||||
v-model:show="chooseCouponData.show"
|
||||
@confirm="confirmCoupon"
|
||||
:list="couponList"
|
||||
></chooseCoupon>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, ref, onMounted } from "vue";
|
||||
import chooseCoupon from "./choose-coupon.vue";
|
||||
import { couponPage } from "@/http/api/market/index.js";
|
||||
|
||||
const chooseCouponData = reactive({
|
||||
couponId: "",
|
||||
show: false,
|
||||
index: -1,
|
||||
item: null,
|
||||
});
|
||||
const modelValue = defineModel({
|
||||
type: Array,
|
||||
default: () => [],
|
||||
});
|
||||
const couponList = ref([]);
|
||||
function showCoupon(item, index) {
|
||||
chooseCouponData.couponId = item ? item.id : "";
|
||||
chooseCouponData.show = true;
|
||||
chooseCouponData.index = index;
|
||||
chooseCouponData.item = item;
|
||||
}
|
||||
function confirmCoupon(e) {
|
||||
modelValue.value[chooseCouponData.index].id = e.id;
|
||||
modelValue.value[chooseCouponData.index].title = e.title;
|
||||
}
|
||||
function removeCoupon(index) {
|
||||
modelValue.value.splice(index, 1);
|
||||
}
|
||||
onMounted(() => {
|
||||
couponPage({ size: 999 }).then((res) => {
|
||||
couponList.value = res.records;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.choose-coupon {
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 8rpx;
|
||||
border: 1px solid #d9d9d9;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
<template>
|
||||
<view>
|
||||
<view @click="open">
|
||||
<slot v-if="$slots.default"> </slot>
|
||||
<view v-else class="choose-goods u-flex u-row-between">
|
||||
<text class="color-999" v-if="!startTime && !endTime"
|
||||
>请选择日期范围</text
|
||||
>
|
||||
<text class="color-333 u-font-24 u-m-r-32 " v-else
|
||||
>{{ startTime }} - {{ endTime }}</text
|
||||
>
|
||||
<view class="u-flex" v-if="startTime&&endTime" @click.stop="clear">
|
||||
<up-icon name="close" size="14"></up-icon>
|
||||
</view>
|
||||
<up-icon size="14" name="arrow-right" v-else ></up-icon>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
<my-date-pickerview
|
||||
@confirm="datePickerConfirm"
|
||||
mode="all"
|
||||
ref="datePicker"
|
||||
></my-date-pickerview>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
const datePicker = ref(null);
|
||||
const startTime = defineModel("startTime", {
|
||||
default: () => "",
|
||||
type: String,
|
||||
});
|
||||
const endTime = defineModel("endTime", {
|
||||
default: () => "",
|
||||
type: String,
|
||||
});
|
||||
|
||||
function clear(){
|
||||
startTime.value = "";
|
||||
endTime.value = "";
|
||||
}
|
||||
function open() {
|
||||
datePicker.value.toggle();
|
||||
}
|
||||
function datePickerConfirm(e) {
|
||||
startTime.value = e.start;
|
||||
endTime.value = e.end;
|
||||
console.log(e);
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.popup-content {
|
||||
background: #fff;
|
||||
width: 640rpx;
|
||||
border-radius: 18rpx;
|
||||
}
|
||||
.top {
|
||||
padding: 40rpx 48rpx;
|
||||
border-bottom: 1px solid #d9d9d9;
|
||||
}
|
||||
.bottom {
|
||||
padding: 48rpx 52rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
border-top: 1px solid #d9d9d9;
|
||||
gap: 50rpx;
|
||||
.btn {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 18rpx 60rpx;
|
||||
border-radius: 100rpx;
|
||||
font-size: 32rpx;
|
||||
border: 2rpx solid transparent;
|
||||
&.success {
|
||||
background-color: $my-main-color;
|
||||
color: #fff;
|
||||
}
|
||||
&.cancel {
|
||||
border-color: #d9d9d9;
|
||||
box-shadow: 0 4rpx 0 0 #00000005;
|
||||
}
|
||||
}
|
||||
}
|
||||
.item {
|
||||
padding: 10rpx 30rpx;
|
||||
border: 1px solid #d9d9d9;
|
||||
margin: 10rpx;
|
||||
border-radius: 8rpx;
|
||||
transition: all 0.3s ease-in-out;
|
||||
box-shadow: 0 0 10px transparent;
|
||||
&.selected {
|
||||
border-color: $my-main-color;
|
||||
box-shadow: 0 0 10px $my-main-color;
|
||||
}
|
||||
}
|
||||
.choose-goods {
|
||||
display: flex;
|
||||
padding: 24rpx;
|
||||
align-items: center;
|
||||
border-radius: 8rpx;
|
||||
border: 2rpx solid #d9d9d9;
|
||||
background: #fff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
min-height: 90rpx;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,84 +1,84 @@
|
|||
<template>
|
||||
<view>
|
||||
<up-popup :show="show" mode="center">
|
||||
<view class="popup-content">
|
||||
<view class="top u-flex u-row-between">
|
||||
<text class="font-bold u-font-32 color-333">{{title}}</text>
|
||||
<up-icon size="18" name="close" @click="show=false"></up-icon>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<scroll-view style="max-height:50vh;">
|
||||
<slot></slot>
|
||||
</scroll-view>
|
||||
<up-line></up-line>
|
||||
<view>
|
||||
<up-popup :show="show" mode="center">
|
||||
<view class="popup-content">
|
||||
<view class="top u-flex u-row-between">
|
||||
<text class="font-bold u-font-32 color-333">{{ title }}</text>
|
||||
<up-icon size="18" name="close" @click="show = false"></up-icon>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<scroll-view style="max-height: 50vh" :scroll-y="true">
|
||||
<slot></slot>
|
||||
</scroll-view>
|
||||
<up-line></up-line>
|
||||
|
||||
<view class="bottom">
|
||||
<view class="btn success" @click="confirm">{{confirmText}}</view>
|
||||
<view class="btn cancel" @click="close">{{cancelText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</up-popup>
|
||||
</view>
|
||||
<view class="bottom">
|
||||
<view class="btn cancel" @click="close">{{ cancelText }}</view>
|
||||
<view class="btn success" @click="confirm">{{ confirmText }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</up-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "标题",
|
||||
},
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: "保存",
|
||||
},
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: "取消",
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: "标题",
|
||||
},
|
||||
confirmText: {
|
||||
type: String,
|
||||
default: "保存",
|
||||
},
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: "取消",
|
||||
},
|
||||
});
|
||||
const show = defineModel({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
})
|
||||
const emits=defineEmits(['close','confirm'])
|
||||
function close(){
|
||||
show.value=false
|
||||
emits('close')
|
||||
type: Boolean,
|
||||
default: false,
|
||||
});
|
||||
const emits = defineEmits(["close", "confirm"]);
|
||||
function close() {
|
||||
show.value = false;
|
||||
emits("close");
|
||||
}
|
||||
function confirm(){
|
||||
emits('confirm')
|
||||
function confirm() {
|
||||
emits("confirm");
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.popup-content{
|
||||
background: #fff;
|
||||
width: 640rpx;
|
||||
border-radius: 18rpx;
|
||||
.popup-content {
|
||||
background: #fff;
|
||||
width: 640rpx;
|
||||
border-radius: 18rpx;
|
||||
}
|
||||
.top{
|
||||
padding: 40rpx 48rpx;
|
||||
.top {
|
||||
padding: 40rpx 48rpx;
|
||||
}
|
||||
.bottom{
|
||||
padding: 48rpx 52rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 50rpx;
|
||||
.btn{
|
||||
flex:1;
|
||||
text-align: center;
|
||||
padding: 18rpx 60rpx;
|
||||
border-radius: 100rpx;
|
||||
font-size: 32rpx;
|
||||
border: 2rpx solid transparent;
|
||||
&.success{
|
||||
background-color: $my-main-color;
|
||||
color:#fff;
|
||||
}
|
||||
&.cancel{
|
||||
border-color:#D9D9D9;
|
||||
box-shadow: 0 4rpx 0 0 #00000005;
|
||||
}
|
||||
.bottom {
|
||||
padding: 48rpx 52rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 50rpx;
|
||||
.btn {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 18rpx 60rpx;
|
||||
border-radius: 100rpx;
|
||||
font-size: 32rpx;
|
||||
border: 2rpx solid transparent;
|
||||
&.success {
|
||||
background-color: $my-main-color;
|
||||
color: #fff;
|
||||
}
|
||||
&.cancel {
|
||||
border-color: #d9d9d9;
|
||||
box-shadow: 0 4rpx 0 0 #00000005;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,191 @@
|
|||
<template>
|
||||
<view class="min-page bg-f7 default-box-padding u-font-28 color-333">
|
||||
<view class="default-box-padding bg-fff default-box-radius">
|
||||
<view>
|
||||
<view class="font-bold u-m-b-16">兑换码名称</view>
|
||||
<up-input
|
||||
placeholder="请输入兑换码名称"
|
||||
border="none"
|
||||
v-model="form.name"
|
||||
placeholder-class="color-999 u-font-28"
|
||||
></up-input>
|
||||
<view class="u-m-t-24">
|
||||
<up-line></up-line>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="u-m-t-24">
|
||||
<view class="font-bold u-m-b-16">活动日期</view>
|
||||
<DateTimePicker
|
||||
v-model:startTime="form.startTime"
|
||||
v-model:endTime="form.endTime"
|
||||
>
|
||||
</DateTimePicker>
|
||||
</view>
|
||||
<view class="u-m-t-24">
|
||||
<view class="font-bold u-m-b-16">发行数量</view>
|
||||
<view class="u-flex u-m-t-16">
|
||||
<input
|
||||
class="number-box"
|
||||
placeholder="请输入"
|
||||
placeholder-class="color-999 u-font-28"
|
||||
type="number"
|
||||
v-model="form.total"
|
||||
/>
|
||||
<view class="unit">个</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="default-box-padding bg-fff default-box-radius u-m-t-32">
|
||||
<view class="font-bold">优惠券</view>
|
||||
<view class="u-m-t-16">
|
||||
<CouponList v-model="form.couponInfoList"></CouponList>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="u-m-t-16 u-flex">
|
||||
<view class="u-flex" @click="addCoupon">
|
||||
<up-icon name="plus-circle-fill" color="#318AFE" size="18"></up-icon>
|
||||
<text class="font-bold u-m-l-20">添加</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<my-bottom-btn-group
|
||||
@cancel="cancel"
|
||||
@save="save"
|
||||
direction="column"
|
||||
></my-bottom-btn-group>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, onMounted } from "vue";
|
||||
import DateTimePicker from "@/pageMarket/components/date-time-picker.vue";
|
||||
import CouponList from "@/pageMarket/components/coupon-list.vue";
|
||||
import * as couponRedemptionApi from "@/http/api/market/couponRedemption.js";
|
||||
import {
|
||||
onLoad,
|
||||
onReady,
|
||||
onShow,
|
||||
onPageScroll,
|
||||
onReachBottom,
|
||||
onBackPress,
|
||||
} from "@dcloudio/uni-app";
|
||||
|
||||
|
||||
function cancel() {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
}
|
||||
|
||||
const form = reactive({
|
||||
name: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
stock: "",
|
||||
total: 0,
|
||||
couponInfoList: [
|
||||
{
|
||||
id: "",
|
||||
num: "",
|
||||
title: "",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function save() {
|
||||
if (!form.name) {
|
||||
uni.showToast({
|
||||
title: "请输入兑换码名称",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!form.startTime || !form.endTime) {
|
||||
uni.showToast({
|
||||
title: "请选择活动日期",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!form.total) {
|
||||
uni.showToast({
|
||||
title: "请输入发行数量",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (options.type == "edit") {
|
||||
couponRedemptionApi
|
||||
.editSuggest({
|
||||
title: form.title,
|
||||
id: form.id,
|
||||
foods: form.foods,
|
||||
useDays: form.useDays.join(","),
|
||||
useStartTime: form.useStartTime,
|
||||
useTimeType: form.useTimeType,
|
||||
useEndTime: form.useEndTime,
|
||||
})
|
||||
.then((res) => {
|
||||
uni.showToast({
|
||||
title: "修改成功",
|
||||
icon: "none",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
}, 1500);
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log('form.couponInfoList',form.couponInfoList)
|
||||
|
||||
//判断优惠券列表是否选择了优惠券,数量是否填写
|
||||
if (form.couponInfoList.some((item) => !item.id || !item.num)) {
|
||||
uni.showToast({
|
||||
title: "请选择优惠券并填写数量",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
couponRedemptionApi.add(form).then((res) => {
|
||||
uni.showToast({
|
||||
title: "添加成功",
|
||||
icon: "none",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
}, 1500);
|
||||
});
|
||||
}
|
||||
function addCoupon() {
|
||||
form.couponInfoList.push({
|
||||
id: "",
|
||||
num: "",
|
||||
title: "",
|
||||
});
|
||||
}
|
||||
const options = reactive({});
|
||||
onLoad((opt) => {});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.my-hour-area .container) {
|
||||
padding: 32rpx 28rpx;
|
||||
background-color: #f7f7f7;
|
||||
border-radius: 8rpx;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
:deep(.my-hour-area .box) {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
:deep(.fixed-bottom) {
|
||||
left: 110rpx;
|
||||
right: 110rpx;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<template>
|
||||
<view class="u-flex">
|
||||
<view @click="show = true">
|
||||
<slot v-if="$slots.default"> </slot>
|
||||
<view v-else class="choose-goods u-flex u-row-between">
|
||||
<text class="color-333 u-font-28 font-bold">{{ statusText }}</text>
|
||||
<up-icon size="14" name="arrow-down" color="#333" bold></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<up-action-sheet
|
||||
:show="show"
|
||||
cancel-text="取消"
|
||||
closeOnClickAction
|
||||
@close="show = false"
|
||||
:actions="actions"
|
||||
@select="confirm"
|
||||
></up-action-sheet>
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref ,computed } from "vue";
|
||||
const show = ref(false);
|
||||
const modelValue = defineModel({
|
||||
type: String,
|
||||
default: "",
|
||||
});
|
||||
function confirm(item) {
|
||||
modelValue.value = item.value;
|
||||
}
|
||||
const actions = ref([
|
||||
{
|
||||
name: "全部",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "已兑换",
|
||||
value: "1",
|
||||
},
|
||||
{
|
||||
name: "未兑换",
|
||||
value: "0",
|
||||
},
|
||||
]);
|
||||
|
||||
const statusText = computed(() => {
|
||||
if (modelValue.value === "") {
|
||||
return "全部";
|
||||
}
|
||||
return modelValue.value === "1" ? "已兑换" : "未兑换";
|
||||
});
|
||||
</script>
|
||||
|
|
@ -0,0 +1,328 @@
|
|||
<template>
|
||||
<view class="min-page bg-f7 default-box-padding u-font-28 color-333">
|
||||
<view class="bg-fff default-box-radius">
|
||||
<view class="default-box-padding u-flex u-row-between">
|
||||
<text class="font-bold">兑换码名称</text>
|
||||
<text class="color-666">{{ form.name }}</text>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="default-box-padding u-flex u-row-between">
|
||||
<text class="font-bold">活动日期</text>
|
||||
<text class="color-666 u-font-24"
|
||||
>{{ form.startTime }} 至 {{ form.endTime }}</text
|
||||
>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="default-box-padding u-flex u-row-between">
|
||||
<text class="font-bold">总数</text>
|
||||
<text class="color-666 u-font-24">{{ form.total }}</text>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="default-box-padding u-flex u-row-between">
|
||||
<text class="font-bold">库存</text>
|
||||
<view style="width: 158rpx">
|
||||
<up-input
|
||||
v-model="form.stock"
|
||||
type="number"
|
||||
placeholder="库存"
|
||||
placeholder-class="color-999 u-font-28"
|
||||
></up-input>
|
||||
</view>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="default-box-padding u-flex u-row-between">
|
||||
<text class="font-bold no-wrap">优惠券</text>
|
||||
<view class="u-p-l-30">
|
||||
<text class="">{{ returnCoupon }}</text>
|
||||
<text class="color-main u-font-32 u-m-l-20" @click="showModal"
|
||||
>修改</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<up-line></up-line>
|
||||
<view class="u-p-b-24"></view>
|
||||
</view>
|
||||
<view class="u-p-t-48 u-p-b-48 u-p-l-60 u-p-r-60">
|
||||
<my-button type="primary" shape="circle" @click="save">保存</my-button>
|
||||
</view>
|
||||
|
||||
<view class="bg-fff default-box-radius">
|
||||
<view class="default-box-x-padding u-p-t-32 u-flex u-row-between">
|
||||
<couponStatus v-model="query.status"></couponStatus>
|
||||
|
||||
<view class="u-flex">
|
||||
<view class="border u-flex default-box-radius search-box">
|
||||
<up-icon name="search"></up-icon>
|
||||
<input
|
||||
style="width: 140rpx"
|
||||
placeholder="输入兑换码"
|
||||
class="u-font-28 u-m-l-20"
|
||||
placeholder-class="color-999 u-font-28"
|
||||
@input="codeChange"
|
||||
v-model="query.code"
|
||||
/>
|
||||
</view>
|
||||
<view class="daochu u-m-l-24" @click="exportCode">导出</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="list u-m-t-48">
|
||||
<view
|
||||
class="item default-box-padding"
|
||||
v-for="(item, index) in list"
|
||||
:key="index"
|
||||
>
|
||||
<view class="u-flex u-row-between">
|
||||
<text class="status" :class="['status-' + item.status]">{{
|
||||
item.status == 0 ? "未兑换" : "已兑换"
|
||||
}}</text>
|
||||
<view>
|
||||
<text class="color-666">{{ item.code }}</text>
|
||||
<text class="color-main u-m-l-20" @click="copyCode(item.code)"
|
||||
>复制</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<view class="u-m-t-16 u-flex u-row-between color-666">
|
||||
<text>{{ item.redemptionTime }}</text>
|
||||
<view>
|
||||
<text>{{ item.nickName }}</text>
|
||||
<text>{{ item.phone }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<up-loadmore :status="isEnd ? 'nomore' : 'loading'"></up-loadmore>
|
||||
|
||||
<Modal
|
||||
:title="ModalData.title"
|
||||
v-model="ModalData.show"
|
||||
@confirm="modelConfirm"
|
||||
>
|
||||
<view class="default-box-padding">
|
||||
<CouponList v-model="form.couponInfoList"></CouponList>
|
||||
<view class="u-m-t-16 u-flex">
|
||||
<view class="u-flex" @click="addCoupon">
|
||||
<up-icon
|
||||
name="plus-circle-fill"
|
||||
color="#318AFE"
|
||||
size="18"
|
||||
></up-icon>
|
||||
<text class="font-bold u-m-l-20">添加</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</Modal>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
onLoad,
|
||||
onReady,
|
||||
onShow,
|
||||
onPageScroll,
|
||||
onReachBottom,
|
||||
onBackPress,
|
||||
} from "@dcloudio/uni-app";
|
||||
import couponStatus from "./components/status.vue";
|
||||
import CouponList from "@/pageMarket/components/coupon-list.vue";
|
||||
|
||||
import Modal from "@/pageMarket/components/modal.vue";
|
||||
import * as couponRedemptionApi from "@/http/api/market/couponRedemption.js";
|
||||
import { saveFileFromTemp } from "@/utils/downloadFile.js";
|
||||
import {
|
||||
reactive,
|
||||
toRefs,
|
||||
computed,
|
||||
watch,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
ref,
|
||||
} from "vue";
|
||||
function addCoupon() {
|
||||
form.couponInfoList.push({
|
||||
id: "",
|
||||
num: "",
|
||||
title: "",
|
||||
});
|
||||
}
|
||||
function modelConfirm() {
|
||||
//判断优惠券列表是否选择了优惠券,数量是否填写
|
||||
if (form.couponInfoList.some((item) => !item.id || !item.num)) {
|
||||
uni.showToast({
|
||||
title: "请选择优惠券并填写数量",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
ModalData.show = false;
|
||||
}
|
||||
const ModalData = reactive({
|
||||
show: false,
|
||||
title: "修改优惠券",
|
||||
});
|
||||
function save() {
|
||||
if (form.stock === "" || form.stock === null) {
|
||||
uni.showToast({
|
||||
title: "请填写库存",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
couponRedemptionApi.edit(form).then((res) => {
|
||||
uni.showToast({
|
||||
title: "修改成功",
|
||||
icon: "none",
|
||||
});
|
||||
ModalData.show = false;
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
function showModal() {
|
||||
ModalData.show = true;
|
||||
}
|
||||
const form = reactive({
|
||||
couponInfoList: [],
|
||||
});
|
||||
onLoad((opt) => {
|
||||
const item = uni.getStorageSync("couponRedemptionItem");
|
||||
Object.assign(form, item);
|
||||
console.log(form);
|
||||
getList();
|
||||
});
|
||||
const query = reactive({
|
||||
status: "",
|
||||
code: "",
|
||||
page: 1,
|
||||
size: 10,
|
||||
});
|
||||
|
||||
function copyCode(code) {
|
||||
uni.setClipboardData({
|
||||
data: code,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: "复制成功",
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
const returnCoupon = computed(() => {
|
||||
return form.couponInfoList
|
||||
.reduce((prev, cur) => prev + cur.title + "*" + cur.num + "、", "")
|
||||
.slice(0, -1);
|
||||
});
|
||||
const list = ref([]);
|
||||
const isEnd = ref(false);
|
||||
function getList() {
|
||||
couponRedemptionApi
|
||||
.codeList({ ...query, redemptionId: form.id })
|
||||
.then((res) => {
|
||||
if (query.page == 1) {
|
||||
list.value = res.records;
|
||||
} else {
|
||||
list.value = [...list.value, ...res.records];
|
||||
}
|
||||
if (query.page >= res.totalPage * 1) {
|
||||
isEnd.value = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
function refresh() {
|
||||
isEnd.value = false;
|
||||
query.page = 1;
|
||||
getList();
|
||||
}
|
||||
watch(() => query.status, refresh);
|
||||
|
||||
//节流
|
||||
const throttle = (fn, delay = 500) => {
|
||||
let timer = null;
|
||||
return function () {
|
||||
if (timer) {
|
||||
return;
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(this, arguments);
|
||||
timer = null;
|
||||
}, delay);
|
||||
};
|
||||
};
|
||||
|
||||
const codeChange = throttle(() => {
|
||||
console.log(query.code);
|
||||
refresh();
|
||||
});
|
||||
|
||||
function exportCode() {
|
||||
couponRedemptionApi
|
||||
.codeExport({
|
||||
status: query.status,
|
||||
redemptionId: form.id,
|
||||
code: query.code,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
if (res.statusCode == 200) {
|
||||
saveFileFromTemp({
|
||||
tempFilePath: res.tempFilePath,
|
||||
fileName: '优惠券兑换码.xlsx',
|
||||
isNowOpen:true
|
||||
});
|
||||
// uni.getFileSystemManager().saveFile({
|
||||
// tempFilePath: res.tempFilePath,
|
||||
// success: function (res) {
|
||||
// console.log(res);
|
||||
// },
|
||||
// fail: function (err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
console.log("触底");
|
||||
if (isEnd.value) {
|
||||
return;
|
||||
}
|
||||
query.page++;
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.border {
|
||||
border: 1rpx solid #dddfe6;
|
||||
}
|
||||
.search-box {
|
||||
padding: 18rpx 32rpx;
|
||||
}
|
||||
.daochu {
|
||||
border: 1rpx solid $my-main-color;
|
||||
padding: 12rpx 34rpx;
|
||||
border-radius: 8rpx;
|
||||
white-space: nowrap;
|
||||
color: $my-main-color;
|
||||
min-height: 72rpx;
|
||||
}
|
||||
.status {
|
||||
font-weight: 700;
|
||||
&.status-0 {
|
||||
color: #5bbc6d;
|
||||
}
|
||||
&.status-1 {
|
||||
color: #ff895c;
|
||||
}
|
||||
}
|
||||
.item {
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,351 @@
|
|||
<template>
|
||||
<view class="min-page bg-f7 u-font-28">
|
||||
<up-sticky>
|
||||
<view class="bg-fff default-box-padding">
|
||||
<view class="u-flex">
|
||||
<image
|
||||
style="width: 60rpx; height: 60rpx"
|
||||
src="/pageMarket/static/images/coupon_code.png"
|
||||
></image>
|
||||
<view class="u-flex-1 u-flex u-p-l-24">
|
||||
<view class="u-font-28 u-flex-1 u-p-r-24">
|
||||
<view class="color-333 font-bold">券兑换码 </view>
|
||||
<view class="color-666 u-m-t-4 u-font-24"
|
||||
>可添加多券组合兑换
|
||||
</view>
|
||||
</view>
|
||||
<up-switch
|
||||
v-model="accountInfoStore.shopInfo.isProductSuggest"
|
||||
size="18"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
></up-switch>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</up-sticky>
|
||||
<view class="u-p-t-60 default-box-x-padding">
|
||||
<view class="u-flex u-row-between">
|
||||
<view class="shop" @click="showShopModal">适用门店</view>
|
||||
<view
|
||||
class="u-flex status-sel u-row-between bg-fff u-line-1"
|
||||
@click="showStatusModal"
|
||||
>
|
||||
<text class="color-999" v-if="returnStatusText == '全部'">全部</text>
|
||||
<text class="color-333" v-else>{{ returnStatusText }}</text>
|
||||
<up-icon name="arrow-down" size="14"></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="default-box-padding">
|
||||
<view
|
||||
v-for="(item, index) in list"
|
||||
class="u-m-b-56 default-box-radius bg-fff default-box-padding"
|
||||
>
|
||||
<view class="u-flex u-row-between">
|
||||
<text class="u-font-32 font-bold color-333">{{ item.name }}</text>
|
||||
<view class="status" :class="['status' + item.status]">{{
|
||||
item.status == 0 ? "有效" : "无效"
|
||||
}}</view>
|
||||
</view>
|
||||
<view class="u-m-t-22 color-666 u-font-24 u-flex">
|
||||
<view>
|
||||
<view> 有效期:{{ item.startTime }} 至 {{ item.endTime }}</view>
|
||||
<view class="u-m-t-16"
|
||||
>优惠券(张):
|
||||
<text class="color-333 u-font-28 font-bold">{{
|
||||
item.couponNum
|
||||
}}</text></view
|
||||
>
|
||||
<view class="u-m-t-16">{{ returnCoupon(item) }}</view>
|
||||
</view>
|
||||
|
||||
<view class="btn edit" @click="handleEdit(item)">查看</view>
|
||||
</view>
|
||||
<!-- <view class="u-flex u-row-right gap-20 u-m-t-24">
|
||||
<view class="btn del" @click="handleDelete(item)">删除</view>
|
||||
<view class="btn edit" @click="handleEdit(item)">查看</view>
|
||||
</view> -->
|
||||
</view>
|
||||
</view>
|
||||
<view style="height: 100rpx"></view>
|
||||
<view class="fixed-bottom">
|
||||
<my-button @click="go.to('PAGES_MARKET_COUPON_EXCHANGE_CODE_ADD')"
|
||||
>添加兑换码</my-button
|
||||
>
|
||||
</view>
|
||||
|
||||
<Modal
|
||||
v-model="modalData.show"
|
||||
:title="modalData.title"
|
||||
@confirm="handleConfirm"
|
||||
>
|
||||
<template v-if="modalData.key == 'selShop'">
|
||||
<view class="default-box-padding">
|
||||
<my-shop-select
|
||||
@shop-select="shopSelect"
|
||||
v-model:selShops="form.shopIdList"
|
||||
v-model:useType="form.useType"
|
||||
></my-shop-select>
|
||||
</view>
|
||||
</template>
|
||||
</Modal>
|
||||
|
||||
<u-action-sheet
|
||||
:actions="actions"
|
||||
cancelText="取消"
|
||||
:closeOnClickAction="true"
|
||||
round="6"
|
||||
@close="showAction = false"
|
||||
@select="selectStatus"
|
||||
:show="showAction"
|
||||
></u-action-sheet>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
onLoad,
|
||||
onReady,
|
||||
onShow,
|
||||
onPageScroll,
|
||||
onReachBottom,
|
||||
onBackPress,
|
||||
} from "@dcloudio/uni-app";
|
||||
import Modal from "@/pageMarket/components/modal.vue";
|
||||
import * as couponRedemptionApi from "@/http/api/market/couponRedemption.js";
|
||||
import { useAccountInfoStore } from "@/store/account.js";
|
||||
import go from "@/commons/utils/go.js";
|
||||
const accountInfoStore = useAccountInfoStore();
|
||||
import { ref, reactive, onMounted, computed, watch } from "vue";
|
||||
const loadFinish = ref(false);
|
||||
const form = reactive({
|
||||
isEnable: 0,
|
||||
useType: "all",
|
||||
});
|
||||
|
||||
const actions = [
|
||||
{
|
||||
name: "全部",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "有效",
|
||||
value: "0",
|
||||
},
|
||||
{
|
||||
name: "无效",
|
||||
value: "1",
|
||||
},
|
||||
];
|
||||
const returnStatusText = computed(() => {
|
||||
return actions.find((item) => item.value == query.status)?.name || "全部";
|
||||
});
|
||||
|
||||
function returnCoupon(item) {
|
||||
return item.couponInfoList
|
||||
.reduce((prev, cur) => prev + cur.title + "*" + cur.num + "、", "")
|
||||
.slice(0, -1);
|
||||
}
|
||||
const showAction = ref(false);
|
||||
function selectStatus(item) {
|
||||
console.log(item);
|
||||
query.status = item.value;
|
||||
}
|
||||
|
||||
function showStatusModal() {
|
||||
showAction.value = true;
|
||||
}
|
||||
|
||||
function showShopModal() {
|
||||
modalData.show = true;
|
||||
modalData.title = "适用门店";
|
||||
modalData.key = "selShop";
|
||||
}
|
||||
|
||||
const firstModalTime = ref(0);
|
||||
const modalData = reactive({
|
||||
show: false,
|
||||
title: "",
|
||||
key: "",
|
||||
});
|
||||
|
||||
function handleDelete(item) {
|
||||
uni.showModal({
|
||||
title: "确认删除吗?",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
couponRedemptionApi
|
||||
.delete({
|
||||
id: item.id,
|
||||
})
|
||||
.then((res) => {
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
icon: "none",
|
||||
});
|
||||
refreshList();
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
const isEnd = ref(false);
|
||||
const query = reactive({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
status: "",
|
||||
});
|
||||
const list = ref([]);
|
||||
function refreshList() {
|
||||
query.pageNum = 1;
|
||||
isEnd.value = false;
|
||||
getList();
|
||||
}
|
||||
|
||||
function handleEdit(item) {
|
||||
uni.setStorageSync("couponRedemptionItem", item);
|
||||
go.to("PAGES_MARKET_COUPON_EXCHANGE_CODE_DETAIL", {
|
||||
type: "edit",
|
||||
});
|
||||
}
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (form.useType == "custom") {
|
||||
if (form.shopIdList.length == 0) {
|
||||
uni.showToast({
|
||||
title: "请选择适用门店",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
couponRedemptionApi.enable({
|
||||
shopIdList: form.shopIdList,
|
||||
useType: form.useType,
|
||||
isEnable: form.isEnable,
|
||||
});
|
||||
uni.showToast({
|
||||
title: "修改成功",
|
||||
icon: "none",
|
||||
});
|
||||
modalData.show = false;
|
||||
};
|
||||
|
||||
const getList = async () => {
|
||||
loadFinish.value = false;
|
||||
if (isEnd.value) {
|
||||
return;
|
||||
}
|
||||
const res = await couponRedemptionApi.couponRedemptionList(query);
|
||||
loadFinish.value = true;
|
||||
if (query.pageNum >= res.totalPage * 1) {
|
||||
isEnd.value = true;
|
||||
}
|
||||
if (query.pageNum == 1) {
|
||||
list.value = res.records || [];
|
||||
} else {
|
||||
list.value = list.value.concat(res.records || []);
|
||||
}
|
||||
console.log(list.value);
|
||||
query.pageNum++;
|
||||
};
|
||||
|
||||
function getShopInfo() {
|
||||
accountInfoStore.getShopInfo().then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => accountInfoStore.shopInfo.isProductSuggest,
|
||||
(newVal, oldVal) => {
|
||||
if (!loadFinish.value) return;
|
||||
accountInfoStore.editShopInfo({
|
||||
isProductSuggest: newVal,
|
||||
id: accountInfoStore.shopInfo.id,
|
||||
});
|
||||
uni.showToast({
|
||||
title: "修改成功",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
);
|
||||
watch(
|
||||
() => query.status,
|
||||
(newval) => {
|
||||
console.log(newval);
|
||||
refreshList();
|
||||
}
|
||||
);
|
||||
|
||||
async function getConfig() {
|
||||
couponRedemptionApi.status().then((res) => {
|
||||
Object.assign(form, res);
|
||||
});
|
||||
}
|
||||
onReachBottom(() => {
|
||||
console.log("触底");
|
||||
getList();
|
||||
});
|
||||
onMounted(() => {
|
||||
getShopInfo();
|
||||
getConfig();
|
||||
});
|
||||
onShow(() => {
|
||||
refreshList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.status {
|
||||
padding: 8rpx 18rpx;
|
||||
border: 2rpx solid transparent;
|
||||
border-radius: 8rpx;
|
||||
&.status0 {
|
||||
background-color: rgba(123, 209, 54, 0.12);
|
||||
border-color: rgba(123, 209, 54, 1);
|
||||
color: #7bd136;
|
||||
}
|
||||
&.status1 {
|
||||
border-color: rgba(153, 153, 153, 1);
|
||||
background-color: rgba(153, 153, 153, 0.12);
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
.btn {
|
||||
padding: 8rpx 42rpx;
|
||||
white-space: nowrap;
|
||||
border-radius: 100rpx;
|
||||
&.del {
|
||||
background-color: #f7f7fa;
|
||||
color: #999;
|
||||
}
|
||||
&.edit {
|
||||
background-color: $my-main-color;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
.fixed-bottom {
|
||||
}
|
||||
.time {
|
||||
margin-left: 30rpx;
|
||||
padding: 4rpx 20rpx;
|
||||
border: 1px solid $my-main-color;
|
||||
border-radius: 8rpx;
|
||||
color: $my-main-color;
|
||||
}
|
||||
.shop {
|
||||
background-color: rgba(49, 138, 254, 0.07);
|
||||
color: $my-main-color;
|
||||
border: 1px solid $my-main-color;
|
||||
padding: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.status-sel {
|
||||
min-width: 266rpx;
|
||||
padding: 18rpx 32rpx;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -246,7 +246,7 @@ function save() {
|
|||
});
|
||||
return;
|
||||
}
|
||||
if(form.discountType == "FIXED" && form.discountAmount == ""){
|
||||
if(form.discountType == "FIXED" && !form.discountAmount ){
|
||||
uni.showToast({
|
||||
title:'请填写减免金额',
|
||||
icon:'none'
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
23
pages.json
23
pages.json
|
|
@ -726,7 +726,30 @@
|
|||
"style": {
|
||||
"navigationBarTitleText": "添加"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pageId": "PAGES_MARKET_COUPON_EXCHANGE_CODE",
|
||||
"path": "couponExchangeCode/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "券兑换码"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pageId": "PAGES_MARKET_COUPON_EXCHANGE_CODE_ADD",
|
||||
"path": "couponExchangeCode/add",
|
||||
"style": {
|
||||
"navigationBarTitleText": "添加券兑换码"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pageId": "PAGES_MARKET_COUPON_EXCHANGE_CODE_DETAIL",
|
||||
"path": "couponExchangeCode/detail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "券兑换码详情"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ const menuList = ref([
|
|||
{
|
||||
title: '券兑换码',
|
||||
icon: '',
|
||||
pageUrl: '',
|
||||
pageUrl: 'PAGES_MARKET_COUPON_EXCHANGE_CODE',
|
||||
intro: '可添加多券组合兑换'
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,199 @@
|
|||
/**
|
||||
* 多端兼容文件保存(基于已下载的临时路径,无需重复download)
|
||||
* 核心:传入的url是uni.downloadFile返回的tempFilePath,直接用fs.saveFile保存
|
||||
* @param {string} tempFilePath - 已下载的文件临时路径(必填,来自downloadFile返回值)
|
||||
* @param {string} [fileName] - 自定义保存文件名(可选,默认从临时路径提取)
|
||||
* @returns {Promise<void>} - 保存结果Promise
|
||||
*/
|
||||
export function saveFileFromTemp(args) {
|
||||
const {tempFilePath, fileName,isNowOpen=false}=args
|
||||
// 前置校验:临时路径必填
|
||||
if (!tempFilePath) {
|
||||
uni.showToast({ title: "文件临时路径不能为空", icon: "none" });
|
||||
return Promise.reject(new Error("临时路径不能为空"));
|
||||
}
|
||||
|
||||
// 共用逻辑:从临时路径/URL提取默认文件名(适配各端临时路径格式)
|
||||
const getDefaultFileName = () => {
|
||||
let name = `文件_${Date.now()}`;
|
||||
try {
|
||||
// 处理微信小程序临时路径(如:wxfile://tmp/xxx.pdf)
|
||||
if (
|
||||
tempFilePath.includes("wxfile://") ||
|
||||
tempFilePath.includes("/tmp/")
|
||||
) {
|
||||
const lastSlashIndex = tempFilePath.lastIndexOf("/");
|
||||
if (lastSlashIndex !== -1) {
|
||||
name = tempFilePath.slice(lastSlashIndex + 1);
|
||||
}
|
||||
}
|
||||
// 处理App临时路径(如:_doc/tmp/xxx.png)或普通URL
|
||||
else {
|
||||
const urlObj = new URL(tempFilePath, window.location.origin); // 兼容相对路径
|
||||
const pathname = urlObj.pathname;
|
||||
const lastSlashIndex = pathname.lastIndexOf("/");
|
||||
if (lastSlashIndex !== -1) {
|
||||
name = pathname.slice(lastSlashIndex + 1).split("?")[0];
|
||||
}
|
||||
}
|
||||
// 补充文件后缀(如果没有)
|
||||
if (!name.includes(".")) {
|
||||
name += ".bin"; // 兜底后缀,可根据实际业务调整(如:.pdf/.png)
|
||||
}
|
||||
} catch (e) {
|
||||
name = `文件_${Date.now()}.bin`;
|
||||
}
|
||||
return fileName || name;
|
||||
};
|
||||
const targetFileName = getDefaultFileName();
|
||||
|
||||
// -------------------------- H5端处理(临时路径直接触发下载) --------------------------
|
||||
// #ifdef H5
|
||||
return new Promise((resolve, reject) => {
|
||||
// H5的临时路径可能是blob:xxx格式,直接用a标签下载
|
||||
const link = document.createElement("a");
|
||||
link.href = tempFilePath;
|
||||
link.download = targetFileName;
|
||||
link.target = "_blank";
|
||||
link.style.display = "none";
|
||||
|
||||
link.addEventListener("error", () => {
|
||||
uni.showToast({
|
||||
title: "保存失败:H5临时路径无效或跨域",
|
||||
icon: "none",
|
||||
duration: 3000,
|
||||
});
|
||||
reject(new Error("H5临时路径保存失败"));
|
||||
});
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
uni.showToast({ title: "保存成功,请查看浏览器下载列表", icon: "none" });
|
||||
resolve();
|
||||
});
|
||||
// #endif
|
||||
|
||||
// -------------------------- 微信小程序端处理(fs.saveFile 保存临时路径) --------------------------
|
||||
// #ifdef MP-WEIXIN
|
||||
return new Promise((resolve, reject) => {
|
||||
const fs = uni.getFileSystemManager();
|
||||
// 微信小程序保存路径(沙箱目录)
|
||||
const saveFilePath = `${wx.env.USER_DATA_PATH}/${targetFileName}`;
|
||||
|
||||
// 直接保存临时路径(无需下载)
|
||||
fs.saveFile({
|
||||
tempFilePath: tempFilePath, // 传入已下载的临时路径
|
||||
filePath: saveFilePath,
|
||||
success: (saveRes) => {
|
||||
if(isNowOpen){
|
||||
uni.openDocument({
|
||||
filePath: saveRes.savedFilePath,
|
||||
showMenu:true,
|
||||
success: (openRes) => {
|
||||
uni.showToast({
|
||||
title: "文件已打开",
|
||||
icon: "none",
|
||||
duration: 1500,
|
||||
});
|
||||
},
|
||||
fail: (openErr) => {
|
||||
uni.showToast({
|
||||
title: `打开文件失败:${openErr.errMsg}`,
|
||||
icon: "none",
|
||||
duration: 1500,
|
||||
});
|
||||
},
|
||||
});
|
||||
}else{
|
||||
uni.showModal({
|
||||
title: "保存成功",
|
||||
content: `文件已保存至:微信 → 我 → 文件 → 下载管理`,
|
||||
showCancel: false,
|
||||
});
|
||||
}
|
||||
|
||||
resolve(saveRes);
|
||||
},
|
||||
fail: (saveErr) => {
|
||||
uni.showToast({ title: `保存失败:${saveErr.errMsg}`, icon: "none" });
|
||||
reject(saveErr);
|
||||
},
|
||||
});
|
||||
});
|
||||
// #endif
|
||||
|
||||
// -------------------------- App端处理(fs.saveFile 保存临时路径) --------------------------
|
||||
// #ifdef APP
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const fs = uni.getFileSystemManager();
|
||||
// App保存路径(沙箱目录)
|
||||
const saveFilePath = `${uni.env.USER_DATA_PATH}/${targetFileName}`;
|
||||
|
||||
// Android 6.0+ 申请存储权限
|
||||
if (uni.getSystemInfoSync().platform === "android") {
|
||||
try {
|
||||
const permRes = await uni.requestPermissions({
|
||||
scope: "scope.writeExternalStorage",
|
||||
});
|
||||
if (!permRes[0].authSetting["scope.writeExternalStorage"]) {
|
||||
uni.showModal({
|
||||
title: "权限不足",
|
||||
content: "请授予存储权限后重试(设置 → 应用 → 权限管理)",
|
||||
showCancel: false,
|
||||
});
|
||||
return reject(new Error("存储权限未授予"));
|
||||
}
|
||||
} catch (permErr) {
|
||||
uni.showToast({
|
||||
title: `权限申请失败:${permErr.errMsg}`,
|
||||
icon: "none",
|
||||
});
|
||||
return reject(permErr);
|
||||
}
|
||||
}
|
||||
|
||||
// 直接保存临时路径(无需下载)
|
||||
fs.saveFile({
|
||||
tempFilePath: tempFilePath, // 传入已下载的临时路径
|
||||
filePath: saveFilePath,
|
||||
success: (saveRes) => {
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
uni.showModal({
|
||||
title: "保存成功",
|
||||
content:
|
||||
platform === "ios"
|
||||
? "文件已保存至应用沙箱,点击「查看」打开"
|
||||
: `文件路径:内部存储/Android/data/应用包名/files/${targetFileName}`,
|
||||
confirmText: "查看",
|
||||
cancelText: "取消",
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
uni.openDocument({
|
||||
filePath: saveRes.savedFilePath,
|
||||
showMenu: true,
|
||||
fail: (openErr) => {
|
||||
uni.showToast({
|
||||
title: `无法打开:${openErr.errMsg}`,
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
resolve(saveRes);
|
||||
},
|
||||
fail: (saveErr) => {
|
||||
uni.showToast({ title: `保存失败:${saveErr.errMsg}`, icon: "none" });
|
||||
reject(saveErr);
|
||||
},
|
||||
});
|
||||
});
|
||||
// #endif
|
||||
|
||||
// 其他未适配平台
|
||||
return Promise.reject(new Error("当前平台暂不支持文件保存"));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue