<template>
  <div class="app-container">

    <div class = "search-bx"  >
        <div class="search">
          <el-row :gutter="0">

              <el-input v-model="tableObj.getdataListParm.parammaps.contractCode" placeholder="合同编号" class="filter-item" style="width: 120px;padding-bottom:10px;" />

              <el-input v-model="tableObj.getdataListParm.parammaps.beginPlanCost" placeholder="合同金额" style="width:80px"></el-input>
                -
              <el-input v-model="tableObj.getdataListParm.parammaps.endPlanCost" placeholder="合同金额" style="width:80px"></el-input>


              <el-input v-model="tableObj.getdataListParm.parammaps.beginMoneyStep" placeholder="款项分期" style="width:80px"></el-input>
                -
              <el-input v-model="tableObj.getdataListParm.parammaps.endMoneyStep" placeholder="款项分期" style="width:80px"></el-input>


              <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 200px;margin-right:10px" @select="change_customer_select" @clear="clear_customer_select" @blur="customer_search_blur" clearable>
                <template slot-scope="{ item }">
                  <span class="name">{{ item.name }}</span>
                </template>
              </el-autocomplete> -->

              <el-input v-model="tableObj.getdataListParm.parammaps.customerName" placeholder="客户名称" style="width: 180px;" class="filter-item" clearable />

              <el-select v-model="tableObj.getdataListParm.parammaps.groupId" placeholder="集团" class="filter-item" style="width: 120px;" clearable>
                <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>


              <el-select v-model="tableObj.getdataListParm.parammaps.costStatus" placeholder="收款状态" class="filter-item" style="width: 120px;" clearable>
                  <el-option v-for="item in moneyNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>


              <el-input v-model="tableObj.getdataListParm.parammaps.beginPlanCost" placeholder="应收金额" style="width:90px"></el-input>
                -
              <el-input v-model="tableObj.getdataListParm.parammaps.endPlanCost" placeholder="应收金额" style="width:90px;margin-right:10px;"></el-input>

              <el-input v-model="tableObj.getdataListParm.parammaps.beginStages" placeholder="本期期数" style="width:90px"></el-input>
                -
              <el-input v-model="tableObj.getdataListParm.parammaps.endStages" placeholder="本期期数" style="width:90px"></el-input>


              <el-date-picker v-model="tableObj.getdataListParm.parammaps.inputDatetime1" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="本期收款时间" end-placeholder="本期收款时间" style="width: 250px;" />


              <el-select v-model="tableObj.getdataListParm.parammaps.createrId" placeholder="创建人" class="filter-item" style="width: 120px;" clearable filterable>
              <el-option v-for="(item,index) in createrNameList" :key="index" :label="item.name" :value="item.id" />
            </el-select>


                <el-button class="successBorder" @click="form_search">查询</el-button>
                <el-button class="successBorder" @click="form_clear">重置</el-button>

                <!-- <el-button  class="success" icon="el-icon-upload2" @click="form_export">导出</el-button> -->

          </el-row>
        </div>


    </div>


    <div class="table"   >
      <el-table :key="tableObj.tableKey" v-loading="tableObj.listLoading" element-loading-text="给我一点时间" :data="tableObj.list" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable table-fixed" :max-height="myHeight">


        <el-table-column label="序号" align="center" type="index" width="50px"  fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.$index + (tableObj.pageNum-1) * tableObj.pageSize + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同编号" min-width="130px" align="center"  fixed="left">
          <template slot-scope="scope">
            <span  style = "color:#409EFF; cursor: pointer;" @click="form_see(scope.row)">{{ scope.row.contractCode  }}</span>
          </template>
        </el-table-column>
        <el-table-column label="合同金额(元)" min-width="110px" align="center"  fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.contractMoney }}</span>
          </template>
        </el-table-column>
        <el-table-column label="款项分期" min-width="90px" align="center"  fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.moneyStep }}</span>
          </template>
        </el-table-column>
        <el-table-column label="应收金额(元)" min-width="110px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.planCost }}</span>
          </template>
        </el-table-column>
        <el-table-column label="本期期数" min-width="90px" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row.stages }}</span>
          </template>
        </el-table-column>

        <el-table-column label="应收款时间" min-width="110px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.collectionDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实收款时间" min-width="110px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.getCostDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="收款状态" min-width="90px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.costStatus }}</span>
          </template>
        </el-table-column>


        <el-table-column label="剩余款项" min-width="110px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.noReturnCost }}</span>
          </template>
        </el-table-column>

        <el-table-column label="回款金额" min-width="110px" align="center"  >
          <template slot-scope="scope">
            <span>{{ scope.row.returnCost }}</span>
          </template>
        </el-table-column>

        <el-table-column label="客户名称" min-width="120px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属集团" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.groupName  }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.createrName  }}</span>
          </template>
        </el-table-column>


        <el-table-column label="操作" align="center"   :width="autoWidth"  v-if="autoWidth !== 0"   class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">

             <el-button class="miniSuccess" @click="form_sure(row)" v-if="isContractpayRevoke && row.isComplete  == '1'">完成收款</el-button>

             <el-button v-if=" row.costStatus  !== '已收款'" class="miniSuccess" @click="form_close(row)" >关闭</el-button>

            <el-button class="miniSuccess" @click="form_revoke(row)" v-if="isContractpayRevoke && row.isRevoke  == '1'">撤销</el-button>


          </template>
        </el-table-column>

      </el-table>

      <el-row :gutter="0">
        <el-col :span="6" :offset="12" style="color:#f00">
          列表合同总金额：{{tableSumMoney}}
        </el-col>
      </el-row>

      <pagination v-show="tableObj.total>=0" :total="tableObj.total" :page.sync="tableObj.getdataListParm.offset" :limit.sync="tableObj.getdataListParm.pagecount" @pagination="get_table_data" />
    </div>


    <!-- 查看/反馈 -->
    <el-dialog  title="合同详情" :visible.sync="createSee.dialogFormVisible" :close-on-click-modal="false" width="95%" :before-close="dialog_close">
      <div class="app-add">
        <el-tabs v-model="activeName" type="card" >
          <el-tab-pane label="合同信息" name="first">
              <ContractMoreDetail :conmore-data="conmoreData"  />
          </el-tab-pane>
          <el-tab-pane label="合同履历" name="second">
              <ContractCustomerDetail :concustomer-data="concustomerData"  />
          </el-tab-pane>
          <!-- <el-tab-pane label="回款信息" name="third">
              <ContractReturnMoney :resturnm-data="resturnmData"  />
          </el-tab-pane>  -->
        </el-tabs>
        <div slot="footer" class="dialog-footer">
          <!-- <el-button class="success" @click="form_sure(createSee.temp)" v-if="isContractpayRevoke && createSee.temp.isComplete  == '1'">完成收款</el-button> -->
          <el-button class="cancelClose" @click="dialog_close()">关闭</el-button>


        </div>
      </div>
    </el-dialog>


     <!-- 确认是否已收款 -->
    <el-dialog title="确认是否已收款" :visible.sync="sure.dialogFormVisible" :close-on-click-modal="false" width="50%" :before-close="dialog_sure_close">
      <div class="app-add">
        <el-form ref="suretemp" :rules="sure.rules" :model="sure.temp" label-position="right" label-width="150px" style="width: 70%;margin:0 auto 50px">

          <el-form-item label="收款时间：" prop="collectionDate">

            <el-date-picker v-model="sure.temp.collectionDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  :picker-options="setDisabled" style="width: 100%;" :clearable="false"   />

          </el-form-item>

          <el-form-item label="收款金额：" prop="actualCost">
            <el-input ref="actualCost" v-model="sure.temp.actualCost" class="filter-item" style="width: 100%;" maxlength="11" placeholder="请输入" />
          </el-form-item>

          <el-form-item label="应收金额：" prop="noReturnCost">
            <el-input ref="noReturnCost" v-model="sure.temp.noReturnCost" class="filter-item" style="width: 100%;" maxlength="11" placeholder="请输入" />
          </el-form-item>

          <el-form-item label="备注：" prop="remark">
            <el-input ref="remark" v-model="sure.temp.remark" type="textarea" :autosize="{ minRows: 4, maxRows: 8} "  :rows="8" placeholder="请输入备注，最多200个字" maxlength="200" class="filter-item" style="width: 100%;"   />
          </el-form-item>
          <el-form-item label="是否通知发货：" prop="isAlert">
            <el-switch v-model="sure.temp.isAlert"  active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
            <!-- <el-radio v-model="sure.temp.isAlert" label="1"  >是</el-radio>
            <el-radio v-model="sure.temp.isAlert" label="0"  >否</el-radio> -->
          </el-form-item>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="dialog_sure_close()">关闭</el-button>
          <el-button class="success" @click="form_sure_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 撤销 -->
    <el-dialog title="确认是否撤销" :visible.sync="revoke.dialogFormVisible" :close-on-click-modal="false" width="50%">
      <div class="app-add">
        <el-form ref="revoketemp" :rules="revoke.rules" :model="revoke.temp" label-position="right" label-width="150px" style="width: 70%;margin:0 auto 50px">

          <el-form-item label="撤销原因：" prop="revokeReason">
            <el-input ref="remark" v-model="revoke.temp.revokeReason" type="textarea" :autosize="{ minRows: 4, maxRows: 8} "  :rows="8" placeholder="请输入备注，最多200个字" maxlength="200" class="filter-item" style="width: 100%;"   />
          </el-form-item>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="revoke.dialogFormVisible = false;get_table_data()">关闭</el-button>
          <el-button class="success" @click="form_revoke_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>


  </div>
</template>

<script>


import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons, calculativeWidth, wxpush } from '@/api/common'
import Cookies from 'js-cookie'
import {  parseTime, json2excel } from '@/utils/index.js'
// import littleTable from './components/littleTable'
import { getToken } from '@/utils/auth'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'

import ContractMoreDetail from '@/componentView/ContractMoreDetail.vue'
import ContractCustomerDetail from '@/componentView/ContractCustomerDetail.vue'
import ContractReturnMoney from '@/componentView/ContractReturnMoney.vue'
import { constants } from 'zlib';


export default {
  name: 'ContractPayment',
  components: { Pagination , ContractCustomerDetail, ContractMoreDetail,ContractReturnMoney},
  data() {
    return {
      myHeight:document.documentElement.clientHeight - 85 - 220,
      employeid: Cookies.get('employeid'),
      disabled: false,

      rowData:{},
      isHome:"",

      isRoleEdit: [],isContractpayRevoke: [],


      activeName:'first',

      //客户资料详情组件
      conmoreData:{ id:"" },
      concustomerData:{ id:"" },
      resturnmData:{ id:"" },

      send_select_list: [
        { name: 'getDictListSelect', offset: 0, pagecount: 0, parammaps: { "pid": "54" } },
        { name: 'getUsersSelect', offset: 0, pagecount: 0, parammaps: {} },
      ],

      customerNameList: [], // 客户名称
      groupNameList: [], // 集团


       // 下拉框 - 创建人
      createrNameList: [],


      // 下拉框 - 款项状态
      moneyNameList: [
        { "name": "未收款", "id": "未收款" },
        { "name": "已收款", "id": "已收款" },
        { "name": "部分收款", "id": "部分收款" },
      ],


      //表格 - 列表 - 查询
      tableObj: {
        getdataListParm: {
          name: 'getContractCostList',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pagecount')),
          returntype: 'Map',
          parammaps: {
            contractCode: "",
            customerName: "",
            customerId: "",
            groupId: "",
            createrId: "",
            contractStatus: "",

            beginPlanCost: "",
            endPlanCost: "",
            beginMoneyStep: "",
            endMoneyStep: "",
            beginStages: "",
            endStages: "",

            inputDatetime1: "",


            beginCollectionDate: "",
            endCollectionDate: "",


          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      tableSumMoney:1000,

      download: {
        getdataListParm: {
          name: 'getContractCostList',
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: 'Map',
          parammaps: {
            contractCode: "",
            customerName: "",
            customerId: "",
            groupId: "",
            createrId: "",
            contractStatus: "",

            beginPlanCost: "",
            endPlanCost: "",
            beginMoneyStep: "",
            endMoneyStep: "",
            beginStages: "",
            endStages: "",

            inputDatetime1: "",


            beginCollectionDate: "",
            endCollectionDate: "",


          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },


      createSee:{
        temp:{id:"",costId:"",isComplete:""},
        dialogFormVisible: false,
      },


      setDisabled: {
        disabledDate(time) {
           return time.getTime() > Date.now();  // 可选历史天、可选当前天、不可选未来天
          //return time.getTime() > Date.now() - 8.64e7;  // 可选历史天、不可选当前天、不可选未来天
          // return time.getTime() < Date.now() - 8.64e7;  // 不可选历史天、可选当前天、可选未来天
          // return time.getTime() < Date.now(); // 不可选历史天、不可选当前天、可选未来天
        },
      },

      textMap: {
        create: '新增',
        see: '查看',
        update: '编辑'
      },


      imageUrl0:"",

      // 撤销
      revoke: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { revokeReason: '',  id: '' },
        rules: {
          revokeReason: [{ required: true, message: '必填', trigger: 'blur' }],
        }
      },

      // 确认回收
      sure: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { collectionDate: '',  id: '', actualCost: '',planCost: '',remark: '',isAlert: 0, },
        rules: {
          collectionDate: [{ required: true, message: '必填', trigger: 'blur' }],
          actualCost: [{ required: true, message: '必填', trigger: 'blur' }],
         }
      },


      autoWidth: 160,

      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },

  watch: {

    tableStockList: {
      deep: true,
      handler: function (item) {
          //计算总价格
          var sum = 0
          this.tableStockList.forEach(function(i){
              sum = parseInt(i.nums) * parseFloat(i.price) + sum
          })
          this.stockSumPrice = sum

      }
    },

  },

  created() {

    this.get_select_list()
    this.get_auto_buttons()


    var rowData = this.$route.params.rowData
    var isHome = this.$route.params.isHome
    var codeNum = this.$route.params.codeNum

    console.log("rowData",rowData,"======isHome",isHome,"======codeNum",codeNum)


    if(isHome == 'home'){
      this.rowData = rowData
      this.isHome = isHome
      this.tableObj.getdataListParm.parammaps.contractCode = codeNum


      var stages = this.$route.params.stages
      this.tableObj.getdataListParm.parammaps.beginStages = stages
      this.tableObj.getdataListParm.parammaps.endStages = stages


      this.get_table_data()

    } else {
      this.rowData = {}
      this.isHome = ""
      this.codeNum = ""

      this.get_table_data()
    }

  },


  methods: {


    //获取按钮权限
    get_auto_buttons() {
      const Edit = 'ContractPayment'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit

      const ContractpayRevoke = 'review:contractpay:revoke'
      const isContractpayRevoke = checkButtons(this.$store.state.user.buttons, ContractpayRevoke)
      this.isContractpayRevoke = isContractpayRevoke
    },
    //获取所有下拉框的内容
    get_select_list() {

      GetDataByNames(this.send_select_list).then(response => {
        // this.customerNameList = response.data.getCustomerSelect.list
        // console.log("客户名称下拉框", this.houseNameList)
        this.groupNameList = response.data.getDictListSelect.list
        console.log("集团下拉框", this.groupNameList)

        this.createrNameList = response.data.getUsersSelect.list
        console.log("创建人下拉框", this.createrNameList)


      })

    },
    //加载表格
    get_table_data() {
      var me = this

      this.tableObj.listLoading = true
      console.log("this.tableObj.getdataListParm======>", this.tableObj.getdataListParm)
      GetDataByName(this.tableObj.getdataListParm).then(response => {
        console.log('table数据======>', response.data.list)
        if (response.data.list !== null) {


          this.tableObj.list = response.data.list
          this.tableObj.pageNum = response.data.pageNum
          this.tableObj.pageSize = response.data.pageSize
          this.tableObj.total = response.data.total

          console.log('table数据======>', this.tableObj.list)

          //计算操作栏宽度
          var btnNum = 0
              var arrList = response.data.list
              arrList.forEach(function(row){
                  var itemBtnNum = 0
                  if(me.isContractpayRevoke && row.isComplete  == '1'){
                    itemBtnNum = itemBtnNum + 1
                  }
                  if(me.isContractpayRevoke && row.isRevoke  == '1'){
                    itemBtnNum = itemBtnNum + 1
                  }


                  console.log(itemBtnNum)
                  if(itemBtnNum > btnNum){
                    btnNum = itemBtnNum
                  }
              })
              console.log("btnNum=============",btnNum)
              me.autoWidth = btnNum * 90  + 100


        } else {
          this.tableObj.list = []
        }
        setTimeout(() => {
          this.tableObj.listLoading = false
        }, 100)
      })


      var send_price = {
        name: 'getContractCostOfPrice',
        parammaps: this.tableObj.getdataListParm.parammaps
      }

      GetDataByName(send_price).then(response => {
        console.log('table总价格数据======>', response )
        if (response.data.list !== null) {
          this.tableSumMoney = response.data.list[0].totlePrice
        } else {
          this.tableSumMoney = ""
        }
      })


    },
    form_search() {
      console.log('点击了查询')

      if (this.tableObj.getdataListParm.parammaps.inputDatetime1 !== '' && this.tableObj.getdataListParm.parammaps.inputDatetime1 !== null) {
        this.tableObj.getdataListParm.parammaps.beginCollectionDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime1[0], '{y}-{m}-{d}')
        this.tableObj.getdataListParm.parammaps.endCollectionDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime1[1], '{y}-{m}-{d}')
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime1 = ''
        this.tableObj.getdataListParm.parammaps.beginCollectionDate = ''
        this.tableObj.getdataListParm.parammaps.endCollectionDate = ''
      }


      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()
    },
    form_clear() {
      console.log('点击了重置')

      this.tableObj.getdataListParm.parammaps.customerName = ''
      this.tableObj.getdataListParm.parammaps.contractCode = ''
      this.tableObj.getdataListParm.parammaps.customerId = ''
      this.tableObj.getdataListParm.parammaps.groupId = ''

      this.tableObj.getdataListParm.parammaps.contractStatus = ''
      this.tableObj.getdataListParm.parammaps.createrId = ''

      this.tableObj.getdataListParm.parammaps.beginPlanCost = ''
      this.tableObj.getdataListParm.parammaps.endPlanCost = ''
      this.tableObj.getdataListParm.parammaps.beginMoneyStep = ''
      this.tableObj.getdataListParm.parammaps.endMoneyStep = ''
      this.tableObj.getdataListParm.parammaps.beginStages = ''
      this.tableObj.getdataListParm.parammaps.endStages = ''

      this.tableObj.getdataListParm.parammaps.inputDatetime1 = ''

       this.tableObj.getdataListParm.parammaps.beginCollectionDate = ''
      this.tableObj.getdataListParm.parammaps.endCollectionDate = ''

      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()


    },


    //客户失去焦点
    customer_search_blur(item) {
      console.log("客户失去焦点")
      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""
      this.customerNameList = []
    },


    //模糊查询客户
    customer_search(queryString, cb) {
      console.log('模糊查询输入值', queryString)
      GetDataByName({ name: 'getCustomerNameFuzzy', page: 1, offset: 1, pagecount: 10, returntype: 'Map', parammaps: { inputvalue: queryString } }).then(response => {
        this.customerNameList = response.data.list
        console.log("客户名称下拉框", response)
        cb(response.data.list)
      })
    },

    //模糊查询客户选择
    change_customer_select(item) {
      console.log('客户名称模糊查询选中值', item)
      this.tableObj.getdataListParm.parammaps.customerId = item.id
      this.tableObj.getdataListParm.parammaps.customerName = item.name
      this.$forceUpdate()
    },

    //清空客户选择
    clear_customer_select(item) {
      document.activeElement.blur()
      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""
    },


    //监听 - 集团
    change_group(item) {
      console.log(item)
      console.log(this.create.temp.groupId)
      this.create.temp.groupId = item
      this.create.getdataListParmCust.parammaps.groupId = item

      this.create.temp.customerName = ""
      this.create.temp.customerId = ""
      this.create.customerNameList = []

      this.get_customer_list()
      this.$forceUpdate()

    },
    // 弹窗中的客户
    get_customer_list() {
      GetDataByName(this.create.getdataListParmCust).then(response => {
        if (response.data.list !== null) {
          this.create.customerNameList = response.data.list
          console.log('弹窗中的客户数据', response.data.list)
        } else {
          this.create.customerNameList = []
        }
      })
    },


    //监听 - 下拉中客户名称
    change_customer(item) {
      console.log(item)
      this.create.temp.customerId = item


    },


    // 备货信息表格
    getStockTableList() {
      GetDataByName(this.create.getdataListParmStock).then(response => {
        if (response.data.list !== null) {
          this.tableStockList  = response.data.list
          console.log('备货信息表格数据', response.data.list)
        } else {
          this.tableStockList  = []
        }
      })
    },


    //小表格中的删除单号
    form_deleteCode(item, index) {
      console.log('小表格中的删除单号', item)
      this.tableArrList.splice(index, 1)
      this.stockupIdArr.splice(this.stockupIdArr.indexOf(item.stockupId), 1)
      console.log("stockupIdArr===>", this.stockupIdArr)

    },


    //图片展示
    show_pic1() {
      this.imageIsShow = true
    },


    // 查看
    form_see(row) {


      this.concustomerData.id = row.id
      this.conmoreData.id = row.id
      this.resturnmData.id = row.id


      console.log('点击了查看',this.resturnmData.id)

      this.createSee.temp.id = row.id
      this.createSee.temp.costId = row.costId
      this.createSee.temp.isComplete = row.isComplete


      this.createSee.dialogFormVisible = true


    },

      // 关闭
    form_close(row) {

          var send_data =   {
              "name": "closeContractCost",
              "parammaps": {
                  "contractCostId": row.costId
              }
          }


            this.$confirm('是否关闭该条记录?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {

                 PostDataByName(send_data).then(response => {
                    console.log('关闭发送参数', send_data)
                    if (response.msg !== 'fail') {
                      this.$notify({ title: '成功', message: '关闭成功', type: 'success', duration: 2000 })

                      this.get_table_data()


                    } else {
                      this.$notify({ title: '失败', message: '关闭失败' + response.data, type: 'error', duration: 2000 })
                    }
                  })

            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });
            });


    },


    // 确认回收
    form_sure(row) {
      console.log('点击', row)
      this.reset_sure()
      // this.sure.temp.id = row.costId
      // this.sure.temp.planCost = row.planCost

      this.sure.temp = Object.assign({}, row)
      this.sure.temp.collectionDate = parseTime(new Date(), '{y}-{m}-{d}')

      this.sure.dialogFormVisible = true
    },
    // 确认回收 - 重置
    reset_sure() {
      this.sure.temp.collectionDate = ""
    },

    // 确认回收 - 确认
    form_sure_save() {
      this.$refs['suretemp'].validate(valid => {
        if (valid) {


          this.sure.temp.userId = Cookies.get('g_userId')
          var send_data =   {
            "common": { "returnmap": "0" },
            "data": [
                {
                    "name": "insertContractCostDetail",
                    "type": "e",
                    "parammaps": {
                        "contractId": this.sure.temp.id,
                        "contractCostId":  this.sure.temp.costId,
                        "customerId": this.sure.temp.customerId,
                        "stages": this.sure.temp.moneyStep,
                        "planCost": this.sure.temp.noReturnCost,
                        "actualCost": this.sure.temp.actualCost,
                        "collectionDate": this.sure.temp.collectionDate,
                        "getCostDate": this.sure.temp.collectionDate,
                        "createrId": this.sure.temp.userId,
                        "remark": this.sure.temp.remark,
                        "isAlert": this.sure.temp.isAlert,
                    }
                },
                {
                    "name": "refreshContractCost",
                    "type": "e",
                    "parammaps": {
                        "contractCostId": this.sure.temp.costId,
                    }
                }
            ]
        }


             ExecDataByConfig(send_data).then(response => {
                    console.log('确认回收参数', send_data)
                    if (response.msg !== 'fail') {
                      this.$notify({ title: '成功', message: '提交成功', type: 'success', duration: 2000 })
                      this.sure.dialogFormVisible = false
                      this.get_table_data()
                      this.createSee.dialogFormVisible = false

                      var send_weixin_data1 = {
                        name: 'getRemindData',
                        parammaps: {
                          "userId":Cookies.get('g_userId'),
                          "remindId":14,
                          "remindTypeName":'合同',
                          "rowId":this.sure.temp.costId

                        }
                      }

                      GetDataByName(send_weixin_data1).then(response => {
                        console.log('微信推送(获取参数)======>', response )
                        if (response.data.message == 'ok') {
                          var receiverStr = response.data.list[0].receivers
                          var receiverArr = receiverStr.split(',')
                          var value1 = response.data.list[0].value1
                          var value2 = response.data.list[0].value2
                          var value3 = response.data.list[0].value3
                          var value4 = response.data.list[0].value4
                          var send_weixin_data2 = {
                            "target": receiverArr,
                            "serviceId": 14,
                            "content": [
                              { "color": "#173177","value": value1 },
                              { "color": "#173177", "value": value2 },
                              { "color": "#173177", "value": value3 },
                              { "color": "#173177","value": value4 }
                            ]
                          }


                            wxpush(send_weixin_data2).then(response => {
                              console.log('微信推送(获取参数)======>', response )
                            })
                         // this.tableSumMoney = response.data.list[0].totlePrice
                        } else {
                          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                        }
                      })


                      if (this.sure.temp.isAlert == 1){
                        var send_weixin_data3 = {
                          name: 'getRemindData',
                          parammaps: {
                            "userId":Cookies.get('g_userId'),
                            "remindId":71,
                            "remindTypeName":'收款完成发货提醒',
                            "rowId":this.sure.temp.costId

                          }
                        }

                        GetDataByName(send_weixin_data3).then(response => {
                          console.log('微信推送(获取参数)======>', response )
                          if (response.data.message == 'ok') {
                            var receiverStr = response.data.list[0].receivers
                            var receiverArr = receiverStr.split(',')
                            var value1 = response.data.list[0].value1
                            var value2 = response.data.list[0].value2
                            var value3 = response.data.list[0].value3
                            var value4 = response.data.list[0].value4
                            var send_weixin_data4 = {
                              "target": receiverArr,
                              "serviceId":71,
                              "content": [
                                { "color": "#173177","value": value1 },
                                { "color": "#173177", "value": value2 },
                                { "color": "#173177", "value": value3 },
                                { "color": "#173177","value": value4 }
                              ]
                            }


                              wxpush(send_weixin_data4).then(response => {
                                console.log('微信推送(获取参数)======>', response )
                              })
                          // this.tableSumMoney = response.data.list[0].totlePrice
                          } else {
                            // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                          }
                        })
                      }


                      if(this.isHome == 'home'){
                      // 返回首页
                        this.$router.push({ name: 'Dashboard', params: { isTodo: 'contractp' }})
                      }

                    } else {
                      this.$notify({ title: '失败', message: '提交失败' + response.data, type: 'error', duration: 2000 })
                    }
                  })


        }
      })
    },


    // 撤销
    form_revoke(row) {
      console.log('点击了撤销', row)
      this.reset_revoke()

      this.revoke.temp.id = row.costId
      this.revoke.dialogFormVisible = true
    },
    // 撤销 - 重置
    reset_revoke() {
      this.revoke.temp.revokeReason = ""
    },

    // 撤销 - 确认
    form_revoke_save() {
      this.$refs['revoketemp'].validate(valid => {
        if (valid) {
          var send_data =  {

              "common": {   "returnmap": "0"  },
              "data": [
                  {
                      "name": "revokeContractCost",
                      "type": "e",
                      "parammaps": this.revoke.temp
                  },
                  {
                      "name": "revokeContractCostDetail",
                      "type": "e",
                      "parammaps": {
                          "id":  this.revoke.temp.id
                      }
                  }
              ]
          }


            this.$confirm('是否撤销该条记录?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {

              ExecDataByConfig(send_data).then(response => {
                    console.log('撤销发送参数', send_data)
                    if (response.msg !== 'fail') {
                      this.$notify({ title: '成功', message: '撤销成功', type: 'success', duration: 2000 })
                      this.revoke.dialogFormVisible = false
                      this.get_table_data()

                      var send_weixin_data1 = {
                        name: 'getRemindData',
                        parammaps: {
                          "userId":Cookies.get('g_userId'),
                          "remindId":15,
                          "remindTypeName":'合同',
                          "rowId":this.revoke.temp.id

                        }
                      }

                      GetDataByName(send_weixin_data1).then(response => {
                        console.log('微信推送(获取参数)======>', response )
                        if (response.data.message == 'ok') {
                          var receiverStr = response.data.list[0].receivers
                          var receiverArr = receiverStr.split(',')
                          var value1 = response.data.list[0].value1
                          var value2 = response.data.list[0].value2
                          var value3 = response.data.list[0].value3
                          var value4 = response.data.list[0].value4
                          var send_weixin_data2 = {
                            "target": receiverArr,
                            "serviceId": 15,
                            "content": [
                              { "color": "#173177","value": value1 },
                              { "color": "#173177", "value": value2 },
                              { "color": "#173177", "value": value3 },
                              { "color": "#173177","value": value4 }
                            ]
                          }


                            wxpush(send_weixin_data2).then(response => {
                              console.log('微信推送(获取参数)======>', response )
                            })
                         // this.tableSumMoney = response.data.list[0].totlePrice
                        } else {
                          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                        }
                      })


                    } else {
                      this.$notify({ title: '失败', message: '撤销失败' + response.data, type: 'error', duration: 2000 })
                    }
                  })

            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });
            });


        }
      })
    },


    dialog_close(){
      this.createSee.dialogFormVisible = false

      this.conmoreData.id = ""
      this.concustomerData.id = ""
      this.resturnmData.id = ""

      this.get_table_data()
      if(this.isHome == 'home'){
       // 返回首页
       this.$router.push({ name: 'Dashboard', params: { isTodo: 'contractp' }})
      }
    },

    dialog_sure_close(){
      this.sure.dialogFormVisible = false
      this.get_table_data()
      if(this.isHome == 'home'){
       // 返回首页
       this.$router.push({ name: 'Dashboard', params: { isTodo: 'contractp' }})
      }
    },

    // 导出
    form_export(item) {

       this.download.getdataListParm.parammaps = this.tableObj.getdataListParm.parammaps

       GetDataByName(this.download.getdataListParm).then(response => {
         if (response.data.list !== null) {
           this.download.list = response.data.list
         } else {
           this.download.list = []
         }
         var excelDatas = [
           {
             tHeader: ['序号', '合同编号', '合同金额（元）', '款项分期', '应收金额（元）', '本期期数', '本期收款时间', '收款状态', '剩余款项', '客户名称', '客户集团', '创建人' ],
             filterVal: ['sort', 'contractCode', 'contractMoney', 'moneyStep', 'planCost', 'stages', 'collectionDate', 'costStatus', 'getCostDate', 'customerName', 'groupName', 'createrName'],
             tableDatas: this.download.list,
             sheetName: 'Sheet1'
           }
         ]
         json2excel(excelDatas, '合同款项', true, 'xlsx')
       })

    },

    // 导入
    form_inport() {
      console.log('点击了导入')
    }

  }
}
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}

#uploadPic {
  width: 700px;
}


 .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

// #uploadPic .el-upload-list--picture-card .el-upload-list__item {
//   width: 70px;
//   height: 70px;
// }
// #uploadPic .el-upload--picture-card {
//   width: 70px;
//   height: 70px;
//   line-height: 70px;
// }
// #uploadPic .hide .el-upload--picture-card {
//   display: none;
// }

// // 查看 隐藏删除
// #uploadPicSee {
//   height: 70px;
// }
// #uploadPicSee .el-upload-list--picture-card .el-upload-list__item {
//   width: 70px;
//   height: 70px;
// }
// #uploadPicSee .el-upload--picture-card {
//   width: 70px;
//   height: 70px;
//   line-height: 70px;
// }
// #uploadPicSee
//   .el-upload-list--picture-card
//   .el-upload-list__item-actions
//   .el-upload-list__item-delete {
//   display: none;
// }

/deep/ .el-input.is-disabled .el-input__inner {color: #000000!important;}
/deep/ .el-textarea.is-disabled .el-textarea__inner {color: #000000!important;}
/deep/ .el-radio__input.is-disabled+span.el-radio__label {color: #000000!important;}
/deep/ .el-checkbox__input.is-disabled+span.el-checkbox__label { color: #000000!important;}

</style>
