winingRecord.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <a-card :bordered="false" class="winRecord-table-page-search-wrapper">
  3. <div class="winRecord-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="5">
  7. <a-form-item label="中奖时间" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  8. <a-range-picker
  9. id="winRecord-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="5">
  18. <a-form-item label="奖品" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  19. <a-input id="winRecord-prizeDesc" allowClear v-model="queryParam.prizeDesc" placeholder="请输入奖品名称" />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="5">
  23. <a-form-item label="用户" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  24. <a-input id="winRecord-customerMobile" allowClear v-model="queryParam.customerMobile" placeholder="请输入用户账号" />
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="4">
  28. <a-form-item label="状态" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  29. <v-select
  30. v-model="queryParam.state"
  31. ref="orderState"
  32. id="winRecord-state"
  33. code="PRIZE_WIN_STATE"
  34. placeholder="请选择状态"
  35. allowClear></v-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :span="4">
  39. <a-button class="handle-btn serach-btn" id="winRecord-btn-serach" type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  40. <a-button class="handle-btn serach-btn" type="" id="winRecord-btn-reset" @click="handleReset">重置</a-button>
  41. <a-button class="export-btn" id="winRecord-btn--export" :loading="loading" v-hasPermission="'B_winingRecord_export'" @click="handleExport">导出</a-button>
  42. </a-col>
  43. </a-row>
  44. <a-row :gutter="20">
  45. <a-col :span="5">
  46. <a-form-item label="活动名称" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  47. <a-input id="winRecord-activeName" allowClear v-model="queryParam.activeName" placeholder="请输入活动名称" />
  48. </a-form-item>
  49. </a-col>
  50. <a-col :span="5">
  51. <a-form-item label="奖品类型" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
  52. <v-select
  53. v-model="queryParam.prizeType"
  54. ref="orderState"
  55. id="winRecord-prizeType"
  56. code="PRIZE_TYPE"
  57. placeholder="请选择奖品类型"
  58. allowClear></v-select>
  59. </a-form-item>
  60. </a-col>
  61. </a-row>
  62. </a-form>
  63. </div>
  64. <s-table
  65. ref="table"
  66. size="default"
  67. :rowKey="(record) => record.id"
  68. :columns="columns"
  69. :data="loadData"
  70. bordered>
  71. <!-- 操作 -->
  72. <template slot="action" slot-scope="text, record">
  73. <a-icon
  74. type="rocket"
  75. id="winRecord-sendGood"
  76. title="发货"
  77. v-if="record.prizeType=='GOODS'&&record.state=='WAIT_SEND_EXPRESS'&&$hasPermissions('B_winingRecord_sendGood')"
  78. class="actionBtn icon-blues"
  79. @click="sendGood(record)" />
  80. <a-icon
  81. type="eye"
  82. id="winRecord-handleView"
  83. title="详情"
  84. v-else-if="record.prizeType=='GOODS'&&record.state=='FINISH'&&$hasPermissions('B_winingRecord_view')"
  85. class="actionBtn icon-green"
  86. @click="handleView(record)" />
  87. <span v-else>--</span>
  88. </template>
  89. <template slot="prizeDesc" slot-scope="text, record">
  90. {{ record.prizeType == 'GOODS' ? text : (text+'乐豆') }}
  91. </template>
  92. </s-table>
  93. <!-- 发货 -->
  94. <GoodsLogistics :openModal="openModal" :itemId="itemId" @submit="handleSubmit" @close="openModal=false" />
  95. <!-- 发货详情 -->
  96. <GoodsLogisticsDetail :openModal="openDetailModal" :itemId="itemId" @close="openDetailModal=false" />
  97. </a-card>
  98. </template>
  99. <script>
  100. import {
  101. STable,
  102. VSelect
  103. } from '@/components'
  104. import GoodsLogistics from './GoodsLogistics.vue'
  105. import GoodsLogisticsDetail from './GoodsLogisticsDetail.vue'
  106. import getDate from '@/libs/getDate.js'
  107. import moment from 'moment'
  108. import {
  109. getLuckyWinList,
  110. sendExpress,
  111. exportLuckyDrawWin
  112. } from '@/api/luckyDraw.js'
  113. export default {
  114. name: 'WinRecord',
  115. components: {
  116. STable,
  117. VSelect,
  118. GoodsLogistics,
  119. GoodsLogisticsDetail
  120. },
  121. data () {
  122. return {
  123. openModal: false, // 是否填写物流信息
  124. openDetailModal: false, // 是否查看物流信息
  125. formItemLayout: {
  126. labelCol: {
  127. span: 6
  128. },
  129. wrapperCol: {
  130. span: 18
  131. }
  132. },
  133. // 查询参数
  134. queryParam: {
  135. beginDate: null, // 开始时间
  136. endDate: null, // 结束时间
  137. prizeDesc: '', // 奖品
  138. customerMobile: '', // 用户
  139. state: '', // 状态
  140. activeName: '', // 活动名称
  141. prizeType: '' // 奖品类型
  142. },
  143. itemId: '', // 发货列id
  144. luckyDrawWinNo: '', // 中奖奖品编码
  145. loading: false, // 导出loading
  146. // 表头
  147. columns: [{
  148. title: '序号',
  149. dataIndex: 'no',
  150. width: 80,
  151. align: 'center'
  152. },
  153. {
  154. title: '中奖时间',
  155. dataIndex: 'winTime',
  156. width: 200,
  157. align: 'center'
  158. },
  159. {
  160. title: '活动名称',
  161. dataIndex: 'activeName',
  162. width: 200,
  163. align: 'center'
  164. },
  165. {
  166. title: '奖品类型',
  167. dataIndex: 'prizeTypeDictValue',
  168. width: 200,
  169. align: 'center'
  170. },
  171. {
  172. title: '奖品',
  173. dataIndex: 'prizeDesc',
  174. scopedSlots: {
  175. customRender: 'prizeDesc'
  176. },
  177. width: 200,
  178. align: 'center'
  179. },
  180. {
  181. title: '中奖用户',
  182. dataIndex: 'customerMobile',
  183. width: 200,
  184. align: 'center'
  185. },
  186. {
  187. title: '状态',
  188. dataIndex: 'stateDictValue',
  189. width: 200,
  190. align: 'center'
  191. },
  192. {
  193. title: '操作',
  194. scopedSlots: {
  195. customRender: 'action'
  196. },
  197. width: 150,
  198. align: 'center'
  199. }
  200. ],
  201. // 加载数据方法 必须为 Promise 对象
  202. loadData: parameter => {
  203. const searchData = Object.assign(parameter, this.queryParam)
  204. if (this.time && this.time.length) {
  205. searchData.beginDate = moment(this.time[0]).format('YYYY-MM-DD 00:00:00')
  206. searchData.endDate = moment(this.time[1]).format('YYYY-MM-DD 23:59:59')
  207. } else {
  208. searchData.beginDate = ''
  209. searchData.endDate = ''
  210. }
  211. return getLuckyWinList(searchData).then(res => {
  212. if (res.status == 200) {
  213. const no = (res.data.pageNo - 1) * res.data.pageSize
  214. for (let i = 0; i < res.data.list.length; i++) {
  215. const _item = res.data.list[i]
  216. _item.no = no + i + 1
  217. _item.status = _item.status + '' === '1'
  218. }
  219. return res.data
  220. }
  221. })
  222. },
  223. // 将默认当天时间日期回显在时间选择框中
  224. time: [
  225. moment(getDate.getToday().starttime, this.dateFormat),
  226. moment(getDate.getToday().endtime, this.dateFormat)
  227. ],
  228. dateFormat: 'YYYY-MM-DD'
  229. }
  230. },
  231. methods: {
  232. moment,
  233. // 不可选日期
  234. disabledDate (date, dateStrings) {
  235. return date && date.valueOf() > Date.now()
  236. },
  237. // 创建时间change
  238. onChange (dates, dateStrings) {
  239. if ((dates, dateStrings)) {
  240. this.queryParam.beginDate = dateStrings[0]
  241. this.queryParam.endDate = dateStrings[1]
  242. }
  243. },
  244. // 重置
  245. handleReset () {
  246. this.queryParam.beginDate = getDate.getToday().starttime
  247. this.queryParam.endDate = getDate.getToday().endtime
  248. this.time = [
  249. moment(getDate.getToday().starttime, this.dateFormat),
  250. moment(getDate.getToday().endtime, this.dateFormat)
  251. ]
  252. this.queryParam.customerMobile = ''
  253. this.queryParam.activeName = ''
  254. this.queryParam.prizeType = ''
  255. this.queryParam.prizeDesc = ''
  256. this.queryParam.state = ''
  257. this.$refs.table.refresh(true)
  258. },
  259. // 导出
  260. handleExport () {
  261. const params = this.queryParam
  262. if (this.time && this.time.length) {
  263. params.beginDate = moment(this.time[0]).format('YYYY-MM-DD 00:00:00')
  264. params.endDate = moment(this.time[1]).format('YYYY-MM-DD 23:59:59')
  265. } else {
  266. params.beginDate = ''
  267. params.endDate = ''
  268. }
  269. if (!params.beginDate && !params.endDate) {
  270. this.$message.error('请先选择需要导出的中奖时间区间再进行导出!')
  271. return
  272. }
  273. // 判断两个时间段是否相差m个月 第二个参数指相差单位,第三个参数指是否返回浮点形式(小数)
  274. if (moment(params.endDate).diff(moment(params.beginDate), 'months', true) > 1) {
  275. this.$message.error('单次最多只能导出1个月的数据,请缩小查询区间后再进行导出!')
  276. return
  277. }
  278. this.$confirm({
  279. title: '提示',
  280. content: '导出过程可能需要一段时间,且导出期间不可进行其他操作,确认要导出吗?',
  281. onOk: () => {
  282. this.loading = true
  283. exportLuckyDrawWin(params).then(res => {
  284. this.loading = false
  285. this.download(res)
  286. })
  287. },
  288. onCancel () {}
  289. })
  290. // this.loading = true
  291. // exportLuckyDrawWin(params).then(res => {
  292. // this.loading = false
  293. // this.download(res)
  294. // })
  295. },
  296. download (data) {
  297. if (!data) {
  298. return
  299. }
  300. const url = window.URL.createObjectURL(new Blob([data]))
  301. const link = document.createElement('a')
  302. link.style.display = 'none'
  303. link.href = url
  304. // const a = moment().format('YYYY-MM-DD')
  305. const a = moment(this.queryParam.beginDate).format('LL') + '-' + moment(this.queryParam.endDate).format('LL')
  306. console.log(a)
  307. const fname = a + '中奖记录表'
  308. link.setAttribute('download', fname + '.xlsx')
  309. document.body.appendChild(link)
  310. link.click()
  311. },
  312. // 查看物流详情
  313. handleView (row) {
  314. this.itemId = row.id
  315. this.openDetailModal = true
  316. },
  317. // 发货
  318. sendGood (row) {
  319. this.itemId = row.id
  320. this.luckyDrawWinNo = row.luckyDrawWinNo
  321. this.openModal = true
  322. },
  323. // 提交发货
  324. handleSubmit (data) {
  325. console.log(data, 'ppppppp')
  326. const params = data
  327. params.luckyDrawWinNo = this.luckyDrawWinNo
  328. sendExpress(params).then(res => {
  329. if (res.status == 200) {
  330. this.openModal = false
  331. this.$message.success(res.message)
  332. this.$refs.table.refresh(true)
  333. }
  334. })
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="less" scoped>
  340. .winRecord-table-page-search-wrapper {
  341. .winRecord-searchForm {
  342. .ant-form-inline .ant-form-item {
  343. width: 100%;
  344. }
  345. // 搜索框的下间距
  346. .ant-form-item {
  347. margin-bottom: 10px;
  348. }
  349. .handle-btn {
  350. margin-top: 4px;
  351. margin-bottom: 20px;
  352. }
  353. .serach-btn {
  354. margin-right: 10px;
  355. }
  356. }
  357. .export-btn {
  358. background-color: #ff9900;
  359. border-color: #ff9900;
  360. color: #fff;
  361. }
  362. .export-btn.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),
  363. .export-btn.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger) {
  364. color: #fff;
  365. border-color: #ff9900;
  366. }
  367. }
  368. </style>