index.vue 4.8 KB
<template>
  <d2-container>
    <div class="promotion">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="晋升/降级配置" name="first">
          <div class="sub-promotion">
            <el-tabs v-model="subActiveName" type="card" @tab-click="handleSubClick">
              <el-tab-pane v-for="(item, index) in tabList" :key="index" :label="item.label" :name="item.name"></el-tab-pane>
            </el-tabs>
          </div>
        </el-tab-pane>
        <el-tab-pane label="" name="second"></el-tab-pane>
      </el-tabs>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
        <el-form-item label="职级介绍:" prop="rankIntroduction">
          <TextBox ref="rankIntroduction" class="editor-box" id="rankIntroduction" :excludeMenus="['code', 'video', 'table', 'justify', 'todo', 'splitLine']" @change="(e) => handleTextBoxChange(e, 'rankIntroduction')" @focus="handleTextBoxFocus('rankIntroduction')" :boxHeight="120"></TextBox>
        </el-form-item>
        <el-form-item label="晋升介绍:" prop="promotionIntroduction">
          <TextBox ref="promotionIntroduction" class="editor-box" id="promotionIntroduction" :excludeMenus="['code', 'video', 'table', 'justify', 'todo', 'splitLine']" @change="(e) => handleTextBoxChange(e, 'promotionIntroduction')" :boxHeight="120"></TextBox>
        </el-form-item>
        <el-form-item label="降级介绍:" prop="downgradeIntroduction">
          <TextBox ref="downgradeIntroduction" class="editor-box" id="downgradeIntroduction" :excludeMenus="['code', 'video', 'table', 'justify', 'todo', 'splitLine']" @change="(e) => handleTextBoxChange(e, 'downgradeIntroduction')" :boxHeight="120"></TextBox>
        </el-form-item>
      </el-form>
      <div class="btn">
        <el-button type="primary" @click="submit">保存</el-button>
      </div>
    </div>
  </d2-container>
</template>

<script>
import TextBox from './TextBox.vue';
import { getRankConfig, addRankConfig } from "@api/resident"
export default {
  components: {
    TextBox
  },
  data() {
    return {
      activeName: 'first',
      subActiveName: '1',
      tabList: [
        {
          label: '实习生',
          name: '1'
        },
        {
          label: '见习驻店',
          name: '10'
        },
        {
          label: '初级驻店',
          name: '2'
        },
        {
          label: '中级驻店',
          name: '3'
        },
        {
          label: '高级驻店',
          name: '4'
        }
      ],
      formKey: ['rankIntroduction', 'promotionIntroduction', 'downgradeIntroduction'],
      ruleForm: {
        rankIntroduction: '',
        promotionIntroduction: '',
        downgradeIntroduction: ''
      },
      rules: {
        rankIntroduction: [{ required: true, message: '请输入职级介绍', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getConfig()
  },
  methods: {
    getConfig() {
      getRankConfig({jobType: this.subActiveName}).then(res => {
        // this.ruleForm = res
        if (res) {
          this.formKey.forEach(i => {
            this.ruleForm[i] = res[i]
            this.$refs[i].setEdit(res[i])
          })
          if (res.id) this.ruleForm.id = res.id
        } else {
          console.log('121321');
          this.formKey.forEach(i => {
            this.ruleForm[i] = ''
            this.$refs[i].setEdit('')
            if (this.ruleForm.id) delete this.ruleForm.id
          })
        }
      })
    },
    handleTextBoxChange(val, key) {
      console.log(val, key)
      this.ruleForm[key] = val
    },
    handleTextBoxFocus(key) {
      console.log(key, 'focus');
      // this.$refs.TextBox.setEdit(this.formData.content)
    },
    handleClick(tab) {
    },
    handleSubClick(tab) {
      this.subActiveName = tab.name
      console.log(this.subActiveName);
      this.$refs.ruleForm.resetFields()
      this.getConfig()
    },
    submit() {
      console.log(this.ruleForm);
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          addRankConfig({...this.ruleForm, jobType: this.subActiveName}).then(res => {
            if (res) this.$message.success('保存成功')
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.promotion {
  background-color: #fff;
}
.btn {
  width: 100%;
  text-align: center;
  padding-bottom: 20px;
}
</style>
<style lang="scss">
.promotion {
  #tab-first {
    padding-left: 20px !important;
  }

  .el-tabs__nav-wrap {
    line-height: 54px;

    .el-tabs__item {
      font-size: 16px !important;
    }
  }
  .sub-promotion {
    padding: 0 20px;
    .el-tabs__nav-wrap {
      line-height: 40px;

      .el-tabs__item {
        font-size: 14px !important;
      }
    }
  }
}
</style>
<style lang="scss">
.editor-box {
  #div-demo {
    width: calc(100% - 20px);
  }
}
</style>