rent_computer_ledger.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <!--
  2. * @Author: 倚楼听风雨 18408246387@163.com
  3. * @Date: 2022-11-16 17:16:17
  4. * @LastEditors: 倚楼听风雨 18408246387@163.com
  5. * @LastEditTime: 2023-02-20 15:47:22
  6. * @FilePath: \log-server-web\src\view\logComputer\list_computer_distinct.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <div>
  11. <div class="gva-search-box">
  12. <div class="gva-btn-list">
  13. <el-form ref="searchForm" :inline="true" :model="searchInfo">
  14. <el-form-item label="电脑编号">
  15. <el-input
  16. v-model="searchInfo.pc_num"
  17. placeholder="编号"
  18. size="small"
  19. />
  20. </el-form-item>
  21. <el-form-item label="供应商">
  22. <el-select v-model="searchInfo.shop_id" size="small">
  23. <el-option
  24. v-for="item in shopOptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="套餐">
  32. <el-select v-model="searchInfo.set_meal_id" size="small"
  33. ><el-option
  34. v-for="item in setMealOptions"
  35. :key="item.value"
  36. :label="item.label"
  37. :value="item.value"
  38. /></el-select>
  39. </el-form-item>
  40. <el-form-item label="日期" prop="new_date">
  41. <el-date-picker
  42. v-model="searchInfo.new_date"
  43. popper-class="picker-popovers"
  44. class="timefilter"
  45. type="date"
  46. :disabled-date="disabledDate"
  47. :shortcuts="shortcuts"
  48. placeholder="选择日期时间"
  49. value-format="YYYY-MM-DD"
  50. >
  51. </el-date-picker>
  52. </el-form-item>
  53. <!-- <el-form-item label="是否到期">
  54. <el-select v-model="searchInfo.is_expire" size="small">
  55. <el-option label="否" value="0" />
  56. <el-option label="是" value="1" />
  57. <el-option label="明日到期" value="2" />
  58. </el-select>
  59. </el-form-item> -->
  60. <el-form-item>
  61. <el-button
  62. size="small"
  63. type="primary"
  64. icon="search"
  65. @click="onSubmit"
  66. >查询</el-button
  67. >
  68. <el-button size="small" icon="refresh" @click="onReset"
  69. >重置</el-button
  70. >
  71. <el-button
  72. class="excel-btn"
  73. size="small"
  74. type="primary"
  75. icon="download"
  76. @click="handleExcelRentExport"
  77. >导出表格</el-button
  78. >
  79. </el-form-item>
  80. </el-form>
  81. </div>
  82. <!-- <div class="gva-btn-list">
  83. <el-button
  84. icon="delete"
  85. size="small"
  86. type="danger"
  87. :disabled="!apis.length"
  88. style="margin-left: 10px"
  89. @click="deletesMenu()"
  90. >删除</el-button
  91. >
  92. </div> -->
  93. </div>
  94. <div class="row center">
  95. <el-tag size="large">电脑数量 : {{ computerNum }} </el-tag>
  96. </div>
  97. <div class="gva-table-box">
  98. <el-table
  99. height="500px"
  100. :data="tableData"
  101. @sort-change="sortChange"
  102. @selection-change="handleSelectionChange"
  103. border
  104. >
  105. <el-table-column type="selection" width="55" />
  106. <el-table-column
  107. align="left"
  108. label="日期"
  109. min-width="80"
  110. prop="new_date"
  111. />
  112. <el-table-column
  113. align="left"
  114. label="供应商"
  115. min-width="70"
  116. prop="shop_name"
  117. />
  118. <el-table-column
  119. align="left"
  120. label="编号"
  121. min-width="80"
  122. prop="pc_num"
  123. />
  124. <el-table-column
  125. align="left"
  126. label="机房名称"
  127. min-width="80"
  128. prop="pc_name"
  129. />
  130. <el-table-column
  131. align="left"
  132. label="起租时间"
  133. min-width="150"
  134. prop="rent_start_then"
  135. />
  136. <el-table-column
  137. align="left"
  138. label="到期时间"
  139. min-width="150"
  140. prop="rent_end_then"
  141. />
  142. <el-table-column
  143. align="left"
  144. label="租期"
  145. min-width="50"
  146. prop="rent_duration_then"
  147. />
  148. <el-table-column
  149. align="left"
  150. label="套餐"
  151. min-width="70"
  152. prop="set_meal_name"
  153. />
  154. <el-table-column
  155. align="left"
  156. label="价格"
  157. min-width="70"
  158. prop="rent_price_then"
  159. />
  160. <!-- <el-table-column
  161. align="center"
  162. label="套餐"
  163. min-width="150"
  164. prop="set_meal_name"
  165. >
  166. <template #default="scope">
  167. <span v-if="scope.row.price_type == 0">{{
  168. scope.row.set_meal_name +
  169. "-天卡(" +
  170. scope.row.rent_price_then +
  171. "元)"
  172. }}</span>
  173. <span v-else-if="scope.row.price_type == 1">{{
  174. scope.row.set_meal_name +
  175. "-周卡(" +
  176. scope.row.rent_price_then +
  177. "元)"
  178. }}</span>
  179. <span v-else>{{
  180. scope.row.set_meal_name +
  181. "-月卡(" +
  182. scope.row.rent_price_then +
  183. "元)"
  184. }}</span>
  185. </template>
  186. </el-table-column> -->
  187. <el-table-column
  188. align="left"
  189. label="折算天租金"
  190. min-width="100"
  191. prop="rent_price_day_then"
  192. />
  193. <el-table-column
  194. align="left"
  195. label="已产生租金"
  196. min-width="100"
  197. prop="rent_price_used_then"
  198. />
  199. <!-- <el-table-column
  200. align="center"
  201. label="是否到期"
  202. min-width="100"
  203. prop="is_expire"
  204. >
  205. <template #default="scope">
  206. <el-button
  207. v-if="scope.row.is_expire == 2"
  208. size="small"
  209. type="warning"
  210. plain
  211. >即将到期</el-button
  212. >
  213. <el-button
  214. v-if="scope.row.is_expire == 1"
  215. size="small"
  216. type="info"
  217. plain
  218. >到期未续</el-button
  219. >
  220. <el-button
  221. v-if="scope.row.is_expire == 0"
  222. size="small"
  223. type="success"
  224. plain
  225. >在租期中</el-button
  226. >
  227. </template>
  228. </el-table-column> -->
  229. <el-table-column
  230. align="left"
  231. label="备注"
  232. min-width="150"
  233. prop="remark"
  234. show-overflow-tooltip
  235. />
  236. <el-table-column
  237. align="left"
  238. label="更新时间"
  239. min-width="150"
  240. prop="update_time"
  241. />
  242. <el-table-column align="left" fixed="right" label="操作" width="130">
  243. <template #default="scope">
  244. <el-button
  245. size="small"
  246. type="primary"
  247. link
  248. icon="edit"
  249. @click="editMenu(scope.row.id)"
  250. >编辑</el-button
  251. >
  252. <el-button
  253. size="small"
  254. type="primary"
  255. link
  256. icon="delete"
  257. @click="deleteMenu(scope.row.id)"
  258. >删除</el-button
  259. >
  260. </template>
  261. </el-table-column>
  262. </el-table>
  263. <!-- </el-scrollbar> -->
  264. <div class="gva-pagination">
  265. <el-pagination
  266. :current-page="page"
  267. :page-size="pageSize"
  268. :page-sizes="[10, 20, 30, 50, 100]"
  269. :total="total"
  270. layout="total, sizes, prev, pager, next, jumper"
  271. @current-change="handleCurrentChange"
  272. @size-change="handleSizeChange"
  273. />
  274. </div>
  275. </div>
  276. </div>
  277. </template>
  278. <script>
  279. export default {
  280. name: "computer",
  281. };
  282. </script>
  283. <script setup>
  284. import {
  285. getRentComputerLedgerList,
  286. getRentComputerLedgerNum,
  287. listRentComputerShopList,
  288. listRentSetMealList,
  289. getRentComputerById,
  290. exportRentLedgerListExcel,
  291. editRentComputer,
  292. deleteRentComputerById,
  293. deleteRentComputerByIds,
  294. } from "@/api/rentComputer";
  295. // import { useUserStore } from "@/pinia/modules/user";
  296. import { toSQLLine } from "@/utils/stringFun";
  297. import { ref } from "vue";
  298. import { ElMessage, ElMessageBox } from "element-plus";
  299. import { formatDate } from "@/utils/format";
  300. // import { downloadTemplate } from "@/api/excel";
  301. // import dayjs from "dayjs";
  302. const apis = ref([]);
  303. const form = ref({
  304. id: 0,
  305. pc_num: "",
  306. pc_name: "",
  307. shop_id: null,
  308. set_meal_id: null,
  309. todesk_id: "",
  310. todesk_password: "",
  311. sunflower_id: "",
  312. sunflower_password: "",
  313. rent_start: new Date(),
  314. rent_duration: 0,
  315. rent_end: new Date(),
  316. remark: "",
  317. // is_expire: -1,
  318. is_off_shelf: -1,
  319. });
  320. const rules = ref({
  321. pc_num: [{ required: true, message: "请输入电脑编号", trigger: "blur" }],
  322. pc_name: [{ required: true, message: "请输入电脑名称", trigger: "blur" }],
  323. shop_id: [{ required: true, message: "请选择供应商", trigger: "blur" }],
  324. set_meal_id: [{ required: true, message: "请选择套餐", trigger: "blur" }],
  325. rent_start: [{ required: true, message: "请选择起租日期", trigger: "blur" }],
  326. rent_duration: [
  327. { required: true, message: "请输入租赁天数", trigger: "blur" },
  328. ],
  329. // is_expire: [{ required: true, message: "请选择是否到期", trigger: "blur" }],
  330. // is_off_shelf: [
  331. // { required: true, message: "请选择是否下架", trigger: "blur" },
  332. // ],
  333. });
  334. const page = ref(1);
  335. const total = ref(0);
  336. const pageSize = ref(20);
  337. const tableData = ref([]);
  338. let spanArr = [];
  339. const searchInfo = ref({});
  340. const computerNum = ref("");
  341. const shopOptions = ref();
  342. const setMealOptions = ref();
  343. // const defaultTime = ref(new Date(2000, 1, 1, 12, 0, 0));
  344. // const path = ref(import.meta.env.VITE_BASE_API);
  345. // const userStore = useUserStore();
  346. const shortcuts = [
  347. {
  348. text: "今日",
  349. value: new Date(),
  350. },
  351. {
  352. text: "昨日",
  353. value: () => {
  354. const date = new Date();
  355. date.setTime(date.getTime() - 3600 * 1000 * 24);
  356. return date;
  357. },
  358. },
  359. ];
  360. const disabledDate = (time) => {
  361. return time.getTime() > Date.now();
  362. };
  363. // 计算租机到期时间
  364. const calculateRentDuration = async (scope) => {
  365. scope.rent_end = new Date(
  366. Date.parse(scope.rent_start) +
  367. 1 * 24 * 60 * 60 * 1000 * parseInt(scope.rent_duration)
  368. );
  369. };
  370. const getSpanArr = (data) => {
  371. spanArr = [];
  372. var pos = 0;
  373. for (var i = 0; i < data.length; i++) {
  374. if (i === 0) {
  375. spanArr.push(1);
  376. pos = 0;
  377. } else {
  378. if (data[i].pc_code === data[i - 1].pc_code) {
  379. spanArr[pos] += 1;
  380. spanArr.push(0);
  381. } else {
  382. spanArr.push(1);
  383. pos = i;
  384. }
  385. }
  386. }
  387. // console.log(spanArr);
  388. };
  389. // 分页
  390. const handleSizeChange = (val) => {
  391. pageSize.value = val;
  392. getTableData();
  393. };
  394. const onReset = () => {
  395. searchInfo.value = {};
  396. };
  397. const handleCurrentChange = (val) => {
  398. page.value = val;
  399. getTableData();
  400. };
  401. const handleExcelRentExport = async () => {
  402. var fileName = "";
  403. if (searchInfo.value.new_date == null) {
  404. let dt = new Date(Date.parse(new Date()) - 1 * 24 * 60 * 60 * 1000);
  405. var y = dt.getFullYear();
  406. var mt = (dt.getMonth() + 1).toString().padStart(2, "0");
  407. var day = dt.getDate().toString().padStart(2, "0");
  408. var timeStr = y + "-" + mt + "-" + day;
  409. fileName = timeStr + "-租机台账.xlsx";
  410. } else {
  411. fileName = searchInfo.value.new_date + "-租机台账.xlsx";
  412. }
  413. exportRentLedgerListExcel(
  414. { page: page.value, pageSize: pageSize.value, ...searchInfo.value },
  415. fileName
  416. );
  417. };
  418. // 排序
  419. const sortChange = ({ prop, order }) => {
  420. if (prop) {
  421. if (prop === "id") {
  422. prop = "id";
  423. }
  424. searchInfo.value.orderKey = toSQLLine(prop);
  425. searchInfo.value.desc = order === "descending";
  426. }
  427. getTableData();
  428. };
  429. // 搜索
  430. const onSubmit = () => {
  431. page.value = 1;
  432. pageSize.value = 20;
  433. if (typeof searchInfo.value.set_meal_id != "undefined") {
  434. searchInfo.value.set_meal_id = Number(searchInfo.value.set_meal_id);
  435. }
  436. // if (typeof searchInfo.value.is_expire != "undefined") {
  437. // searchInfo.value.is_expire = Number(searchInfo.value.is_expire);
  438. // }
  439. // if (typeof searchInfo.value.is_off_shelf != "undefined") {
  440. // searchInfo.value.is_off_shelf = Number(searchInfo.value.is_off_shelf);
  441. // }
  442. // console.log(searchInfo);
  443. getTableData();
  444. };
  445. // 查询
  446. const getTableData = async () => {
  447. const table = await getRentComputerLedgerList({
  448. page: page.value,
  449. pageSize: pageSize.value,
  450. ...searchInfo.value,
  451. });
  452. if (table.code === 0) {
  453. tableData.value = table.data.list;
  454. total.value = table.data.total;
  455. page.value = table.data.page;
  456. pageSize.value = table.data.pageSize;
  457. getSpanArr(table.data.list);
  458. getComputerNum();
  459. getSelectList();
  460. }
  461. };
  462. //获取下拉框list
  463. const getSelectList = async () => {
  464. //listRentComputerShopList
  465. const rentComputerShop = await listRentComputerShopList({
  466. page: 1,
  467. pageSize: 999,
  468. });
  469. let rentComputerShopList = [];
  470. const data = rentComputerShop.data.list;
  471. data.forEach((e) => {
  472. rentComputerShopList.push({ value: e.id, label: e.name });
  473. });
  474. shopOptions.value = rentComputerShopList;
  475. //listRentSetMealList
  476. const setMealShop = await listRentSetMealList({
  477. page: 1,
  478. pageSize: 999,
  479. });
  480. let setMealList = [];
  481. const data2 = setMealShop.data.list;
  482. data2.forEach((e) => {
  483. var priceStr = "";
  484. if (e.price_type == 0) {
  485. priceStr = "天卡(" + e.rent_price + "元)";
  486. } else if (e.price_type == 1) {
  487. priceStr = "周卡(" + e.rent_price + "元)";
  488. } else {
  489. priceStr = "月卡(" + e.rent_price + "元)";
  490. }
  491. setMealList.push({
  492. value: e.id,
  493. label: e.shop_name + "-" + e.name + "-" + priceStr,
  494. });
  495. });
  496. setMealOptions.value = setMealList;
  497. };
  498. // 查询
  499. const getComputerNum = async () => {
  500. const table = await getRentComputerLedgerNum({ ...searchInfo.value });
  501. if (table.code === 0) {
  502. // console.log(table.data);
  503. computerNum.value = table.data;
  504. }
  505. };
  506. getTableData();
  507. // 批量操作
  508. const handleSelectionChange = (val) => {
  509. apis.value = val;
  510. };
  511. const dialogFormVisible = ref(false);
  512. // 弹窗相关
  513. const menuForm = ref(null);
  514. const checkFlag = ref(false);
  515. const initForm = () => {
  516. checkFlag.value = false;
  517. menuForm.value.resetFields();
  518. form.value = {
  519. id: 0,
  520. coding: "",
  521. describe: "",
  522. parent_id: "",
  523. };
  524. };
  525. const menuOption = ref([
  526. {
  527. id: "0",
  528. title: "根编号",
  529. },
  530. ]);
  531. const setOptions = () => {
  532. menuOption.value = [
  533. {
  534. id: "0",
  535. title: "根目录",
  536. },
  537. ];
  538. setMenuOptions(tableData.value, menuOption.value, false);
  539. };
  540. const setMenuOptions = (menuData, optionsData, disabled) => {
  541. menuData &&
  542. menuData.forEach((item) => {
  543. if (item.children && item.children.length) {
  544. const option = {
  545. ID: String(item.id),
  546. disabled: disabled || item.id === form.value.id,
  547. children: [],
  548. };
  549. setMenuOptions(
  550. item.children,
  551. option.children,
  552. disabled || item.id === form.value.id
  553. );
  554. optionsData.push(option);
  555. } else {
  556. const option = {
  557. ID: String(item.id),
  558. disabled: disabled || item.id === form.value.id,
  559. };
  560. optionsData.push(option);
  561. }
  562. });
  563. };
  564. const loadExcel = (res) => {
  565. if (res.code === 0) {
  566. ElMessage({
  567. type: "success",
  568. message: res.msg,
  569. });
  570. } else {
  571. ElMessage({
  572. type: "error",
  573. message: res.msg,
  574. showClose: true,
  575. });
  576. }
  577. getTableData();
  578. };
  579. // 添加菜单方法,id为 0则为添加根菜单
  580. const isEdit = ref(false);
  581. const dialogTitle = ref("新增租机");
  582. const addMenu = async (id) => {
  583. dialogTitle.value = "新增租机";
  584. form.value.parent_id = String(id);
  585. isEdit.value = false;
  586. setOptions();
  587. dialogFormVisible.value = true;
  588. getSelectList();
  589. };
  590. // 修改菜单方法
  591. const editMenu = async (id) => {
  592. dialogTitle.value = "编辑租机";
  593. const res = await getRentComputerById({ id });
  594. form.value = res.data;
  595. if (form.value.is_off_shelf == 1) {
  596. form.value.is_off_shelf = true;
  597. } else {
  598. form.value.is_off_shelf = false;
  599. }
  600. isEdit.value = true;
  601. setOptions();
  602. dialogFormVisible.value = true;
  603. getSelectList();
  604. };
  605. const closeDialog = () => {
  606. initForm();
  607. dialogFormVisible.value = false;
  608. };
  609. // 批量删除菜单
  610. const deletesMenu = async () => {
  611. ElMessageBox.confirm("确定批量删除所选吗?", "提示", {
  612. confirmButtonText: "确定",
  613. cancelButtonText: "取消",
  614. type: "warning",
  615. })
  616. .then(async () => {
  617. const ids = apis.value.map((item) => item.id);
  618. // console.log(ids);
  619. const res = await deleteRentComputerByIds({ ids });
  620. if (res.code === 0) {
  621. ElMessage({
  622. type: "success",
  623. message: "删除成功!",
  624. });
  625. getTableData();
  626. }
  627. })
  628. .catch(() => {
  629. ElMessage({
  630. type: "info",
  631. message: "已取消删除",
  632. });
  633. });
  634. };
  635. // 删除菜单
  636. const deleteMenu = async (id) => {
  637. ElMessageBox.confirm("确定删除?", "提示", {
  638. confirmButtonText: "确定",
  639. cancelButtonText: "取消",
  640. type: "warning",
  641. })
  642. .then(async () => {
  643. console.log(id);
  644. const res = await deleteRentComputerById({ id });
  645. if (res.code === 0) {
  646. ElMessage({
  647. type: "success",
  648. message: "删除成功!",
  649. });
  650. getTableData();
  651. }
  652. })
  653. .catch(() => {
  654. ElMessage({
  655. type: "info",
  656. message: "已取消删除",
  657. });
  658. });
  659. };
  660. // const enterDialog = async () => {
  661. // // console.log(form.value);
  662. // menuForm.value.validate(async (valid) => {
  663. // if (valid) {
  664. // let res;
  665. // form.value.id = Number(form.value.id);
  666. // form.value.shop_id = Number(form.value.shop_id);
  667. // form.value.set_meal_id = Number(form.value.set_meal_id);
  668. // form.value.rent_duration = Number(form.value.rent_duration);
  669. // form.value.rent_start = formatDate(form.value.rent_start);
  670. // form.value.rent_end = formatDate(form.value.rent_end);
  671. // form.value.is_expire = Number(form.value.is_expire);
  672. // if (form.value.is_off_shelf == true) {
  673. // form.value.is_off_shelf = 1;
  674. // } else {
  675. // form.value.is_off_shelf = 0;
  676. // }
  677. // if (isEdit.value) {
  678. // res = await editRentComputer(form.value);
  679. // } else {
  680. // // res = await addRentComputer(form.value);
  681. // }
  682. // if (res.code === 0) {
  683. // ElMessage({
  684. // type: "success",
  685. // message: isEdit.value ? "编辑成功" : "添加成功!",
  686. // });
  687. // getTableData();
  688. // } else {
  689. // ElMessage({
  690. // type: "error",
  691. // message: res.message,
  692. // });
  693. // }
  694. // initForm();
  695. // dialogFormVisible.value = false;
  696. // }
  697. // });
  698. // };
  699. </script>
  700. <style scoped lang="scss">
  701. .button-box {
  702. padding: 10px 20px;
  703. .el-button {
  704. float: right;
  705. }
  706. }
  707. .warning {
  708. color: #dc143c;
  709. }
  710. </style>