描述:当我点击开启门店,门店变为关闭,(这时候的门店的状态是开启)。当我点击关闭门店的,门店变为开启,(这时候的门店状态时关闭)
效果:
代码:
pageList.vue
<el-table-column label="操作" width="500">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleUpload(scope.$index, scope.row)"
>编辑形象图</el-button
>
<el-button
size="mini"
@click="onUploadBanner(scope.$index, scope.row)"
>编辑轮播图</el-button
>
<!-- 普通门店的关闭开启 -->
<el-button
size="mini"
@click="handleOpenClose(scope.$index, scope.row)"
>{{ getStatusText(scope.row) }}
</el-button>
<!-- 进销存门店的关闭开启 -->
<el-button
size="mini"
@click="handleSaleOpenClose(scope.$index, scope.row)"
>{{ getSaleStatusText(scope.row) }}
</el-button>
</template>
</el-table-column>
<script>
import { Loading } from "element-ui";
import {
postStoreOpenClose, //普通门店的开启关闭
} from "api/request";
export default {
data() {
return {
};
},
mounted() {
},
methods: {
handleOpenClose(index, row) {
var newStatus;
if (row.status == "2") newStatus = "1";
if (row.status == "1") newStatus = "2";
let param = {
id: row.id,
status: newStatus
};
loadingInstance(Loading);
postStoreOpenClose(param).then(res => {
loadingInstance(Loading).close();
if (res.status === ERR_OK) {
this._getList();
} else {
Error(this, res);
}
});
},
// 普通门店的关闭开启
getStatusText(row) {
if (row.status == "2") return "开启";
if (row.status == "1") return "关闭";
return "";
},
}
}
</script>
request.js
/********************门店--------------开启 或 关闭****************/
export function postStoreOpenClose(parameter) {
const url = PUBLIC_URL + "store/openCloseStore";
return axios
.post(url, parameter, {
headers: {
"Content-Type": "application/json;charset=utf-8",
token: window.localStorage.getItem("token")
}
})
.then(res => {
return Promise.resolve(res.data);
});
}
上面的是,用的post发的请求,下面我们再看一个用get请求发送的,这里的get请求发送参数是携带在路径上面的。
接口和需要传的参数要看清楚(要不就会报错)
代码:
pageList.vue
<el-table-column label="操作" width="500">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleUpload(scope.$index, scope.row)"
>编辑形象图</el-button
>
<el-button
size="mini"
@click="onUploadBanner(scope.$index, scope.row)"
>编辑轮播图</el-button
>
<!-- 普通门店的关闭开启 -->
<el-button
size="mini"
@click="handleOpenClose(scope.$index, scope.row)"
>{{ getStatusText(scope.row) }}
</el-button>
<!-- 进销存门店的关闭开启 -->
<el-button
size="mini"
@click="handleSaleOpenClose(scope.$index, scope.row)"
>{{ getSaleStatusText(scope.row) }}
</el-button>
</template>
</el-table-column>
<script>
import { Loading } from "element-ui";
import {
postStoreOpenClose, //普通门店的开启关闭
} from "api/request";
export default {
data() {
return {
};
},
mounted() {
},
methods: {
// 进销存门店的关闭开启
handleSaleOpenClose(index, row) {
var isErp;
if (row.isErp == "1") isErp = "0";
if (row.isErp == "0") isErp = "1";
let param = {
storeId: row.id,
isErp: isErp
};
loadingInstance(Loading);
postSaleStoreOpenClose(param).then(res => {
loadingInstance(Loading).close();
if (res.status === ERR_OK) {
this._getList();
} else {
Error(this, res);
}
});
},
// 进销存门店的关闭开启
getSaleStatusText(row) {
if (row.isErp == "1") return "开启进销存门店";
if (row.isErp == "0") return "关闭进销存门店";
return "";
},
}
}
</script>
request.js
/********************进销存门店--------------开启 或 关闭****************/
export function postSaleStoreOpenClose(parameter) {
const url = PUBLIC_URL + "store/updateIsErp?" +qs.stringify(parameter);
return axios
.get(url, {
parameter,
headers: {
"Content-Type": "application/json;charset=utf-8",
token: window.localStorage.getItem("token")
}
})
.then(res => {
return Promise.resolve(res.data);
});
}