猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
9.2 KiB

6 months ago
6 months ago
6 months ago
2 months ago
6 months ago
5 months ago
6 months ago
2 months ago
2 months ago
6 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
6 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
  1. <template>
  2. <!-- <div>交易明细</div> -->
  3. <view class="box">
  4. <view class="top flex" :style="{ borderRadius: '31.5rpx' }">
  5. <view @click="changeTab(0)" :class="{ active : type == 0 }" class="income flex element"
  6. :style="{ borderRadius: '31.5rpx' }">
  7. 收入明细
  8. </view>
  9. <view @click="changeTab(1)" :class="{ active : type == 1 }" class="income flex element"
  10. :style="{ borderRadius: '31.5rpx' }">
  11. 支出明细
  12. </view>
  13. </view>
  14. <view v-for="(item,index) in list" :key="index" class="Recharge">
  15. <view class="flex">
  16. <image style="width: 80rpx;height: 80rpx" src="https://img1.baidu.com/it/u=3034232350,1041791648&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500"
  17. mode="aspectFill"></image>
  18. <view class="text1">
  19. <view class="text2">
  20. {{ item.title }}
  21. <!-- 金额类型标签 -->
  22. <!-- <text v-if="item.moneyType !== undefined" class="money-type-tag" :class="getMoneyTypeClass(item.moneyType)">
  23. {{ getMoneyTypeText(item.moneyType) }}
  24. </text> -->
  25. </view>
  26. <view>
  27. {{ item.createTime }}
  28. </view>
  29. <!-- 审核状态显示 - 只在支出明细中显示 -->
  30. <view v-if="type === 1 && item.auditStatus !== undefined" class="audit-status">
  31. <text v-if="item.auditStatus === 0" class="status-pending">待审核</text>
  32. <text v-if="item.auditStatus === 1" class="status-approved">审核通过</text>
  33. <text v-if="item.auditStatus === 2" class="status-rejected">审核不通过</text>
  34. </view>
  35. <!-- 审核不通过时显示备注 - 只在支出明细中显示 -->
  36. <view v-if="type === 1 && item.auditStatus === 2 && item.remark" class="remark">
  37. 备注{{ item.remark }}
  38. </view>
  39. </view>
  40. </view>
  41. <view class="right-content">
  42. <view class="text3">
  43. {{ item.amount }}
  44. </view>
  45. <!-- 审核通过的提现显示领取按钮 -->
  46. <view v-if="item.auditStatus === 1 && type === 1 && item.state == 0" class="receive-btn" @click="receiveWithdrawal(item)">
  47. 领取
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script setup>
  54. import {
  55. ref
  56. } from "vue"
  57. import { useStore } from 'vuex'
  58. import {
  59. amountLogList
  60. } from "@/api/amount/index.js"
  61. import {
  62. withdrawalSuccessful
  63. } from "@/api/amount/index.js"
  64. import {
  65. onShow,
  66. onLoad
  67. } from "@dcloudio/uni-app"
  68. onLoad((options) => {
  69. console.log(options);
  70. // 如果有type参数,设置默认选中的tab
  71. if (options.type) {
  72. type.value = parseInt(options.type)
  73. }
  74. if (options.moneyType) {
  75. moneyType.value = parseInt(options.moneyType)
  76. }
  77. })
  78. onShow(() => {
  79. getRunningWater()
  80. })
  81. const store = useStore()
  82. const list = ref([]);
  83. const type = ref(0);
  84. const moneyType = ref(1);
  85. // 获取流水
  86. const getRunningWater = async () => {
  87. let response = await amountLogList({
  88. type: type.value,
  89. moneyType : moneyType.value,
  90. userId: store.state.user.userInfo.userId
  91. });
  92. if (response.code == 200) {
  93. list.value = response.data
  94. }
  95. }
  96. const changeTab = (index) => {
  97. type.value = index;
  98. getRunningWater();
  99. }
  100. // 获取金额类型文本
  101. const getMoneyTypeText = (moneyType) => {
  102. switch (moneyType) {
  103. case 0:
  104. return '合伙人余额'
  105. case 1:
  106. return '伴宠师余额'
  107. case 2:
  108. return '保证金余额'
  109. default:
  110. return ''
  111. }
  112. }
  113. // 获取金额类型样式类名
  114. const getMoneyTypeClass = (moneyType) => {
  115. switch (moneyType) {
  116. case 0:
  117. return 'money-type-partner'
  118. case 1:
  119. return 'money-type-sitter'
  120. case 2:
  121. return 'money-type-deposit'
  122. default:
  123. return ''
  124. }
  125. }
  126. // 领取提现
  127. const receiveWithdrawal = async (item) => {
  128. try {
  129. console.log('开始领取提现,item:', item)
  130. // 先确认是否要领取
  131. const confirmResult = await new Promise((resolve) => {
  132. uni.showModal({
  133. title: '确认领取',
  134. content: `确定要领取¥${item.amount}吗?`,
  135. success: (res) => {
  136. resolve(res.confirm)
  137. }
  138. })
  139. })
  140. if (!confirmResult) {
  141. return
  142. }
  143. uni.showLoading({
  144. title: '处理中...'
  145. })
  146. // 检查是否支持微信转账
  147. if (typeof wx === 'undefined' || !wx.canIUse('requestMerchantTransfer')) {
  148. console.log('微信API不可用,尝试直接调用后端接口')
  149. // 如果微信API不可用,直接调用后端接口标记为已领取
  150. const result = await withdrawalSuccessful({
  151. id: item.id,
  152. userId: store.state.user.userInfo.userId
  153. })
  154. console.log('withdrawalSuccessful result:', result)
  155. uni.hideLoading()
  156. if (result.code === 200) {
  157. uni.showToast({
  158. title: '领取成功',
  159. icon: 'success',
  160. duration: 1500,
  161. success() {
  162. // 刷新列表
  163. getRunningWater()
  164. }
  165. })
  166. } else {
  167. uni.showToast({
  168. title: result.msg || '领取失败',
  169. icon: 'error',
  170. duration: 2000
  171. })
  172. }
  173. return
  174. }
  175. // 调用微信商户转账API
  176. wx.requestMerchantTransfer({
  177. mchId: '1665639691', // 商户ID
  178. appId: wx.getAccountInfoSync().miniProgram.appId,
  179. package: item.packageInfo || '', // 从后端获取的转账包信息
  180. success: async (res) => {
  181. console.log('微信转账成功:', res)
  182. // 转账成功后调用成功接口
  183. try {
  184. const result = await withdrawalSuccessful({
  185. id: item.id,
  186. userId: store.state.user.userInfo.userId
  187. })
  188. console.log('withdrawalSuccessful result:', result)
  189. uni.hideLoading()
  190. if (result.code === 200) {
  191. uni.showToast({
  192. title: '领取成功',
  193. icon: 'success',
  194. duration: 1500,
  195. success() {
  196. // 刷新列表
  197. getRunningWater()
  198. }
  199. })
  200. } else {
  201. uni.showToast({
  202. title: result.msg || '领取失败',
  203. icon: 'error',
  204. duration: 2000
  205. })
  206. }
  207. } catch (error) {
  208. console.error('调用withdrawalSuccessful失败:', error)
  209. uni.hideLoading()
  210. uni.showToast({
  211. title: '网络异常,请重试',
  212. icon: 'error',
  213. duration: 2000
  214. })
  215. }
  216. },
  217. fail: (res) => {
  218. }
  219. })
  220. } catch (error) {
  221. uni.hideLoading()
  222. console.error('领取提现异常:', error)
  223. uni.showToast({
  224. title: '网络异常,请重试',
  225. icon: 'error',
  226. duration: 2000
  227. })
  228. }
  229. }
  230. </script>
  231. <style scoped lang="scss">
  232. .box {
  233. width: 750rpx;
  234. min-height: 100vh;
  235. background-color: #FFFFFF;
  236. padding: 32rpx 24rpx 0 24rpx;
  237. box-sizing: border-box;
  238. }
  239. .top {
  240. width: 722rpx;
  241. height: 63rpx;
  242. background-color: #F3F3F3;
  243. }
  244. .active {
  245. background-color: #FFBF60;
  246. color: white;
  247. font-weight: 600;
  248. box-shadow: 0 2rpx 8rpx rgba(255, 191, 96, 0.3);
  249. }
  250. .income {
  251. width: 361rpx;
  252. height: 63rpx;
  253. line-height: 63rpx;
  254. font-size: 28rpx;
  255. font-weight: 500;
  256. justify-content: center;
  257. transition: all 0.3s ease;
  258. }
  259. .Recharge {
  260. padding: 32rpx 24rpx;
  261. box-sizing: border-box;
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: flex-start;
  265. border-bottom: 1rpx solid #f5f5f5;
  266. &:last-child {
  267. border-bottom: none;
  268. }
  269. }
  270. .flex {
  271. display: flex;
  272. }
  273. .text1 {
  274. font-size: 26rpx;
  275. color: #666666;
  276. line-height: 1.4;
  277. margin-left: 20rpx;
  278. }
  279. .Recharge image {
  280. width: 80rpx;
  281. height: 80rpx;
  282. border-radius: 8rpx;
  283. margin-top: 0;
  284. }
  285. .text2 {
  286. font-weight: 500;
  287. color: #333333;
  288. font-size: 28rpx;
  289. line-height: 40rpx;
  290. margin-bottom: 8rpx;
  291. display: flex;
  292. align-items: center;
  293. }
  294. .text3 {
  295. color: #FF2A2A;
  296. font-size: 30rpx;
  297. font-weight: 600;
  298. line-height: 44rpx;
  299. }
  300. .right-content {
  301. display: flex;
  302. flex-direction: column;
  303. align-items: flex-end;
  304. min-width: 120rpx;
  305. }
  306. .right-content > .text3 {
  307. margin-bottom: 16rpx;
  308. }
  309. .audit-status {
  310. margin-top: 12rpx;
  311. font-size: 22rpx;
  312. }
  313. .status-pending {
  314. color: #FF9800;
  315. background-color: #FFF3E0;
  316. padding: 6rpx 12rpx;
  317. border-radius: 12rpx;
  318. font-size: 20rpx;
  319. font-weight: 500;
  320. display: inline-block;
  321. }
  322. .status-approved {
  323. color: #4CAF50;
  324. background-color: #E8F5E8;
  325. padding: 6rpx 12rpx;
  326. border-radius: 12rpx;
  327. font-size: 20rpx;
  328. font-weight: 500;
  329. display: inline-block;
  330. }
  331. .status-rejected {
  332. color: #F44336;
  333. background-color: #FFEBEE;
  334. padding: 6rpx 12rpx;
  335. border-radius: 12rpx;
  336. font-size: 20rpx;
  337. font-weight: 500;
  338. display: inline-block;
  339. }
  340. .remark {
  341. margin-top: 12rpx;
  342. color: #666;
  343. font-size: 24rpx;
  344. line-height: 36rpx;
  345. background-color: #f8f8f8;
  346. padding: 12rpx;
  347. border-radius: 8rpx;
  348. border-left: 4rpx solid #F44336;
  349. }
  350. .receive-btn {
  351. background-color: #FFBF60;
  352. color: #FFFFFF;
  353. padding: 12rpx 24rpx;
  354. border-radius: 24rpx;
  355. font-size: 26rpx;
  356. font-weight: 500;
  357. text-align: center;
  358. min-width: 80rpx;
  359. cursor: pointer;
  360. box-shadow: 0 4rpx 12rpx rgba(255, 191, 96, 0.3);
  361. transition: all 0.3s ease;
  362. }
  363. .receive-btn:active {
  364. background-color: #E6A84D;
  365. transform: translateY(2rpx);
  366. box-shadow: 0 2rpx 8rpx rgba(255, 191, 96, 0.2);
  367. }
  368. /* 金额类型标签样式 */
  369. .money-type-tag {
  370. font-size: 20rpx;
  371. font-weight: 500;
  372. padding: 4rpx 8rpx;
  373. border-radius: 8rpx;
  374. margin-left: 12rpx;
  375. display: inline-block;
  376. line-height: 1;
  377. flex-shrink: 0;
  378. }
  379. .money-type-partner {
  380. color: #1976D2;
  381. background-color: #E3F2FD;
  382. }
  383. .money-type-sitter {
  384. color: #388E3C;
  385. background-color: #E8F5E8;
  386. }
  387. .money-type-deposit {
  388. color: #F57C00;
  389. background-color: #FFF3E0;
  390. }
  391. </style>