<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="card-title">请款单</div>
        <el-form ref="form" :model="form" label-width="120px" label-position="left">
            <el-descriptions :column="3" class="card" border>
              <el-descriptions-item label="供应商" >
                <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="supplierId" required error="供应商不能为空">
                    <customer-selector v-model="form.supplierId" @change="consignor = $event" />
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="部门" >
                <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="departmentId" required error="部门不能为空">
                    <el-select v-model="form.departmentId" style="width: 300px;" placeholder="请选择部门">
                      <el-option v-for="item in deptData" :key="item.id" :label="item.name" :value="item.id"/>
                      </el-select>
                </el-form-item>
              </el-descriptions-item>
              <el-descriptions-item label="业务员" >
                <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="salesmanId" required error="客户不能为空">
                    <el-select v-model="form.salesmanName" placeholder="请选择业务员">
                      <el-option v-for="item in creatorData" :key="item.id" :label="item.nickname" :value="item.nickname"/>
                      </el-select>
                </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="申请日期" >
                  <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="consignorId" required error="申请日期不能为空">
                      <el-date-picker clearable v-model="form.applicationAt" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" placeholder="选择申请日期" />
                  </el-form-item>
                </el-descriptions-item>
                  <el-descriptions-item label="供应商银行账号" style="width: 50%;">
                    <el-form-item label="" label-width="0" style="margin-bottom: 0;" prop="consignorId" required error="请选择收款账户">
                        <el-select v-model="form.supplierId" placeholder="请选择收款账户">
                          <el-option v-for="item in bankData" :key="item.id" :label="item.baAccountName+'('+item.baAccountNum+')'" :value="item.id"/>
                        </el-select>
                    </el-form-item>
                  </el-descriptions-item>
             </el-descriptions>
             <el-descriptions :column="3" class="card" border>
              <el-descriptions-item label="最后付款日期" >
                <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="latestPayAt" required error="最后付款日期不能为空">
                    <el-date-picker clearable v-model="form.latestPayAt" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" placeholder="选择最后付款日期" />
                </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="结算方式" >
                  <el-form-item label="" label-width="0" style="margin-bottom: 0"  required error="选择结算方式">
                       <dict-selector :type="DICT_TYPE.CUSTOMER_BALANCE" v-model="form.settlementType" />
                  </el-form-item>
                </el-descriptions-item>
          </el-descriptions>
        </el-form>
    </el-card>
    <el-card class="card">
       <div slot="header" class="card-title">费用信息</div>
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" style="padding: 10px;margin-bottom: 10px;"
                     >添加供应商未付款项</el-button>
        </el-col>
        <el-table v-loading="loadings" :data="list" border>
            <el-table-column label="订单编号" align="center" prop="orderNo" />

            <el-table-column label="费用类型" align="center" prop="transportId">
              <template slot-scope="scope">
                 <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="scope.row.transportId"></dict-tag>
              </template>
            </el-table-column>
            <el-table-column label="发票号码" align="center" prop="channelName" />
            <el-table-column label="应付金额" align="center" prop="toDepartureId" />
            <el-table-column label="币种" align="center" prop="toDepartureId" />
            <el-table-column label="汇率" align="center" prop="toDepartureId" />
            <el-table-column label="税率" align="center" prop="sumNum" />
            <el-table-column label="价格合计(RMB)" align="center" prop="payType" />
          </el-table>

          <el-form ref="forms" :model="form" label-width="120px" label-position="left"  style="width: 50%;">
            <el-descriptions :column="1" class="card" border>
                <el-descriptions-item label="账单号">
                  <el-form-item label="" label-width="0" style="margin-bottom: 0;" required error="账单号不能为空">
                        <el-input v-model="form.accountNumber"  placeholder="请输入账单号"></el-input>
                  </el-form-item>
                </el-descriptions-item>
                <el-descriptions-item label="发票">
                  <el-form-item label="" label-width="0" style="margin-bottom: 0" prop="invoiceStatus" required error="请选择是否开票">
                        <el-select v-model="form.invoiceStatus" placeholder="请选择是否开票">
                           <el-option label="未开票" value="0"/>
                           <el-option label="已开票" value="1"/>
                          </el-select>
                  </el-form-item>
                </el-descriptions-item>
            </el-descriptions>
        </el-form>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button type="primary" @click="submitForm">新 增</el-button>
    </div>
    <el-dialog  :visible.sync="open" title="添加未收客户款项" width="80%" append-to-body>
      <div>
          <!-- <div slot="header" class="card-title">添加未收客户款项</div> -->
        <!-- 搜索工作栏 -->
           <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="80px">
             <el-row>
               <el-form-item label="供应商">
                   <customer-selector v-model="form.supplierId" @change="consignor = $event" />
               </el-form-item>
               <el-form-item label="始发城市">
                   <el-select v-model="queryParams.departureId" placeholder="请选择始发地">
                       <el-option v-for="item in expoerCityList" :label="item.titleZh" :value="item.id" :key="item.id"></el-option>
                   </el-select>
               </el-form-item>
               <el-form-item label="目的城市">
                   <el-select v-model="queryParams.objectiveId" placeholder="请选择始发地">
                   <el-option v-for="item in importCityList" :label="item.titleZh" :value="item.id" :key="item.id"></el-option>
                   </el-select>
               </el-form-item>
               <el-form-item label="运输方式" >
                 <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model="queryParams.transportId" formatter="number" />
               </el-form-item>
               <el-form-item label="出货渠道" >
                   <el-select v-model="queryParams.channelId" placeholder="请选择出货渠道">
                   <el-option v-for="item in channelList" :label="item.nameZh" :value="item.channelId" :key="item.channelId"></el-option>
                   </el-select>
                </el-form-item>
              </el-row>
              <el-row>
               <el-form-item label="报关方式">
                   <dict-selector :type="DICT_TYPE.ECW_CUSTOMS_TYPE" v-model="queryParams.customsType" />
               </el-form-item>
               <el-form-item label="控货">
                     <dict-selector :type="DICT_TYPE.INFRA_BOOLEAN_STRING" v-model="queryParams.control" />
                </el-form-item>
               <el-form-item label="客户名称" >
                    <customer-selector v-model="queryParams.consignorId" @change="consignor = $event" />
                </el-form-item>
               </el-row>
                <el-form-item label="订单编号" prop="orderNo">
                  <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable/>
                </el-form-item>

                <el-form-item label="自编号" prop="orderNo">
                  <el-input v-model="queryParams.orderNo" placeholder="请输入自编号" clearable/>
                </el-form-item>

                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
                </el-form-item>
              </el-form>
            </el-col>
            <el-table v-loading="loadings" :data="orderData" border  @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column label="自编号" align="center" prop="orderNo" />
                <el-table-column label="柜号" align="center" prop="orderNo" />
                <el-table-column label="运输方式" align="center" prop="transportId">
                  <template slot-scope="scope">
                     <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="scope.row.transportId"></dict-tag>
                  </template>
                </el-table-column>
                <el-table-column label="出货渠道" align="center" prop="channelName" />
                <el-table-column label="始发地" align="center" prop="toDepartureId" />
                <el-table-column label="目的地" align="center" prop="toDepartureId" />
                <el-table-column label="金额" align="center" prop="totalAmount" />
                <el-table-column label="备注" align="center" prop="toDepartureId" />
              </el-table>
        <!-- </el-card> -->
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确认添加</el-button>
          <el-button @click="hiddenDialog">取 消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { userList } from "@/api/system/user"
  import {DICT_TYPE} from  '@/utils/dict'
  import { getToken } from "@/utils/auth"
  import {getChannelList} from '@/api/ecw/channel'
  import CustomerSelector from '@/components/CustomerSelector'
  import { getBankAccountPage } from "@/api/ecw/bankAccount"
  import { listSimpleDepts } from "@/api/system/dept"
    import {getTradeCityList} from '@/api/ecw/region'
  export default {
    name: "CreatPayment",
  components: {
     CustomerSelector
  },
    data() {
      return {
        orderData:[],
        loadings: false,
        open:false,
        form:{},
        creatorData:[],
        list:[],
        channelList:[],
        loading:'',
        bankData:[],
        params:{
           page:1,
           rows:20,
        },
        deptData:[],
        deptArr:[],
        queryParams:{
          page:1,
          rows:20,
        },
        multipleSelection:[],
        tradeCityList:[]
      }
    },
    created() {
      let that = this
      userList('salesman').then(res =>that.creatorData = res.data)
      getChannelList().then(res => that.channelList = res.data)
      getTradeCityList().then(res => that.tradeCityList = res.data)
      getBankAccountPage(that.params).then(res =>that.bankData = res.data.list)
      listSimpleDepts().then(res =>{
        res.data.forEach((item)=>{
          if(item.parentId==0){

            that.deptArr.push(item)

          }else{
            that.deptData.push(item)
          }
        })

        that.deptData.forEach((value)=>{
           var dept = that.deptArr.filter(itt=>itt.id==value.parentId)
           if(dept.length>0){
             value.name =dept[0].name+' | '+ value.name
           }

        })
      })
    },
    computed:{
      expoerCityList(){
          return this.tradeCityList.filter(item => item.type == 2)
      },
      importCityList(){
          return this.tradeCityList.filter(item => item.type == 1)
      },
    },
    methods: {
      /** 新增按钮操作 */
      handleAdd() {
        this.open = true
      },
      submitForm(){

      },
      handleQuery(){

      },
      handleSelectionChange(val) {
         this.multipleSelection = val;
       },
      hiddenDialog(){
        this.open = false
      }
    },
  }
</script>

<style>
  .card{
    margin-top: 20px;
  }
  .dialog-footer{
    padding: 40px;
  }
  .card-title{
      font-size: 18px;
      font-weight: bold;
  }
</style>
