注意修改字段名和请求方法地址
html
```
<el-table-column prop="on_sale" label="是否销售" sortable="custom" :resizable="false" min-width="120">
<template slot-scope="{row}">
<el-switch v-model="row.on_sale" @change="editStatus(row)" :active-value="1" :inactive-value="2"/>
</template>
</el-table-column>
```
js
```
editStatus(row) {
const loading = this.$loading({lock: true});
let params = Object.assign({}, row);
this.$http.post('/product/status', params).then(res => {
loading.close();
if (res.data.code === 0) {
this.$message({type: 'success', message: res.data.msg});
} else {
row.status = !row.status ? 2 : 1;
this.$message.error(res.data.msg);
}
}).catch(e => {
loading.close();
this.$message.error(e.message);
});
},
```
service
```
public function status()
{
$data = request()->param();
// 记录ID
$id = getter($data, "id", 0);
if (!$id) {
return message('记录ID不能为空', false);
}
// 状态
$status = getter($data, "on_sale", 0);
if (!$status) {
return message('记录状态不能为空', false);
}
$error = '';
$item = [
'id' => $id,
'on_sale' => $status
];
$rowId = $this->model->edit($item, $error);
if (!$rowId) {
return message($error, false);
}
return message();
}
```