ludc
2023-09-13 4a2835ddadb796c69f180097b95f971dbab4687d
Source/UBCS-WEB/src/components/code-dialog-page/cloneRuleDialog.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,223 @@
<template>
  <el-dialog
      :close-on-click-modal="false"
      :visible.sync="cloneSettingBox"
      append-to-body
      class="avue-dialog avue-dialog--top"
      style="height: 100vh"
      title="克隆编码规则"
      top="-3%"
      @close="closeCloneDialog"
      width="800px">
      <div>
        <el-row>
          <el-form ref="form" :inline="true" :model="form" label-width="80px">
            <el-form-item label="编号" required>
              <el-input v-model="cloneCodeRuleForm.id"></el-input>
            </el-form-item>
            <el-form-item label="名称" required>
              <el-input v-model="cloneCodeRuleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="依据" required>
              <el-input v-model="cloneCodeRuleForm.accordingTo"></el-input>
            </el-form-item>
            <el-form-item class="clone-input-textarea" label="描述">
              <el-input
                v-model="cloneCodeRuleForm.description"
                :autosize="{ minRows: 3, maxRows: 5 }"
                type="textarea"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-row>
        <el-row>
          <p
            style="
              margin: 0 0px 16px 50%;
              font-weight: 500;
              font-size: 20px;
              color: #000;">
            ç æ®µç®¡ç†
          </p>
          <avue-crud
            :data="cloneData"
            :option="cloneOption"
            :table-loading="cloneTableLoading"
            class="clone-avue-crud">
            <template slot="menu" slot-scope="scope">
              <el-button
                v-show="scope.row.orderNum > 1"
                icon="el-icon-arrow-up"
                plain
                size="small"
                type="text"
                @click="upOrderNum(scope.row)"
                >上移
              </el-button>
              <el-button
                icon="el-icon-arrow-down"
                plain
                size="small"
                type="text"
                @click="downOrderNum(scope.row)"
                >下移
              </el-button>
            </template>
          </avue-crud>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveCloneCodeRule" :loading="cloneCodeRuleLoading">保 å­˜</el-button>
        <el-button @click="cloneSettingBox = false">取 æ¶ˆ</el-button>
      </div>
  </el-dialog>
</template>
<script>
import cloneOption from "@/const/code/cloneOption";
import {clone} from "@/api/code/mdmrule";
import {downOrderNum, upOrderNum, gridCodeBasicSec} from "@/api/code/codebasic";
export default {
    name: "cloneRuleDialog",
    props: {
        // å¯¹è¯æ¡†æ˜¾ç¤ºéšè—æŽ§åˆ¶
        visible: {
            type: "Boolean",
            default: false,
        },
        ruleData:{
            type: "Object",
        }
    },
    data() {
        return {
            cloneSettingBox: this.visible,
            /*克隆编码规则对话框控制变量*/
            cloneTableLoading: false,
            cloneCodeRuleLoading: false,
            cloneOption: cloneOption,
            cloneData: [],
            cloneCodeRuleForm: {
                id: "",
                name: "",
                accordingTo: "",
                description: "",
            },
        };
    },
    watch: {
        // ç›‘听父组件传的窗口显示隐藏的值,以及值的回填
        visible() {
            //console.log(this.visible);
            if(this.visible){
                this.loadBasic(this.ruleData);
                this.cloneCodeRuleForm.id = this.ruleData.id;
                this.cloneCodeRuleForm.name = this.ruleData.name;
                this.cloneCodeRuleForm.accordingTo = this.ruleData.accordingTo;
                this.cloneCodeRuleForm.description = this.ruleData.description;
            }
            this.cloneSettingBox = this.visible;
        },
    },
    methods: {
        //关闭对话框
        closeCloneDialog(){
            this.$emit('update:visible',false);
            this.cloneData = [];
        },
        /** ä¸Šç§»ä¸‹ç§»åŸºç¡€ç æ®µ*/
        async upOrderNum(row) {
            if (this.ruleData.lcStatus != "Editing") {
                this.$message.warning(
                "只有编码规则的状态是 [编辑中] çš„æ—¶å€™ï¼Œæ‰èƒ½è°ƒæ•´ç æ®µé¡ºåº!"
                );
                return;
            }
            if (row.oid == null || row.oid == "") {
                this.$message.warning("未获取到必填参数!");
                return;
            }
            await upOrderNum(row.oid).then(() => {
                this.loadBasic(this.ruleData);
                this.$message({
                type: "success",
                message: "操作成功!",
                });
            });
        },
        downOrderNum(row) {
            let codeRuleOid = this.ruleData.oid;
            if (this.ruleData.lcStatus != "Editing") {
                this.$message.warning(
                "只有编码规则的状态是 [编辑中] çš„æ—¶å€™ï¼Œæ‰èƒ½è°ƒæ•´ç æ®µé¡ºåº!"
                );
                return;
            }
            if (row.oid == null || row.oid == "") {
                this.$message.warning("未获取到必填参数!");
                return;
            }
            downOrderNum(row.oid).then(() => {
                this.loadBasic({ oid: codeRuleOid });
                this.$message({
                type: "success",
                message: "操作成功!",
                });
            });
        },
        /** ç‚¹å‡»è§¦å‘加载基础码段信息*/
        loadBasic(row) {
            this.cloneTableLoading = true;
            if (row != "" || row != null) {
                let conditionMap = {};
                conditionMap["conditionMap[pkCodeRule]"] = row.oid.trim();
                gridCodeBasicSec(1, -1, conditionMap).then((res) => {
                    const data = res.data.data;
                    this.cloneData = data.records;
                    this.cloneTableLoading = false;
                });
            }
        },
         /** å…‹éš†ç¼–码规则保存功能*/
        saveCloneCodeRule() {
            this.cloneCodeRuleLoading = true;
            let form = this.cloneCodeRuleForm;
            if (form.id.trim() == "") {
                this.$message.warning("编号不能为空!");
                return;
            }
            if (form.name.trim() == "") {
                this.$message.warning("码值不能为空!");
                return;
            }
            let data = Object.assign({}, form, {
                oid: "",
                createTime: new Date().getTime(),
                ts: new Date(this.ruleData.ts).getTime(),
                lcStatus: "Editing",
                elements: this.cloneData,
            });
            // console.log(data);
            this.cloneCodeRuleLoading = true;
            clone(data).then(() => {
                this.cloneSettingBox = false;
                // è°ƒç”¨çˆ¶ç»„件方法重新加载码段表
                this.$emit('refreshRuleTable',{"currentPage":1,"pageSize":10});
                this.$message({
                    type: "success",
                    message: "操作成功!",
                });
            },
            (error) => {
                window.console.log(error);
            });
        },
    }
}
</script>
<style>
</style>