invoice.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <view class="page client-theme client-subpage">
  3. <view class="client-subpage-hero invoice-hero">
  4. <text class="client-subpage-hero__title">发票管理</text>
  5. <text class="client-subpage-hero__sub">申请开票与查看开票记录</text>
  6. <button class="apply-btn" @click="openApply">申请开票</button>
  7. </view>
  8. <scroll-view scroll-y class="client-subpage-scroll invoice-scroll" :show-scrollbar="true">
  9. <view class="client-subpage-body invoice-body">
  10. <view v-if="loading && list.length === 0" class="hint">加载中...</view>
  11. <view v-else-if="list.length === 0" class="empty">暂无发票记录</view>
  12. <view v-for="row in list" :key="row.id" class="card" hover-class="card--pressed" :hover-stay-time="100">
  13. <view class="row">
  14. <text class="no">{{ row.invoiceNo }}</text>
  15. <text class="st">{{ statusText[row.status] || row.status }}</text>
  16. </view>
  17. <text class="sub">订单金额(元) ¥{{ formatYuan(row.invoiceAmount) }}</text>
  18. <text class="sub">抬头 {{ row.title }}</text>
  19. <text class="time">{{ row.createAt }}</text>
  20. </view>
  21. </view>
  22. </scroll-view>
  23. <view v-if="showApply" class="mask" @click.self="showApply = false">
  24. <view class="dialog" @click.stop>
  25. <text class="dlg-title">申请开票</text>
  26. <picker
  27. v-if="availOrders.length"
  28. mode="selector"
  29. :range="availOrders"
  30. range-key="orderNo"
  31. :value="pickerIndex"
  32. @change="onPickerChange"
  33. >
  34. <view class="picker">
  35. <view class="picker-row">
  36. <text class="picker-text">订单:{{ availOrders[pickerIndex]?.orderNo || '选择订单' }}</text>
  37. <SqCopyBtn
  38. v-if="availOrders[pickerIndex]?.orderNo"
  39. class="picker-copy"
  40. :text="availOrders[pickerIndex]?.orderNo"
  41. label="订单号"
  42. icon-only
  43. />
  44. </view>
  45. </view>
  46. </picker>
  47. <text v-else class="hint">暂无可开票订单(需已完成且无发票)</text>
  48. <input v-model="applyTitle" class="input" placeholder="发票抬头,默认「个人」" />
  49. <view class="dlg-actions">
  50. <button class="btn plain" @click="showApply = false">取消</button>
  51. <button class="btn primary" @click="submitApply">提交</button>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script setup>
  58. import { ref, onMounted } from 'vue'
  59. import { onShow } from '@dcloudio/uni-app'
  60. import { useUserStore } from '@/stores/user'
  61. import { request, parseResponseJson } from '@/utils/request'
  62. import { API_URL } from '@/config/api'
  63. import { formatYuan } from '@/utils/format'
  64. import SqCopyBtn from '@/components/sq-copy-btn.vue'
  65. const userStore = useUserStore()
  66. const list = ref([])
  67. const loading = ref(false)
  68. const page = ref(1)
  69. const totalPages = ref(1)
  70. const showApply = ref(false)
  71. const availOrders = ref([])
  72. const applyOrderId = ref('')
  73. const applyTitle = ref('')
  74. const pickerIndex = ref(0)
  75. const statusText = {
  76. pending: '待开票',
  77. issued: '已开票',
  78. rejected: '已驳回',
  79. cancelled: '已取消'
  80. }
  81. async function fetchList(reset = false) {
  82. if (reset) page.value = 1
  83. loading.value = true
  84. try {
  85. const res = await request({
  86. url: API_URL.CLIENT_INVOICES,
  87. method: 'GET',
  88. data: { page: page.value, pageSize: 20 }
  89. })
  90. const body = parseResponseJson(res)
  91. if (body.code === 200 && body.data && body.data.list) {
  92. list.value = body.data.list
  93. totalPages.value = body.data.totalPages || 1
  94. }
  95. } finally {
  96. loading.value = false
  97. }
  98. }
  99. function onPickerChange(e) {
  100. const i = Number(e.detail.value)
  101. pickerIndex.value = i
  102. applyOrderId.value = (availOrders.value[i] && availOrders.value[i].orderId) || ''
  103. }
  104. async function openApply() {
  105. showApply.value = true
  106. applyOrderId.value = ''
  107. applyTitle.value = ''
  108. pickerIndex.value = 0
  109. try {
  110. const res = await request({
  111. url: API_URL.INVOICE_AVAILABLE_ORDERS,
  112. method: 'GET'
  113. })
  114. const body = parseResponseJson(res)
  115. if (body.code === 200) {
  116. availOrders.value = (body.data && body.data.list) || []
  117. if (availOrders.value.length) {
  118. applyOrderId.value = availOrders.value[0].orderId
  119. }
  120. }
  121. } catch {
  122. uni.showToast({ title: '加载可开票订单失败', icon: 'none' })
  123. }
  124. }
  125. async function submitApply() {
  126. if (!applyOrderId.value) {
  127. uni.showToast({ title: '请选择订单', icon: 'none' })
  128. return
  129. }
  130. try {
  131. const res = await request({
  132. url: API_URL.CLIENT_INVOICES,
  133. method: 'POST',
  134. data: {
  135. orderId: applyOrderId.value,
  136. title: applyTitle.value || '个人',
  137. invoiceType: 'normal'
  138. }
  139. })
  140. const body = parseResponseJson(res)
  141. if (body.code === 200) {
  142. uni.showToast({ title: '已提交申请', icon: 'success' })
  143. showApply.value = false
  144. fetchList(true)
  145. } else {
  146. uni.showToast({ title: body.message || '提交失败', icon: 'none' })
  147. }
  148. } catch {
  149. uni.showToast({ title: '提交失败', icon: 'none' })
  150. }
  151. }
  152. onMounted(() => {
  153. userStore.checkLoginStatus()
  154. if (!userStore.isLoggedIn) {
  155. uni.reLaunch({ url: '/pages/login/login' })
  156. return
  157. }
  158. if (!userStore.isClient) {
  159. uni.showToast({ title: '仅客户可访问', icon: 'none' })
  160. setTimeout(() => userStore.navigateToHome(), 1200)
  161. return
  162. }
  163. fetchList(true)
  164. })
  165. onShow(() => {
  166. userStore.checkLoginStatus()
  167. if (!userStore.isLoggedIn || !userStore.isClient) return
  168. void fetchList(true)
  169. })
  170. </script>
  171. <style lang="scss" scoped>
  172. .page {
  173. min-height: 100vh;
  174. background: var(--c-bg);
  175. box-sizing: border-box;
  176. }
  177. .invoice-hero {
  178. position: relative;
  179. }
  180. .apply-btn {
  181. margin-top: 24rpx;
  182. width: 100%;
  183. max-width: 420rpx;
  184. background: rgba(255, 255, 255, 0.95);
  185. color: var(--c-brand-green);
  186. font-size: 28rpx;
  187. border-radius: 44rpx;
  188. border: none;
  189. font-weight: 600;
  190. height: 80rpx;
  191. line-height: 80rpx;
  192. }
  193. .invoice-scroll {
  194. flex: 1;
  195. min-height: 0;
  196. height: 0;
  197. }
  198. .invoice-body {
  199. min-height: 100%;
  200. }
  201. .card--pressed {
  202. opacity: 0.94;
  203. }
  204. .hint,
  205. .empty {
  206. text-align: center;
  207. color: var(--c-muted);
  208. padding: 60rpx 0;
  209. font-size: 28rpx;
  210. }
  211. .card {
  212. background: var(--c-card);
  213. border: 1rpx solid var(--c-border);
  214. border-radius: var(--c-radius-card);
  215. padding: 24rpx;
  216. margin-bottom: 20rpx;
  217. }
  218. .row {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. }
  223. .no {
  224. font-size: 30rpx;
  225. font-weight: 600;
  226. color: var(--c-text);
  227. }
  228. .st {
  229. font-size: 24rpx;
  230. color: var(--c-brand-green);
  231. }
  232. .sub {
  233. display: block;
  234. font-size: 26rpx;
  235. color: var(--c-muted);
  236. margin-top: 12rpx;
  237. }
  238. .time {
  239. display: block;
  240. font-size: 22rpx;
  241. color: #c0c4cc;
  242. margin-top: 12rpx;
  243. }
  244. .mask {
  245. position: fixed;
  246. inset: 0;
  247. background: rgba(0, 0, 0, 0.45);
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. z-index: 100;
  252. }
  253. .dialog {
  254. width: 600rpx;
  255. background: var(--c-card);
  256. border: 1rpx solid var(--c-border);
  257. border-radius: var(--c-radius-card);
  258. padding: 32rpx;
  259. }
  260. .dlg-title {
  261. font-size: 32rpx;
  262. font-weight: 500;
  263. display: block;
  264. margin-bottom: 24rpx;
  265. }
  266. .picker {
  267. padding: 20rpx;
  268. background: #f8fcfa;
  269. border-radius: 16rpx;
  270. font-size: 26rpx;
  271. margin-bottom: 20rpx;
  272. border: 1rpx solid rgba(220, 235, 228, 0.65);
  273. }
  274. .picker-row {
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. gap: 12rpx;
  279. }
  280. .picker-text {
  281. flex: 1;
  282. min-width: 0;
  283. overflow: hidden;
  284. text-overflow: ellipsis;
  285. white-space: nowrap;
  286. }
  287. .picker-copy {
  288. flex: 0 0 auto;
  289. }
  290. .input {
  291. border: 1rpx solid var(--c-border);
  292. border-radius: 16rpx;
  293. padding: 16rpx;
  294. font-size: 26rpx;
  295. margin-bottom: 24rpx;
  296. }
  297. .dlg-actions {
  298. display: flex;
  299. gap: 20rpx;
  300. justify-content: flex-end;
  301. }
  302. .btn {
  303. font-size: 28rpx;
  304. padding: 0 32rpx;
  305. height: 72rpx;
  306. line-height: 72rpx;
  307. }
  308. .plain {
  309. background: #f8fcfa;
  310. color: var(--c-muted);
  311. }
  312. .primary {
  313. background: linear-gradient(145deg, var(--c-barley-yellow), #e4b458);
  314. color: #fff;
  315. font-weight: 600;
  316. }
  317. </style>