猫妈狗爸伴宠师小程序前端代码
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.

431 lines
9.1 KiB

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