shopOrder.vue 8.7 KB

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