bill.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <div class="search">
  3. <Row>
  4. <Col>
  5. <Card>
  6. <Row @keydown.enter.native="handleSearch">
  7. <Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
  8. <Form-item label="账单编号" prop="sn">
  9. <Input type="text" v-model="searchForm.sn" placeholder="请输入账单编号" clearable style="width: 200px" />
  10. </Form-item>
  11. <Form-item label="出帐时间" prop="createTime">
  12. <DatePicker v-model="selectDate" type="daterange" format="yyyy-MM-dd HH:mm:ss" clearable @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px">
  13. </DatePicker>
  14. </Form-item>
  15. <Form-item label="筛选状态">
  16. <Select v-model="searchForm.billStatus" style="width:160px">
  17. <Option value="">全部</Option>
  18. <Option value="OUT">已出账</Option>
  19. <Option value="CHECK">已核对</Option>
  20. <Option value="COMPLETE">已完成</Option>
  21. </Select>
  22. </Form-item>
  23. <Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn">搜索</Button>
  24. </Form>
  25. </Row>
  26. <Row class="operation padding-row">
  27. <Button @click="add" type="primary">添加</Button>
  28. <Button @click="delAll">批量删除</Button>
  29. </Row>
  30. <Row>
  31. <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort" @on-selection-change="changeSelect">
  32. </Table>
  33. </Row>
  34. <Row type="flex" justify="end" class="page">
  35. <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10, 20, 50]"
  36. size="small" show-total show-elevator show-sizer></Page>
  37. </Row>
  38. </Card>
  39. </Col>
  40. </Row>
  41. <Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500">
  42. <Form ref="form" :model="form" :label-width="100" :rules="formValidate">
  43. <FormItem label="账单号" prop="sn">
  44. <Input v-model="form.sn" clearable style="width: 100%" />
  45. </FormItem>
  46. <FormItem label="店铺名称" prop="sellerName">
  47. <Input v-model="form.sellerName" clearable style="width: 100%" />
  48. </FormItem>
  49. <FormItem label="结算开始时间" prop="startTime">
  50. <DatePicker v-model="form.startTime" valueType="yyyy-MM-dd HH:mm:ss" clearable style="width: 100%"></DatePicker>
  51. </FormItem>
  52. <FormItem label="结算结束时间" prop="endTime">
  53. <DatePicker type="date" v-model="form.endTime" clearable style="width: 100%"></DatePicker>
  54. </FormItem>
  55. <FormItem label="最终结算金额" prop="billPrice">
  56. <Input v-model="form.billPrice" clearable style="width: 100%" />
  57. </FormItem>
  58. </Form>
  59. <div slot="footer">
  60. <Button type="text" @click="modalVisible = false">取消</Button>
  61. <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交
  62. </Button>
  63. </div>
  64. </Modal>
  65. </div>
  66. </template>
  67. <script>
  68. import * as API_Shop from "@/api/shops";
  69. export default {
  70. name: "bill",
  71. components: {},
  72. data() {
  73. return {
  74. loading: true, // 表单加载状态
  75. modalType: 0, // 添加或编辑标识
  76. modalVisible: false, // 添加或编辑显示
  77. modalTitle: "", // 添加或编辑标题
  78. searchForm: {
  79. // 搜索框初始化对象
  80. pageNumber: 1, // 当前页数
  81. pageSize: 10, // 页面大小
  82. sort: "createTime", // 默认排序字段
  83. order: "desc", // 默认排序方式
  84. startDate: "", // 起始时间
  85. endDate: "", // 终止时间
  86. billStatus:"" //状态
  87. },
  88. selectDate: null, // 选择一个时间段
  89. form: {
  90. // 添加或编辑表单对象初始化数据
  91. sn: "",
  92. sellerName: "",
  93. startTime: "",
  94. endTime: "",
  95. billPrice: "",
  96. },
  97. // 表单验证规则
  98. formValidate: {},
  99. submitLoading: false, // 添加或编辑提交状态
  100. selectList: [], // 多选数据
  101. selectCount: 0, // 多选计数
  102. columns: [
  103. // 表头
  104. {
  105. type: "selection",
  106. width: 60,
  107. align: "center",
  108. },
  109. {
  110. title: "账单号",
  111. key: "sn",
  112. minWidth: 200,
  113. tooltip: true,
  114. },
  115. {
  116. title: "生成时间",
  117. key: "createTime",
  118. width: 120,
  119. },
  120. {
  121. title: "结算时间段",
  122. key: "startTime",
  123. width: 200,
  124. render: (h, params) => {
  125. return h("div", params.row.startTime + "~" + params.row.endTime);
  126. },
  127. },
  128. {
  129. title: "店铺名称",
  130. key: "storeName",
  131. minWidth: 120,
  132. tooltip: true,
  133. },
  134. {
  135. title: "结算金额",
  136. key: "billPrice",
  137. width: 130,
  138. render: (h, params) => {
  139. return h(
  140. "div",
  141. this.$options.filters.unitPrice(params.row.billPrice, "¥")
  142. );
  143. },
  144. },
  145. {
  146. title: "状态",
  147. key: "billStatus",
  148. width: 100,
  149. render: (h, params) => {
  150. if (params.row.billStatus == "OUT") {
  151. return h("div", "已出账");
  152. } else if (params.row.billStatus == "CHECK") {
  153. return h("div", "已对账");
  154. } else if (params.row.billStatus == "EXAMINE") {
  155. return h("div", "已审核");
  156. } else {
  157. return h("div", "已付款");
  158. }
  159. },
  160. },
  161. {
  162. title: "操作",
  163. key: "action",
  164. align: "center",
  165. fixed: "right",
  166. width: 120,
  167. render: (h, params) => {
  168. return h("div", [
  169. h(
  170. "Button",
  171. {
  172. props: {
  173. type: "info",
  174. size: "small",
  175. },
  176. style: {
  177. marginRight: "5px",
  178. },
  179. on: {
  180. click: () => {
  181. this.detail(params.row);
  182. },
  183. },
  184. },
  185. "详细"
  186. ),
  187. ]);
  188. },
  189. },
  190. ],
  191. data: [], // 表单数据
  192. total: 0, // 表单数据总数
  193. };
  194. },
  195. methods: {
  196. init() {
  197. this.getDataList();
  198. },
  199. changePage(v) {
  200. this.searchForm.pageNumber = v;
  201. this.getDataList();
  202. },
  203. changePageSize(v) {
  204. this.searchForm.pageSize = v;
  205. this.getDataList();
  206. },
  207. handleSearch() {
  208. this.searchForm.pageNumber = 1;
  209. this.searchForm.pageSize = 10;
  210. this.getDataList();
  211. },
  212. changeSort(e) {
  213. this.searchForm.sort = e.key;
  214. this.searchForm.order = e.order;
  215. if (e.order === "normal") {
  216. this.searchForm.order = "";
  217. }
  218. this.getDataList();
  219. },
  220. changeSelect(e) {
  221. this.selectList = e;
  222. this.selectCount = e.length;
  223. },
  224. selectDateRange(v) {
  225. if (v) {
  226. this.searchForm.startDate = v[0];
  227. this.searchForm.endDate = v[1];
  228. }
  229. },
  230. getDataList() {
  231. this.loading = true;
  232. // this.searchForm
  233. this.searchForm.startTime &&
  234. (this.searchForm.startTime = this.$options.filters.unixToDate(
  235. this.searchForm.startTime / 1000
  236. ));
  237. this.searchForm.endTime &&
  238. (this.searchForm.endTime = this.$options.filters.unixToDate(
  239. this.searchForm.endTime / 1000
  240. ));
  241. API_Shop.getBuyBillPage(this.searchForm).then((res) => {
  242. this.loading = false;
  243. if (res.success) {
  244. this.data = res.result.records;
  245. this.total = res.result.total;
  246. }
  247. });
  248. this.total = this.data.length;
  249. this.loading = false;
  250. },
  251. handleSubmit() {
  252. this.$refs.form.validate((valid) => {
  253. if (valid) {
  254. this.submitLoading = true;
  255. if (this.modalType === 0) {
  256. // 添加 避免编辑后传入id等数据 记得删除
  257. delete this.form.id;
  258. this.postRequest("/bill/insertOrUpdate", this.form).then((res) => {
  259. this.submitLoading = false;
  260. if (res.success) {
  261. this.$Message.success("操作成功");
  262. this.getDataList();
  263. this.modalVisible = false;
  264. }
  265. });
  266. } else {
  267. // 编辑
  268. this.postRequest("/bill/insertOrUpdate", this.form).then((res) => {
  269. this.submitLoading = false;
  270. if (res.success) {
  271. this.$Message.success("操作成功");
  272. this.getDataList();
  273. this.modalVisible = false;
  274. }
  275. });
  276. }
  277. }
  278. });
  279. },
  280. add() {
  281. this.modalType = 0;
  282. this.modalTitle = "添加";
  283. this.$refs.form.resetFields();
  284. delete this.form.id;
  285. this.modalVisible = true;
  286. },
  287. detail(v) {
  288. let id = v.id;
  289. this.$router.push({
  290. name: "bill-detail",
  291. query: { id: id },
  292. });
  293. },
  294. remove(v) {
  295. this.$Modal.confirm({
  296. title: "确认删除",
  297. // 记得确认修改此处
  298. content: "您确认要删除 " + v.name + " ?",
  299. loading: true,
  300. onOk: () => {
  301. // 删除
  302. this.deleteRequest("/bill/delByIds/" + v.id).then((res) => {
  303. this.$Modal.remove();
  304. if (res.success) {
  305. this.$Message.success("操作成功");
  306. this.getDataList();
  307. }
  308. });
  309. // 模拟请求成功
  310. //this.$Message.success("操作成功");
  311. //this.$Modal.remove();
  312. //this.getDataList();
  313. },
  314. });
  315. },
  316. delAll() {
  317. if (this.selectCount <= 0) {
  318. this.$Message.warning("您还未选择要删除的数据");
  319. return;
  320. }
  321. this.$Modal.confirm({
  322. title: "确认删除",
  323. content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
  324. loading: true,
  325. onOk: () => {
  326. let ids = "";
  327. this.selectList.forEach(function (e) {
  328. ids += e.id + ",";
  329. });
  330. ids = ids.substring(0, ids.length - 1);
  331. // 批量删除
  332. this.deleteRequest("/bill/delByIds/" + ids).then((res) => {
  333. this.$Modal.remove();
  334. if (res.success) {
  335. this.$Message.success("操作成功");
  336. this.getDataList();
  337. }
  338. });
  339. },
  340. });
  341. },
  342. },
  343. mounted() {
  344. this.init();
  345. },
  346. };
  347. </script>
  348. <style lang="scss">
  349. // 建议引入通用样式 可删除下面样式代码
  350. @import "@/styles/table-common.scss";
  351. </style>