<!-- 回款 -->
<template>
  <div class="context">
    <!-- <div style="text-align: right;margin-bottom: 20px;">
      <el-button type="primary" @click="newrefund = !newrefund">
        新增回款信息
      </el-button> 
    </div> -->
    <div>
      <el-table
        :data="tableData"
        border
        size='small'
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
        style="width: 100%;">
        <el-table-column
        type="index"
        label="序号"
        width="50">
        </el-table-column>
        <el-table-column
        prop="name"
        label="客户名称"
        width="">
        </el-table-column>
        <el-table-column
        prop="xinxi"
        label="回款信息"
        width="120">
        </el-table-column>
        <el-table-column
        prop="jiner"
        label="回款金额"
        width="130">
        </el-table-column>
        <el-table-column
        prop="time"
        label="回款日期"
        width="100">
        </el-table-column>
        <el-table-column
        prop="caozuo"
        label="操作人"
        width="100">
        </el-table-column>
        <!-- <el-table-column
        prop="examine"
        label="审核人"
        width="100">
        </el-table-column> -->
        <el-table-column
        prop="address"
        label="操作"
        width="180">
        <template slot-scope="scope">
          <el-button type="primary" @click="cahkan_click(scope.row)">查看</el-button>
          <!-- <el-button type="danger">删除</el-button> -->
        </template>
        </el-table-column>
    </el-table>
    </div>
    <!-- 弹窗 -->
    <div>
      <!-- 新增 -->
      <el-dialog
        title="新增回款信息"
        :visible.sync="newrefund"
        :modal-append-to-body="false"
        width="60%"
        >
        <div style="height: 50vh;overflow: overlay;">
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>客户名称：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>回款类型：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>回款总金额(元)：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
                <span>软件回款信息(元)：</span>
                <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
              </div>
          </div>

          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>硬件回款信息(元)：</span>
                <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>回款日期：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>回款人员：</span>
                <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
            <div style="flex: 1;">
              <span> 回款凭证<br/>(上传付款回执图片)：</span>
              <el-input v-model="input" placeholder="请输入内容" style="width: 150px;"></el-input>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span style="position: relative;bottom: 20px;left: 0;">
                  备注：
              </span>
              <el-input type="textarea" :row="2" v-model="textarea" placeholder="请输入内容" style="width: 80%;"></el-input>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="newrefund = false">取 消</el-button>
          <el-button type="primary" @click="newrefund = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 查看 -->
      <el-dialog
        title="编辑回款信息"
        :visible.sync="refund"
        :modal-append-to-body="false"
        width="60%"
        >
        <div style="height: 50vh;overflow: overlay;">
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>客户名称：</span>
              <el-input v-model="refundview.name" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>回款类型：</span>
              <el-select v-model="refundview.type" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span>回款总金额(元)：</span>
              <el-input v-model="refundview.totalamount" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
                <span>软件回款信息(元)：</span>
                <el-input v-model="refundview.software" placeholder="请输入内容" style="width: 60%;"></el-input>
              </div>
          </div>

          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>硬件回款信息(元)：</span>
                <el-input v-model="refundview.hardware" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span>回款日期：</span>
              <el-date-picker
                  v-model="refundview.date"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期">
                </el-date-picker>
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
                <span>回款人员：</span>
                <el-input v-model="refundview.role" placeholder="请输入内容" style="width: 60%;"></el-input>
            </div>
            <div style="flex: 1;">
              <span style="display: inline-block;position: relative;top: -68px;"> 回款凭证<br/>(上传付款回执图片)：</span>
              <div style="display: inline-block;">
                <el-image 
                  style="width: 100px; height: 100px"
                  :src="refundview.url" 
                  :preview-src-list="srcList">
                </el-image>
              </div>
                
                <!-- <el-upload
                  :data="uploadData"
                  class="avatar-uploader"
                  action="https://upload.qiniup.com"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess2"
                  :before-upload="beforeAvatarUpload2"
                  style="height: 178px;width: 178px;">
                  
                  <img v-if="refundview.url" :src="refundview.url" class="avatar" style="height: 178px;width: 178px;">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload> -->
            </div>
          </div>
          <div class="xinxi"  style="">
            <div style="flex: 1;">
              <span style="position: relative;bottom: 20px;left: 0;">
                  备注：
              </span>
              <el-input type="textarea" :row="2" v-model="refundview.remark" placeholder="请输入内容" style="width: 80%;"></el-input>
            </div>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="refund = false">取 消</el-button>
          <el-button type="primary" @click="view_click">审核</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import {getFileExtension, uParseTime } from "@/utils/tools";
import {getpaymentcollectionlist,getpaymentcollectionget,getpaymentcollectioncheck} from '../../../api/index'
  export default{
    props:{
      Message:Object
    },
    data(){
      return{
        tableData: [],
        newrefund:false,
        refund:false,
        input:'',
        textarea:'',

        options:[{value:1,label:'首年回款'},{value:2,label:'续费回款'}],
        refundview:{
          name:'',
          type:'',
          totalamount:'',
          software:'',
          hardware:'',
          date:this.getTime(new Date()),
          role:'',
          url:'',
          remark:'',
        },
        srcList:[
        'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
          'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
        ]
      }
    },
    created(){
      this.getlist()
      console.log('Message',this.Message);
    },
    methods:{
      // 查看
      cahkan_click(row){
        this.refund = true
        this.editor_id = row.id
       
        getpaymentcollectionget(row.id).then(res =>{
          const srclist = []
          const response = res.data.pc
          console.log('row',response);
          this.refundview={
            name:response.custom_name,
            type:response.payment_collection_type,
            totalamount:response.payment_collection_sumamt,
            software:response.software_sumamt,
            hardware:response.hardware_sumamt,
            date:response.payment_collection_date,
            role:response.payment_collection_role,
            url:response.url,
            remark:response.remark,
          }
          srclist.push(response.url)
          this.srcList = srclist
        })
      },
      view_click(){
        getpaymentcollectioncheck(this.editor_id).then(res =>{
          console.log('tttt',res);
          this.refund = false
          this.getlist()
        })
      },
      // 
      getlist(){
        getpaymentcollectionlist().then(res =>{
          const list = res.data.list
          const table = []
          list.forEach((item,index) => {
            if(item.is_check==0){
              const arr = {
                id:item.id,
                index:index+1,
                name:item.custom_name,
                xinxi:this.getoptions(item.payment_collection_type),
                jiner:item.payment_collection_sumamt,
                time:item.payment_collection_date,
                caozuo:item.payment_collection_role,
                remark:item.remark,
                examine:'',
              }
              table.unshift(arr)
            }
          });
            this.tableData = table
        })
      },
      // 回款类型
      getoptions(val){
        const options = this.options
        for(let i in options){
          if(val == options[i].value){
            return options[i].label
          }
        }
      },
      // 转换时间
      getTime(val) {
        if(val < 0){
          return ""
        }
        if(val == ""){
          return ""
        }else {
          return uParseTime(val, '{y}-{m}-{d}')
        }
      },
    }
  }
</script>
<style lang="scss" scoped>
  .context{
    padding: 20px 0;
    .xinxi{
      display: flex;
      margin-bottom: 15px;
    }
  }

</style>