leduQuery.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <a-card :bordered="false" class="leduQuery-table-page-search-wrapper">
  3. <div class="leduQuery-searchForm">
  4. <a-form layout="inline" @keyup.enter.native="refresh">
  5. <a-row :gutter="20">
  6. <a-col :span="6">
  7. <a-form-item label="交易时间:" :label-col="{ span: 7 }" :wrapper-col="{ span: 17}">
  8. <a-range-picker
  9. style="width:100%"
  10. id="releaseRecordList-queryOrderDate"
  11. :disabledDate="disabledDate"
  12. v-model="queryOrderDate"
  13. :format="dateFormat"
  14. :placeholder="['开始时间', '结束时间']" />
  15. </a-form-item>
  16. </a-col>
  17. <a-col :span="6">
  18. <a-form-item label="商户名称" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  19. <a-input id="releaseRecordList-officialPartnerName" allowClear :maxLength="11" v-model=" queryParam.officialPartnerName" placeholder="请输入商户名称" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="6">
  23. <a-button class="handle-btn serach-btn" id="releaseRecordList-serach" type="primary" @click="refresh">查询</a-button>
  24. <a-button class="handle-btn" id="releaseRecordList-reset" @click="handleReset">重置</a-button>
  25. <a-button class="handle-btn export-btn" id="releaseRecordList-export" v-hasPermission="'B_ledouTjExport'" :loading="loading" @click="handleExport">导出</a-button>
  26. </a-col>
  27. </a-row>
  28. </a-form>
  29. </div>
  30. <!-- 合计 -->
  31. <a-alert type="info" showIcon style="margin-bottom:15px">
  32. <div class="ftext" slot="message">总计<span> {{ orderTotal }} </span>条记录,收取乐豆<span> {{ amountTotal }} </span>个</div>
  33. </a-alert>
  34. <s-table
  35. ref="table"
  36. size="default"
  37. :rowKey="(record) => record.id"
  38. :columns="columns"
  39. :data="loadData"
  40. bordered>
  41. </s-table>
  42. </a-card>
  43. </template>
  44. <script>
  45. import { STable, VSelect } from '@/components'
  46. import { getOffPartnerGoldLog, exportOffPartnerGoldLog, getQueryStatistic } from '@/api/offPartnerGoldLog.js'
  47. import moment from 'moment'
  48. import getDate from '@/libs/getDate.js'
  49. export default {
  50. components: { STable, VSelect },
  51. data () {
  52. return {
  53. loading: false,
  54. form: this.$form.createForm(this),
  55. formItemLayout: {
  56. labelCol: { span: 4 },
  57. wrapperCol: { span: 16 }
  58. },
  59. // 将默认当天时间日期回显在时间选择框中
  60. queryOrderDate: [
  61. moment(getDate.getRecentday().starttime, this.dateFormat),
  62. moment(getDate.getRecentday().endtime, this.dateFormat)
  63. ],
  64. dateFormat: 'YYYY-MM-DD',
  65. // 查询参数
  66. queryParam: {
  67. beginDate: null, // 开始时间
  68. endDate: null, // 结束时间
  69. officialPartnerName: '' // 用户手机
  70. },
  71. optionData: [],
  72. orderTotal: 0, // 总单数
  73. amountTotal: 0, // 总金额
  74. // 表头
  75. columns: [
  76. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  77. { title: '商户名称', dataIndex: 'officialPartnerName', align: 'center' },
  78. { title: '收取乐豆个数', dataIndex: 'changeNum', width: 200, align: 'center' }
  79. // { title: '交易时间', dataIndex: 'createDate', width: 200, align: 'center' }
  80. ],
  81. // 加载数据方法 必须为 Promise 对象
  82. loadData: parameter => {
  83. const searchData = Object.assign(parameter, this.queryParam)
  84. if (this.queryOrderDate && this.queryOrderDate.length) {
  85. searchData.beginDate = moment(this.queryOrderDate[0]).format('YYYY-MM-DD')
  86. searchData.endDate = moment(this.queryOrderDate[1]).format('YYYY-MM-DD')
  87. } else {
  88. searchData.beginDate = ''
  89. searchData.endDate = ''
  90. }
  91. return getOffPartnerGoldLog(searchData).then(res => {
  92. if (res.status == 200) {
  93. const no = (res.data.pageNo - 1) * res.data.pageSize
  94. for (let i = 0; i < res.data.list.length; i++) {
  95. const _item = res.data.list[i]
  96. _item.no = no + i + 1
  97. }
  98. this.getListTotal()
  99. return res.data
  100. }
  101. })
  102. }
  103. }
  104. },
  105. beforeRouteEnter (to, from, next) {
  106. next(vm => {
  107. vm.handleReset()
  108. })
  109. },
  110. methods: {
  111. moment,
  112. // 不可选日期
  113. disabledDate (date, dateStrings) {
  114. return date && date.valueOf() > Date.now()
  115. },
  116. // 导出
  117. handleExport () {
  118. const params = {
  119. officialPartnerName: this.queryParam.officialPartnerName
  120. }
  121. if (this.queryOrderDate && this.queryOrderDate.length) {
  122. params.beginDate = moment(this.queryOrderDate[0]).format('YYYY-MM-DD')
  123. params.endDate = moment(this.queryOrderDate[1]).format('YYYY-MM-DD')
  124. } else {
  125. params.beginDate = ''
  126. params.endDate = ''
  127. }
  128. if (!params.beginDate && !params.endDate) {
  129. this.$message.error('请先选择需要导出的交易时间区间再进行导出!')
  130. return
  131. }
  132. // 判断两个时间段是否相差m个月 第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
  133. if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 3) {
  134. this.$message.error('单次最多只能导出3个月的数据,请缩小查询区间后再进行导出!')
  135. }
  136. this.loading = true
  137. exportOffPartnerGoldLog(params).then(res => {
  138. this.loading = false
  139. this.download(res)
  140. })
  141. },
  142. download (data) {
  143. if (!data) { return }
  144. const url = window.URL.createObjectURL(new Blob([data]))
  145. const link = document.createElement('a')
  146. link.style.display = 'none'
  147. link.href = url
  148. const a = moment().format('YYYYMMDDhhmmss')
  149. const fname = '商户乐豆统计-' + a
  150. link.setAttribute('download', fname + '.xlsx')
  151. document.body.appendChild(link)
  152. link.click()
  153. },
  154. // 查询
  155. refresh () {
  156. this.$refs.table.refresh(true)
  157. },
  158. // 合计
  159. getListTotal () {
  160. const params = {
  161. officialPartnerName: this.queryParam.officialPartnerName,
  162. beginDate: this.queryParam.beginDate,
  163. endDate: this.queryParam.endDate
  164. }
  165. if (this.queryOrderDate && this.queryOrderDate.length) {
  166. params.beginDate = moment(this.queryOrderDate[0]).format('YYYY-MM-DD')
  167. params.endDate = moment(this.queryOrderDate[1]).format('YYYY-MM-DD')
  168. } else {
  169. params.beginDate = ''
  170. params.endDate = ''
  171. }
  172. getQueryStatistic(params).then(res => {
  173. if (res.status == 200) {
  174. if (res.data) {
  175. this.orderTotal = res.data.dataCount || 0
  176. this.amountTotal = res.data.dataSum || 0
  177. } else {
  178. this.orderTotal = 0
  179. this.amountTotal = 0
  180. }
  181. }
  182. })
  183. },
  184. // 重置
  185. handleReset () {
  186. this.queryOrderDate = [
  187. moment(getDate.getRecentday().starttime, this.dateFormat),
  188. moment(getDate.getRecentday().endtime, this.dateFormat)
  189. ]
  190. this.queryParam.officialPartnerName = ''
  191. this.$refs.table.refresh(true)
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="less" scoped>
  197. .leduQuery-table-page-search-wrapper{
  198. .leduQuery-searchForm{
  199. .ant-form-inline .ant-form-item{
  200. width: 100%;
  201. }
  202. // 搜索框的下间距
  203. .ant-form-item {
  204. margin-bottom: 10px;
  205. }
  206. .handle-btn{
  207. margin-top: 4px;
  208. }
  209. .serach-btn{
  210. margin-right: 10px;
  211. }
  212. }
  213. .export-btn{
  214. background-color: #ff9900;
  215. border-color: #ff9900;
  216. color: #fff;
  217. margin-left: 10px;
  218. }
  219. .export-btn.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger), .export-btn.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger){
  220. color: #fff;
  221. border-color: #ff9900;
  222. }
  223. }
  224. </style>