    <template>
      <div class="CashierWithdrawal">
        <div class="content">
          <div>
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="提现" name="first">
                <el-form label-width="130px">
                  <el-form-item label="不能开票总额：">
                    <span style="display:inline-block;" class="w160">{{TixianMoney}}</span><span
                      style="color:red;">*注意，此金额只包含不能开票商品的收入金额</span>
                  </el-form-item>
                  <el-form-item label="提现金额：">
                    <el-input type="number" class="w160" size="small" @keyup.native="checkPrice(msg,'Money')"
                      :max="5000" v-model="msg.Money"></el-input> <span style="color:red;">*注意每个账户最多单日提现5千</span>
                  </el-form-item>
                  <el-form-item label="到账账号：">
                    <el-select class="w160" v-model="msg.User_Id" size="small" placeholder="请选择">
                      <el-option v-for="item in createrList" :key="item.Id" :label="item.Name" :value="item.Id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-form>
              </el-tab-pane>
              <el-tab-pane label="提现记录" name="second">
                <div class="Cashier_Search">
                  <span>交易日期：
                    <el-date-picker v-model="dateList" @change="awalMsg.pageIndex=1,searchList()" size="small"
                      type="datetimerange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss"
                      start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                  </span>
                  <span>到账账户：
                    <el-select class="w150" v-model="awalMsg.User_Id" size="small" placeholder="请选择">
                      <el-option label="不限" :value="0"></el-option>
                      <el-option v-for="item in createrList" :key="item.Id" :label="item.Name" :value="item.Id">
                      </el-option>
                    </el-select>
                  </span>
                  <span>创建人：
                    <el-select class="w150" v-model="awalMsg.CreateBy" size="small" placeholder="请选择">
                      <el-option label="不限" :value="0"></el-option>
                      <el-option v-for="item in AccountList" :key="item.EmpId" :label="item.EmpName"
                        :value="item.EmpId">
                      </el-option>
                    </el-select>
                  </span>
                  <span>交易流水号：<el-input type="text" class="w250" size="small" v-model="awalMsg.Transaction_Id">
                    </el-input>
                  </span>
                  <span>交易金额：
                    <el-input type="text" class="w100" size="small" @keyup.native="checkPrice(awalMsg,'StartMoney')"
                      v-model="awalMsg.StartMoney"></el-input> -
                    <el-input type="text" class="w100" size="small" @keyup.native="checkPrice(awalMsg,'EndMoney')"
                      v-model="awalMsg.EndMoney"></el-input>
                  </span>
                  <span>
                    <el-button type="primary" @click="searchList()" size="small">查询</el-button>
                  </span>
                </div>
                <el-table :data="tableData" v-loading="loading" border style="width: 100%;margin:20px 0">
                  <el-table-column prop="Out_Trade_No" label="流水号">
                  </el-table-column>
                  <el-table-column prop="UserName" label="到账账户">
                  </el-table-column>
                  <el-table-column prop="Money" label="提现金额">
                  </el-table-column>
                  <el-table-column prop="Pay_DateStr" label="提现时间">
                  </el-table-column>
                  <el-table-column prop="Transaction_Id" label="微信交易流水号">
                  </el-table-column>
                  <el-table-column prop="CreateByName" width="150" label="创建人">
                  </el-table-column>
                </el-table>
                <el-pagination style="text-align:right" background @current-change="handleCurrentChange"
                  :page-size="awalMsg.pageSize" :current-page.sync="awalMsg.pageIndex" layout="prev, pager, next"
                  :total="total">
                </el-pagination>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
        <el-button style="margin-top:20px;padding:9px 25px;" :disabled="isCanSubmit" v-if="isShowBtn" type="primary"
          @click="saveMsg()" size="small">提交
        </el-button>
      </div>
    </template>
    <script>
      export default {
        data() {
          return {
            msg: {
              User_Id: '', //提现人
              Money: '', //金额
              CreateBy:0 //创建人
            },
            //提现记录msg
            awalMsg: {
              pageIndex: 1,
              pageSize: 10,
              CreateBy: 0, //创建人
              User_Id: 0, //提现人  
              Transaction_Id: '', //微信交易流水号
              StartTime: '', //开始时间  
              EndTime: '', //结束时间
              StartMoney: '', //开始金额
              EndMoney: '' //结束金额
            },
            activeName: 'first',
            aa: '',
            loading: false,
            tableData: [], //数据
            total: 0,
            isShowBtn: true, //是否显示保存按钮
            dateList: [], //日期数组
            createrList: [], //创建人下拉
            AccountList: [], //到账账户
            TixianMoney: 0, //提现金额
            isCanSubmit: false, //是否可以提交
          };
        },
        created() {

        },
        methods: {
          //保存
          saveMsg() {
            if (parseFloat(this.msg.Money) > 5000) {
              this.msg.Money = 5000;
              this.Error('注意每个账户最多单日提现5千');
            }
            if(parseFloat(this.msg.Money) > this.TixianMoney){
              this.msg.Money = this.TixianMoney;
              this.Error("提现金额不能超过开票总额");
            }
            let mall_userInfo = JSON.parse(localStorage.mall_userInfo);
            if(mall_userInfo.EmpId){
              this.msg.CreateBy = mall_userInfo.EmpId;
            }
            this.apipost('/api/order/SetInvoiceOnlineTrade', this.msg,
              res => {
                this.loading = false;
                if (res.data.resultCode === 1) {
                  this.Success('提现成功');
                } else {
                  this.Error(res.data.message);
                }
              },
              null
            );
          },
          //查询记录
          searchList() {
            if (this.dateList && this.dateList.length > 0) {
              this.awalMsg.StartTime = this.dateList[0];
              this.awalMsg.EndTime = this.dateList[1];
            } else {
              this.awalMsg.StartTime = '';
              this.awalMsg.EndTime = '';
            }
            if (parseFloat(this.awalMsg.StartMoney) > parseFloat(this.awalMsg.EndMoney)) {
              this.Error('开始金额大于结束金额');
              return;
            }
            this.loading = true;
            this.apipost('/api/order/GetInvoiceOnlineTradePageList', this.awalMsg,
              res => {
                this.loading = false;
                if (res.data.resultCode === 1) {
                  this.tableData = res.data.data.pageData;
                  this.total = res.data.data.count;
                } else {
                  this.Error(res.data.message);
                }
              },
              null
            );
          },
          //点击tab 切换
          handleClick() {
            if (this.activeName == 'first') {
              this.isShowBtn = true;
            } else {
              this.searchList();
              this.getCreaterList();
              this.isShowBtn = false;
            }
          },
          //翻页
          handleCurrentChange(val) {
            this.awalMsg.pageIndex = val;
            this.searchList();
          },
          //获取创建人下拉
          getCreaterList() {
            this.apipost('/api/user/GetMemberUserDropDownList_V2', {
                pageIndex: 1,
                pageSize: 9999
              },
              res => {
                this.loading = false;
                if (res.data.resultCode === 1) {
                  this.createrList = res.data.data.pageData;
                } else {
                  this.Error(res.data.message);
                }
              },
              null
            );
          },
          //获取到账账户
          getAccountList() {
            this.apipost("/api/Employee/GetEmployeePageList", {
              pageIndex: 1,
              pageSize: 9999,
              EmpName: ''
            }, res => {
              if (res.data.resultCode == 1) {
                this.AccountList = res.data.data.pageData;
              } else {
                this.Error(res.data.message);
              }
            })
          },
          //获取提现金额
          getMoney() {
            this.apipost("/api/order/GetInvoiceOnlineTradeInfo", {}, res => {
              if (res.data.resultCode == 1) {
                this.TixianMoney = res.data.data.TotalPrice;
                if (this.TixianMoney == 0 || this.TixianMoney < 0) {
                  this.isCanSubmit = true;
                } else {
                  this.isCanSubmit = false;
                }
                if (this.TixianMoney > 0) {
                  this.msg.Money = this.TixianMoney;
                }
                if (this.TixianMoney > 5000) {
                  this.msg.Money = 5000;
                }
              } else {
                this.Error(res.data.message);
              }
            })
          }
        },
        mounted() {
          this.getMoney();
          this.getAccountList();
          this.getCreaterList();
        }
      };

    </script>
    <style>
      .CashierWithdrawal .content {
        background: #fff;
        margin-top: 10px;
        padding: 20px;
        box-sizing: border-box;
      }

      .CashierWithdrawal .Cashier_Search>span {
        display: inline-block;
        margin: 0 20px 20px 0;
      }

      .CashierWithdrawal .w250 {
        width: 250px !important;
      }

    </style>
