123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <script>
- import {
- add,
- bindList,
- removeBind,
- removeAllBind,
- classifyTree,
- } from "@/api/material/label";
- export default {
- name: "BindDialog",
- data() {
- const initDict = {
- labelType: [
- { label: "类别", value: 1 },
- { label: "标签", value: 2 },
- ],
- parentId: [],
- };
- const initColumns = () => [
- {
- type: "text",
- prop: "materialCode",
- label: "物料编码",
- required: true,
- showOverflowTooltip: true,
- },
- {
- type: "select",
- prop: "materialName",
- label: "物料名称",
- required: true,
- showOverflowTooltip: true,
- },
- {
- type: "text",
- prop: "materialClassifyId",
- label: "物料分类",
- required: false,
- showOverflowTooltip: true,
- },
- {
- type: "text",
- prop: "materialState",
- label: "物料状态",
- required: false,
- showOverflowTooltip: true,
- },
- {
- type: "text",
- prop: "createTime",
- label: "创建时间",
- required: false,
- showOverflowTooltip: true,
- },
- {
- type: "text",
- prop: "bindTime",
- label: "绑定时间",
- required: false,
- showOverflowTooltip: true,
- },
- ];
- const initForm = () => {
- let form = {};
- initColumns().forEach((item) => (form[item.prop] = ""));
- return form;
- };
- return {
- loading: false,
- dialogFormVisible: false,
- autoInnerVisible: false,
- handInnerVisible: false,
- form: initForm(),
- columns: initColumns(),
- tableData: [],
- page: { pageNum: 1, pageSize: 25, total: 0 },
- dict: initDict,
- filterText: "",
- options: [],
- innerForm: {},
- };
- },
- methods: {
- async fetchList(prop) {
- this.loading = true;
- let { pageNum, pageSize } = this.page;
- await bindList({ ...prop, pageNum, pageSize })
- .then((res) => {
- this.tableData = res.rows;
- })
- .finally(() => {
- this.loading = false;
- });
- },
- async fetchItem(prop) {
- // console.log(prop);
- // return;
- this.dialogFormVisible = true;
- this.form = { ...this.form, ...prop };
- await this.fetchList({ labelId: this.form.id });
- },
- async fetchClassifyTree() {
- let data = await classifyTree();
- this.options = data;
- },
- onAutoBindLabel(prop) {
- this.$parent.$children
- .find((el) => el.$vnode.tag.indexOf("AutoBindDialog") > -1)
- .fetchItem(prop);
- },
- onHandBindLabel(prop) {
- this.$parent.$children
- .find((el) => el.$vnode.tag.indexOf("HandBindDialog") > -1)
- .fetchItem(prop);
- },
- async onUnbind(prop) {
- const { materialId: id } = prop;
- await removeBind({ id });
- await this.fetchList({ labelId: this.form.id });
- },
- async onAllUnbind(prop) {
- const { id } = prop;
- await removeAllBind({ id });
- await this.fetchList({ labelId: id });
- },
- onSubmit(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.loading = true;
- if (this.form.labelType === 1) this.form.parentId = 0;
- add(this.form)
- .then((res) => {
- let { code } = res;
- if (code === 200) {
- this.dialogFormVisible = false;
- this.$message.success("success");
- this.$parent.$children[0].fetchList();
- this.form = {};
- }
- })
- .finally(() => {
- this.loading = false;
- });
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- created() {},
- };
- </script>
- <template>
- <el-dialog destroy-on-close title="绑定" :visible.sync="dialogFormVisible">
- <el-button :disabled="loading" @click="onAutoBindLabel(form)">
- 自动绑定
- </el-button>
- <el-button :disabled="loading" @click="onHandBindLabel(form)">
- 手动绑定
- </el-button>
- <el-button :disabled="loading" @click="onAllUnbind(form)">
- 全部解绑
- </el-button>
- <el-table
- v-loading="loading"
- lazy
- border
- row-key="id"
- :data="tableData"
- style="margin-top: 16px"
- >
- <el-table-column
- v-for="column in columns"
- :key="column.prop"
- :prop="column.prop"
- :label="column.label"
- :show-overflow-tooltip="column.showOverflowTooltip"
- >
- </el-table-column>
- <el-table-column fixed="right" label="操作" width="225">
- <template slot-scope="scope">
- <el-button @click.native.prevent="onUnbind(scope.row)" size="small">
- 解绑
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <div slot="footer" class="dialog-footer">
- <el-button :disabled="loading" @click="dialogFormVisible = false"
- >取 消</el-button
- >
- <el-button type="primary" :disabled="loading" @click="onSubmit('addForm')"
- >确 定</el-button
- >
- </div>
- </el-dialog>
- </template>
- <style scoped></style>
|