quanwei
3 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
  <!--
        描述:签约
    -->
  <el-dialog title="上传合同" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false">
   <el-form size="small" :model="form" ref="form"><!-- :rules="rules" -->
 
     <el-form-item label="合同" :label-width="formLabelWidth" prop="mark_manager">
          <!--
          list-type="picture" -->
       <el-upload
          :data="up_data"
          class="upload-demo"
          :action="up_url"
          :before-remove="beforeRemove"
          multiple
          :on-change="tip"
          :limit="7"
          :on-exceed="handleExceed"
          :file-list="fileList">
         <el-button size="small" type="primary">上传合同</el-button>
       </el-upload>
     </el-form-item>
 
     <el-form-item label="已有合同" :label-width="formLabelWidth">
        <div v-for="(item,index) in get_list" :key="index" style="float: left;text-align: center;margin: 3px 5px;">
            <img :src="item.url" style="width: 200px;" />
            <span>{{item.name}}</span>
        </div>
 
     </el-form-item>
 
   </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="editClick()" :loading="loading">确定</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
  import ContractApi from '@/api/contract.js';
 
  export default {
    data() {
      return {
        form: {},
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        dialogVisible: false,
        /*是否正在加载*/
        loading: false,
 
        fileList: [],//上传图片数组
        up_url:'/index.php/admin/admin.upload/contract_upload',
        up_data:{
          id:0,
          name:'',
        },
        contract:[],
        get_list:[1,2],
      };
    },
    props: ['open_contract','curModel'],
    created() {
 
      this.dialogVisible = this.open_contract;
      this.form=this.curModel;
      this.up_data = {
        id:this.form.client_id,
        name:this.form.client_name,
      };
      this.get_contract();
    },
    methods: {
      //获取相应客户下的合同
      get_contract(){
        let self = this;
        self.loading = true;
        ContractApi.getcontract([self.curModel.client_id],true)
        .then(res => {
            //self.contract = res.data.contract.split(';');
            // for(let i=0;i<res.data.contract.length;i++){
            //   self.fileList.push(res.data.contract[i]);
            //   console.log(self.fileList,'sss');
            // }
            //self.contract = res.data.contract;
            console.log(res.data.contract,'res1');
            self.get_list = res.data.contract;
            console.log(self.get_list,'res2');
            self.loading = false;
          })
        .catch(error => {
            self.loading = false;
          });
      },
 
 
      tip(file, fileList){//上传完成后提示
        let self = this;
        if(file.response){
              if(file.response.code == 1){
                //self.fileList.push(file.response.data);
                console.log(file.response.data);
                self.$message({message: '上传成功',type: 'success'});
                self.contract.push({
                        client_id:self.form.client_id,
                        name:file.name.split('.')[0],
                        suffix:file.name.split('.')[1],
                        url:file.response.data,
                  });
                //console.log(self.contract,'*******');
                //debugger;
                //this.form.app_icon = file.response.data;
              }else{
                self.$message({message: '上传失败',type: 'error'});
              }
        }
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 7 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }?`);
      },
 
      /*修改合同*/
      editClick() {
        let self = this;
        let params = this.contract;
        self.$refs.form.validate((valid) => {
          if (valid) {
            console.log(self.contract,'con');
            self.loading = true;
            ContractApi.addcontract(params, true)
            .then(res => {
                self.loading = false;
                self.$message({
                  message: '恭喜你,修改成功',
                  type: 'success'
                });
                self.dialogFormVisible(true);
              })
            .catch(error => {
                self.loading = false;
              });
          }
        });
 
      },
      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }
 
    }
  };
</script>
 
<style></style>