123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <template>
- <el-container direction="vertical">
- <el-header height="40px" style="border-bottom: 1px solid #eee">
- <div style="float:left;">柜体控制</div>
- <div style="float:right;height:40px;">
- <el-dropdown @command="onHandleCabinet">
- <span class="el-dropdown-link">
- 柜体操作
- <i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item icon="el-icon-lock" style="color:red;" command="lock">锁柜</el-dropdown-item>
- <el-dropdown-item icon="el-icon-unlock" command="unlock">解除锁柜</el-dropdown-item>
- <el-dropdown-item icon="el-icon-warning" command="unwarn">解除报警</el-dropdown-item>
- <el-dropdown-item icon="el-icon-refresh-left" style="color:#409EFF;" command="reset">重启</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </div>
- </el-header>
- <el-tabs type="card" v-model="tabActive" style="margin-top:10px;" :before-leave="onBeforeChangeTab" @tab-click="onTabClick">
- <template v-for="(item,index) in cabinetList">
- <el-tab-pane :label="item.alias" :key="index" :name="item.id">
- <div>
- <el-row justify="space-around" :gutter="10">
- <template v-for="(v,k) in boxList[index]">
- <el-col :span="6" :key="k">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span>
- {{v.box_number}}号箱
- <el-tag size="mini">已{{v.status_text}}</el-tag>
- </span>
- <el-dropdown @command="command=>onHandleBox(command,v.cabinet_number,v.box_number,v.order_sn)">
- <span class="el-dropdown-link">
- 操作
- <i class="el-icon-arrow-down el-icon--right"></i>
- </span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item icon="el-icon-unlock" style="color:red;" command="openBox">开箱</el-dropdown-item>
- <el-dropdown-item icon="el-icon-phone-outline" style="color:#409EFF;" command="inform" :disabled="v.order_sn == ''">通知</el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </div>
- <!-- <div style="height:72px;">
- <el-row type="flex" align="middle" style="height:100%;">
- <el-tag effect="dark">箱子已{{v.status_text}}</el-tag>
- </el-row>
- </div>-->
- <div v-if="v.order_sn == ''">
- <div style="height:72px;display:flex;justify-content:center;align-items:center;">
- <h4>空闲中</h4>
- </div>
- </div>
- <el-row type="flex" justify="space-between" v-if="v.order_sn != ''">
- <!-- <el-row type="flex" align="middle">
- <el-tag type="danger" effect="dark">{{v.status_text}}</el-tag>
- </el-row>-->
- <div style="height:72px;">
- <h4 class="info">
- <div class="label">订单号:</div>
- <div class="value">{{v.order_sn}}</div>
- <!-- <el-button style="margin-left:10px;" size="mini" type="primary">通知</el-button> -->
- </h4>
- <h4 class="info">
- <div class="label">入柜日期:</div>
- <div class="value">{{v.enter_time}}</div>
- </h4>
- <h4 class="info">
- <div class="label">存件时间:</div>
- <div class="value">{{v.use_time}}</div>
- </h4>
- </div>
- </el-row>
- <!-- <div style="height:72px;" v-if="v.box_status == 3">
- <el-row type="flex" align="middle" style="height:100%;">
- <el-tag type="info" effect="dark">{{v.status_text}}</el-tag>
- </el-row>
- </div>-->
- </el-card>
- </el-col>
- </template>
- <el-col :span="6">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span>新增箱子</span>
- </div>
- <div style="height:72px;">
- <el-row type="flex" align="middle" justify="center" style="height:100%;">
- <el-button type="primary" @click="onAddBox(item.id)">新增</el-button>
- </el-row>
- </div>
- </el-card>
- </el-col>
- </el-row>
- <!-- <el-row style="margin-top:10px;" type="flex" justify="end">
- <el-pagination background layout="prev, pager, next" :total="30"></el-pagination>
- </el-row>
- -->
- </div>
- </el-tab-pane>
- </template>
- <el-tab-pane name="add">
- <span slot="label">
- <i class="el-icon-plus">新增</i>
- </span>
- </el-tab-pane>
- </el-tabs>
- <el-dialog title="新增柜体" :visible.sync="addVisible" width="50%" @closed="onCloseAddDialog">
- <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
- <el-form-item label="请求地址" prop="requrl">
- <el-input v-model="ruleForm.requrl"></el-input>
- </el-form-item>
- <el-form-item label="柜子名称" prop="alias">
- <el-input v-model="ruleForm.alias"></el-input>
- </el-form-item>
- <el-form-item label="柜子编号" prop="number">
- <el-input v-model="ruleForm.number"></el-input>
- </el-form-item>
- <el-form-item label="柜子登录key" prop="login_key">
- <el-input v-model="ruleForm.login_key"></el-input>
- </el-form-item>
- <el-form-item label="箱子个数" prop="count">
- <el-input v-model="ruleForm.count"></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="onCloseAddDialog">取 消</el-button>
- <el-button type="primary" @click="onAddSubmit('ruleForm')">立即添加</el-button>
- </span>
- </el-dialog>
- </el-container>
- </template>
- <script>
- import {
- cabinetList,
- boxList,
- addCabinet,
- reboot,
- openBox,
- sendMsg,
- addBox,
- lockCabinet,
- unLockCabinet,
- releaseAlarm
- } from "@/api";
- import moment from "moment";
- export default {
- data() {
- return {
- tabActive: "",
- addVisible: false,
- ruleForm: {
- requrl: "",
- alias: "",
- number: "",
- login_key: "",
- count: "",
- },
- rules: {
- requrl: [{
- required: true,
- message: "请输入请求地址",
- trigger: "blur",
- }, ],
- alias: [{
- required: true,
- message: "请输入柜子名称",
- trigger: "blur",
- }, ],
- number: [{
- required: true,
- message: "请输入柜子编号",
- trigger: "blur",
- }, ],
- login_key: [{
- required: true,
- message: "请输入柜子登录key",
- trigger: "blur",
- }, ],
- count: [{
- required: true,
- message: "请输入箱子个数",
- trigger: "blur",
- }, ],
- },
- cabinetList: [],
- boxList: [],
- currentCabinetState: {},
- };
- },
- computed: {
- diffTime() {
- return (date) => {
- const currentTime = moment();
- const startDate = moment(date);
- const date3 = currentTime.diff(startDate, "minute"); //计算相差的分钟数
- const h = Math.floor(date3 / 60); //相差的小时数
- const mm = date3 % 60; //计算相差小时后余下的分钟数
- return `${h}小时${mm}分钟`;
- };
- },
- },
- created() {
- this.getCabinetList();
- },
- methods: {
- getCabinetList() {
- cabinetList().then((res) => {
- console.log(res);
- if (res && res.msg == "ok") {
- this.cabinetList = res.data.rows.map((item) => {
- item.id = item.id + "";
- return item;
- });
- this.boxList = res.data.rows.map(() => {
- return [];
- });
- this.getBoxList(res.data.rows[0].id, 0);
- this.tabActive = res.data.rows[0].id + "";
- console.log(this.tabActive);
- }
- });
- },
- getBoxList(id, cabinetIndex) {
- const _self = this;
- boxList({
- cabinet_number: id,
- }).then((res) => {
- console.log(res);
- if (res && res.data.rows) {
- let boxList = [..._self.boxList];
- boxList[cabinetIndex] = res.data.rows;
- _self.boxList = boxList;
- }
- });
- },
- onCloseAddDialog() {
- this.ruleForm = {};
- this.addVisible = false;
- this.$refs.ruleForm.resetFields();
- },
- onBeforeChangeTab(activeName) {
- if (activeName == "add") {
- this.addVisible = true;
- return false;
- }
- },
- onAddSubmit(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.addCabinet();
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- addCabinet() {
- let requrl = "";
- let alias = "";
- let number = "";
- let login_key = "";
- let count = "";
- addCabinet(requrl, alias, number, login_key, count).then((res) => {
- console.log(res);
- if (res && res.msg == "ok") {
- this.getCabinetList();
- }
- });
- },
- onTabClick(e) {
- if (e.name != "add") {
- this.getBoxList(e.name, e.index);
- }
- },
- onHandleBox(command, cabinet_number, box_number, order_sn) {
- if (command == "openBox") {
- this.$confirm(
- `确认打开【${cabinet_number}】柜【${box_number}】箱?`,
- "提示"
- )
- .then(() => {
- openBox({
- cabinet_number: cabinet_number,
- box_number: box_number,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "操作成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "操作失败",
- type: "error",
- center: true,
- duration: 1000,
- });
- }
- console.log(res);
- });
- })
- .catch(() => {
- console.log("取消");
- });
- } else if (command == "inform") {
- this.$confirm(`是否通知用户?`, "提示")
- .then(() => {
- sendMsg({
- cabinet_number: cabinet_number,
- box_number: box_number,
- order_sn: order_sn,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "操作成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- } else {
- this.$message({
- message: "操作失败",
- type: "error",
- center: true,
- duration: 1000,
- });
- }
- console.log(res);
- });
- })
- .catch(() => {
- console.log("取消");
- });
- }
- },
- onHandleCabinet(command) {
- const cabinet_number = this.tabActive;
- if (command == "lock") {
- this.$confirm("确认锁定当前柜体?", "提示").then(() => {
- lockCabinet({
- cabinet_number,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "锁定成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "锁定失败",
- type: "success",
- center: true,
- duration: 1000,
- });
- }
- });
- });
- } else if (command == "unlock") {
- this.$confirm("确认解锁当前柜体?", "提示").then(() => {
- unLockCabinet({
- cabinet_number,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "解锁成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "解锁失败",
- type: "success",
- center: true,
- duration: 1000,
- });
- }
- });
- });
- } else if (command == 'unwarn') {
- this.$confirm("确认解除当前报警?", "提示").then(() => {
- releaseAlarm({
- cabinet_number,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "解除成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "解除失败",
- type: "success",
- center: true,
- duration: 1000,
- });
- }
- });
- });
- } else if (command == 'reset') {
- this.$confirm("确认重启当前柜体?", "提示").then(() => {
- reboot({
- cabinet_number,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "重启成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "重启失败",
- type: "success",
- center: true,
- duration: 1000,
- });
- }
- });
- });
- }
- console.log(command);
- },
- onAddBox(id) {
- this.$confirm("确定新增箱子?", "提示")
- .then(() => {
- addBox({
- cabinet_number: id,
- }).then((res) => {
- if (res && res.msg == "ok") {
- this.$message({
- message: "新增成功",
- type: "success",
- center: true,
- duration: 1000,
- });
- this.getCabinetList();
- } else {
- this.$message({
- message: "新增失败",
- type: "success",
- center: true,
- duration: 1000,
- });
- }
- });
- })
- .catch(() => {
- console.log("取消");
- });
- },
- },
- };
- </script>
- <style scoped>
- .box-card {
- color: #fff;
- background: rgba(107, 107, 107, 1);
- margin-top: 10px;
- }
- .el-dropdown-link {
- cursor: pointer;
- color: #409eff;
- }
- .el-icon-arrow-down {
- font-size: 12px;
- }
- .clearfix {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .el-tag {
- background: transparent;
- color: #fff;
- }
- .info {
- display: flex;
- }
- .info .label {
- width: 80px;
- text-align: right;
- }
- .info .value {
- flex: 1;
- }
- </style>
|