| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <template>
- <div class="infrastructures">
- <div class="til">
- <p>项目表单设置</p>
- <div style="display: flex;">
- <p style="cursor:pointer;margin-left: 30px;color: #20A0FF;" @click="addJa('添加表单字段', 'ruleForm')"><i class="el-icon-circle-plus-outline"></i>添加</p>
- </div>
- </div>
- <div class="tabl">
- <el-table :data="dataList" highlight-current-row v-loading="listLoading" :height="heightDoms" style="width: 100%;">
- <el-table-column type="index" label="序号" width="250px">
- <template slot-scope="scope" >
- {{scope.$index + 1}}
- </template>
- </el-table-column>
- <el-table-column prop="customName" label="自定义名称" sortable></el-table-column>
- <el-table-column prop="customType" label="类型" sortable>
- <template slot-scope="scope">
- {{scope.row.customType == '2' ? '日期' : (scope.row.customType == '1' ? '图片' : '文本')}}
- </template>
- </el-table-column>
- <el-table-column label="操作" width="280">
- <template slot-scope="scope">
- <el-button size="mini" type="primary" @click="editor(scope.row, '编辑表单字段')">编辑</el-button>
- <el-button size="mini" type="danger" @click="deteles(scope.row)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <!-- 弹窗 -->
- <el-dialog :title="titleTex" :visible.sync="dialogVisible" width="400px" :before-close="handleClose">
- <div>
- <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
- <el-form-item label="类型">
- <el-radio-group v-model="ruleForm.customType">
- <el-radio-button label="0">文本</el-radio-button>
- <el-radio-button label="1">图片</el-radio-button>
- <el-radio-button label="2">日期</el-radio-button>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="名称" prop="customName">
- <el-input placeholder="请输入自定义名称" v-model.trim="ruleForm.customName" clearable></el-input>
- </el-form-item>
- </el-form>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogVisible = false">取 消</el-button>
- <el-button type="primary" @click="determine('ruleForm')" v-loading="listLoading">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- export default {
- props: {},
- components: {},
- data() {
- return {
- heightDoms: document.documentElement.clientHeight - 130,
- titleTex: '添加表单字段',
- dialogVisible: false,
- ruleForm: {
- id: '',
- companyId: '',
- customName: '',
- customType: '0'
- },
- rules: {customName: [{required: true, message: '请输入自定义名称', trigger: 'blur'}]},
- listLoading: false,
- user: JSON.parse(sessionStorage.getItem("user")),
- dataList: []
- };
- },
- computed: {},
- watch: {},
- created() {},
- mounted() {
- this.getObtain()
- },
- methods: {
- getObtain() {
- this.listLoading = true
- this.http.post('/project-custom/getProjectCustom', this.ruleForm,
- res => {
- this.listLoading = false
- if(res.code == 'ok') {
- this.dataList = res.data
- } else {
- this.$message({
- message: error,
- type: "error"
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- addJa(tex) {
- if(this.dataList.length >= 10) {
- this.$message({
- message: '最多只能存在十个自定义字段',
- type: 'warning'
- });
- return
- }
- if(this.$refs['ruleForm']) {
- this.$refs['ruleForm'].resetFields();
- }
- this.titleTex = tex
- this.ruleForm = {
- id: '',
- companyId: '',
- customName: '',
- customType: '0'
- },
- this.dialogVisible = true
- },
- editor(item, tex) {
- if(this.$refs['ruleForm']) {
- this.$refs['ruleForm'].resetFields();
- }
- this.titleTex = tex
- this.ruleForm = JSON.parse(JSON.stringify(item))
- this.dialogVisible = true
- },
- determine(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.listLoading = true
- this.ruleForm.companyId = this.user.companyId
- this.http.post( '/project-custom/editProjectCustom', this.ruleForm,
- res => {
- this.listLoading = false
- if(res.code == 'ok') {
- this.$message({
- message: this.titleTex == '添加表单字段' ? '添加成功' : '编辑成功',
- type: 'success'
- });
- this.dialogVisible = false
- this.getObtain()
- } else {
- this.$message({
- message: this.titleTex == '添加表单字段' ? '添加失败: ' + res.msg : '编辑失败: ' + res.msg,
- type: 'error'
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- } else {
- console.log('error submit!!');
- return false;
- }
- });
- },
- deteles(item) {
- this.http.post( '/project-custom/delete', {
- id: item.id
- },
- res => {
- if(res.code == 'ok') {
- this.$message({
- message: '删除成功',
- type: 'success'
- });
- this.getObtain()
- } else {
- this.$message({
- message: '删除失败:' + res.msg,
- type: 'error'
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- }
- },
- };
- </script>
- <style scoped lang="scss">
- .infrastructures {
- color: #666;
- .til {
- display: flex;
- justify-content: space-between;
- line-height: 0;
- background: #f2f2f2;
- padding: 10px 25px 10px 25px;
- align-items: center;
- p {
- font-size: 14px;
- i {
- display: inline-block;
- margin-right: 5px;
- }
- }
- }
- .tabl {
- padding-left: 15px;
- box-sizing: border-box;
- }
- }
- </style>
|