wait-pay.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import dayjs from 'dayjs'
  2. import {
  3. Button,
  4. Cell,
  5. CellGroup,
  6. DatePicker,
  7. Icon,
  8. Image,
  9. List,
  10. Picker,
  11. Popup,
  12. showConfirmDialog,
  13. Sticky
  14. } from 'vant'
  15. import { defineComponent, onMounted, reactive } from 'vue'
  16. import styles from '../index.module.less'
  17. import iconOrder from '../images/icon_order.png'
  18. import request from '@/helpers/request'
  19. import OEmpty from '@/components/o-empty'
  20. import { orderStatus, orderType } from '@/constant'
  21. import { moneyFormat } from '@/helpers/utils'
  22. import { useRouter } from 'vue-router'
  23. export default defineComponent({
  24. name: 'wait_pay',
  25. props: {
  26. height: {
  27. type: Number,
  28. default: 50
  29. }
  30. },
  31. setup(props) {
  32. const router = useRouter()
  33. const form = reactive({
  34. isClick: false,
  35. timeShow: false,
  36. currentData: [dayjs().year() + ''],
  37. typeShow: false,
  38. currentType: 'ALL',
  39. typeArray: [{ text: '全部', value: 'ALL' }] as any,
  40. list: [] as any,
  41. listState: {
  42. dataShow: true, // 判断是否有数据
  43. loading: false,
  44. finished: false
  45. },
  46. params: {
  47. paymentStatus: ['WAIT_PAY', 'PAYING'],
  48. page: 1,
  49. rows: 20
  50. }
  51. })
  52. const getList = async () => {
  53. try {
  54. if (form.isClick) return
  55. form.isClick = true
  56. const res = await request.post('/api-student/userPaymentOrder/page', {
  57. data: {
  58. ...form.params,
  59. orderType: form.currentType === 'ALL' ? null : form.currentType,
  60. paymentYear: form.currentData[0]
  61. }
  62. })
  63. form.listState.loading = false
  64. const result = res.data || {}
  65. // 处理重复请求数据
  66. if (form.list.length > 0 && result.current === 1) {
  67. return
  68. }
  69. form.list = form.list.concat(result.rows || [])
  70. form.listState.finished = result.current >= result.pages
  71. form.params.page = result.current + 1
  72. form.listState.dataShow = form.list.length > 0
  73. form.isClick = false
  74. } catch {
  75. form.listState.dataShow = false
  76. form.listState.finished = true
  77. form.isClick = false
  78. }
  79. }
  80. const onSearch = () => {
  81. form.params.page = 1
  82. form.list = []
  83. form.listState.dataShow = true // 判断是否有数据
  84. form.listState.loading = false
  85. form.listState.finished = false
  86. getList()
  87. }
  88. const formatOrderType = (orderType: string) => {
  89. let select = {} as any
  90. form.typeArray.forEach((item: any) => {
  91. if (item.value === orderType) {
  92. select = item
  93. }
  94. })
  95. return select.text
  96. }
  97. const onCancelOrder = async (item: any) => {
  98. showConfirmDialog({
  99. message: '您是否关闭该订单',
  100. cancelButtonText: '取消',
  101. confirmButtonText: '确定'
  102. }).then(async () => {
  103. try {
  104. await request.post('/api-student/userPaymentOrder/cancelPayment/' + item.orderNo)
  105. onSearch()
  106. } catch {
  107. //
  108. }
  109. })
  110. }
  111. const onConfirmOrder = async (item: any) => {
  112. try {
  113. const { data } = await request.get('/api-student/userPaymentOrder/unpaid', {
  114. params: {
  115. orderNo: item.orderNo,
  116. paymentType: item.orderType
  117. }
  118. })
  119. const paymentConfig = data.paymentConfig
  120. router.push({
  121. path: '/orderDetail',
  122. query: {
  123. config: JSON.stringify(paymentConfig.paymentConfig),
  124. orderNo: paymentConfig.orderNo
  125. }
  126. })
  127. } catch {
  128. //
  129. }
  130. }
  131. const onDetails = (item: any) => {
  132. router.push({
  133. path: 'payment-result',
  134. query: {
  135. orderNo: item.orderNo
  136. }
  137. })
  138. }
  139. onMounted(() => {
  140. getList()
  141. Object.keys(orderType).forEach((key) => {
  142. form.typeArray.push({
  143. text: orderType[key],
  144. value: key
  145. })
  146. })
  147. })
  148. return () => (
  149. <>
  150. <Sticky position="top" offsetTop={props.height}>
  151. <div style={{ padding: '12px 13px 16px', background: '#F8F8F8' }}>
  152. <div class={styles.searchBand} onClick={() => (form.timeShow = true)}>
  153. {form.currentData[0]}年 <Icon name={form.timeShow ? 'arrow-up' : 'arrow-down'} />
  154. </div>
  155. <div
  156. class={styles.searchBand}
  157. onClick={() => (form.typeShow = true)}
  158. style="margin-left: 16px"
  159. >
  160. {formatOrderType(form.currentType)}
  161. <Icon name={form.typeShow ? 'arrow-up' : 'arrow-down'} />
  162. </div>
  163. </div>
  164. </Sticky>
  165. {form.listState.dataShow ? (
  166. <List
  167. v-model:loading={form.listState.loading}
  168. finished={form.listState.finished}
  169. finishedText=" "
  170. class={[styles.liveList]}
  171. onLoad={getList}
  172. immediateCheck={false}
  173. >
  174. {form.list.map((item: any) => (
  175. <CellGroup inset class={styles.cellGroup} onClick={() => onDetails(item)}>
  176. <Cell center titleClass={styles.times}>
  177. {{
  178. title: () => <span class={styles.times}>{item.createTime}</span>,
  179. value: () => <span class={styles.status}>{orderStatus[item.status]}</span>
  180. }}
  181. </Cell>
  182. <Cell isLink center clickable={false} titleStyle={{ flex: '0 auto' }}>
  183. {{
  184. icon: () => <Image class={styles.img} src={iconOrder} />,
  185. title: () => <span class={styles.name}>{orderType[item.orderType]}</span>,
  186. value: () => (
  187. <div class={styles.price}>
  188. <span>¥</span>
  189. {moneyFormat(item.paymentCashAmount)}
  190. </div>
  191. )
  192. }}
  193. </Cell>
  194. <Cell>
  195. {{
  196. value: () => (
  197. <div class={styles.btnGroup}>
  198. <Button
  199. plain
  200. round
  201. size="small"
  202. color="#777777"
  203. class={styles.smallBtn}
  204. onClick={(e: any) => {
  205. e.stopPropagation()
  206. onCancelOrder(item)
  207. }}
  208. >
  209. 取消订单
  210. </Button>
  211. <Button
  212. plain
  213. round
  214. size="small"
  215. type="primary"
  216. class={styles.smallBtn}
  217. onClick={(e: any) => {
  218. e.stopPropagation()
  219. onConfirmOrder(item)
  220. }}
  221. >
  222. 继续支付
  223. </Button>
  224. </div>
  225. )
  226. }}
  227. </Cell>
  228. </CellGroup>
  229. ))}
  230. </List>
  231. ) : (
  232. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无订单" />
  233. )}
  234. <Popup v-model:show={form.timeShow} position="bottom" round>
  235. <DatePicker
  236. v-model={form.currentData}
  237. columnsType={['year']}
  238. onConfirm={(date: any) => {
  239. form.currentData = date.selectedValues
  240. form.timeShow = false
  241. onSearch()
  242. }}
  243. onCancel={() => (form.timeShow = false)}
  244. />
  245. </Popup>
  246. <Popup v-model:show={form.typeShow} position="bottom" round>
  247. <Picker
  248. columns={form.typeArray}
  249. onCancel={() => (form.typeShow = false)}
  250. onConfirm={(val: any) => {
  251. form.currentType = val.selectedValues[0]
  252. form.typeShow = false
  253. onSearch()
  254. }}
  255. />
  256. </Popup>
  257. </>
  258. )
  259. }
  260. })