| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <template>
- <el-card shadow="never" style="min-height: 450px; max-height: 450px; overflow: auto;">
- <el-tabs tab-position="left" style="height: 100%; overflow: auto;" v-model="tabValue" @tab-click="handleClick">
- <el-tab-pane v-for="(item,index) in tabData" :label="item.label" :name="item.value">
- </el-tab-pane>
- <el-table :data="tableData" style="width: 100%" border :ref="'multipleTable_' + tabValue" stripe
- highlight-current-row @select="handleSelectionChange" @select-all="handleAllSelect"
- @current-change="handleCurrentChange">
- <!-- <el-table-column type="index" width="55">
- </el-table-column> -->
- <el-table-column prop="selected_d" label="店铺关联规格" width="90" height="40">
-
- <template #default="{row}">
- <el-checkbox v-model="row.selected_d" size="large" disabled/>
- </template>
- </el-table-column>
- <el-table-column prop="name" label="规格" align="center">
- </el-table-column>
- <!-- <el-table-column prop="packet" label="包装箱" align="center">
- <template #default="{row}">
- <span>{{options[row.box_id]}}</span>
- </template>
- </el-table-column>
- <el-table-column prop="price" label="发货价" align="center" ></el-table-column> -->
- </el-table>
- </el-tabs>
- </el-card>
- <div style="width: 100%;display: flex; align-items: center; justify-content: center; position: fixed; bottom: 6px;">
- <el-button type="primary" @click="onSubmit">立即创建</el-button>
- <el-button @click="cancelDialog">取消</el-button>
- </div>
- </template>
- <script>
- import table from "@components/Table.js";
- export default {
- components: { 'YunTable': table },
- data: {
- extend: {
- index_url: 'general/category/index',
- },
- row: Yunqi.data.row,
- tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
- tableData: [],
- value: "",
- form: {
- nameValue: null,
- },
- options: Yunqi.data.packingList,//品种
- tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
- chooseSpec: [], // 当前分类选中的规格
- allData: {},
- type: 0, // 1编辑 0新增,
- shop_allData: []
- },
- methods: {
- onSubmit() {
- if (this.allData == "") return;
- let arr = Object.values(this.allData).flat(Infinity)
- Yunqi.ajax.post('goods/import_list/specs', { ids: Yunqi.data.row.id, all_data: arr }, false, false, true).then(res => {
- // console.log(res)
- if (res.code == 200) {
- this.$message.success(__('设置成功'));
- //倒计时刷新窗口
- setTimeout(() => {
- Yunqi.api.closelayer(Yunqi.app.window.id, true);
- }, 1000);
- } else {
- Yunqi.alert(__('请选择规格'), __('温馨提示'), { type: 'error' });
- }
- });
- },
- handleAllSelect(e) {
- this.allData[this.tabValue] = e || []
- },
- handleCurrentChange(e) {
- this.allData[this.tabValue] = e || []
- },
- handleSelectionChange(e) {
- console.log(this.allData, "=====this.allData")
- },
- handleClick(data, row) {
- // 品种切换事件 可以在这里请求规格接口
- this.tabValue = data.props.name
- this.tabName = data.props.label
- this.tableData = [];
- this.getSpecData()
- },
- cancelDialog: function () {
- Yunqi.api.closelayer(Yunqi.app.window.id, true);
- },
- getSpecData() {
- //获取规格 ;
- Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
- //编辑数据
- if (res.length > 0) {
- for (var key in Object(res)) {
- let index = this.tableData.findIndex(item => item.id == res[key]['id']);
- const isExist = this.shop_allData.includes(res[key]['id'])
- if (index != -1) {
- this.tableData.splice(index, 1)
- } else {
- this.tableData.push({ name: res[key]['title'], id: res[key]['id'], type_id: this.tabValue, selected_d: isExist });
- }
- }
- // this.$nextTick(() => {
- // const tableRef = this.$refs['multipleTable_' + this.tabValue];
- // if (this.type == 0 && this.allData[this.tabValue]?.length > 0 && tableRef) {
- // this.tableData.forEach((item, index) => {
- // const matched = this.allData[this.tabValue].find(row => {
- // return row.id == item.id
- // });
- // if (matched) {
- // this.tableData[index] = matched
- // }
- // })
- // this.allData[this.tabValue].forEach(selected => {
- // const matched = this.tableData.find(row => row.id === selected.id);
- // if (matched) {
- // this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
- // }
- // });
- // }
- // else if (this.type == 1 && this.allData[Number(this.tabValue)]) {
- // this.tableData.forEach((item, index) => {
- // const matched = this.allData[Number(this.tabValue)].find(row => {
- // if (row.product_id) {
- // return row.product_id == item.value
- // } else {
- // return row.value == item.value
- // }
- // });
- // if (matched) {
- // // this.tableData[index] = { name: 'kam', value: 3, price: '111', type_id: '4', packet: '3' }
- // if (matched.product_id) {
- // this.tableData[index].name = matched.name
- // this.tableData[index].box_name = matched.box_name
- // this.tableData[index].type_name = matched.type_name
- // this.tableData[index].price = matched.price
- // this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
- // } else {
- // this.tableData[index] = matched
- // }
- // }
- // })
- // this.allData[Number(this.tabValue)].forEach(selected => {
- // const matched = this.tableData.find(row => {
- // if (selected.product_id) {
- // return selected.product_id == row.value
- // } else {
- // return row.value === selected.value
- // }
- // });
- // if (matched) {
- // this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
- // }
- // });
- // console.log(this.allData)
- // }
- // });
- }
- });
- }
- },
- onLoad: function (query) {
- let rows = Yunqi.data.rows;
- if (rows) {
- const grouped = JSON.parse(rows).reduce((acc, item) => {
- const key = item.type_id;
- if (!acc[key]) {
- acc[key] = [];
- }
- acc[key].push(item);
- return acc;
- }, {});
- this.shop_allData = JSON.parse(JSON.stringify(grouped))
- let arr = Object.values(this.shop_allData).flat(Infinity)
- let acc = [];
- for (var key in Object(arr)) {
- acc[key] = Number(arr[key]['value']);
- }
- this.shop_allData = acc;
- }
- //你只需要保存规格是吧, 是你末尾加了个row
- this.getSpecData()
- },
- }
- </script>
- <style>
- .el-table_1_column_1{
- padding: 0px !important;
- }
- .el-checkbox__input.is-checked .el-checkbox__inner {
- background-color: var(--el-checkbox-checked-bg-color) !important;
- border-color: var(--el-checkbox-checked-input-border-color) !important;
- }
- </style>
|