quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<template>
  <!--
        作者:luoyiming
        时间:2019-10-25
        描述:商品-添加
    -->
  <el-dialog :title="title" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false">
    <!--添加消息模板-->
    <div class="common-level-rail">
      <el-button size="small" type="primary" @click="addClick">添加字段</el-button>
    </div>
    <el-form size="small">
      <div class="table-wrap">
        <el-table border :data="fieldData" v-loading="loading">
          <el-table-column label="字段名称" width="120px">
            <template slot-scope="scope">
              <el-input size="small" prop="field_name" v-model="scope.row.field_name"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="字段英文名" width="130px">
            <template slot-scope="scope">
              <el-input size="small" prop="field_ename" v-model="scope.row.field_ename"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="字段默认值">
            <template slot-scope="scope">
              <el-input size="small" prop="filed_value" v-model="scope.row.filed_value"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="是否变量" width="70px">
            <template slot-scope="scope">
              <el-checkbox prop="is_var" :checked="scope.row.is_var === 1" @change="checked=>checkRow(checked, scope.row)"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column label="排序" width="70px">
            <template slot-scope="scope">
              <el-input size="small" prop="sort" v-model="scope.row.sort"></el-input>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="70px">
            <template slot-scope="scope">
              <el-button @click="deleteClick(scope.$index)" type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="saveField" :loading="loading">确 定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
  import MessageApi from '@/api/message.js';
  export default {
    data() {
      return {
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        dialogVisible: false,
        title: '字段管理',
        fieldData: [],
        deleteIds: [],
        loading: true,
      };
    },
    props: ['open_field', 'form'],
    created() {
      this.dialogVisible = this.open_field;
      this.title = this.title + '(' + this.form.message_name + ')';
      /*获取字段列表*/
      this.getFieldList();
    },
    methods: {
      /*获取字段列表*/
      getFieldList: function() {
        let self = this;
        MessageApi.fieldList({
            message_id: self.form.message_id
          }, true)
          .then(data => {
            self.loading = false;
            self.fieldData = data.data.list;
          })
          .catch(error => {
            self.loading = false;
          });
      },
      /*修改插件*/
      saveField: function() {
        let self = this;
        MessageApi.saveField({
            message_id: self.form.message_id,
            fieldData: self.fieldData,
            deleteIds: self.deleteIds
          }, true)
          .then(data => {
            self.$message({
              message: '恭喜你,修改成功',
              type: 'success'
            });
            self.dialogFormVisible(true);
          })
          .catch(error => {
 
          });
      },
      /*添加字段*/
      addClick: function() {
        this.fieldData.push({
          message_field_id: 0,
          message_id: this.form.message_id,
          field_name: '',
          field_ename: '',
          filed_value: '',
          sort: 100
        });
      },
      deleteClick: function($index) {
        let field = this.fieldData[$index];
        if (field.message_field_id > 0) {
          this.deleteIds.push(field.message_field_id);
        }
        this.fieldData.splice($index, 1);
      },
      checkRow: function(checked, row) {
        row.is_var = checked ? 1 : 0;
      },
      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }
    }
  };
</script>
 
<style></style>