express.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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-row justify="space-around" :gutter="10">
  25. <template v-for="(v,k) in boxList[index]">
  26. <el-col :span="6" :key="k">
  27. <el-card class="box-card">
  28. <div slot="header" class="clearfix">
  29. <span>
  30. {{v.box_number}}号箱
  31. <el-tag size="mini">已{{v.status_text}}</el-tag>
  32. </span>
  33. <el-dropdown @command="command=>onHandleBox(command,v.cabinet_number,v.box_number,v.order_sn)">
  34. <span class="el-dropdown-link">
  35. 操作
  36. <i class="el-icon-arrow-down el-icon--right"></i>
  37. </span>
  38. <el-dropdown-menu slot="dropdown">
  39. <el-dropdown-item icon="el-icon-unlock" style="color:red;" command="openBox">开箱</el-dropdown-item>
  40. <el-dropdown-item icon="el-icon-phone-outline" style="color:#409EFF;" command="inform" :disabled="v.order_sn == ''">通知</el-dropdown-item>
  41. </el-dropdown-menu>
  42. </el-dropdown>
  43. </div>
  44. <!-- <div style="height:72px;">
  45. <el-row type="flex" align="middle" style="height:100%;">
  46. <el-tag effect="dark">箱子已{{v.status_text}}</el-tag>
  47. </el-row>
  48. </div>-->
  49. <div v-if="v.order_sn == ''">
  50. <div style="height:72px;display:flex;justify-content:center;align-items:center;">
  51. <h4>空闲中</h4>
  52. </div>
  53. </div>
  54. <el-row type="flex" justify="space-between" v-if="v.order_sn != ''">
  55. <!-- <el-row type="flex" align="middle">
  56. <el-tag type="danger" effect="dark">{{v.status_text}}</el-tag>
  57. </el-row>-->
  58. <div style="height:72px;">
  59. <h4 class="info">
  60. <div class="label">订单号:</div>
  61. <div class="value">{{v.order_sn}}</div>
  62. <!-- <el-button style="margin-left:10px;" size="mini" type="primary">通知</el-button> -->
  63. </h4>
  64. <h4 class="info">
  65. <div class="label">入柜日期:</div>
  66. <div class="value">{{v.enter_time}}</div>
  67. </h4>
  68. <h4 class="info">
  69. <div class="label">存件时间:</div>
  70. <div class="value">{{v.use_time}}</div>
  71. </h4>
  72. </div>
  73. </el-row>
  74. <!-- <div style="height:72px;" v-if="v.box_status == 3">
  75. <el-row type="flex" align="middle" style="height:100%;">
  76. <el-tag type="info" effect="dark">{{v.status_text}}</el-tag>
  77. </el-row>
  78. </div>-->
  79. </el-card>
  80. </el-col>
  81. </template>
  82. <el-col :span="6">
  83. <el-card class="box-card">
  84. <div slot="header" class="clearfix">
  85. <span>新增箱子</span>
  86. </div>
  87. <div style="height:72px;">
  88. <el-row type="flex" align="middle" justify="center" style="height:100%;">
  89. <el-button type="primary" @click="onAddBox(item.id)">新增</el-button>
  90. </el-row>
  91. </div>
  92. </el-card>
  93. </el-col>
  94. </el-row>
  95. <!-- <el-row style="margin-top:10px;" type="flex" justify="end">
  96. <el-pagination background layout="prev, pager, next" :total="30"></el-pagination>
  97. </el-row>
  98. -->
  99. </div>
  100. </el-tab-pane>
  101. </template>
  102. <el-tab-pane name="add">
  103. <span slot="label">
  104. <i class="el-icon-plus">新增</i>
  105. </span>
  106. </el-tab-pane>
  107. </el-tabs>
  108. <el-dialog title="新增柜体" :visible.sync="addVisible" width="50%" @closed="onCloseAddDialog">
  109. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
  110. <el-form-item label="请求地址" prop="requrl">
  111. <el-input v-model="ruleForm.requrl"></el-input>
  112. </el-form-item>
  113. <el-form-item label="柜子名称" prop="alias">
  114. <el-input v-model="ruleForm.alias"></el-input>
  115. </el-form-item>
  116. <el-form-item label="柜子编号" prop="number">
  117. <el-input v-model="ruleForm.number"></el-input>
  118. </el-form-item>
  119. <el-form-item label="柜子登录key" prop="login_key">
  120. <el-input v-model="ruleForm.login_key"></el-input>
  121. </el-form-item>
  122. <el-form-item label="箱子个数" prop="count">
  123. <el-input v-model="ruleForm.count"></el-input>
  124. </el-form-item>
  125. </el-form>
  126. <span slot="footer" class="dialog-footer">
  127. <el-button @click="onCloseAddDialog">取 消</el-button>
  128. <el-button type="primary" @click="onAddSubmit('ruleForm')">立即添加</el-button>
  129. </span>
  130. </el-dialog>
  131. </el-container>
  132. </template>
  133. <script>
  134. import {
  135. cabinetList,
  136. boxList,
  137. addCabinet,
  138. reboot,
  139. openBox,
  140. sendMsg,
  141. addBox,
  142. lockCabinet,
  143. unLockCabinet,
  144. releaseAlarm
  145. } from "@/api";
  146. import moment from "moment";
  147. export default {
  148. data() {
  149. return {
  150. tabActive: "",
  151. addVisible: false,
  152. ruleForm: {
  153. requrl: "",
  154. alias: "",
  155. number: "",
  156. login_key: "",
  157. count: "",
  158. },
  159. rules: {
  160. requrl: [{
  161. required: true,
  162. message: "请输入请求地址",
  163. trigger: "blur",
  164. }, ],
  165. alias: [{
  166. required: true,
  167. message: "请输入柜子名称",
  168. trigger: "blur",
  169. }, ],
  170. number: [{
  171. required: true,
  172. message: "请输入柜子编号",
  173. trigger: "blur",
  174. }, ],
  175. login_key: [{
  176. required: true,
  177. message: "请输入柜子登录key",
  178. trigger: "blur",
  179. }, ],
  180. count: [{
  181. required: true,
  182. message: "请输入箱子个数",
  183. trigger: "blur",
  184. }, ],
  185. },
  186. cabinetList: [],
  187. boxList: [],
  188. currentCabinetState: {},
  189. };
  190. },
  191. computed: {
  192. diffTime() {
  193. return (date) => {
  194. const currentTime = moment();
  195. const startDate = moment(date);
  196. const date3 = currentTime.diff(startDate, "minute"); //计算相差的分钟数
  197. const h = Math.floor(date3 / 60); //相差的小时数
  198. const mm = date3 % 60; //计算相差小时后余下的分钟数
  199. return `${h}小时${mm}分钟`;
  200. };
  201. },
  202. },
  203. created() {
  204. this.getCabinetList();
  205. },
  206. methods: {
  207. getCabinetList() {
  208. cabinetList().then((res) => {
  209. console.log(res);
  210. if (res && res.msg == "ok") {
  211. this.cabinetList = res.data.rows.map((item) => {
  212. item.id = item.id + "";
  213. return item;
  214. });
  215. this.boxList = res.data.rows.map(() => {
  216. return [];
  217. });
  218. this.getBoxList(res.data.rows[0].id, 0);
  219. this.tabActive = res.data.rows[0].id + "";
  220. console.log(this.tabActive);
  221. }
  222. });
  223. },
  224. getBoxList(id, cabinetIndex) {
  225. const _self = this;
  226. boxList({
  227. cabinet_number: id,
  228. }).then((res) => {
  229. console.log(res);
  230. if (res && res.data.rows) {
  231. let boxList = [..._self.boxList];
  232. boxList[cabinetIndex] = res.data.rows;
  233. _self.boxList = boxList;
  234. }
  235. });
  236. },
  237. onCloseAddDialog() {
  238. this.ruleForm = {};
  239. this.addVisible = false;
  240. this.$refs.ruleForm.resetFields();
  241. },
  242. onBeforeChangeTab(activeName) {
  243. if (activeName == "add") {
  244. this.addVisible = true;
  245. return false;
  246. }
  247. },
  248. onAddSubmit(formName) {
  249. this.$refs[formName].validate((valid) => {
  250. if (valid) {
  251. this.addCabinet();
  252. } else {
  253. console.log("error submit!!");
  254. return false;
  255. }
  256. });
  257. },
  258. addCabinet() {
  259. let requrl = "";
  260. let alias = "";
  261. let number = "";
  262. let login_key = "";
  263. let count = "";
  264. addCabinet(requrl, alias, number, login_key, count).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. }
  339. },
  340. onHandleCabinet(command) {
  341. const cabinet_number = this.tabActive;
  342. if (command == "lock") {
  343. this.$confirm("确认锁定当前柜体?", "提示").then(() => {
  344. lockCabinet({
  345. cabinet_number,
  346. }).then((res) => {
  347. if (res && res.msg == "ok") {
  348. this.$message({
  349. message: "锁定成功",
  350. type: "success",
  351. center: true,
  352. duration: 1000,
  353. });
  354. this.getCabinetList();
  355. } else {
  356. this.$message({
  357. message: "锁定失败",
  358. type: "success",
  359. center: true,
  360. duration: 1000,
  361. });
  362. }
  363. });
  364. });
  365. } else if (command == "unlock") {
  366. this.$confirm("确认解锁当前柜体?", "提示").then(() => {
  367. unLockCabinet({
  368. cabinet_number,
  369. }).then((res) => {
  370. if (res && res.msg == "ok") {
  371. this.$message({
  372. message: "解锁成功",
  373. type: "success",
  374. center: true,
  375. duration: 1000,
  376. });
  377. this.getCabinetList();
  378. } else {
  379. this.$message({
  380. message: "解锁失败",
  381. type: "success",
  382. center: true,
  383. duration: 1000,
  384. });
  385. }
  386. });
  387. });
  388. } else if (command == 'unwarn') {
  389. this.$confirm("确认解除当前报警?", "提示").then(() => {
  390. releaseAlarm({
  391. cabinet_number,
  392. }).then((res) => {
  393. if (res && res.msg == "ok") {
  394. this.$message({
  395. message: "解除成功",
  396. type: "success",
  397. center: true,
  398. duration: 1000,
  399. });
  400. this.getCabinetList();
  401. } else {
  402. this.$message({
  403. message: "解除失败",
  404. type: "success",
  405. center: true,
  406. duration: 1000,
  407. });
  408. }
  409. });
  410. });
  411. } else if (command == 'reset') {
  412. this.$confirm("确认重启当前柜体?", "提示").then(() => {
  413. reboot({
  414. cabinet_number,
  415. }).then((res) => {
  416. if (res && res.msg == "ok") {
  417. this.$message({
  418. message: "重启成功",
  419. type: "success",
  420. center: true,
  421. duration: 1000,
  422. });
  423. this.getCabinetList();
  424. } else {
  425. this.$message({
  426. message: "重启失败",
  427. type: "success",
  428. center: true,
  429. duration: 1000,
  430. });
  431. }
  432. });
  433. });
  434. }
  435. console.log(command);
  436. },
  437. onAddBox(id) {
  438. this.$confirm("确定新增箱子?", "提示")
  439. .then(() => {
  440. addBox({
  441. cabinet_number: id,
  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. .catch(() => {
  462. console.log("取消");
  463. });
  464. },
  465. },
  466. };
  467. </script>
  468. <style scoped>
  469. .box-card {
  470. color: #fff;
  471. background: rgba(107, 107, 107, 1);
  472. margin-top: 10px;
  473. }
  474. .el-dropdown-link {
  475. cursor: pointer;
  476. color: #409eff;
  477. }
  478. .el-icon-arrow-down {
  479. font-size: 12px;
  480. }
  481. .clearfix {
  482. display: flex;
  483. align-items: center;
  484. justify-content: space-between;
  485. }
  486. .el-tag {
  487. background: transparent;
  488. color: #fff;
  489. }
  490. .info {
  491. display: flex;
  492. }
  493. .info .label {
  494. width: 80px;
  495. text-align: right;
  496. }
  497. .info .value {
  498. flex: 1;
  499. }
  500. </style>