TradeOrder.vue 13 KB

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