PurchasedSetmeal.vue 12 KB

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