| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <template>
- <div>
- <el-form :model="formData" :rules="rules" ref="form" label-width="80px" label-position="right" size="small"
- style="max-width: 500px;">
- <el-form-item prop="market" label="推广人">
- <el-input v-model="formData.market" :disabled="'market'==subColumn"></el-input>
- </el-form-item>
- <el-form-item prop="code" label="推广CODE">
- <el-input v-model="formData.code" :disabled="'code'==subColumn"></el-input>
- </el-form-item>
- <el-form-item prop="typeId" label="类型">
- <template>
- <el-select v-model="formData.typeId" clearable placeholder="请选择" :disabled="'typeId'==subColumn">
- <el-option
- v-for="item in typeIdOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </template>
- </el-form-item>
- <el-form-item prop="remark" label="备注">
- <el-input v-model="formData.remark" :disabled="'remark'==subColumn"></el-input>
- </el-form-item>
- <el-form-item>
- <el-button @click="onSave" :loading="$store.state.fetchingData" type="primary">保存</el-button>
- <el-button @click="onDelete" v-if="formData.id" type="danger">删除</el-button>
- <el-button @click="$router.go(-1)">取消</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <script>
- import formValidator from '../formValidator'
- export default {
- created() {
- if (this.$route.query.column) {
- this.subColumn = this.$route.query.column.split(',')[1];
- this.subValue = this.$route.query.column.split(',')[0];
- }
- if (this.$route.query.id) {
- this.$http.get({
- url: '/marketCode/getOne',
- data: {
- id: this.$route.query.id
- }
- }).then(res => {
- if (res.success) {
-
- this.formData = res.data;
- if (this.$route.query.column) {
- this.formData[this.subColumn] = this.subValue;
- }
- }
- })
- }else {
- if (this.$route.query.column) {
- this.formData[this.subColumn] = this.subValue;
- }
- }
-
- this.$http.get({
- url:'/marketType/all'
- }).then(res => {
- if (res.success) {
- if (res.data.length > 0) {
- res.data.forEach(item => {
- this.typeIdOptions.push({label: item.typeName, value:item.id});
- })
- }
- }
- });
- },
- data() {
- return {
- saving: false,
- formData: {},
- rules: {
- market:
- [
- {required: true, message: '请输入 推广人', trigger: 'blur'},
- ],
- code:
- [
- {required: true, message: '请输入 推广CODE', trigger: 'blur'},
- ],
- typeId:
- [
- {required: true, message: '请输入 类型', trigger: 'blur'},
- ],
- },
- typeIdOptions:[],
- subColumn: '',
- subValue: '',
- }
- },
- methods: {
- onSave() {
- this.$refs.form.validate((valid) => {
- if (valid) {
- this.submit();
- } else {
- return false;
- }
- });
- },
- submit() {
- var data = JSON.parse(JSON.stringify(this.formData));
- this.$http.post({
- url: this.formData.id ? '/marketCode/update' : '/marketCode/save',
- data: data
- }).then(res => {
- if (res.success) {
- this.$message.success('成功');
- this.$router.go(-1);
- } else {
- this.$message.warning('失败')
- }
- });
- },
- onDelete() {
- this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' }).then(() => {
- return this.$http.post({
- url: '/marketCode/del',
- data: { id: this.formData.id }
- })
- }).then(() => {
- this.$message.success('删除成功');
- this.$router.go(-1);
- }).catch(action => {
- if (action === 'cancel') {
- this.$message.info('删除取消');
- } else {
- this.$message.error('删除失败');
- }
- })
- },
- }
- }
- </script>
- <style lang="less" scoped>
- </style>
|