express.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <el-container direction="vertical">
  3. <el-header height="40px" style="border-bottom: 1px solid #eee">
  4. <div style="float:left;">柜体控制</div>
  5. <div style="float:right;height:40px;">
  6. <el-dropdown @command="onHandleCabinet">
  7. <span class="el-dropdown-link">
  8. 柜体操作
  9. <i class="el-icon-arrow-down el-icon--right"></i>
  10. </span>
  11. <el-dropdown-menu slot="dropdown">
  12. <el-dropdown-item icon="el-icon-lock" style="color:red;" command="lock">锁柜</el-dropdown-item>
  13. <el-dropdown-item icon="el-icon-unlock" command="unlock">解除锁柜</el-dropdown-item>
  14. <el-dropdown-item icon="el-icon-warning" command="unwarn">解除报警</el-dropdown-item>
  15. <el-dropdown-item icon="el-icon-refresh-left" style="color:#409EFF;" command="reset">重启</el-dropdown-item>
  16. </el-dropdown-menu>
  17. </el-dropdown>
  18. </div>
  19. </el-header>
  20. <el-tabs type="card" v-model="tabActive" style="margin-top:10px;" :before-leave="onBeforeChangeTab" @tab-click="onTabClick">
  21. <template v-for="(item,index) in cabinetList">
  22. <el-tab-pane :label="item.alias" :key="index" :name="item.id">
  23. <div>
  24. <el-button type="primary" @click="onAddBox(item.id)">新增箱子</el-button>
  25. <el-row justify="space-around" :gutter="10">
  26. <template v-for="(v,k) in boxList[index]">
  27. <el-col :span="6" :key="k" v-if="k <= currentPage * pageSize - 1 && k >= (currentPage - 1) * pageSize">
  28. <el-card class="box-card">
  29. <div slot="header" class="clearfix">
  30. <span>
  31. {{v.box_number}}号箱
  32. <el-tag size="mini">已{{v.status_text}}</el-tag>
  33. </span>
  34. <el-dropdown @command="command=>onHandleBox(command,v.cabinet_number,v.box_number,v.order_sn)">
  35. <span class="el-dropdown-link">
  36. 操作
  37. <i class="el-icon-arrow-down el-icon--right"></i>
  38. </span>
  39. <el-dropdown-menu slot="dropdown">
  40. <el-dropdown-item icon="el-icon-unlock" style="color:red;" command="openBox">开箱</el-dropdown-item>
  41. <el-dropdown-item icon="el-icon-phone-outline" style="color:#409EFF;" command="inform" :disabled="v.order_sn == ''">通知</el-dropdown-item>
  42. <el-dropdown-item icon="el-icon-upload2" style="color:black;" command="reported">手动取出上报</el-dropdown-item>
  43. </el-dropdown-menu>
  44. </el-dropdown>
  45. </div>
  46. <div v-if="v.order_sn == ''">
  47. <div style="height:72px;display:flex;justify-content:center;align-items:center;">
  48. <h4>空闲中</h4>
  49. </div>
  50. </div>
  51. <el-row type="flex" justify="space-between" v-if="v.order_sn != ''">
  52. <div style="height:72px;">
  53. <h4 class="info">
  54. <div class="label">订单编号:</div>
  55. <div class="value">{{v.order_sn}}</div>
  56. </h4>
  57. <h4 class="info">
  58. <div class="label">存件时间:</div>
  59. <div class="value">{{v.enter_time}}</div>
  60. </h4>
  61. <h4 class="info">
  62. <div class="label">存箱时长:</div>
  63. <div class="value">{{v.use_time}}</div>
  64. </h4>
  65. </div>
  66. </el-row>
  67. </el-card>
  68. </el-col>
  69. </template>
  70. <!-- <el-col :span="6">
  71. <el-card class="box-card">
  72. <div slot="header" class="clearfix">
  73. <span>新增箱子</span>
  74. </div>
  75. <div style="height:72px;">
  76. <el-row type="flex" align="middle" justify="center" style="height:100%;">
  77. <el-button type="primary" @click="onAddBox(item.id)">新增</el-button>
  78. </el-row>
  79. </div>
  80. </el-card>
  81. </el-col> -->
  82. </el-row>
  83. <el-row style="margin-top:10px;" type="flex" justify="end">
  84. <el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize" :current-page="currentPage" @current-change="onPageChange"></el-pagination>
  85. </el-row>
  86. </div>
  87. </el-tab-pane>
  88. </template>
  89. <el-tab-pane name="add">
  90. <span slot="label">
  91. <i class="el-icon-plus">新增</i>
  92. </span>
  93. </el-tab-pane>
  94. </el-tabs>
  95. <el-dialog title="新增柜体" :visible.sync="addVisible" width="50%" @closed="onCloseAddDialog">
  96. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
  97. <el-form-item label="请求地址" prop="requrl">
  98. <el-input v-model="ruleForm.requrl"></el-input>
  99. </el-form-item>
  100. <el-form-item label="柜子名称" prop="alias">
  101. <el-input v-model="ruleForm.alias"></el-input>
  102. </el-form-item>
  103. <el-form-item label="柜子编号" prop="number">
  104. <el-input v-model="ruleForm.number"></el-input>
  105. </el-form-item>
  106. <el-form-item label="柜子登录key" prop="login_key">
  107. <el-input v-model="ruleForm.login_key"></el-input>
  108. </el-form-item>
  109. <el-form-item label="箱子个数" prop="count">
  110. <el-input v-model="ruleForm.count"></el-input>
  111. </el-form-item>
  112. </el-form>
  113. <span slot="footer" class="dialog-footer">
  114. <el-button @click="onCloseAddDialog">取 消</el-button>
  115. <el-button type="primary" @click="onAddSubmit('ruleForm')">立即添加</el-button>
  116. </span>
  117. </el-dialog>
  118. </el-container>
  119. </template>
  120. <script>
  121. import {
  122. cabinetList,
  123. boxList,
  124. addCabinet,
  125. reboot,
  126. openBox,
  127. sendMsg,
  128. addBox,
  129. lockCabinet,
  130. unLockCabinet,
  131. releaseAlarm,
  132. manualSave
  133. } from "@/api";
  134. import moment from "moment";
  135. export default {
  136. data() {
  137. return {
  138. tabActive: "",
  139. addVisible: false,
  140. ruleForm: {
  141. requrl: "",
  142. alias: "",
  143. number: "",
  144. login_key: "",
  145. count: "",
  146. },
  147. rules: {
  148. requrl: [{
  149. required: true,
  150. message: "请输入请求地址",
  151. trigger: "blur",
  152. }, ],
  153. alias: [{
  154. required: true,
  155. message: "请输入柜子名称",
  156. trigger: "blur",
  157. }, ],
  158. number: [{
  159. required: true,
  160. message: "请输入柜子编号",
  161. trigger: "blur",
  162. }, ],
  163. login_key: [{
  164. required: true,
  165. message: "请输入柜子登录key",
  166. trigger: "blur",
  167. }, ],
  168. count: [{
  169. required: true,
  170. message: "请输入箱子个数",
  171. trigger: "blur",
  172. }, ],
  173. },
  174. cabinetList: [],
  175. boxList: [],
  176. currentCabinetState: {},
  177. currentPage: 1,
  178. total: 0,
  179. pageSize: 10
  180. };
  181. },
  182. computed: {
  183. diffTime() {
  184. return (date) => {
  185. const currentTime = moment();
  186. const startDate = moment(date);
  187. const date3 = currentTime.diff(startDate, "minute"); //计算相差的分钟数
  188. const h = Math.floor(date3 / 60); //相差的小时数
  189. const mm = date3 % 60; //计算相差小时后余下的分钟数
  190. return `${h}小时${mm}分钟`;
  191. };
  192. },
  193. },
  194. created() {
  195. this.getCabinetList();
  196. },
  197. methods: {
  198. getCabinetList() {
  199. cabinetList().then((res) => {
  200. console.log(res);
  201. if (res && res.msg == "ok") {
  202. this.cabinetList = res.data.rows.map((item) => {
  203. item.id = item.id + "";
  204. return item;
  205. });
  206. this.boxList = res.data.rows.map(() => {
  207. return [];
  208. });
  209. this.getBoxList(res.data.rows[0].id, 0);
  210. this.tabActive = res.data.rows[0].id + "";
  211. console.log(this.tabActive);
  212. }
  213. });
  214. },
  215. getBoxList(id, cabinetIndex) {
  216. const _self = this;
  217. boxList({
  218. cabinet_number: id,
  219. }).then((res) => {
  220. console.log(323, res);
  221. if (res && res.data.rows) {
  222. _self.currentPage = 1;
  223. _self.total = res.data.total;
  224. let boxList = [..._self.boxList];
  225. boxList[cabinetIndex] = res.data.rows;
  226. _self.boxList = boxList;
  227. }
  228. });
  229. },
  230. onCloseAddDialog() {
  231. this.ruleForm = {};
  232. this.addVisible = false;
  233. this.$refs.ruleForm.resetFields();
  234. },
  235. onBeforeChangeTab(activeName) {
  236. if (activeName == "add") {
  237. this.addVisible = true;
  238. return false;
  239. }
  240. },
  241. onAddSubmit(formName) {
  242. this.$refs[formName].validate((valid) => {
  243. if (valid) {
  244. this.addCabinet();
  245. } else {
  246. console.log("error submit!!");
  247. return false;
  248. }
  249. });
  250. },
  251. addCabinet() {
  252. let requrl = this.ruleForm.requrl;
  253. let alias = this.ruleForm.alias;
  254. let number = this.ruleForm.number;
  255. let login_key = this.ruleForm.login_key;
  256. let count = this.ruleForm.count;
  257. console.log(requrl, alias, number, login_key, count);
  258. addCabinet({
  259. url: requrl,
  260. alias: alias,
  261. number: number,
  262. login_key: login_key,
  263. count: count,
  264. }).then((res) => {
  265. console.log(res);
  266. if (res && res.msg == "ok") {
  267. this.getCabinetList();
  268. }
  269. });
  270. },
  271. onTabClick(e) {
  272. if (e.name != "add") {
  273. this.getBoxList(e.name, e.index);
  274. }
  275. },
  276. onHandleBox(command, cabinet_number, box_number, order_sn) {
  277. if (command == "openBox") {
  278. this.$confirm(
  279. `确认打开【${cabinet_number}】柜【${box_number}】箱?`,
  280. "提示"
  281. )
  282. .then(() => {
  283. openBox({
  284. cabinet_number: cabinet_number,
  285. box_number: box_number,
  286. }).then((res) => {
  287. if (res && res.msg == "ok") {
  288. this.$message({
  289. message: "操作成功",
  290. type: "success",
  291. center: true,
  292. duration: 1000,
  293. });
  294. this.getCabinetList();
  295. } else {
  296. this.$message({
  297. message: "操作失败",
  298. type: "error",
  299. center: true,
  300. duration: 1000,
  301. });
  302. }
  303. console.log(res);
  304. });
  305. })
  306. .catch(() => {
  307. console.log("取消");
  308. });
  309. } else if (command == "inform") {
  310. this.$confirm(`是否通知用户?`, "提示")
  311. .then(() => {
  312. sendMsg({
  313. cabinet_number: cabinet_number,
  314. box_number: box_number,
  315. order_sn: order_sn,
  316. }).then((res) => {
  317. if (res && res.msg == "ok") {
  318. this.$message({
  319. message: "操作成功",
  320. type: "success",
  321. center: true,
  322. duration: 1000,
  323. });
  324. } else {
  325. this.$message({
  326. message: "操作失败",
  327. type: "error",
  328. center: true,
  329. duration: 1000,
  330. });
  331. }
  332. console.log(res);
  333. });
  334. })
  335. .catch(() => {
  336. console.log("取消");
  337. });
  338. } else if (command == 'reported') {
  339. this.$confirm(`确认取出上报?`, "提示").then(() => {
  340. manualSave({
  341. cabinet_number: cabinet_number,
  342. box_number: box_number,
  343. order_sn: order_sn,
  344. }).then(res => {
  345. if (res && res.msg == "ok") {
  346. this.$message({
  347. message: "操作成功",
  348. type: "success",
  349. center: true,
  350. duration: 1000,
  351. });
  352. } else {
  353. this.$message({
  354. message: "操作失败",
  355. type: "error",
  356. center: true,
  357. duration: 1000,
  358. });
  359. }
  360. console.log(res);
  361. })
  362. }).catch(() => {
  363. console.log("取消");
  364. })
  365. }
  366. },
  367. onHandleCabinet(command) {
  368. const cabinet_number = this.tabActive;
  369. if (command == "lock") {
  370. this.$confirm("确认锁定当前柜体?", "提示").then(() => {
  371. lockCabinet({
  372. cabinet_number,
  373. }).then((res) => {
  374. if (res && res.msg == "ok") {
  375. this.$message({
  376. message: "锁定成功",
  377. type: "success",
  378. center: true,
  379. duration: 1000,
  380. });
  381. this.getCabinetList();
  382. } else {
  383. this.$message({
  384. message: "锁定失败",
  385. type: "success",
  386. center: true,
  387. duration: 1000,
  388. });
  389. }
  390. });
  391. });
  392. } else if (command == "unlock") {
  393. this.$confirm("确认解锁当前柜体?", "提示").then(() => {
  394. unLockCabinet({
  395. cabinet_number,
  396. }).then((res) => {
  397. if (res && res.msg == "ok") {
  398. this.$message({
  399. message: "解锁成功",
  400. type: "success",
  401. center: true,
  402. duration: 1000,
  403. });
  404. this.getCabinetList();
  405. } else {
  406. this.$message({
  407. message: "解锁失败",
  408. type: "success",
  409. center: true,
  410. duration: 1000,
  411. });
  412. }
  413. });
  414. });
  415. } else if (command == "unwarn") {
  416. this.$confirm("确认解除当前报警?", "提示").then(() => {
  417. releaseAlarm({
  418. cabinet_number,
  419. }).then((res) => {
  420. if (res && res.msg == "ok") {
  421. this.$message({
  422. message: "解除成功",
  423. type: "success",
  424. center: true,
  425. duration: 1000,
  426. });
  427. this.getCabinetList();
  428. } else {
  429. this.$message({
  430. message: "解除失败",
  431. type: "success",
  432. center: true,
  433. duration: 1000,
  434. });
  435. }
  436. });
  437. });
  438. } else if (command == "reset") {
  439. this.$confirm("确认重启当前柜体?", "提示").then(() => {
  440. reboot({
  441. cabinet_number,
  442. }).then((res) => {
  443. if (res && res.msg == "ok") {
  444. this.$message({
  445. message: "重启成功",
  446. type: "success",
  447. center: true,
  448. duration: 1000,
  449. });
  450. this.getCabinetList();
  451. } else {
  452. this.$message({
  453. message: "重启失败",
  454. type: "success",
  455. center: true,
  456. duration: 1000,
  457. });
  458. }
  459. });
  460. });
  461. }
  462. console.log(command);
  463. },
  464. onAddBox(id) {
  465. this.$confirm("确定新增箱子?", "提示")
  466. .then(() => {
  467. addBox({
  468. cabinet_number: id,
  469. }).then((res) => {
  470. if (res && res.msg == "ok") {
  471. this.$message({
  472. message: "新增成功",
  473. type: "success",
  474. center: true,
  475. duration: 1000,
  476. });
  477. this.getCabinetList();
  478. } else {
  479. this.$message({
  480. message: "新增失败",
  481. type: "success",
  482. center: true,
  483. duration: 1000,
  484. });
  485. }
  486. });
  487. })
  488. .catch(() => {
  489. console.log("取消");
  490. });
  491. },
  492. onPageChange(page) {
  493. this.currentPage = page;
  494. }
  495. },
  496. };
  497. </script>
  498. <style scoped>
  499. .box-card {
  500. color: #fff;
  501. background: rgba(107, 107, 107, 1);
  502. margin-top: 10px;
  503. }
  504. .el-dropdown-link {
  505. cursor: pointer;
  506. color: #409eff;
  507. }
  508. .el-icon-arrow-down {
  509. font-size: 12px;
  510. }
  511. .clearfix {
  512. display: flex;
  513. align-items: center;
  514. justify-content: space-between;
  515. }
  516. .el-tag {
  517. background: transparent;
  518. color: #fff;
  519. }
  520. .info {
  521. display: flex;
  522. }
  523. .info .label {
  524. width: 80px;
  525. text-align: right;
  526. }
  527. .info .value {
  528. flex: 1;
  529. }
  530. </style>