TradeOrder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div class="trade-order">
  3. <!-- 搜索条件 -->
  4. <el-card class="search-card">
  5. <el-form :model="searchForm" label-width="140px" inline>
  6. <el-form-item>
  7. <el-input
  8. v-model="searchForm.keyword"
  9. placeholder="请输入订单编号/交易号等"
  10. clearable
  11. @keyup.enter="handleSearch"
  12. style="width: 400px;"
  13. >
  14. <template #prepend>
  15. <el-select v-model="searchForm.searchType" placeholder="请选择" style="width: 130px;">
  16. <el-option label="订单编号" value="order_sn"></el-option>
  17. <el-option label="商户支付订单号" value="out_trade_no"></el-option>
  18. <el-option label="拉卡拉交易号" value="transaction_id"></el-option>
  19. <el-option label="微信交易号" value="wechat_transaction_id"></el-option>
  20. </el-select>
  21. </template>
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" @click="handleSearch">查询</el-button>
  26. <el-button @click="handleReset">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </el-card>
  30. <!-- 列表数据 -->
  31. <el-card class="table-card">
  32. <template #header>
  33. <div class="table-header">
  34. <div class="header-title">拉卡拉交易记录列表</div>
  35. </div>
  36. </template>
  37. <el-table
  38. v-loading="loading"
  39. :data="tableData"
  40. border
  41. stripe
  42. >
  43. <el-table-column prop="id" label="ID" width="80" />
  44. <el-table-column label="订单与交易编号" min-width="300">
  45. <template #default="{ row }">
  46. <div class="order-numbers">
  47. <div class="number-item">
  48. <span class="label">订单编号:</span>
  49. <span class="value">{{ row.order_sn || '-' }}</span>
  50. </div>
  51. <div class="number-item">
  52. <span class="label">商户支付订单号:</span>
  53. <span class="value">{{ row.out_trade_no || '-' }}</span>
  54. </div>
  55. <div class="number-item">
  56. <span class="label">拉卡拉交易号:</span>
  57. <span class="value">{{ row.transaction_id || '-' }}</span>
  58. </div>
  59. <div class="number-item">
  60. <span class="label">微信交易号:</span>
  61. <span class="value">{{ row.wechat_transaction_id || '-' }}</span>
  62. </div>
  63. </div>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="amount" label="支付金额(元)" width="120" align="right">
  67. <template #default="{ row }">
  68. <span class="amount-highlight">¥{{ formatAmount(row.amount) }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column prop="order_state_text" label="状态" width="120">
  72. <template #default="{ row }">
  73. <div>
  74. <span>{{ row.order_state_text }}</span>
  75. <el-tag v-if="isPaymentOverdue(row)" type="danger" size="mini" effect="dark">超时</el-tag>
  76. </div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="支付时间" width="150">
  80. <template #default="{ row }">
  81. <div>{{ formatPaymentTime(row.payment_time) }}</div>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="更新时间" prop="update_time" width="150" />
  85. <el-table-column label="快递信息" min-width="250">
  86. <template #default="{ row }">
  87. <div class="express-info">
  88. <div>快递公司:{{ row.express_name || '-' }}</div>
  89. <div>快递单号:{{ row.express_number || '-' }}</div>
  90. <div>快递公司编号: {{ row.express_company || '-' }}</div>
  91. <div v-if="!row.express_company && row.express_company_name" class="correct-button">
  92. <el-button type="primary" size="small" @click="handleCorrectExpress(row)">纠正</el-button>
  93. </div>
  94. </div>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="收货人信息" min-width="250">
  98. <template #default="{ row }">
  99. <div class="consignee-info">
  100. <div>收货人:{{ row.consignee || '-' }}</div>
  101. <div>联系电话:{{ row.mobile || '-' }}</div>
  102. <div class="address-line">收货地址:{{ (row.province || '') + (row.city || '') + (row.district || '') + (row.address || '') }}</div>
  103. </div>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <!-- 分页 -->
  108. <el-pagination
  109. v-model:current-page="pagination.page"
  110. v-model:page-size="pagination.limit"
  111. :total="pagination.total"
  112. :page-sizes="[10, 20, 50, 100]"
  113. layout="total, sizes, prev, pager, next, jumper"
  114. @size-change="handleSizeChange"
  115. @current-change="handleCurrentChange"
  116. class="pagination"
  117. />
  118. </el-card>
  119. <!-- 快递公司选择弹窗 -->
  120. <el-dialog
  121. title="选择快递公司"
  122. v-model="dialogVisible"
  123. width="500px"
  124. >
  125. <el-select
  126. v-model="selectedExpress"
  127. placeholder="请选择快递公司"
  128. style="width: 100%"
  129. filterable
  130. >
  131. <el-option
  132. v-for="item in expressList"
  133. :key="item.delivery_id"
  134. :label="item.delivery_name"
  135. :value="item.delivery_id"
  136. />
  137. </el-select>
  138. <template #footer>
  139. <span class="dialog-footer">
  140. <el-button @click="dialogVisible = false">取消</el-button>
  141. <el-button type="primary" @click="confirmCorrect">确定</el-button>
  142. </span>
  143. </template>
  144. </el-dialog>
  145. </div>
  146. </template>
  147. <script>
  148. export default {
  149. name: "TradeOrder",
  150. props: {
  151. axiosInstance: {
  152. type: Object,
  153. default: null
  154. }
  155. },
  156. data() {
  157. return {
  158. loading: false,
  159. searchForm: {
  160. searchType: 'order_sn',
  161. keyword: ''
  162. },
  163. statusOptions: [
  164. { label: '待支付', value: 0 },
  165. { label: '支付中', value: 1 },
  166. { label: '成功', value: 2 },
  167. { label: '失败', value: 3 },
  168. { label: '已关闭', value: 4 },
  169. { label: '退款中', value: 5 }
  170. ],
  171. bizTypeOptions: [
  172. { label: '商品订单支付', value: 1 }
  173. ],
  174. tableData: [],
  175. pagination: {
  176. page: 1,
  177. limit: 10,
  178. total: 0
  179. },
  180. dialogVisible: false,
  181. expressList: [], // 快递公司列表
  182. currentRow: null, // 当前操作行
  183. selectedExpress: '' // 选中的快递公司
  184. }
  185. },
  186. async created() {
  187. this.fetchData()
  188. },
  189. methods: {
  190. // 格式化金额显示
  191. formatAmount(amount) {
  192. return amount || amount === 0 ? amount : '-';
  193. },
  194. // 格式化支付时间显示
  195. formatPaymentTime(timestamp) {
  196. if (!timestamp) return '-';
  197. const date = new Date(timestamp * 1000);
  198. return date.getFullYear() + '-' +
  199. String(date.getMonth() + 1).padStart(2, '0') + '-' +
  200. String(date.getDate()).padStart(2, '0') + ' ' +
  201. String(date.getHours()).padStart(2, '0') + ':' +
  202. String(date.getMinutes()).padStart(2, '0') + ':' +
  203. String(date.getSeconds()).padStart(2, '0');
  204. },
  205. // 获取业务类型文本
  206. getBizTypeText(bizType) {
  207. const bizTypeMap = {
  208. 1: '商品订单支付'
  209. };
  210. return bizTypeMap[bizType] || bizType;
  211. },
  212. // 判断是否支付超时(超过48小时且订单状态为1)
  213. isPaymentOverdue(row) {
  214. // 判断支付时间是否超过48小时且订单状态为1
  215. if (row.order_state === 1 && row.payment_time) {
  216. const paymentTime = new Date(row.payment_time * 1000).getTime();
  217. const currentTime = new Date().getTime();
  218. const hoursDiff = (currentTime - paymentTime) / (1000 * 60 * 60);
  219. return hoursDiff > 48;
  220. }
  221. return false;
  222. },
  223. // 获取列表数据
  224. async fetchData() {
  225. if (!this.axiosInstance) {
  226. this.$message.error('无法获取请求实例')
  227. return
  228. }
  229. this.loading = true
  230. try {
  231. const params = {
  232. page: this.pagination.page,
  233. limit: this.pagination.limit
  234. }
  235. // 添加搜索参数
  236. if (this.searchForm.keyword) {
  237. params[this.searchForm.searchType] = this.searchForm.keyword
  238. }
  239. const res = await this.axiosInstance.get('/lakala/trade_order', { params })
  240. if (res.code === 200) {
  241. this.tableData = res.page.data
  242. this.pagination.total = res.page.total
  243. this.pagination.limit = res.page.per_page
  244. } else {
  245. this.$message.error(res.msg || res.message || '获取数据失败')
  246. }
  247. } catch (error) {
  248. console.error('获取交易记录列表失败:', error)
  249. this.$message.error('获取数据失败: ' + (error.message || '未知错误'))
  250. } finally {
  251. this.loading = false
  252. }
  253. },
  254. // 查询
  255. handleSearch() {
  256. this.pagination.page = 1
  257. this.fetchData()
  258. },
  259. // 重置
  260. handleReset() {
  261. this.searchForm = {
  262. searchType: 'order_sn',
  263. keyword: ''
  264. }
  265. this.pagination.page = 1
  266. this.fetchData()
  267. },
  268. // 分页相关
  269. handleSizeChange(val) {
  270. this.pagination.limit = val
  271. this.pagination.page = 1
  272. this.fetchData()
  273. },
  274. handleCurrentChange(val) {
  275. this.pagination.page = val
  276. this.fetchData()
  277. },
  278. // 纠正快递公司信息
  279. async handleCorrectExpress(row) {
  280. this.currentRow = row;
  281. // 获取快递公司列表
  282. try {
  283. const res = await this.axiosInstance.get('/wechat/delivery');
  284. if (res.code === 200) {
  285. this.expressList = res.page.data;
  286. this.dialogVisible = true;
  287. } else {
  288. this.$message.error(res.msg || '获取快递公司列表失败');
  289. }
  290. } catch (error) {
  291. console.error('获取快递公司列表失败:', error);
  292. this.$message.error('获取快递公司列表失败: ' + (error.message || '未知错误'));
  293. }
  294. },
  295. // 确认纠正快递公司
  296. async confirmCorrect() {
  297. if (!this.selectedExpress) {
  298. this.$message.warning('请选择快递公司');
  299. return;
  300. }
  301. try {
  302. const params = {
  303. express_company: this.selectedExpress
  304. };
  305. const res = await this.axiosInstance.put(`/lakala/trade_order/${this.currentRow.wechat_payment_id}/express_company`, params);
  306. if (res.code === 200) {
  307. this.$message.success('纠正成功');
  308. this.dialogVisible = false;
  309. this.selectedExpress = '';
  310. // 重新获取数据
  311. this.fetchData();
  312. } else {
  313. this.$message.error(res.msg || '纠正失败');
  314. }
  315. } catch (error) {
  316. console.error('纠正快递公司失败:', error);
  317. this.$message.error('纠正失败: ' + (error.message || '未知错误'));
  318. }
  319. }
  320. }
  321. }
  322. </script>
  323. <style scoped>
  324. .trade-order {
  325. padding: 20px;
  326. }
  327. .search-card {
  328. margin-bottom: 20px;
  329. }
  330. .table-card {
  331. margin-bottom: 20px;
  332. }
  333. .table-header {
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. }
  338. .header-title {
  339. font-size: 16px;
  340. font-weight: bold;
  341. }
  342. .pagination {
  343. margin-top: 20px;
  344. text-align: right;
  345. }
  346. /* 支付金额高亮显示 */
  347. .amount-highlight {
  348. font-size: 16px;
  349. font-weight: 600;
  350. color: #e65a00;
  351. }
  352. /* 快递信息样式 */
  353. .express-info div {
  354. margin-bottom: 4px;
  355. font-size: 13px;
  356. }
  357. .express-info div:last-child {
  358. margin-bottom: 0;
  359. }
  360. /* 收货人信息样式 */
  361. .consignee-info div {
  362. margin-bottom: 4px;
  363. font-size: 13px;
  364. }
  365. .consignee-info div:last-child {
  366. margin-bottom: 0;
  367. }
  368. .address-line {
  369. white-space: nowrap;
  370. overflow: hidden;
  371. text-overflow: ellipsis;
  372. }
  373. .correct-button {
  374. margin-top: 8px;
  375. }
  376. .order-numbers {
  377. font-size: 12px;
  378. }
  379. .number-item {
  380. margin-bottom: 4px;
  381. display: flex;
  382. }
  383. .number-item:last-child {
  384. margin-bottom: 0;
  385. }
  386. .label {
  387. font-weight: 500;
  388. color: #606266;
  389. min-width: 90px;
  390. flex-shrink: 0;
  391. text-align: right;
  392. }
  393. .value {
  394. color: #303133;
  395. word-break: break-all;
  396. margin-left: 8px;
  397. }
  398. </style>