123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- <template>
- <div>
- <Toptitle
- :title="
- type == 1 ? '复制' : type == 2 ? '编辑' : type == 3 ? '查看' : '新增'
- "
- >
- <Button type="primary" style="margin-right:5px" ghost @click="back()"
- >取消</Button
- >
- <Button type="primary" v-show="type != 3" @click="handleSaveData"
- >保存</Button
- >
- </Toptitle>
- <div>
- <Row type="flex" justify="space-between" style="padding:10px 0">
- <Col span="4">
- <span>ID:</span>
- <span>
- <Input
- type="text"
- disabled
- style="width:80px"
- v-model="formData.id"
- placeholder="自动生成"
- />
- </span>
- </Col>
- <Col span="12">
- <span>工艺属性分类:</span>
- <span>
- <Select
- filterable
- filter-by-label
- v-model="formData.process_id"
- style="width: 100px;margin-right:5px"
- @on-change="handleProcessSelected"
- >
- <Option
- v-for="(item, index) in basic_process_list"
- :key="index"
- :label="item.title"
- :value="item.id"
- ></Option>
- </Select>
- </span>
- <span>
- <Select
- filterable
- filter-by-label
- @on-change="(e) => handleGetProcessIds(formData.process_id, e)"
- v-model="formData.type_title"
- style="width: 100px;margin-right:5px"
- >
- <Option
- v-for="(item, index) in type_title_list"
- :key="index"
- :label="item"
- :value="item"
- ></Option>
- </Select>
- </span>
- <span>
- <Select
- filterable
- filter-by-label
- multiple
- :max-tag-count="2"
- v-model="formData.process_ids"
- style="width: 300px"
- >
- <Option
- v-for="(item, index) in process_list"
- :key="index"
- :label="item.title"
- :value="item.id"
- ></Option>
- </Select>
- </span>
- </Col>
- <Col span="8">
- <span>部件名称:</span>
- <span>
- <Select
- filterable
- filter-by-label
- v-model="formData.part_id"
- @on-change="handlePartSelected"
- style="width: 200px"
- >
- <Option
- v-for="(item, index) in parts_list"
- :key="index"
- :label="item.title"
- :value="item.id"
- ></Option>
- </Select>
- </span>
- </Col>
- </Row>
- <Row
- type="flex"
- align="bottom"
- justify="space-between"
- style="padding-bottom:5px"
- >
- <Col><span>规则:</span> </Col>
- <Col>
- <Button
- size="small"
- type="primary"
- @click="handleSet({}, tableData.length, 1)"
- >新增规则</Button
- >
- </Col>
- </Row>
- <div>
- <Table
- :columns="tableColumns"
- border
- :max-height="500"
- :data="tableData"
- >
- <template slot="partDetailTitle" slot-scope="{ index }">
- <Select
- v-model="tableData[index].parts_detail_id"
- transfer
- @on-change="
- (e) => handlePartDetailSelected(tableData[index], index, e)
- "
- >
- <Option
- v-for="(item, index) in tableData[index].part_detail_list"
- :key="index"
- :label="item.spare_parts"
- :value="item.id"
- ></Option>
- </Select>
- </template>
- <template slot="measureSlot" slot-scope="{ index }">
- <Select v-model="tableData[index].basics_measure_id" transfer>
- <Option
- v-for="(item, index) in measure_list"
- :key="index"
- :label="item.title"
- :value="item.id"
- ></Option>
- </Select>
- </template>
- <template slot="numSlot" slot-scope="{ index }">
- <Input
- type="text"
- style="width:80px"
- v-model="tableData[index].num"
- />
- </template>
- <template slot="minSlot" slot-scope="{ index }">
- <Input
- type="text"
- style="width:80px"
- v-model="tableData[index].min"
- />
- </template>
- <template slot="maxSlot" slot-scope="{ index }">
- <Input
- type="text"
- style="width:80px"
- v-model="tableData[index].max"
- />
- </template>
- <template slot="materialDetailSlot" slot-scope="{ index }">
- <Select v-model="tableData[index].material_detail_id" transfer>
- <Option
- v-for="(item, index) in tableData[index].materialDetailList"
- :key="index"
- :label="item.materialDetailShow"
- :value="item.id"
- ></Option>
- </Select>
- </template>
- <template slot="setSlot" slot-scope="{ index }">
- <div>
- <a
- style="margin:0 5px;"
- @click="handleSet(tableData[index], index, 2)"
- >复制</a
- >
- <a
- style="margin:0 5px;"
- @click="handleSet(tableData[index], index, 3)"
- >删除</a
- >
- </div>
- </template>
- </Table>
- </div>
- </div>
- </div>
- </template>
- <script>
- // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
- // 例如:import 《组件名称》 from '《组件路径》';
- export default {
- name: "",
- components: {},
- props: {},
- // import引入的组件需要注入到对象中才能使用
- data() {
- // 这里存放数据
- return {
- type: this.$route.query.type,
- id: this.$route.query.id,
- formData: {
- id: this.$route.query.id,
- process_id: "",
- part_id: "",
- type_title: "",
- process_ids: [],
- },
- urlSelectList: [],
- tableColumns: [
- {
- title: "零部件名称",
- align: "center",
- minWidth: 120,
- slot: "partDetailTitle",
- },
- {
- title: "物料名称",
- align: "center",
- minWidth: 100,
- key: "parts_detail_title",
- },
- {
- title: "测量字段",
- align: "center",
- minWidth: 100,
- slot: "measureSlot",
- },
- {
- title: "数量",
- align: "center",
- minWidth: 70,
- key: "num",
- slot: "numSlot",
- },
- {
- title: "最小数值(含)",
- align: "center",
- minWidth: 120,
- slot: "minSlot",
- },
- { title: "最大数值", align: "center", minWidth: 120, slot: "maxSlot" },
- {
- title: "物料规格",
- align: "center",
- minWidth: 100,
- key: "material_detail_id",
- slot: "materialDetailSlot",
- },
- { title: "操作", align: "center", minWidth: 120, slot: "setSlot" },
- ],
- tableData: [{}],
- basic_process_list: [], //工艺属性分类
- parts_list: [],
- type_title_list: [],
- process_list: [],
- measure_list: [],
- };
- },
- // 生命周期 - 创建完成(可以访问当前this实例)
- created() {
- this.axios.get("/api/basics_properties_index").then((res) => {
- this.basic_process_list = res.data.data;
- });
- this.axios.get("/api/parts_index").then((res) => {
- this.parts_list = res.data.data;
- });
- this.axios.get("/api/basics_measure_index").then((res) => {
- this.measure_list = res.data.data;
- });
- },
- // 生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- this.id && this.initData(this.id);
- },
- methods: {
- back() {
- this.$router.go(-1);
- },
- handleSet(row, index, type) {
- if (!this.formData.part_id) {
- return this.$Message.warning("请先选择部件");
- }
- row.part_detail_list = JSON.parse(JSON.stringify(this.part_detail_list));
- row.part_id = this.formData.part_id;
- const obj = JSON.parse(JSON.stringify(row));
- switch (type) {
- case 1:
- case 2:
- this.tableData.splice(index, 0, obj);
- break;
- case 3:
- this.tableData.splice(index, 1);
- break;
- }
- },
- initData(id) {
- this.axios
- .get("/api/process_part_detail", { params: { id } })
- .then((res) => {
- this.formData = res.data.detail;
- this.formData.process_id = this.formData.bp_id;
- this.tableData = res.data.list;
- this.handleProcessSelected(res.data.detail.process_id);
- this.handleGetProcessIds(
- res.data.detail.process_id,
- res.data.detail.type_title
- );
- this.handlePartSelected(this.formData.part_id, 2);
- });
- },
- handleProcessSelected(p_id) {
- p_id &&
- this.axios.post("/api/process_sub_title", { p_id }).then((res) => {
- this.type_title_list = res.data;
- });
- },
- handleGetProcessIds(p_id, type_title) {
- this.axios
- .get("/api/properties_index", { params: { p_id, type_title } })
- .then((res) => {
- this.process_list = res.data.data;
- });
- },
- handlePartSelected(id, type) {
- id &&
- this.axios.get("/api/parts_detail", { params: { id } }).then((res) => {
- this.part_detail_list = res.data.detail;
- if (type == 2) {
- this.tableData.map((v, k) => {
- v.part_detail_list = JSON.parse(
- JSON.stringify(this.part_detail_list)
- );
- this.handlePartDetailSelected(v, k, v.parts_detail_id);
- });
- } else {
- this.tableData = [];
- }
- this.tableData = JSON.parse(JSON.stringify(this.tableData));
- });
- },
- handlePartDetailSelected(row, index, id) {
- if (id) {
- const material_id = row.part_detail_list.filter((v) => v.id == id)[0]
- .material_id;
- this.axios
- .get("/api/material", { params: { id: material_id } })
- .then((res) => {
- this.tableData[index].parts_detail_title = res.data[0].title;
- this.tableData[index].materialDetailList = res.data[0].detail.map(
- (v) => {
- return { id: v.id, materialDetailShow: v.long + "*" + v.width };
- }
- );
- this.tableData.splice(index, 1, this.tableData[index]);
- });
- }
- },
- handleSaveData() {
- if (this.type == 1) {
- this.formData.id = "";
- }
- this.axios
- .post("/api/process_part_edit", {
- ...this.formData,
- detail: this.tableData,
- })
- .then((res) => {
- if (res.code == 200) {
- this.$Message.success(res.msg);
- this.back();
- }
- });
- },
- },
- // 监听属性 类似于data概念
- computed: {},
- // 监控data中的数据变化
- watch: {},
- beforeCreate() {}, // 生命周期 - 创建之前
- beforeMount() {}, // 生命周期 - 挂载之前
- beforeUpdate() {}, // 生命周期 - 更新之前
- updated() {}, // 生命周期 - 更新之后
- beforeDestroy() {}, // 生命周期 - 销毁之前
- destroyed() {}, // 生命周期 - 销毁完成
- activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang="scss" scoped></style>
|