123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="title"
- :center="true"
- align="left"
- top="25vh"
- width="600px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- append-to-body
- @close="closeModel"
- >
- <el-card style="margin-top: -20px">
- <el-row>
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- is_show-icon
- :rules="rulesThis"
- label-width="100px"
- class="demo-ruleForm"
- >
- <el-form-item label="分类名称:" prop="className">
- <el-input
- v-model="ruleForm.className"
- :disabled="isDetail"
- placeholder="请输入分类名称"
- />
- </el-form-item>
- </el-form>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-button v-if="!isDetail" type="primary" @click="submitForm">
- 保 存
- </el-button>
- <el-button @click="showModelThis = false">{{
- isDetail ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/purchaseIn/goodsClass";
- import btnList from "@/assets/js/btnList";
- import resToken from "@/mixins/resToken";
- export default {
- mixins: [resToken],
- props: [
- "showModel",
- "id",
- "isDetail",
- "pid",
- "level",
- "isAdd",
- "type",
- "formData",
- "goodsName",
- ],
- data() {
- return {
- loading: false,
- showIconModel: false,
- title: "",
- btnList,
- showModelThis: this.showModel,
- ruleForm: {
- className: "", //分类名称
- },
- rulesThis: this.rules,
- rules: {
- className: [
- {
- required: true,
- message: "请输入分类名称",
- trigger: "blur",
- },
- {
- min: 1,
- max: 50,
- message: "长度在 1 到 50 个字符",
- trigger: "blur",
- },
- ],
- },
- };
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.$emit("cancel");
- }
- },
- },
- methods: {
- closeModel() {
- console.log("closeModel!!");
- },
- async initForm() {
- if (this.isAdd) {
- this.title = "添加商品分类";
- this.loading = false;
- this.rulesThis = this.rules;
- } else {
- if (this.isDetail) {
- this.title = "商品分类详情";
- this.rulesThis = {};
- } else {
- this.title = "修改商品分类";
- this.rulesThis = this.rules;
- }
- }
- await this.resetForm();
- },
- async resetForm() {
- this.ruleForm = {
- id: this.id,
- pid: this.pid,
- className: this.goodsName || "", // 名称
- };
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- // 去掉验证信息
- this.$refs.ruleForm.clearValidate();
- }
- });
- },
- async submitForm() {
- if (this.loading) {
- return false;
- }
- this.loading = true;
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- let model = {};
- let res = {};
- const { className } = this.ruleForm;
- model = {
- id: this.id,
- pid: this.pid,
- cat_name: className,
- };
- if (this.level === 1) {
- // delete model["pid"];
- // delete model["menuid"];
- // delete model["url"];
- // delete model["action_code"];
- // delete model["status"];
- } else if (this.level === 2) {
- delete model["menuid"];
- delete model["action_code"];
- delete model["status"];
- } else {
- delete model["pid"];
- delete model["img"];
- delete model["is_show"];
- delete model["weight"];
- delete model["route"];
- delete model["is_display"];
- delete model["url"];
- }
- if (this.isAdd) {
- delete model["id"];
- }
- if (this.isAdd) {
- res = await asyncRequest.add(model);
- } else {
- res = await asyncRequest.update(model);
- // if (this.isAdd) {
- // res = await asyncRequest.actionadd(model);
- // } else {
- // res = await asyncRequest.actionedit(model);
- // }
- }
- this.loading = false;
- if (res && res.code === 0) {
- this.ruleForm = {};
- const title = this.isAdd ? "添加成功" : "修改成功";
- this.$notify.success({
- title,
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- let pids = this.pid;
- if (this.id === 0) {
- // 添加组织
- pids = "0";
- }
- this.$emit("refresh", this.id, pids, this.level);
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- } else {
- this.loading = false;
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .g-block {
- display: inline-block;
- padding: 10px 5px;
- text-align: center;
- border: 1px #ccc dashed;
- margin: 1px;
- font-size: 0px;
- cursor: pointer;
- i {
- font-size: 30px;
- line-height: 30px;
- display: block;
- margin: 0 auto;
- width: 30px;
- }
- }
- </style>
|