绑定课程

This commit is contained in:
liuyuan
2025-06-23 17:47:14 +08:00
parent e7669413e6
commit 2c89e36035
6 changed files with 2256 additions and 1 deletions

View File

@@ -0,0 +1,375 @@
<template>
<div>
<el-drawer
:title="`新增关联${title}`"
v-if="drawer"
:wrapperClosable="false"
:visible.sync="drawer"
destroy-on-close
direction="rtl"
:append-to-body="true"
:modal-append-to-body="false"
:modal="!isNoModal"
size="70%"
>
<div class="shop_drawer_box demo-drawer__content">
<div class="addFormBox">
<el-form ref="addForm" label-width="80px" :model="dataForm">
<slot name="searchFormItem" :dataForm="dataForm"></slot>
<el-form-item
label=""
class="form_item"
label-width="20px"
style="width: 160px !important"
>
<el-button
type="primary"
plain
@click="
pageIndex = 1;
getDataList(bookMarketId);
"
size="small"
>查询</el-button
>
<el-button @click="handleReset()" size="small" plain
>重置</el-button
>
</el-form-item>
</el-form>
</div>
<!-- @selection-change="handleSelectionChange" -->
<!-- @current-change="handleCurrentChange" -->
<el-table
ref="table"
height="calc(100% - 120px)"
:data="dataList"
:row-key="getRowKeys"
border
size="mini"
highlight-current-row
v-loading="dataListLoading"
style="width: 100%"
>
<!-- <el-table-column align="center" width="40px">
<template slot-scope="scope">
<el-radio v-model="currentRow" :label="scope.row"
>&nbsp;</el-radio
>
</template>
</el-table-column> -->
<!-- <el-table-column :reserve-selection="true" type="selection" header-align="center" align="center" width="50">
</el-table-column> -->
<slot name="tableItem"></slot>
<el-table-column
header-align="center"
align="center"
label="操作"
width="80"
>
<template slot-scope="scope">
<el-button
type="text"
@click="handleCurrentChange(scope.row)"
size="mini"
>{{CustomOperationText?CustomOperationText:'绑定'}}</el-button
>
</template>
</el-table-column>
<!-- -->
</el-table>
<el-pagination
style="float: right;margin-top: 20px;"
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper"
>
</el-pagination>
<div class="demo-drawer__footer">
<!-- <div style="float: right; margin-top: 20px">
<el-button @click="close" size="small"> </el-button>
<el-button type="primary" @click="submit" :loading="loading" size="small">{{ loading ? "提交中 ..." : "确 定"
}}</el-button>
</div> -->
</div>
<!-- 弹窗, 新增 / 修改 -->
<!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" @showchooseBookf = "showchooseBookf"></add-or-update>
<choose-book v-if="chooseBookVisible" :bookIds = bookIds ref="chooseBook" :chooseBookVisible = chooseBookVisible @closeBookf = "closeBookf"></choose-book> -->
</div>
</el-drawer>
</div>
</template>
<script>
// import chooseBook from './chooseBook.vue'
// import AddOrUpdate from './shopproduct-add-or-update'
export default {
props: [
"defaultForm",
"otherInfo",
"marketIdKey",
"currentType",
"currentId",
"title",
"isNoModal",
"urlList",
"CustomOperationText",
],
data() {
return {
timer: null,
drawer: false,
loading: false,
currentRow: null,
multipleSelectionAll: [], // 所有选中的数据包含跨页数据
multipleSelection: [], // 当前页选中的数据
idKey: "productId", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
dataForm: {},
bookMarketId: null,
dataList: [],
publishStatus: false,
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
chooseBookVisible: false,
bookIds: [],
goodsTypeList: []
};
},
components: {
// AddOrUpdate,
// chooseBook
},
activated() {
this.getDataList();
},
methods: {
handleReset() {
this.dataForm = {};
this.pageIndex = 1;
this.getDataList();
},
submit() {
var ids = this.multipleSelection.map(e => e.productId).toString(",");
this.$emit("submit", ids);
console.log(
"🚀 ~ submit ~ this.multipleSelection:",
this.multipleSelection
);
},
// 获取商品类型
getGoodsTypeList() {
this.$http({
url: this.$http.adornUrl("/book/sysdictdata/selectByType/goodsType"),
method: "get"
}).then(({ data }) => {
this.goodsTypeList = data.dataList;
});
},
handleClose(done) {
done();
},
handleCurrentChange(val) {
this.$emit("submit", val.id,val);
// table组件选中事件,记得加上@selection-change="handleSelectionChange"
// this.multipleSelection = val;
// this.changePageCoreRecordData();
},
async open() {
this.drawer = true;
this.dataForm = {};
this.pageIndex = 1;
await this.getGoodsTypeList();
await this.getDataList();
},
close() {
this.drawer = false;
},
getRowKeys(row) {
return row.productId;
},
handleSelectionChange(val) {
console.log("🚀 ~ handleSelectionChange ~ val:", val);
// table组件选中事件,记得加上@selection-change="handleSelectionChange"
this.multipleSelection = val;
// this.changePageCoreRecordData();
},
closeBookf() {
this.chooseBookVisible = false;
},
showchooseBookf(e) {
// 显示图书列表
this.chooseBookVisible = true;
},
// 获取数据列表
async getDataList() {
var form = {
...this.defaultForm,
current: this.pageIndex,
limit: this.pageSize
};
this.dataListLoading = true;
this.clear();
form.page = this.pageIndex;
form.current = this.pageIndex;
this.$http
.request({
url: this.$http.adornUrl(`${this.urlList.CanBindProductList}`),
method: "POST",
data: {
...form
},
header: {
//默认 无 说明:请求头
"Content-Type": "application/json"
}
})
.then(({ data }) => {
console.log('data at line 263:', data)
if (data && data.code === 0) {
this.dataList = [...data.page[this.otherInfo.httpDataValueName]];
this.totalPage = data.page[this.otherInfo.httpDataTotalName];
} else {
this.dataList = [];
this.totalPage = 0;
}
// setTimeout(async () => {
// await this.setSelectRow();
// }, 200);
this.dataListLoading = false;
});
},
clear() {
// this.$refs.table.clearSelection();
this.multipleSelection = [];
},
// 每页数
sizeChangeHandle(val) {
// this.changePageCoreRecordData();
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
// 当前页
currentChangeHandle(val) {
// 改变页的时候调用一次
// this.changePageCoreRecordData();
this.pageIndex = val;
this.getDataList();
},
// 多选
selectionChangeHandle(val) {
this.dataListSelections = val;
},
// 新增 / 修改
addOrUpdateHandle(id) {
this.addOrUpdateVisible = true;
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id);
});
},
// 删除
deleteHandle(id) {
var ids = id
? [id]
: this.dataListSelections.map(item => {
return item.productId;
});
this.$confirm(
`确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}
).then(() => {
this.$http({
url: this.$http.adornUrl("/book/shopproduct/delete"),
method: "post",
data: this.$http.adornData(ids, false)
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.getDataList();
}
});
} else {
this.$message.error(data.msg);
}
});
});
},
SwitchChange(event) {
/*点击时他会自动把你绑定的值变更,直接去请求数据就可以了*/
var parms = {
publishStatus: event.publishStatus,
productId: event.productId
};
// console.log(parms)
this.$http({
url: this.$http.adornUrl("/book/shopproduct/update"),
method: "post",
data: parms
})
.then(res => {
this.$message({
message: "成功",
type: "success"
});
this.loading = false;
this.getDataList();
})
.catch(error => {
this.loading = false;
console.log(error);
});
console.log(event);
}
}
};
</script>
<style lang="less" scoped>
.shop_drawer_box {
padding: 20px !important;
padding-top: 0px !important;
box-sizing: border-box;
width: 100%;
height: 100%;
}
.addFormBox {
width: 100%;
// overflow: hidden;
.form_item {
width: 33%;
float: left;
}
}
::v-deep.el-drawer__header {
margin-bottom: 10px !important;
}
</style>