rent_computer.vue 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. <!--
  2. * @Author: 倚楼听风雨 18408246387@163.com
  3. * @Date: 2022-11-16 17:16:17
  4. * @LastEditors: 倚楼听风雨 18408246387@163.com
  5. * @LastEditTime: 2023-03-30 16:20:57
  6. * @FilePath: \log-server-web\src\view\rentComputer\rent_computer.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="是否到期">
  41. <el-select v-model="searchInfo.is_expire" size="small">
  42. <el-option label="否" value="0" />
  43. <el-option label="是" value="1" />
  44. <el-option label="明日到期" value="2" />
  45. <el-option label="一周内到期" value="3" />
  46. </el-select>
  47. </el-form-item>
  48. <el-form-item label="使用人">
  49. <el-select v-model="searchInfo.director_name" size="small">
  50. <el-option
  51. v-for="item in directorOptions"
  52. :key="item.value"
  53. :label="item.label"
  54. :value="item.value"
  55. />
  56. </el-select>
  57. </el-form-item>
  58. <el-form-item label="是否下架">
  59. <el-select v-model="searchInfo.is_off_shelf" size="small">
  60. <el-option label="否" value="0" />
  61. <el-option label="是" value="1" />
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item>
  65. <el-button
  66. size="small"
  67. type="primary"
  68. icon="search"
  69. @click="onSubmit"
  70. >查询</el-button
  71. >
  72. <el-button size="small" icon="refresh" @click="onReset"
  73. >重置</el-button
  74. >
  75. </el-form-item>
  76. </el-form>
  77. </div>
  78. <div class="gva-btn-list">
  79. <el-button size="small" type="primary" icon="plus" @click="addMenu('0')"
  80. >新增</el-button
  81. >
  82. <el-button
  83. class="excel-btn"
  84. size="small"
  85. type="success"
  86. icon="download"
  87. @click="downloadExcelTemplate()"
  88. >下载模板</el-button
  89. >
  90. <el-upload
  91. style="margin-left: 1%"
  92. class="excel-btn"
  93. :action="`${path}/rentComputer/importExcel`"
  94. :headers="{ 'x-token': userStore.token }"
  95. :on-success="loadExcel"
  96. :show-file-list="false"
  97. >
  98. <el-button size="small" type="primary" icon="upload">导入</el-button>
  99. </el-upload>
  100. <el-button
  101. icon="delete"
  102. size="small"
  103. type="danger"
  104. :disabled="!apis.length"
  105. style="margin-left: 10px"
  106. @click="deletesMenu()"
  107. >删除</el-button
  108. >
  109. <el-button
  110. icon="money"
  111. size="small"
  112. type="success"
  113. :disabled="!apis.length"
  114. style="margin-left: 10px"
  115. @click="switchRenews()"
  116. >批量续费</el-button
  117. >
  118. </div>
  119. </div>
  120. <div class="row center">
  121. <el-tag size="large">电脑数量 : {{ computerNum }} </el-tag>
  122. <el-tag
  123. size="large"
  124. type="danger"
  125. hit
  126. effect="dark"
  127. style="margin-left: 20px"
  128. v-if="tagExpire"
  129. >有租机即将到期,请注意续费!!!</el-tag
  130. >
  131. </div>
  132. <div class="gva-table-box">
  133. <!-- <el-scrollbar height="550px"> -->
  134. <el-table
  135. height="500px"
  136. :data="tableData"
  137. @sort-change="sortChange"
  138. @selection-change="handleSelectionChange"
  139. border
  140. v-loading="loading"
  141. >
  142. <el-table-column type="selection" width="55" />
  143. <el-table-column
  144. align="left"
  145. label="供应商"
  146. min-width="70"
  147. prop="shop_name"
  148. />
  149. <!-- <el-table-column
  150. align="left"
  151. label="套餐"
  152. min-width="100"
  153. prop="set_meal_name"
  154. /> -->
  155. <el-table-column
  156. align="center"
  157. label="套餐"
  158. min-width="150"
  159. prop="set_meal_name"
  160. >
  161. <template #default="scope">
  162. <span v-if="scope.row.price_type == 0">{{
  163. scope.row.set_meal_name + "-天卡(" + scope.row.rent_price + "元)"
  164. }}</span>
  165. <span v-else-if="scope.row.price_type == 1">{{
  166. scope.row.set_meal_name + "-周卡(" + scope.row.rent_price + "元)"
  167. }}</span>
  168. <span v-else>{{
  169. scope.row.set_meal_name + "-月卡(" + scope.row.rent_price + "元)"
  170. }}</span>
  171. </template>
  172. </el-table-column>
  173. <el-table-column
  174. align="left"
  175. label="编号"
  176. min-width="80"
  177. prop="pc_num"
  178. />
  179. <el-table-column
  180. align="left"
  181. label="名称"
  182. min-width="80"
  183. prop="pc_name"
  184. />
  185. <el-table-column
  186. align="left"
  187. label="起租时间"
  188. min-width="150"
  189. prop="rent_start"
  190. />
  191. <el-table-column
  192. align="left"
  193. label="到期时间"
  194. min-width="150"
  195. prop="rent_end"
  196. />
  197. <el-table-column
  198. align="left"
  199. label="租期"
  200. min-width="50"
  201. prop="rent_duration"
  202. />
  203. <el-table-column
  204. align="left"
  205. label="使用人"
  206. min-width="80"
  207. prop="director_name"
  208. />
  209. <el-table-column
  210. align="center"
  211. label="是否到期"
  212. min-width="100"
  213. prop="is_expire"
  214. >
  215. <template #default="scope">
  216. <el-button
  217. v-if="scope.row.is_expire == 3"
  218. size="small"
  219. type="warning"
  220. plain
  221. >即将到期</el-button
  222. >
  223. <el-button
  224. v-else-if="scope.row.is_expire == 2"
  225. size="small"
  226. type="danger"
  227. plain
  228. >明日到期</el-button
  229. >
  230. <el-button
  231. v-else-if="scope.row.is_expire == 1"
  232. size="small"
  233. type="info"
  234. plain
  235. >到期未续</el-button
  236. >
  237. <el-button v-else size="small" type="success" plain
  238. >在租期中</el-button
  239. >
  240. </template>
  241. </el-table-column>
  242. <el-table-column
  243. align="center"
  244. label="是否下架"
  245. min-width="100"
  246. prop="is_off_shelf"
  247. >
  248. <template #default="scope">
  249. <el-button
  250. v-if="scope.row.is_off_shelf == 1"
  251. size="small"
  252. type="warning"
  253. plain
  254. >是</el-button
  255. >
  256. <el-button v-else size="small" type="success" plain>否</el-button>
  257. </template>
  258. </el-table-column>
  259. <el-table-column
  260. align="left"
  261. label="TD号"
  262. min-width="100"
  263. prop="todesk_id"
  264. />
  265. <el-table-column
  266. align="left"
  267. label="TD密码"
  268. min-width="100"
  269. prop="todesk_password"
  270. />
  271. <el-table-column
  272. align="left"
  273. label="向日葵号"
  274. min-width="100"
  275. prop="sunflower_id"
  276. />
  277. <el-table-column
  278. align="left"
  279. label="向日葵密码"
  280. min-width="100"
  281. prop="sunflower_password"
  282. />
  283. <el-table-column
  284. align="left"
  285. label="最近一次修改日志"
  286. min-width="250"
  287. show-overflow-tooltip
  288. >
  289. <template #default="scope">
  290. <el-row>
  291. <el-col :span="20">
  292. <span
  293. style="
  294. display: block;
  295. max-width: 15em;
  296. overflow: hidden;
  297. white-space: nowrap;
  298. text-overflow: ellipsis;
  299. "
  300. >{{ scope.row.remark }}</span
  301. >
  302. </el-col>
  303. <el-col :span="4">
  304. <el-button
  305. size="small"
  306. type="warning"
  307. link
  308. icon="tickets"
  309. @click="switchLog(scope.row)"
  310. >more</el-button
  311. >
  312. </el-col>
  313. </el-row>
  314. </template>
  315. </el-table-column>
  316. <el-table-column
  317. align="left"
  318. label="更新时间"
  319. min-width="150"
  320. prop="update_time"
  321. />
  322. <el-table-column align="left" fixed="right" label="操作" width="430">
  323. <template #default="scope">
  324. <el-button
  325. size="small"
  326. type="primary"
  327. link
  328. icon="link"
  329. @click="linkTd(scope.row)"
  330. >TD连接</el-button
  331. >
  332. <el-button
  333. size="small"
  334. type="primary"
  335. link
  336. icon="edit"
  337. @click="switchRenew(scope.row)"
  338. >续费</el-button
  339. >
  340. <el-button
  341. v-if="scope.row.is_expire != 1"
  342. size="small"
  343. type="primary"
  344. link
  345. icon="edit"
  346. @click="switchRentingOut(scope.row)"
  347. >退租</el-button
  348. >
  349. <el-button
  350. v-if="scope.row.is_expire != 1"
  351. size="small"
  352. type="primary"
  353. link
  354. icon="edit"
  355. @click="switchReplaceNum(scope.row)"
  356. >换编号</el-button
  357. >
  358. <el-button
  359. v-if="scope.row.is_off_shelf == 0"
  360. size="small"
  361. type="primary"
  362. link
  363. icon="edit"
  364. @click="offShelf(scope.row)"
  365. >下架</el-button
  366. >
  367. <el-button
  368. size="small"
  369. type="primary"
  370. link
  371. icon="edit"
  372. @click="editMenu(scope.row.id)"
  373. >编辑</el-button
  374. >
  375. <el-button
  376. size="small"
  377. type="primary"
  378. link
  379. icon="delete"
  380. @click="deleteMenu(scope.row.id)"
  381. >删除</el-button
  382. >
  383. </template>
  384. </el-table-column>
  385. </el-table>
  386. <!-- </el-scrollbar> -->
  387. <div class="gva-pagination">
  388. <el-pagination
  389. :current-page="page"
  390. :page-size="pageSize"
  391. :page-sizes="[10, 20, 30, 50, 100]"
  392. :total="total"
  393. layout="total, sizes, prev, pager, next, jumper"
  394. @current-change="handleCurrentChange"
  395. @size-change="handleSizeChange"
  396. />
  397. </div>
  398. </div>
  399. <el-dialog v-model="dialogFormVisible" :title="dialogTitle">
  400. <el-form
  401. v-if="dialogFormVisible"
  402. ref="menuForm"
  403. :inline="true"
  404. :model="form"
  405. :rules="rules"
  406. label-position="left"
  407. label-width="85px"
  408. >
  409. <el-row :gutter="10">
  410. <el-col :span="6">
  411. <el-form-item label="电脑编号" prop="pc_num">
  412. <el-input v-model="form.pc_num" />
  413. </el-form-item>
  414. </el-col>
  415. <el-col :span="6">
  416. <el-form-item label="电脑名称" prop="pc_name">
  417. <el-input v-model="form.pc_name" />
  418. </el-form-item>
  419. </el-col>
  420. <el-col :span="6">
  421. <el-form-item label="供应商" prop="shop_id">
  422. <el-select v-model="form.shop_id">
  423. <el-option
  424. v-for="item in shopOptions"
  425. :key="item.value"
  426. :label="item.label"
  427. :value="item.value"
  428. />
  429. </el-select>
  430. </el-form-item>
  431. </el-col>
  432. <el-col :span="6">
  433. <el-form-item label="套餐名" prop="set_meal_id">
  434. <el-select v-model="form.set_meal_id">
  435. <el-option
  436. v-for="item in setMealOptions"
  437. :key="item.value"
  438. :label="item.label"
  439. :value="item.value"
  440. />
  441. </el-select>
  442. </el-form-item>
  443. </el-col>
  444. <el-col :span="6">
  445. <el-form-item label="使用人" prop="director_name">
  446. <el-select v-model="form.director_name" size="small">
  447. <el-option
  448. v-for="item in directorOptions"
  449. :key="item.value"
  450. :label="item.label"
  451. :value="item.value"
  452. />
  453. </el-select>
  454. </el-form-item>
  455. </el-col>
  456. </el-row>
  457. <el-row :gutter="10">
  458. <el-col :span="6">
  459. <el-form-item label="Todesk号" prop="todesk_id">
  460. <el-input v-model="form.todesk_id" />
  461. </el-form-item>
  462. </el-col>
  463. <el-col :span="6">
  464. <el-form-item label="Todesk密码" prop="todesk_password">
  465. <el-input v-model="form.todesk_password" />
  466. </el-form-item>
  467. </el-col>
  468. <el-col :span="6">
  469. <el-form-item label="向日葵号" prop="sunflower_id">
  470. <el-input v-model="form.sunflower_id" />
  471. </el-form-item>
  472. </el-col>
  473. <el-col :span="6">
  474. <el-form-item label="向日葵密码" prop="sunflower_password">
  475. <el-input v-model="form.sunflower_password" />
  476. </el-form-item>
  477. </el-col>
  478. </el-row>
  479. <el-row :gutter="10">
  480. <el-col :span="8">
  481. <el-form-item label="起租时间" prop="rent_start">
  482. <el-date-picker
  483. v-model="form.rent_start"
  484. type="datetime"
  485. placeholder="起租时间"
  486. :default-time="defaultTime"
  487. @change="calculateRentDuration(form)"
  488. />
  489. </el-form-item>
  490. </el-col>
  491. <el-col :span="6">
  492. <el-form-item label="租赁天数" prop="rent_duration">
  493. <el-input
  494. v-model="form.rent_duration"
  495. @change="calculateRentDuration(form)"
  496. />
  497. </el-form-item>
  498. </el-col>
  499. <el-col :span="8">
  500. <el-form-item label="到期时间" prop="rent_end">
  501. <el-date-picker
  502. v-model="form.rent_end"
  503. type="datetime"
  504. placeholder="到期时间"
  505. :default-time="defaultTime"
  506. readonly
  507. />
  508. </el-form-item>
  509. </el-col>
  510. </el-row>
  511. <el-row :gutter="10">
  512. <el-col :span="12">
  513. <el-form-item label="是否到期" prop="is_expire">
  514. <el-radio-group v-model="form.is_expire">
  515. <el-radio :label="0" size="large">在租期中</el-radio>
  516. <el-radio :label="1" size="large">到期未续</el-radio>
  517. <el-radio :label="2" size="large">明日到期</el-radio>
  518. </el-radio-group>
  519. </el-form-item>
  520. </el-col>
  521. </el-row>
  522. <!-- <el-row :gutter="10">
  523. <el-col :span="12">
  524. <el-form-item label="是否下架" prop="is_off_shelf">
  525. <el-switch v-model="form.is_off_shelf" />
  526. </el-form-item>
  527. </el-col>
  528. </el-row> -->
  529. <el-row :gutter="10">
  530. <el-col :span="20">
  531. <el-form-item label="备注" prop="remark">
  532. <el-input
  533. v-model="form.remark"
  534. type="textarea"
  535. :rows="4"
  536. style="width: 500px"
  537. />
  538. </el-form-item>
  539. </el-col>
  540. </el-row>
  541. </el-form>
  542. <template #footer>
  543. <div class="dialog-footer">
  544. <el-button size="small" @click="closeDialog">取 消</el-button>
  545. <el-button size="small" type="primary" @click="enterDialog"
  546. >确 定</el-button
  547. >
  548. </div>
  549. </template>
  550. </el-dialog>
  551. <!--日志-->
  552. <el-dialog v-model="visible_log" title="操作日志">
  553. <el-table :data="logData">
  554. <el-table-column property="create_time" label="操作时间" width="150" />
  555. <el-table-column property="pc_num" label="租机编号" width="80" />
  556. <el-table-column property="log" label="日志" />
  557. </el-table>
  558. </el-dialog>
  559. <!--租机续费-->
  560. <el-dialog title="租机续费" v-model="visible_renew">
  561. <el-form :model="renewForm" size="default" label-width="100px">
  562. <el-row>
  563. <el-form-item label="警告:" prop="">
  564. <el-col :span="24">
  565. <p style="color: red; font-size: larger">请勿随意操作!!!</p>
  566. </el-col>
  567. </el-form-item>
  568. </el-row>
  569. <el-row>
  570. <el-form-item label="租机编号" prop="pc_num">
  571. <el-col :span="12">
  572. <el-input
  573. v-model="renewForm.pc_num"
  574. placeholder="租机编号"
  575. :disabled="true"
  576. ></el-input>
  577. </el-col>
  578. </el-form-item>
  579. <el-form-item label="续费时间" prop="rent_renew">
  580. <el-col>
  581. <el-date-picker
  582. v-model="renewForm.rent_renew"
  583. format="YYYY-MM-DD HH:mm:ss"
  584. type="datetime"
  585. :style="{ width: '100%' }"
  586. placeholder="请选择日期"
  587. clearable
  588. @change="calculateRenewDay(renewForm)"
  589. ></el-date-picker>
  590. </el-col>
  591. </el-form-item>
  592. </el-row>
  593. <el-row>
  594. <el-form-item label="续费天数" prop="">
  595. <el-col :span="24">
  596. <el-tag :key="renewForm.day" type="warning" effect="light">
  597. {{ renewForm.day }}
  598. </el-tag>
  599. </el-col>
  600. </el-form-item>
  601. </el-row>
  602. <el-divider />
  603. <el-form-item>
  604. <el-button size="small" @click="visible_renew = false"
  605. >取消</el-button
  606. >
  607. <el-button type="primary" size="small" @click="renew(renewForm)"
  608. >提交</el-button
  609. >
  610. </el-form-item>
  611. </el-form>
  612. </el-dialog>
  613. <!-- 批量续费 -->
  614. <el-dialog title="批量续费" v-model="visible_renews">
  615. <p style="color: red; font-size: larger">严重警告:请勿随意操作!!!</p>
  616. <span style="font-size: larger">续费天数:</span>
  617. <el-input
  618. v-model="renewsDay"
  619. size="small"
  620. style="width: 30%"
  621. placeholder="天数"
  622. ></el-input>
  623. <el-button
  624. type="primary"
  625. style="margin-left: 20px"
  626. size="small"
  627. @click="calculateRenewEnd()"
  628. >计算</el-button
  629. >
  630. <p style="font-size: larger">续费明细如下,请认真核对后再提交:</p>
  631. <el-table size="small" height="400px" :data="renewDatas" border>
  632. <el-table-column type="index" width="55" />
  633. <el-table-column
  634. align="left"
  635. label="编号"
  636. min-width="70"
  637. prop="pc_num"
  638. />
  639. <el-table-column
  640. align="left"
  641. label="当前到期时间"
  642. min-width="100"
  643. prop="rent_end"
  644. />
  645. <el-table-column
  646. align="left"
  647. label="续费后到期时间"
  648. min-width="100"
  649. prop="rent_end_new"
  650. />
  651. </el-table>
  652. <el-divider />
  653. <el-button size="small" @click="visible_renews = false">取消</el-button>
  654. <el-button type="primary" size="small" @click="renewByBatch()"
  655. >提交</el-button
  656. >
  657. </el-dialog>
  658. <!--退租-->
  659. <el-dialog title="租机退租" v-model="visible_rentingOut">
  660. <el-form
  661. ref="elForm"
  662. :model="rentingOutForm"
  663. size="medium"
  664. label-width="100px"
  665. >
  666. <el-row>
  667. <el-form-item label="警告:" prop="">
  668. <el-col :span="24">
  669. <p style="color: red; font-size: larger">请勿随意操作!!!</p>
  670. </el-col>
  671. </el-form-item>
  672. </el-row>
  673. <el-row>
  674. <el-form-item label="租机编号" prop="pc_num">
  675. <el-col :span="12">
  676. <el-input
  677. v-model="rentingOutForm.pc_num"
  678. placeholder="租机编号"
  679. :disabled="true"
  680. ></el-input>
  681. </el-col>
  682. </el-form-item>
  683. <el-form-item label="退租时间" prop="rent_end">
  684. <el-col>
  685. <el-date-picker
  686. v-model="rentingOutForm.rent_end"
  687. format="YYYY-MM-DD HH:mm:ss"
  688. type="datetime"
  689. :style="{ width: '100%' }"
  690. placeholder="请选择日期"
  691. clearable
  692. @change="calculateRentDay(rentingOutForm)"
  693. ></el-date-picker>
  694. </el-col>
  695. </el-form-item>
  696. </el-row>
  697. <el-row>
  698. <el-form-item label="剩余天数" prop="">
  699. <el-col :span="24">
  700. <el-tag :key="rentingOutForm.day" type="warning" effect="light">
  701. {{ rentingOutForm.day }}
  702. </el-tag>
  703. </el-col>
  704. </el-form-item>
  705. </el-row>
  706. <el-row
  707. ><el-col :span="12" style="margin-left: 30px"
  708. ><el-button size="small" @click="addCardMsg()"
  709. >匀时间</el-button
  710. ></el-col
  711. ></el-row
  712. >
  713. <el-row>
  714. <div class="container-scrollbar">
  715. <el-scrollbar max-height="200px">
  716. <el-row
  717. :gutter="24"
  718. v-for="(item, index) in cardList"
  719. :key="index"
  720. >
  721. <el-col :span="10">
  722. <el-form-item label="租机编号">
  723. <el-input v-model="item.pc_num"></el-input>
  724. </el-form-item>
  725. </el-col>
  726. <el-col :span="8">
  727. <el-form-item label="增加天数">
  728. <el-input v-model="item.add_day"></el-input>
  729. </el-form-item>
  730. </el-col>
  731. <el-col :span="2" v-if="cardList.length !== 1">
  732. <el-button
  733. size="mini"
  734. circle
  735. icon="delete"
  736. @click="deleteCardMsg(index)"
  737. ></el-button>
  738. </el-col>
  739. </el-row>
  740. </el-scrollbar>
  741. </div>
  742. </el-row>
  743. <el-divider />
  744. <el-form-item>
  745. <el-button size="small" @click="visible_rentingOut = false"
  746. >取消</el-button
  747. >
  748. <el-button
  749. type="primary"
  750. size="small"
  751. @click="rentingOut(rentingOutForm)"
  752. >提交</el-button
  753. >
  754. </el-form-item>
  755. </el-form>
  756. </el-dialog>
  757. <!--租机编号更换-->
  758. <el-dialog title="租机编号更换" v-model="visible_replaceNum">
  759. <el-form
  760. ref="elForm"
  761. :model="replaceNumForm"
  762. size="medium"
  763. label-width="100px"
  764. >
  765. <el-row>
  766. <el-form-item label="警告:" prop="">
  767. <el-col :span="24">
  768. <p style="color: red; font-size: larger">
  769. 请勿随意更换,会影响租机续费
  770. </p>
  771. </el-col>
  772. </el-form-item>
  773. </el-row>
  774. <el-row>
  775. <el-form-item label="供应商:" prop="shop_name">
  776. <el-col :span="24">
  777. <p>
  778. <span style="color: red; font-size: larger">{{
  779. replaceNumForm.shop_name
  780. }}</span
  781. >, 只可更改为同一供应商的编号
  782. </p>
  783. </el-col>
  784. </el-form-item>
  785. </el-row>
  786. <el-row>
  787. <el-form-item label="原租机编号" prop="pc_num_old">
  788. <el-col :span="24">
  789. <el-input
  790. v-model="replaceNumForm.pc_num_old"
  791. placeholder="原租机编号"
  792. :disabled="true"
  793. ></el-input>
  794. </el-col>
  795. </el-form-item>
  796. <el-form-item label="更换编号" prop="pc_num_new">
  797. <el-col :span="24">
  798. <el-input
  799. v-model="replaceNumForm.pc_num_new"
  800. placeholder="更换编号"
  801. ></el-input>
  802. </el-col>
  803. </el-form-item>
  804. </el-row>
  805. <el-divider />
  806. <el-form-item>
  807. <el-button size="small" @click="visible_replaceNum = false"
  808. >取消</el-button
  809. >
  810. <el-button
  811. type="primary"
  812. size="small"
  813. @click="replaceNum(replaceNumForm)"
  814. >提交</el-button
  815. >
  816. </el-form-item>
  817. </el-form>
  818. </el-dialog>
  819. </div>
  820. </template>
  821. <script>
  822. export default {
  823. name: "computer",
  824. };
  825. </script>
  826. <script setup>
  827. import {
  828. getRentComputerList,
  829. getRentComputerNum,
  830. listRentComputerShopList,
  831. listRentSetMealList,
  832. getRentComputerById,
  833. addRentComputer,
  834. editRentComputer,
  835. deleteRentComputerById,
  836. deleteRentComputerByIds,
  837. renewRentComputer,
  838. renewRentComputerByBatch,
  839. replaceNumRentComputer,
  840. rentingOutRentComputer,
  841. offShelfRentComputer,
  842. queryRentComputerLogByPcNum,
  843. } from "@/api/rentComputer";
  844. import { getDirectorList } from "@/api/responsiblePerson";
  845. import { useUserStore } from "@/pinia/modules/user";
  846. import { toSQLLine } from "@/utils/stringFun";
  847. import { ref } from "vue";
  848. import { ElMessage, ElMessageBox, ElLoading } from "element-plus";
  849. import { formatDate } from "@/utils/format";
  850. import { downloadTemplate } from "@/api/excel";
  851. import dayjs from "dayjs";
  852. const apis = ref([]);
  853. const form = ref({
  854. id: 0,
  855. pc_num: "",
  856. pc_name: "",
  857. shop_id: null,
  858. set_meal_id: null,
  859. todesk_id: "",
  860. todesk_password: "",
  861. sunflower_id: "",
  862. sunflower_password: "",
  863. rent_start: new Date(),
  864. rent_duration: 0,
  865. rent_end: new Date(),
  866. remark: "",
  867. is_expire: -1,
  868. is_off_shelf: -1,
  869. director_name: "ALL",
  870. });
  871. const rules = ref({
  872. pc_num: [{ required: true, message: "请输入电脑编号", trigger: "blur" }],
  873. pc_name: [{ required: true, message: "请输入电脑名称", trigger: "blur" }],
  874. shop_id: [{ required: true, message: "请选择供应商", trigger: "blur" }],
  875. set_meal_id: [{ required: true, message: "请选择套餐", trigger: "blur" }],
  876. rent_start: [{ required: true, message: "请选择起租日期", trigger: "blur" }],
  877. rent_duration: [
  878. { required: true, message: "请输入租赁天数", trigger: "blur" },
  879. ],
  880. is_expire: [{ required: true, message: "请选择是否到期", trigger: "blur" }],
  881. is_off_shelf: [
  882. { required: true, message: "请选择是否下架", trigger: "blur" },
  883. ],
  884. });
  885. const page = ref(1);
  886. const total = ref(0);
  887. const pageSize = ref(20);
  888. const tableData = ref([]);
  889. const renewDatas = ref([]);
  890. const logData = ref([]);
  891. const loading = ref(false);
  892. const searchInfo = ref({
  893. is_expire: -1,
  894. is_off_shelf: -1,
  895. director_name: "ALL",
  896. });
  897. const computerNum = ref("");
  898. const tagExpire = ref(false);
  899. const shopOptions = ref();
  900. const directorOptions = ref();
  901. const setMealOptions = ref();
  902. const defaultTime = ref(new Date(2000, 1, 1, 12, 0, 0));
  903. const path = ref(import.meta.env.VITE_BASE_API);
  904. const userStore = useUserStore();
  905. const visible_renew = ref(false);
  906. const visible_renews = ref(false);
  907. const visible_rentingOut = ref(false);
  908. const visible_replaceNum = ref(false);
  909. const visible_log = ref(false);
  910. const rent_end = ref("");
  911. const renewForm = ref({
  912. pc_num: "",
  913. pc_id: 0,
  914. day: 0,
  915. rent_renew: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
  916. });
  917. const renewsDay = ref(0);
  918. const rentingOutForm = ref({
  919. pc_num: "",
  920. pc_id: 0,
  921. day: 0,
  922. rent_end: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
  923. addList: [],
  924. });
  925. const replaceNumForm = ref({
  926. pc_num_old: "",
  927. pc_num_new: "",
  928. shop_id: 0,
  929. shop_name: "",
  930. });
  931. let cardList = ref([]);
  932. // 计算租机到期时间
  933. const calculateRentDuration = async (scope) => {
  934. scope.rent_end = new Date(
  935. Date.parse(scope.rent_start) +
  936. 1 * 24 * 60 * 60 * 1000 * parseInt(scope.rent_duration)
  937. );
  938. };
  939. // 计算退租剩余时间
  940. function calculateRentDay(scope) {
  941. if (Date.parse(rent_end.value) < Date.parse(scope.rent_end)) {
  942. scope.rent_end = rent_end.value;
  943. ElMessage.error("退租时间不能大于到期时间");
  944. }
  945. scope.day = Math.ceil(
  946. parseInt(
  947. (Date.parse(rent_end.value) - Date.parse(scope.rent_end)) /
  948. (24 * 60 * 60 * 1000) +
  949. ""
  950. )
  951. );
  952. // console.log(scope.day);
  953. }
  954. // 计算续费时间
  955. function calculateRenewDay(scope) {
  956. if (Date.parse(rent_end.value) >= Date.parse(scope.rent_renew)) {
  957. scope.rent_renew = rent_end.value;
  958. ElMessage.error("续费时间不能小于到期时间");
  959. visible_renew.value = false;
  960. }
  961. scope.day = Math.ceil(
  962. parseInt(
  963. (Date.parse(scope.rent_renew) - Date.parse(rent_end.value)) /
  964. (24 * 60 * 60 * 1000) +
  965. ""
  966. )
  967. );
  968. }
  969. // 查询日志
  970. async function switchLog(rowData) {
  971. const loadingLog = ElLoading.service({
  972. lock: true,
  973. text: "查询日志中...",
  974. background: "rgba(0, 0, 0, 0.7)",
  975. });
  976. let logForm = {
  977. pc_num: rowData.pc_num,
  978. shop_id: Number(rowData.shop_id),
  979. // set_meal_id: Number(rowData.set_meal_id),
  980. };
  981. // console.log(logForm);
  982. const data = await queryRentComputerLogByPcNum(logForm);
  983. if (data.code == 0) {
  984. visible_log.value = true;
  985. loadingLog.close();
  986. // ElMessage.success(data.msg);
  987. logData.value = data.data.list;
  988. } else {
  989. ElMessage.error(data.msg);
  990. }
  991. }
  992. // 拉起续费弹窗
  993. async function switchRenew(rowData) {
  994. // console.log(rowData);
  995. renewForm.value.pc_num = rowData.pc_num;
  996. renewForm.value.pc_id = rowData.id;
  997. renewForm.value.rent_renew = rowData.rent_end;
  998. renewForm.value.day = 0;
  999. rent_end.value = rowData.rent_end;
  1000. // console.log(renewForm);
  1001. if (visible_renew.value == false) {
  1002. visible_renew.value = true;
  1003. }
  1004. }
  1005. // 续费
  1006. async function renew(rowData) {
  1007. let doForm = {
  1008. pc_num: rowData.pc_num,
  1009. pc_id: rowData.pc_id,
  1010. rent_renew: dayjs(new Date(rowData.rent_renew)).format(
  1011. "YYYY-MM-DD HH:mm:ss"
  1012. ),
  1013. day: rowData.day,
  1014. };
  1015. // renewRentComputer
  1016. const data = await renewRentComputer(doForm);
  1017. if (data.code == 0) {
  1018. visible_renew.value = false;
  1019. ElMessage.success(data.msg);
  1020. getTableData();
  1021. } else {
  1022. ElMessage.error(data.msg);
  1023. }
  1024. }
  1025. // 拉起批量续费弹窗
  1026. async function switchRenews(rowData) {
  1027. renewDatas.value = [];
  1028. if (visible_renews.value == false) {
  1029. visible_renews.value = true;
  1030. }
  1031. calculateRenewEnd();
  1032. }
  1033. // 计算批量续费到期时间
  1034. function calculateRenewEnd() {
  1035. renewDatas.value = [];
  1036. //
  1037. apis.value.map((item) => {
  1038. // console.log(item);
  1039. let temp = {
  1040. pc_id: item.id,
  1041. pc_num: item.pc_num,
  1042. rent_end: item.rent_end,
  1043. rent_end_new: dayjs(new Date(item.rent_end))
  1044. .add(renewsDay.value, "day")
  1045. .format("YYYY-MM-DD HH:mm:ss"),
  1046. };
  1047. renewDatas.value.push(temp);
  1048. });
  1049. }
  1050. // 批量续费
  1051. const renewByBatch = async () => {
  1052. const loadingByBatch = ElLoading.service({
  1053. lock: true,
  1054. text: "批量续费中,请勿操作界面...",
  1055. background: "rgba(0, 0, 0, 0.7)",
  1056. });
  1057. let rentMessage = [];
  1058. renewDatas.value.map((item) => {
  1059. let temp = {
  1060. pc_num: item.pc_num,
  1061. pc_id: item.pc_id,
  1062. rent_renew: item.rent_end_new,
  1063. day: Number(renewsDay.value),
  1064. };
  1065. rentMessage.push(temp);
  1066. });
  1067. let xxxx = {
  1068. rent_message: rentMessage,
  1069. };
  1070. const data = await renewRentComputerByBatch(xxxx);
  1071. if (data.code == 0) {
  1072. visible_renews.value = false;
  1073. loadingByBatch.close();
  1074. ElMessage.success(data.msg);
  1075. getTableData();
  1076. } else {
  1077. ElMessage.error(data.msg);
  1078. }
  1079. };
  1080. // 拉起退租弹窗
  1081. async function switchRentingOut(rowData) {
  1082. cardList.value = [];
  1083. rentingOutForm.value.pc_num = rowData.pc_num;
  1084. rentingOutForm.value.pc_id = rowData.id;
  1085. rentingOutForm.value.rent_end = dayjs(new Date(rowData.rent_end)).format(
  1086. "YYYY-MM-DD HH:mm:ss"
  1087. );
  1088. rentingOutForm.value.day = 0;
  1089. rent_end.value = rowData.rent_end;
  1090. if (visible_rentingOut.value == false) {
  1091. visible_rentingOut.value = true;
  1092. }
  1093. }
  1094. function addCardMsg() {
  1095. let hasFlag = false;
  1096. for (let i = 0; i < cardList.value.length; i++) {
  1097. if (
  1098. cardList.value[i].pc_num == "" ||
  1099. cardList.value[i].add_day == undefined
  1100. ) {
  1101. hasFlag = true;
  1102. break;
  1103. }
  1104. }
  1105. if (hasFlag == true) {
  1106. ElMessage.error("有未填写项");
  1107. } else {
  1108. cardList.value.push({
  1109. pc_id: "",
  1110. add_day: null,
  1111. });
  1112. }
  1113. }
  1114. function deleteCardMsg(index) {
  1115. cardList.value.splice(index, 1);
  1116. }
  1117. // 退租
  1118. async function rentingOut(rowData) {
  1119. var numDay = 0;
  1120. let AddList = [];
  1121. cardList.value.forEach((e) => {
  1122. numDay += e.add_day;
  1123. let temp = {
  1124. pc_num: e.pc_num,
  1125. add_day: Number(e.add_day),
  1126. };
  1127. AddList.push(temp);
  1128. });
  1129. if (numDay != rowData.day) {
  1130. ElMessage.error("匀时间天数错误!!!");
  1131. return;
  1132. }
  1133. let doForm = {
  1134. pc_id: rowData.pc_id,
  1135. rent_end: dayjs(new Date(rowData.rent_end)).format("YYYY-MM-DD HH:mm:ss"),
  1136. add_list: AddList,
  1137. };
  1138. const data = await rentingOutRentComputer(doForm);
  1139. // console.log(data)
  1140. if (data.code == 0) {
  1141. visible_rentingOut.value = false;
  1142. ElMessage.success(data.msg);
  1143. getTableData();
  1144. } else {
  1145. // ElMessage.error(data.msg);
  1146. }
  1147. }
  1148. // 拉起换编号弹窗
  1149. async function switchReplaceNum(rowData) {
  1150. replaceNumForm.value.pc_num_old = rowData.pc_num;
  1151. replaceNumForm.value.shop_id = rowData.shop_id;
  1152. replaceNumForm.value.shop_name = rowData.shop_name;
  1153. if (visible_replaceNum.value == false) {
  1154. visible_replaceNum.value = true;
  1155. }
  1156. }
  1157. // 换编
  1158. async function replaceNum(rowData) {
  1159. let doForm = {
  1160. pc_num_old: rowData.pc_num_old,
  1161. pc_num_new: rowData.pc_num_new,
  1162. shop_id: rowData.shop_id,
  1163. };
  1164. const data = await replaceNumRentComputer(doForm);
  1165. // console.log(data)
  1166. if (data.code == 0) {
  1167. visible_replaceNum.value = false;
  1168. ElMessage.success(data.msg);
  1169. getTableData();
  1170. } else {
  1171. // ElMessage.error(data.msg);
  1172. }
  1173. }
  1174. const downloadExcelTemplate = () => {
  1175. downloadTemplate("RentComputerTemplate.xlsx");
  1176. };
  1177. // 删除/下架
  1178. async function offShelf(rowData) {
  1179. let message = "确定要下架编号为" + rowData.pc_num + "的租机吗?";
  1180. if (rowData.is_expire != 1) {
  1181. message = "机器未到期,确定强制下架编号为" + rowData.pc_num + "的租机吗?";
  1182. }
  1183. let doForm = {
  1184. id: rowData.id,
  1185. pc_num: rowData.pc_num,
  1186. };
  1187. // console.log(doForm);
  1188. ElMessageBox.confirm(message, "租机下架", {
  1189. dangerouslyUseHTMLString: true,
  1190. type: "warning",
  1191. })
  1192. .then(async () => {
  1193. const data = await offShelfRentComputer(doForm);
  1194. if (data.code == 0) {
  1195. ElMessage.success(data.msg);
  1196. getTableData();
  1197. } else {
  1198. ElMessage.error(data.msg);
  1199. }
  1200. })
  1201. .catch(() => null);
  1202. }
  1203. // 分页
  1204. const handleSizeChange = (val) => {
  1205. pageSize.value = val;
  1206. getTableData();
  1207. };
  1208. const onReset = () => {
  1209. searchInfo.value = {};
  1210. };
  1211. const handleCurrentChange = (val) => {
  1212. page.value = val;
  1213. getTableData();
  1214. };
  1215. // 排序
  1216. const sortChange = ({ prop, order }) => {
  1217. if (prop) {
  1218. if (prop === "id") {
  1219. prop = "id";
  1220. }
  1221. searchInfo.value.orderKey = toSQLLine(prop);
  1222. searchInfo.value.desc = order === "descending";
  1223. }
  1224. getTableData();
  1225. };
  1226. // 搜索
  1227. const onSubmit = () => {
  1228. page.value = 1;
  1229. pageSize.value = 20;
  1230. if (typeof searchInfo.value.set_meal_id != "undefined") {
  1231. searchInfo.value.set_meal_id = Number(searchInfo.value.set_meal_id);
  1232. }
  1233. if (typeof searchInfo.value.is_expire != "undefined") {
  1234. searchInfo.value.is_expire = Number(searchInfo.value.is_expire);
  1235. }
  1236. if (typeof searchInfo.value.is_off_shelf != "undefined") {
  1237. searchInfo.value.is_off_shelf = Number(searchInfo.value.is_off_shelf);
  1238. }
  1239. // console.log(searchInfo);
  1240. getTableData();
  1241. };
  1242. // 查询
  1243. const getTableData = async () => {
  1244. loading.value = true;
  1245. const table = await getRentComputerList({
  1246. page: page.value,
  1247. pageSize: pageSize.value,
  1248. ...searchInfo.value,
  1249. });
  1250. if (table.code === 0) {
  1251. tableData.value = table.data.list;
  1252. total.value = table.data.total;
  1253. page.value = table.data.page;
  1254. pageSize.value = table.data.pageSize;
  1255. getComputerNum();
  1256. getSelectList();
  1257. }
  1258. await getIsExpireData();
  1259. loading.value = false;
  1260. };
  1261. // 查询是否有到期
  1262. const getIsExpireData = async () => {
  1263. loading.value = true;
  1264. tagExpire.value = false;
  1265. const table = await getRentComputerList({
  1266. page: 1,
  1267. pageSize: 999,
  1268. ...searchInfo.value,
  1269. });
  1270. // console.log(table.data.list)
  1271. if (table.code === 0 && table.data.list != null) {
  1272. for (const item of table.data.list) {
  1273. if (item.is_expire >= 2) {
  1274. ElMessageBox.alert("有租机即将到期,请注意续费!!!", "警告", {
  1275. confirmButtonText: "好的",
  1276. type: "warning",
  1277. callback: (action) => {
  1278. tagExpire.value = true;
  1279. },
  1280. });
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. };
  1286. //获取下拉框list
  1287. const getSelectList = async () => {
  1288. //listRentComputerShopList
  1289. const rentComputerShop = await listRentComputerShopList({
  1290. page: 1,
  1291. pageSize: 999,
  1292. });
  1293. let rentComputerShopList = [];
  1294. const data = rentComputerShop.data.list;
  1295. data.forEach((e) => {
  1296. rentComputerShopList.push({ value: e.id, label: e.name });
  1297. });
  1298. shopOptions.value = rentComputerShopList;
  1299. //listRentSetMealList
  1300. const setMealShop = await listRentSetMealList({
  1301. page: 1,
  1302. pageSize: 999,
  1303. });
  1304. let setMealList = [];
  1305. const data2 = setMealShop.data.list;
  1306. data2.forEach((e) => {
  1307. var priceStr = "";
  1308. if (e.price_type == 0) {
  1309. priceStr = "天卡(" + e.rent_price + "元)";
  1310. } else if (e.price_type == 1) {
  1311. priceStr = "周卡(" + e.rent_price + "元)";
  1312. } else {
  1313. priceStr = "月卡(" + e.rent_price + "元)";
  1314. }
  1315. setMealList.push({
  1316. value: e.id,
  1317. label: e.shop_name + "-" + e.name + "-" + priceStr,
  1318. });
  1319. });
  1320. setMealOptions.value = setMealList;
  1321. //游戏负责人列表===============================
  1322. const directorRes = await getDirectorList();
  1323. let directorList = [
  1324. { value: "ALL", label: "所有机器" },
  1325. // { value: "", label: "备用" },
  1326. ];
  1327. const data3 = directorRes.data.list;
  1328. data3.forEach((e) => {
  1329. directorList.push({ value: e.name, label: e.name });
  1330. });
  1331. directorOptions.value = directorList;
  1332. };
  1333. // 查询
  1334. const getComputerNum = async () => {
  1335. const table = await getRentComputerNum({ ...searchInfo.value });
  1336. if (table.code === 0) {
  1337. // console.log(table.data);
  1338. computerNum.value = table.data;
  1339. }
  1340. };
  1341. //拉起TD连接
  1342. const linkTd = async (row) => {
  1343. let todesk_id = row.todesk_id;
  1344. let todesk_password = row.todesk_password;
  1345. todesk_id = todesk_id.replace(/\s*/g, "");
  1346. todesk_password = todesk_password.replace(/\s*/g, "");
  1347. // console.log(todesk_id);
  1348. // console.log(todesk_password);
  1349. if (todesk_id == "" || todesk_password == "") {
  1350. ElMessage({
  1351. type: "error",
  1352. message: "todesk账号密码不完整!",
  1353. });
  1354. } else {
  1355. window.location.href =
  1356. "ToDesk://connect&" + todesk_id + "&" + todesk_password;
  1357. }
  1358. };
  1359. getTableData();
  1360. // 批量操作
  1361. const handleSelectionChange = (val) => {
  1362. apis.value = val;
  1363. };
  1364. const dialogFormVisible = ref(false);
  1365. // 弹窗相关
  1366. const menuForm = ref(null);
  1367. const checkFlag = ref(false);
  1368. const initForm = () => {
  1369. checkFlag.value = false;
  1370. menuForm.value.resetFields();
  1371. form.value = {
  1372. id: 0,
  1373. coding: "",
  1374. describe: "",
  1375. parent_id: "",
  1376. };
  1377. };
  1378. const menuOption = ref([
  1379. {
  1380. id: "0",
  1381. title: "根编号",
  1382. },
  1383. ]);
  1384. const setOptions = () => {
  1385. menuOption.value = [
  1386. {
  1387. id: "0",
  1388. title: "根目录",
  1389. },
  1390. ];
  1391. setMenuOptions(tableData.value, menuOption.value, false);
  1392. };
  1393. const setMenuOptions = (menuData, optionsData, disabled) => {
  1394. menuData &&
  1395. menuData.forEach((item) => {
  1396. if (item.children && item.children.length) {
  1397. const option = {
  1398. ID: String(item.id),
  1399. disabled: disabled || item.id === form.value.id,
  1400. children: [],
  1401. };
  1402. setMenuOptions(
  1403. item.children,
  1404. option.children,
  1405. disabled || item.id === form.value.id
  1406. );
  1407. optionsData.push(option);
  1408. } else {
  1409. const option = {
  1410. ID: String(item.id),
  1411. disabled: disabled || item.id === form.value.id,
  1412. };
  1413. optionsData.push(option);
  1414. }
  1415. });
  1416. };
  1417. const loadExcel = (res) => {
  1418. if (res.code === 0) {
  1419. ElMessage({
  1420. type: "success",
  1421. message: res.msg,
  1422. });
  1423. } else {
  1424. ElMessage({
  1425. type: "error",
  1426. message: res.msg,
  1427. showClose: true,
  1428. });
  1429. }
  1430. getTableData();
  1431. };
  1432. // 添加菜单方法,id为 0则为添加根菜单
  1433. const isEdit = ref(false);
  1434. const dialogTitle = ref("新增租机");
  1435. const addMenu = async (id) => {
  1436. dialogTitle.value = "新增租机";
  1437. form.value.parent_id = String(id);
  1438. isEdit.value = false;
  1439. setOptions();
  1440. dialogFormVisible.value = true;
  1441. getSelectList();
  1442. };
  1443. // 修改菜单方法
  1444. const editMenu = async (id) => {
  1445. dialogTitle.value = "编辑租机";
  1446. const res = await getRentComputerById({ id });
  1447. form.value = res.data;
  1448. // console.log(form.value);
  1449. if (form.value.is_off_shelf == 1) {
  1450. form.value.is_off_shelf = true;
  1451. } else {
  1452. form.value.is_off_shelf = false;
  1453. }
  1454. isEdit.value = true;
  1455. setOptions();
  1456. dialogFormVisible.value = true;
  1457. getSelectList();
  1458. };
  1459. const closeDialog = () => {
  1460. initForm();
  1461. dialogFormVisible.value = false;
  1462. };
  1463. // 批量删除菜单
  1464. const deletesMenu = async () => {
  1465. ElMessageBox.confirm("确定批量删除所选吗?", "提示", {
  1466. confirmButtonText: "确定",
  1467. cancelButtonText: "取消",
  1468. type: "warning",
  1469. })
  1470. .then(async () => {
  1471. const ids = apis.value.map((item) => item.id);
  1472. // console.log(ids);
  1473. const res = await deleteRentComputerByIds({ ids });
  1474. if (res.code === 0) {
  1475. ElMessage({
  1476. type: "success",
  1477. message: "删除成功!",
  1478. });
  1479. getTableData();
  1480. }
  1481. })
  1482. .catch(() => {
  1483. ElMessage({
  1484. type: "info",
  1485. message: "已取消删除",
  1486. });
  1487. });
  1488. };
  1489. // 删除菜单
  1490. const deleteMenu = async (id) => {
  1491. ElMessageBox.confirm("确定删除?", "提示", {
  1492. confirmButtonText: "确定",
  1493. cancelButtonText: "取消",
  1494. type: "warning",
  1495. })
  1496. .then(async () => {
  1497. // console.log(id);
  1498. const res = await deleteRentComputerById({ id });
  1499. if (res.code === 0) {
  1500. ElMessage({
  1501. type: "success",
  1502. message: "删除成功!",
  1503. });
  1504. getTableData();
  1505. }
  1506. })
  1507. .catch(() => {
  1508. ElMessage({
  1509. type: "info",
  1510. message: "已取消删除",
  1511. });
  1512. });
  1513. };
  1514. const enterDialog = async () => {
  1515. // console.log(form.value);
  1516. menuForm.value.validate(async (valid) => {
  1517. if (valid) {
  1518. let res;
  1519. form.value.id = Number(form.value.id);
  1520. form.value.shop_id = Number(form.value.shop_id);
  1521. form.value.set_meal_id = Number(form.value.set_meal_id);
  1522. form.value.rent_duration = Number(form.value.rent_duration);
  1523. form.value.rent_start = formatDate(form.value.rent_start);
  1524. form.value.rent_end = formatDate(form.value.rent_end);
  1525. form.value.is_expire = Number(form.value.is_expire);
  1526. if (form.value.is_off_shelf == true) {
  1527. form.value.is_off_shelf = 1;
  1528. } else {
  1529. form.value.is_off_shelf = 0;
  1530. }
  1531. if (isEdit.value) {
  1532. res = await editRentComputer(form.value);
  1533. } else {
  1534. res = await addRentComputer(form.value);
  1535. }
  1536. if (res.code === 0) {
  1537. ElMessage({
  1538. type: "success",
  1539. message: isEdit.value ? "编辑成功" : "添加成功!",
  1540. });
  1541. getTableData();
  1542. } else {
  1543. ElMessage({
  1544. type: "error",
  1545. message: res.message,
  1546. });
  1547. }
  1548. initForm();
  1549. dialogFormVisible.value = false;
  1550. }
  1551. });
  1552. };
  1553. </script>
  1554. <style scoped lang="scss">
  1555. .button-box {
  1556. padding: 10px 20px;
  1557. .el-button {
  1558. float: right;
  1559. }
  1560. }
  1561. .warning {
  1562. color: #dc143c;
  1563. }
  1564. </style>