PurchasedSetmeal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <a-card :bordered="false" class="purchasedSetmeal-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="purchasedSetmeal-searchForm">
  5. <a-form ref="searchForm" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="48">
  7. <a-col :span="6">
  8. <a-form-item label="下单时间" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  9. <a-range-picker
  10. id="purchasedSetmeal-time"
  11. v-model="time"
  12. :format="dateFormat"
  13. :placeholder="['开始时间','结束时间']"
  14. :disabledDate="disabledDate"
  15. @change="onChange" />
  16. </a-form-item>
  17. </a-col>
  18. <a-col :span="6">
  19. <a-form-item label="订单号" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  20. <a-input v-model.trim="searchForm.number" id="purchasedSetmeal-number" placeholder="请输入订单号" allowClear />
  21. </a-form-item>
  22. </a-col>
  23. <a-col :span="6">
  24. <a-form-item label="客户信息" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  25. <a-input v-model.trim="searchForm.queryWord" id="purchasedSetmeal-queryWord" placeholder="请输入手机号/车牌号" allowClear />
  26. </a-form-item>
  27. </a-col>
  28. <a-col :span="6">
  29. <a-form-item label="套餐名称" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  30. <a-input v-model.trim="searchForm.bundleName" id="purchasedSetmeal-bundleName" placeholder="请输入套餐名称" allowClear />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="6">
  34. <a-form-item label="单据状态" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  35. <v-select
  36. v-model="searchForm.orderFlag"
  37. ref="orderFlag"
  38. id="purchasedSetmeal-status"
  39. code="PAY_STATUS"
  40. placeholder="请选择单据状态"
  41. allowClear></v-select>
  42. </a-form-item>
  43. </a-col>
  44. <a-col :span="6">
  45. <a-form-item label="结算状态" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
  46. <v-select
  47. v-model="searchForm.salesChannelSettleStatus"
  48. ref="salesChannelSettleStatus"
  49. id="purchasedSetmeal-status"
  50. code="SETTLE_STATUS_ALL"
  51. placeholder="请选择结算状态"
  52. allowClear></v-select>
  53. </a-form-item>
  54. </a-col>
  55. <a-col :span="12">
  56. <a-button class="handle-btn serach-btn" id="purchasedSetmeal-serach" type="primary" @click="handleSearch">查询</a-button>
  57. <a-button class="handle-btn" type="" id="purchasedSetmeal-reset" @click="handleReset">重置</a-button>
  58. <a-button class="handle-btn export-btn" id="purchasedSetmeal-export" type="" :loading="loading" @click="handleExport">导出</a-button>
  59. </a-col>
  60. </a-row>
  61. </a-form>
  62. </div>
  63. <!-- 新建 -->
  64. <div class="table-operator"><a-button type="primary" id="purchasedSetmeal-buy" icon="plus" @click="goBuy()">购买套餐</a-button></div>
  65. <!-- 合计 -->
  66. <div class="total">
  67. <a-icon type="info-circle" class="iconImg" />
  68. <strong>总计:</strong><span v-model="orderTotal">{{ orderTotal || 0 }} 单</span>
  69. <strong style="margin-left: 15px;">收款金额:</strong><span v-model="totalAmounts">{{ totalAmounts || 0 }} 元</span>
  70. </div>
  71. <!-- 列表 -->
  72. <s-table
  73. ref="table"
  74. size="default"
  75. :rowKey="(record) => record.id"
  76. :columns="columns"
  77. :data="loadData"
  78. bordered>
  79. <!-- 客户信息 -->
  80. <p slot="custInfo" slot-scope="text, record">
  81. <span v-if="record.custMobile || record.vehicleNumber">{{ record.custMobile }} / {{ record.vehicleNumber }}</span>
  82. <span v-else>--</span>
  83. </p>
  84. <!-- 单据状态 -->
  85. <span slot="orderFlag" slot-scope="text, record">{{ $refs.orderFlag.getNameByCode(record.orderFlag) }}</span>
  86. <!-- 结算状态 -->
  87. <span slot="salesChannelSettleStatus" slot-scope="text, record">{{ $refs.salesChannelSettleStatus.getNameByCode(record.salesChannelSettleStatus) }}</span>
  88. <!-- 操作 -->
  89. <span slot="action" slot-scope="text, record">
  90. <a-button type="primary" id="purchasedSetmeal-look" @click="seeDetail(record)">详情</a-button>
  91. </span>
  92. </s-table>
  93. <!-- 查看详情弹窗 -->
  94. <setmeal-detail-modal :openModal="openDetailModal" :setmealId="detailId" @close="openDetailModal=false" />
  95. </a-card>
  96. </template>
  97. <script>
  98. import { STable, VSelect } from '@/components'
  99. import getDate from '@/libs/getDate.js'
  100. import { completeDate } from '@/libs/tools.js'
  101. import moment from 'moment'
  102. import SetmealDetailModal from './SetmealDetailModal.vue'
  103. import { listCustomerBundle, exportBundle, countListBundle } from '@/api/customerBundle.js'
  104. export default {
  105. name: 'PurchasedSetmeal',
  106. components: { STable, VSelect, SetmealDetailModal },
  107. data () {
  108. return {
  109. // 查询参数
  110. searchForm: {
  111. beginDate: null, // 开始时间
  112. endDate: null, // 结束时间
  113. bundleName: '', // 套餐名称
  114. number: '', // 订单号
  115. queryWord: '', // 客户信息
  116. orderFlag: '', // 单据状态
  117. salesChannelSettleStatus: '' // 结算状态
  118. },
  119. loading: false, // 导出loading
  120. orderTotal: '', // 合计开单数量
  121. totalAmounts: '', // 合计收款金额
  122. openDetailModal: false, // 查看详情弹窗 默认关闭
  123. detailId: null, // 初始化id
  124. // 将默认当天时间日期回显在时间选择框中
  125. time: [
  126. moment(getDate.getToday().starttime, this.dateFormat),
  127. moment(getDate.getToday().endtime, this.dateFormat)
  128. ],
  129. dateFormat: 'YYYY-MM-DD',
  130. columns: [
  131. { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  132. { title: '订单号', dataIndex: 'number', width: 100, align: 'center' },
  133. { title: '下单时间', dataIndex: 'orderDate', width: 100, align: 'center' },
  134. { title: '套餐名称', dataIndex: 'bundleName', width: 100, align: 'center' },
  135. { title: '客户信息', scopedSlots: { customRender: 'custInfo' }, width: 100, align: 'center' },
  136. { title: '收款金额(¥)', dataIndex: 'payedAmount', width: 80, align: 'center' },
  137. { title: '单据状态', scopedSlots: { customRender: 'orderFlag' }, width: 80, align: 'center' },
  138. { title: '结算状态', scopedSlots: { customRender: 'salesChannelSettleStatus' }, width: 80, align: 'center' },
  139. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center' }
  140. ],
  141. // 加载数据方法 必须为 Promise 对象
  142. loadData: parameter => {
  143. this.searchForm.beginDate == null ? this.searchForm.beginDate = getDate.getToday().starttime : null
  144. this.searchForm.endDate == null ? this.searchForm.endDate = getDate.getToday().endtime : null
  145. return listCustomerBundle(Object.assign(parameter, this.searchForm)).then(res => {
  146. if (res.status == 200) {
  147. const no = (res.data.pageNo - 1) * res.data.pageSize
  148. for (let i = 0; i < res.data.list.length; i++) {
  149. const _item = res.data.list[i]
  150. _item.no = no + i + 1
  151. }
  152. this.getTotal()
  153. return res.data
  154. }
  155. })
  156. }
  157. }
  158. },
  159. methods: {
  160. moment,
  161. // 不可选日期
  162. disabledDate (date, dateStrings) {
  163. return date && date.valueOf() > Date.now()
  164. },
  165. // 购买套餐
  166. goBuy () {
  167. this.$router.push({ path: '/SetmealSales/BuySetmeal' })
  168. },
  169. // 创建时间change
  170. onChange (dates, dateStrings) {
  171. if ((dates, dateStrings)) {
  172. this.searchForm.beginDate = dateStrings[0]
  173. this.searchForm.endDate = dateStrings[1]
  174. }
  175. },
  176. // 合计
  177. getTotal () {
  178. const params = {
  179. beginDate: this.searchForm.beginDate,
  180. endDate: this.searchForm.endDate,
  181. bundleName: this.searchForm.bundleName,
  182. number: this.searchForm.number,
  183. queryWord: this.searchForm.queryWord,
  184. orderFlag: this.searchForm.orderFlag,
  185. salesChannelSettleStatus: this.searchForm.salesChannelSettleStatus
  186. }
  187. params.beginDate == null ? params.beginDate = getDate.getToday().starttime : null
  188. params.endDate == null ? params.endDate = getDate.getToday().endtime : null
  189. countListBundle(params).then(res => {
  190. if (res.status == 200) {
  191. if (res.data) {
  192. this.orderTotal = res.data.cnt || 0
  193. this.totalAmounts = res.data.totalAmounts || 0
  194. } else {
  195. this.orderTotal = 0
  196. this.totalAmounts = 0
  197. }
  198. } else {
  199. this.orderTotal = 0
  200. this.totalAmounts = 0
  201. }
  202. })
  203. },
  204. // 查看详情--跳转到对应的详情页
  205. seeDetail (record) {
  206. // 将当前行的id传递给详情页
  207. this.detailId = String(record.id)
  208. this.openDetailModal = true
  209. },
  210. // 查询
  211. handleSearch () {
  212. this.$refs.table.refresh()
  213. },
  214. // 重置
  215. handleReset () {
  216. this.searchForm.beginDate = getDate.getToday().starttime
  217. this.searchForm.endDate = getDate.getToday().endtime
  218. this.time = [
  219. moment(getDate.getToday().starttime, this.dateFormat),
  220. moment(getDate.getToday().endtime, this.dateFormat)
  221. ]
  222. this.searchForm.bundleName = ''
  223. this.searchForm.number = ''
  224. this.searchForm.queryWord = ''
  225. this.searchForm.orderFlag = null
  226. this.searchForm.salesChannelSettleStatus = null
  227. this.$refs.table.refresh(true)
  228. },
  229. // 导出
  230. handleExport () {
  231. const params = {
  232. beginDate: this.searchForm.beginDate == null ? getDate.getToday().starttime : this.searchForm.beginDate,
  233. endDate: this.searchForm.endDate == null ? getDate.getToday().endtime : this.searchForm.endDate,
  234. bundleName: this.searchForm.bundleName,
  235. number: this.searchForm.number,
  236. queryWord: this.searchForm.queryWord,
  237. orderFlag: this.searchForm.orderFlag,
  238. salesChannelSettleStatus: this.searchForm.salesChannelSettleStatus
  239. }
  240. if (!params.beginDate && !params.endDate) {
  241. this.$message.error('请先选择需要导出的下单时间区间再进行导出!')
  242. return
  243. }
  244. // 判断两个时间段是否相差m个月
  245. if (!completeDate(params.beginDate, params.endDate, 3)) {
  246. this.$message.error('单次最多只能导出3个月的数据,请缩小查询区间后再进行导出!')
  247. return
  248. }
  249. this.loading = true
  250. exportBundle(params).then(res => {
  251. this.loading = false
  252. this.download(res)
  253. })
  254. },
  255. download (data) {
  256. if (!data) { return }
  257. const url = window.URL.createObjectURL(new Blob([data]))
  258. const link = document.createElement('a')
  259. link.style.display = 'none'
  260. link.href = url
  261. const a = moment().format('YYYYMMDDhhmmss')
  262. const fname = '已购套餐记录-' + a
  263. link.setAttribute('download', fname + '.xlsx')
  264. document.body.appendChild(link)
  265. link.click()
  266. }
  267. }
  268. }
  269. </script>
  270. <style lang="less">
  271. .purchasedSetmeal-wrap{
  272. .purchasedSetmeal-searchForm {
  273. // 搜索框的下间距
  274. .ant-form-item {
  275. margin-bottom: 10px;
  276. }
  277. .handle-btn{
  278. margin-top: 4px;
  279. }
  280. .serach-btn{
  281. margin-right: 10px;
  282. }
  283. .export-btn{
  284. background-color: #ff9900;
  285. border-color: #ff9900;
  286. color: #fff;
  287. margin-left: 10px;
  288. }
  289. .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){
  290. color: #fff;
  291. border-color: #ff9900;
  292. }
  293. }
  294. .table-operator{
  295. margin: 18px 0 30px;
  296. }
  297. // 合计
  298. .total {
  299. margin: 15px 0 25px;
  300. width: 100%;
  301. background-color: #e6f7ff;
  302. border: 1px solid #91d5ff;
  303. padding: 8px 15px 8px 27px;
  304. border-radius: 4px;
  305. .iconImg {
  306. color: #1890FF;
  307. margin-right: 10px;
  308. }
  309. }
  310. }
  311. </style>