rent_computer_shop.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <!--
  2. * @Author: 倚楼听风雨 18408246387@163.com
  3. * @Date: 2022-11-16 17:16:17
  4. * @LastEditors: 倚楼听风雨 18408246387@163.com
  5. * @LastEditTime: 2023-01-12 17:17:58
  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-button size="small" type="primary" icon="plus" @click="addMenu('0')"
  14. >新增供应商</el-button
  15. >
  16. </div>
  17. </div>
  18. <div class="row center">
  19. <el-tag size="large">当前供应商数量 : {{ computerNum }} </el-tag>
  20. </div>
  21. <div class="gva-table-box">
  22. <el-scrollbar max-height="550px">
  23. <el-table
  24. :data="tableData"
  25. @sort-change="sortChange"
  26. @selection-change="handleSelectionChange"
  27. border
  28. >
  29. <el-table-column type="selection" width="55" />
  30. <el-table-column
  31. align="left"
  32. label="供应商名"
  33. min-width="150"
  34. prop="name"
  35. sortable="custom"
  36. />
  37. <el-table-column
  38. align="center"
  39. label="结算方式"
  40. min-width="150"
  41. prop="pay_method"
  42. >
  43. <template #default="scope">
  44. <el-button
  45. size="small"
  46. :type="scope.row.pay_method == 0 ? 'primary' : 'success'"
  47. >
  48. {{ scope.row.pay_method == 0 ? "先付后用" : "先用后付" }}
  49. </el-button>
  50. </template>
  51. </el-table-column>
  52. <el-table-column
  53. align="left"
  54. label="描述说明"
  55. min-width="150"
  56. prop="description"
  57. />
  58. <el-table-column
  59. align="left"
  60. label="创建时间"
  61. min-width="150"
  62. prop="create_time"
  63. />
  64. <el-table-column
  65. align="left"
  66. label="更新时间"
  67. min-width="150"
  68. prop="update_time"
  69. />
  70. <el-table-column align="left" fixed="right" label="操作" width="300">
  71. <template #default="scope">
  72. <el-button
  73. size="small"
  74. type="primary"
  75. link
  76. icon="edit"
  77. @click="editMenu(scope.row.id)"
  78. >编辑</el-button
  79. >
  80. <el-button
  81. size="small"
  82. type="primary"
  83. link
  84. icon="delete"
  85. @click="deleteMenu(scope.row.id)"
  86. >删除</el-button
  87. >
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. </el-scrollbar>
  92. <div class="gva-pagination">
  93. <el-pagination
  94. :current-page="page"
  95. :page-size="pageSize"
  96. :page-sizes="[10, 20, 30, 50, 100]"
  97. :total="total"
  98. layout="total, sizes, prev, pager, next, jumper"
  99. @current-change="handleCurrentChange"
  100. @size-change="handleSizeChange"
  101. />
  102. </div>
  103. </div>
  104. <el-dialog
  105. v-model="dialogFormVisible"
  106. :before-close="handleClose"
  107. :title="dialogTitle"
  108. >
  109. <el-form
  110. v-if="dialogFormVisible"
  111. ref="menuForm"
  112. :inline="true"
  113. :model="form"
  114. :rules="rules"
  115. label-position="left"
  116. label-width="85px"
  117. >
  118. <el-row :gutter="10">
  119. <el-col :span="12">
  120. <el-form-item label="供应商名" prop="name">
  121. <el-input v-model="form.name" />
  122. </el-form-item>
  123. </el-col>
  124. </el-row>
  125. <el-row :gutter="10">
  126. <el-col :span="20">
  127. <el-form-item label="描述说明" prop="description">
  128. <el-input v-model="form.description" type="textarea" :rows="4" />
  129. </el-form-item>
  130. </el-col>
  131. </el-row>
  132. <el-row :gutter="10">
  133. <el-col :span="12">
  134. <el-form-item label="结算方式" prop="pay_method">
  135. <el-radio-group v-model="form.pay_method">
  136. <el-radio :label="1" size="large">先用后付</el-radio>
  137. <el-radio :label="0" size="large">先付后用</el-radio>
  138. </el-radio-group>
  139. </el-form-item>
  140. </el-col>
  141. </el-row>
  142. </el-form>
  143. <template #footer>
  144. <div class="dialog-footer">
  145. <el-button size="small" @click="closeDialog">取 消</el-button>
  146. <el-button size="small" type="primary" @click="enterDialog"
  147. >确 定</el-button
  148. >
  149. </div>
  150. </template>
  151. </el-dialog>
  152. </div>
  153. </template>
  154. <script>
  155. export default {
  156. name: "computer-shop",
  157. };
  158. </script>
  159. <script setup>
  160. import {
  161. listRentComputerShopList,
  162. getRentComputerShopNum,
  163. getRentComputerShopById,
  164. addRentComputerShop,
  165. editRentComputerShop,
  166. deleteRentComputerShopById,
  167. } from "@/api/rentComputer";
  168. import { toSQLLine } from "@/utils/stringFun";
  169. import { ref } from "vue";
  170. import { ElMessage, ElMessageBox } from "element-plus";
  171. const apis = ref([]);
  172. const form = ref({
  173. id: 0,
  174. name: "",
  175. description: "",
  176. pay_method: 0,
  177. create_time: "",
  178. });
  179. const rules = ref({
  180. name: [{ required: true, message: "请输入供应商名称", trigger: "blur" }],
  181. description: [{ required: true, message: "请输入描述", trigger: "blur" }],
  182. pay_method: [{ required: true, message: "请选择", trigger: "blur" }],
  183. });
  184. const page = ref(1);
  185. const total = ref(0);
  186. const pageSize = ref(20);
  187. const tableData = ref([]);
  188. let spanArr = [];
  189. const searchInfo = ref({});
  190. // const getSpanArr = (data) => {
  191. // spanArr = [];
  192. // var pos = 0;
  193. // for (var i = 0; i < data.length; i++) {
  194. // if (i === 0) {
  195. // spanArr.push(1);
  196. // pos = 0;
  197. // } else {
  198. // if (data[i].pc_code === data[i - 1].pc_code) {
  199. // spanArr[pos] += 1;
  200. // spanArr.push(0);
  201. // } else {
  202. // spanArr.push(1);
  203. // pos = i;
  204. // }
  205. // }
  206. // }
  207. // console.log(spanArr);
  208. // };
  209. // 分页
  210. const handleSizeChange = (val) => {
  211. pageSize.value = val;
  212. getTableData();
  213. };
  214. const handleCurrentChange = (val) => {
  215. page.value = val;
  216. getTableData();
  217. };
  218. // 排序
  219. const sortChange = ({ prop, order }) => {
  220. if (prop) {
  221. if (prop === "id") {
  222. prop = "id";
  223. }
  224. searchInfo.value.orderKey = toSQLLine(prop);
  225. searchInfo.value.desc = order === "descending";
  226. }
  227. getTableData();
  228. };
  229. // 查询
  230. const getTableData = async () => {
  231. const table = await listRentComputerShopList({
  232. page: page.value,
  233. pageSize: pageSize.value,
  234. ...searchInfo.value,
  235. });
  236. if (table.code === 0) {
  237. tableData.value = table.data.list;
  238. total.value = table.data.total;
  239. page.value = table.data.page;
  240. pageSize.value = table.data.pageSize;
  241. // getSpanArr(table.data.list);
  242. // console.log(table);
  243. getComputerShopNum();
  244. }
  245. };
  246. const computerNum = ref("");
  247. // 查询
  248. const getComputerShopNum = async () => {
  249. // console.log("getRentComputerShopNum");
  250. const table = await getRentComputerShopNum({ ...searchInfo.value });
  251. console.log(table);
  252. if (table.code === 0) {
  253. console.log(table.data);
  254. computerNum.value = table.data;
  255. }
  256. };
  257. getTableData();
  258. // 批量操作
  259. const handleSelectionChange = (val) => {
  260. apis.value = val;
  261. };
  262. const dialogFormVisible = ref(false);
  263. // 弹窗相关
  264. const menuForm = ref(null);
  265. const checkFlag = ref(false);
  266. const initForm = () => {
  267. checkFlag.value = false;
  268. menuForm.value.resetFields();
  269. form.value = {
  270. id: 0,
  271. coding: "",
  272. describe: "",
  273. parent_id: "",
  274. };
  275. };
  276. const menuOption = ref([
  277. {
  278. id: "0",
  279. title: "根编号",
  280. },
  281. ]);
  282. const setOptions = () => {
  283. menuOption.value = [
  284. {
  285. id: "0",
  286. title: "根目录",
  287. },
  288. ];
  289. setMenuOptions(tableData.value, menuOption.value, false);
  290. };
  291. const setMenuOptions = (menuData, optionsData, disabled) => {
  292. menuData &&
  293. menuData.forEach((item) => {
  294. if (item.children && item.children.length) {
  295. const option = {
  296. ID: String(item.id),
  297. disabled: disabled || item.id === form.value.id,
  298. children: [],
  299. };
  300. setMenuOptions(
  301. item.children,
  302. option.children,
  303. disabled || item.id === form.value.id
  304. );
  305. optionsData.push(option);
  306. } else {
  307. const option = {
  308. ID: String(item.id),
  309. disabled: disabled || item.id === form.value.id,
  310. };
  311. optionsData.push(option);
  312. }
  313. });
  314. };
  315. // 添加菜单方法,id为 0则为添加根菜单
  316. const isEdit = ref(false);
  317. const dialogTitle = ref("新增编号");
  318. const addMenu = (id) => {
  319. dialogTitle.value = "新增编号";
  320. form.value.parent_id = String(id);
  321. isEdit.value = false;
  322. setOptions();
  323. dialogFormVisible.value = true;
  324. };
  325. // 修改菜单方法
  326. const editMenu = async (id) => {
  327. dialogTitle.value = "编辑编号";
  328. const res = await getRentComputerShopById({ id });
  329. form.value = res.data;
  330. isEdit.value = true;
  331. setOptions();
  332. dialogFormVisible.value = true;
  333. };
  334. const closeDialog = () => {
  335. initForm();
  336. dialogFormVisible.value = false;
  337. };
  338. // 删除菜单
  339. const deleteMenu = async (id) => {
  340. ElMessageBox.confirm("确定删除?", "提示", {
  341. confirmButtonText: "确定",
  342. cancelButtonText: "取消",
  343. type: "warning",
  344. })
  345. .then(async () => {
  346. console.log(id);
  347. const res = await deleteRentComputerShopById({ id });
  348. if (res.code === 0) {
  349. ElMessage({
  350. type: "success",
  351. message: "删除成功!",
  352. });
  353. getTableData();
  354. }
  355. })
  356. .catch(() => {
  357. ElMessage({
  358. type: "info",
  359. message: "已取消删除",
  360. });
  361. });
  362. };
  363. const enterDialog = async () => {
  364. // console.log(form.value);
  365. menuForm.value.validate(async (valid) => {
  366. if (valid) {
  367. let res;
  368. if (isEdit.value) {
  369. form.value.id = Number(form.value.id);
  370. // form.value.parent_id = Number(form.value.parent_id);
  371. res = await editRentComputerShop(form.value);
  372. } else {
  373. // console.log(form.value.coding);
  374. form.value.id = Number(form.value.id);
  375. // form.value.parent_id = Number(form.value.parent_id);
  376. res = await addRentComputerShop(form.value);
  377. }
  378. if (res.code === 0) {
  379. ElMessage({
  380. type: "success",
  381. message: isEdit.value ? "编辑成功" : "添加成功!",
  382. });
  383. getTableData();
  384. }
  385. initForm();
  386. dialogFormVisible.value = false;
  387. }
  388. });
  389. };
  390. </script>
  391. <style scoped lang="scss">
  392. .button-box {
  393. padding: 10px 20px;
  394. .el-button {
  395. float: right;
  396. }
  397. }
  398. .warning {
  399. color: #dc143c;
  400. }
  401. </style>