<template>
  <div class="order-content">
      <div class="order-status" v-if="order!=null" >
          <el-steps  :active="order.status==3?order.status+1:order.status" align-center>
            <el-step title="待支付"></el-step>
            <el-step title="待发货"></el-step>
            <el-step title="待收货"></el-step>
            <el-step title="交易完成"></el-step>
          </el-steps>
      </div>
      <div>
      <el-card shadow="never" style="margin-top: 15px">
      <div class="operate-container"  v-if="order!=null">
        <span style="margin-left: 20px" class="color-danger">订单状态：
           <el-tag prop="status" v-for="(item, index) in statusOptions"   v-if="order.status==item.dictValue">{{item.dictLabel}}</el-tag>
        </span>
        <div class="operate-button-container" >
          <el-button size="mini" @click="editOrder()"  v-hasPermi="['store:storeOrder:edit']" >修改订单</el-button>
        </div>
        <div class="operate-button-container"  v-hasPermi="['store:storeOrder:finishOrder']" v-if="order.status===2">
          <el-button size="mini" @click="finishOrder()" >确认收货</el-button>
        </div>
        <div class="operate-button-container" v-if="order.status==1||order.status==2"  v-hasPermi="['store:storeOrder:refundOrderMoney']"  >
          <el-button size="mini" @click="refundOrderMoney()" >退款</el-button>
        </div>
        <div class="operate-button-container"  v-hasPermi="['store:storeOrder:express']"  >
          <el-button size="mini" @click="showExpress()" >查看物流</el-button>
        </div>
        <div class="operate-button-container" v-if="order.tuiMoneyStatus==0"  v-hasPermi="['store:storeOrder:editTuiMoney']"  >
          <el-button size="mini" @click="editTuiMoney1()" >解冻</el-button>
        </div>
        <div class="operate-button-container" v-if="order.tuiMoneyStatus==1"  v-hasPermi="['store:storeOrder:editTuiMoney']"  >
          <el-button size="mini" @click="editTuiMoney2()" >冻结</el-button>
        </div>

        <div class="operate-button-container" v-if="order.status==3&&order.tuiMoneyStatus==null"  v-hasPermi="['store:storeOrder:addTuiMoney']"  >
          <el-button size="mini" @click="addTuiMoney()" >分佣</el-button>
        </div>

        <div class="operate-button-container" v-if="order.extendOrderId!=null"  v-hasPermi="['store:storeOrder:getEroOrder']"  >
          <el-button size="mini" @click="showErpOrder()" >查看ERP订单信息</el-button>
        </div>
        <div class="operate-button-container" v-if="order.isPayRemain!=null&&order.isPayRemain==1"  v-hasPermi="['store:storeOrder:auditPayRemain']"  >
          <el-button size="mini" @click="auditPayRemain()" >尾款审核</el-button>
        </div>
        <div class="operate-button-container" >
          <el-button size="mini" @click="editDelivery()"  v-hasPermi="['store:storeOrder:editDeliveryId']" >修改物流</el-button>
        </div>
        <div class="operate-button-container" v-if="order.status >=1 && order.extendOrderId == null && order.deliveryId == null"  v-hasPermi="['store:storeOrder:createErpOrder']"  >
          <el-button size="mini" @click="addErpOrder()" >创建ERP订单信息</el-button>
        </div>
        <!-- <div class="operate-button-container" v-show="order.status===2">
          <el-button size="mini"  >去发货</el-button>
          <el-button size="mini" >备注订单</el-button>
        </div>
        <div class="operate-button-container" v-show="order.status===4">
          <el-button size="mini"  >订单跟踪</el-button>
          <el-button size="mini"  disabled>备注订单</el-button>
        </div> -->
      </div>
      <div style="margin: 20px 0px">
        <span class="font-small">基本信息</span>
      </div>
      <el-descriptions :column="4" border  >
            <el-descriptions-item label="订单编号"  >
                <span v-if="order!=null">
                  {{order.orderCode}}
                </span>
                <el-tag  v-for="(item, index) in createTypeOptions"    v-if="order!=null&&order.orderCreateType==item.dictValue">{{item.dictLabel}}
                </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="会员"  >
                <span v-if="user!=null">
                  {{user.nickname}}({{user.phone}})
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="支付方式"  >
              <el-tag prop="payType" v-for="(item, index) in payTypeOptions"    v-if="order!=null&&order.payType==item.dictValue">{{item.dictLabel}}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="订单类型"  >
              <el-tag prop="orderType" v-for="(item, index) in orderTypeOptions"    v-if="order!=null&&order.orderType==item.dictValue">{{item.dictLabel}}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="物流公司编号"  >
                <span v-if="order!=null">
                  {{order.deliverySn}}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="物流公司名称"  >
                <span v-if="order!=null">
                  {{order.deliveryName}}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="物流单号"  >
                <span v-if="order!=null">
                  {{order.deliveryId}}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="物流状态"  >
                <span v-if="order!=null">
                  <el-tag prop="deliveryId" v-for="(item, index) in deliveryStatusOptions"    v-if="order!=null&&order.deliveryStatus==item.dictValue">{{item.dictLabel}}</el-tag>
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="物流跟踪状态"  >
                <span v-if="order!=null">
                  <el-tag prop="deliveryId" v-for="(item, index) in deliveryTypeOptions"    v-if="order!=null&&order.deliveryType==item.dictValue">{{item.dictLabel}}</el-tag>
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="物流结算费用"  >
                <span v-if="order!=null&&order.deliveryPayMoney!=null ">
                  {{order.deliveryPayMoney.toFixed(2) }}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="快递帐单日期"  >
                <span v-if="order!=null ">
                  {{order.deliveryTime }}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="快递结算日期"  >
                <span v-if="order!=null ">
                  {{order.deliveryPayTime }}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="推广佣金"  >
                <span v-if="order!=null ">
                  {{order.tuiMoney }}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="收货人"  >
                <span v-if="order!=null ">
                  {{order.realName }}
                </span>
            </el-descriptions-item>
            <el-descriptions-item label="手机号码"  >
                <span v-if="order!=null ">
                  {{order.userPhone }}
                </span>
                <el-button icon="el-icon-search" size="mini" @click="handlePhone()" style="margin-left: 20px;" circle v-hasPermi="['store:storeOrder:queryPhone']"></el-button>
            </el-descriptions-item>
            <el-descriptions-item label="收货地址"  >
              <el-popover
                v-if="order!=null"
                placement="top-start"
                title="收货地址"
                width="300"
                trigger="hover"
                :content="order.userAddress">
                <span slot="reference">{{order.userAddress}}</span>
                <el-button icon="el-icon-search" size="mini" @click="handleAddress()" style="margin-left: 20px;" circle v-hasPermi="['store:storeOrder:queryAddress']"></el-button>
              </el-popover>
            </el-descriptions-item>
            <el-descriptions-item label="档期归属"  >
              <el-tag prop="scheduleId" v-for="(item, index) in scheduleOptions"    v-if="order!=null&&order.scheduleId==item.id">{{item.name}}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="用户备注"  >
                <span v-if="order!=null">
                  {{order.mark}}
                </span>
            </el-descriptions-item>
      </el-descriptions>
      <div style="margin: 20px 0px"  v-if="order!=null">
        <span class="font-small">
          凭证信息
        </span>
      </div>
      <el-image 
          v-if="certificates != null"
          :src="certificates"
          :preview-src-list="[certificates]"
          :style="{ width: '100px', height: '100px' }"
          @click.native="showImageDialog"
        ></el-image>
        <el-dialog :visible.sync="dialogVisibleImage" width="10%">
          <img :src="certificates" style="width: 100%" alt="">
        </el-dialog>
      <div style="margin-top: 20px">
        <span class="font-small">商品信息</span>
      </div>
      <el-table
        border
        v-if="items!=null"
        :data="items"
        size="small"
        style="width: 100%;margin-top: 20px" >
        <el-table-column label="商品图片" width="150" align="center">
          <template slot-scope="scope">
            <img :src="JSON.parse(scope.row.jsonInfo).image" style="height: 80px">
          </template>
        </el-table-column>
        <el-table-column label="商品编码" width="300" align="center">
          <template slot-scope="scope">
            <p>{{JSON.parse(scope.row.jsonInfo).barCode}}</p>
          </template>
        </el-table-column>
        <el-table-column label="商品组合编码" width="300" align="center">
          <template slot-scope="scope">
            <p>{{JSON.parse(scope.row.jsonInfo).groupBarCode}}</p>
          </template>
        </el-table-column>
        <el-table-column label="商品名称" width="300" align="center">
          <template slot-scope="scope">
            <p>{{JSON.parse(scope.row.jsonInfo).productName}}</p>
          </template>
        </el-table-column>
        <el-table-column label="单价" width="240" align="center">
          <template slot-scope="scope">
            <p>￥{{JSON.parse(scope.row.jsonInfo).price.toFixed(2)}}</p>
          </template>
        </el-table-column>
        <el-table-column label="规格" width="240" align="center">
          <template slot-scope="scope">
            {{JSON.parse(scope.row.jsonInfo).sku}}
          </template>
        </el-table-column>
        <el-table-column label="数量" width="180" align="center">
          <template slot-scope="scope">
            {{scope.row.num}}
          </template>
        </el-table-column>
        <el-table-column label="处方药" width="240" align="center">
          <template slot-scope="scope">
            {{scope.row.isPrescribe!=null&&scope.row.isPrescribe==1?'是':'否'}}
          </template>
        </el-table-column>
        <el-table-column label="小计"  align="center">
          <template slot-scope="scope" >
            ￥{{scope.row.num*JSON.parse(scope.row.jsonInfo).price.toFixed(2)}}
          </template>
        </el-table-column>
      </el-table>
      <div style="float: right;margin: 20px" v-if="order!=null">
        合计：<span class="color-danger">￥{{order.totalPrice.toFixed(2)}}</span>
      </div>
      <div style="margin: 60px 0px 20px 0px">
        <span class="font-small">费用信息</span>
      </div>
      <el-descriptions   :column="4" border  >
          <el-descriptions-item label="商品合计"  >
              <span v-if="order!=null">
                ￥{{order.totalPrice.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="应付金额"  >
              <span v-if="order!=null">
                ￥{{order.payPrice.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="运费"  >
              <span v-if="order!=null">
                ￥{{order.payPostage.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="优惠券"  >
              <span v-if="order!=null">
                ￥{{order.couponPrice.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="积分抵扣"  >
              <span v-if="order!=null">
                ￥{{order.deductionPrice.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="实付金额"  >
              <span v-if="order!=null">
                ￥{{order.payMoney.toFixed(2)}}
              </span>
          </el-descriptions-item>
          <el-descriptions-item label="代收金额"  >
              <span v-if="order!=null">
                ￥{{order.payDelivery.toFixed(2)}}
              </span>
          </el-descriptions-item>
      </el-descriptions>

      <div style="margin-top: 20px">
        <span class="font-small">支付信息</span>
      </div>
      <el-table
        border
        :data="payments"
        size="small"
        style="width: 100%;margin-top: 20px" >
          <el-table-column label="支付单号" align="center" prop="payCode" width="120px" />
          <el-table-column label="支付金额" align="center" prop="payMoney" />
          <el-table-column label="类型" align="center" prop="payTypeCode" />
          <el-table-column label="交易单号" align="center" prop="bankTransactionId" />
          <el-table-column label="银行单号" align="center" prop="bankSerialNo" />
          <el-table-column label="创建时间" align="center" prop="createTime" />
          <el-table-column label="支付时间" align="center" prop="payTime" />
      </el-table>

      
      <div style="margin-top: 20px">
        <span class="font-small">操作信息</span>
      </div>
      <el-table style="margin-top: 20px;width: 100%"
                ref="orderHistoryTable"
                :data="logs" border>
        <el-table-column label="操作时间"  width="160" align="center">
          <template slot-scope="scope">
            {{scope.row.changeTime}}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            {{scope.row.changeMessage}}
          </template>
        </el-table-column>
      </el-table>

      <div style="margin-top: 20px">
        <!-- <svg-icon icon-class="marker" style="color: #606266"></svg-icon> -->
        <span class="font-small">分佣信息</span>
      </div>
      <el-table
        border
        :data="tuiMoneyLogs"
        size="small"
                style="width: 100%;margin-top: 20px" >
          <el-table-column label="公司名称" align="center" prop="companyName" width="120px" />
          <el-table-column label="金额" align="center" prop="money" />
          <el-table-column label="余额" align="center" prop="balance" />
          <el-table-column label="创建时间" align="center" prop="createTime" />
          <el-table-column label="备注" align="center" prop="remark" />
      </el-table>
      </el-card>
    </div>

    <el-dialog :title="edit.title" :visible.sync="edit.open" width="600px" append-to-body>
      <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="100px">
        <el-form-item label="订单类型" prop="orderType"  >
            <el-select style="width: 200px" v-model="editForm.orderType" placeholder="请选择订单类型" clearable size="small" >
              <el-option
                      v-for="item in orderTypeOptions"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    />
            </el-select>
        </el-form-item>
       <el-form-item label="状态" prop="status" >
           <el-select style="width:220px" v-model="editForm.status" placeholder="请选择状态" clearable size="small">
            <el-option key="0"  label="待支付" value="0" />
            <el-option key="1"  label="待发货" value="1" />
             <el-option key="2"  label="待收货" value="2" />
             <el-option key="3"  label="交易成功" value="3" />
             <el-option key="-1"  label="退款中" value="-1" />
             <el-option key="-2"  label="已退款" value="-2" />
             <el-option key="-3"  label="已取消" value="-3" />
           </el-select>
         </el-form-item>
         <el-form-item label="档期归属" prop="scheduleId"  >
            <el-select filterable style="width: 200px" v-model="editForm.scheduleId" placeholder="请选择档期" clearable size="small" >
              <el-option
                      v-for="item in scheduleOptions"
                      :key="item.id"  
                      :label="item.name"
                      :value="item.id"
                    />
            </el-select>
        </el-form-item>
         <el-form-item label="详情地址" prop="userAddress"  >
          <el-input v-model="editForm.userAddress" placeholder="请输入" />
        </el-form-item>
        <!-- <el-form-item label="erp单号" prop="extendOrderId"  >
          <el-input v-model="editForm.extendOrderId" placeholder="请输入" />
        </el-form-item> -->
        <el-form-item label="备注" prop="mark"  >
          <el-input v-model="editForm.mark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEditForm">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="editDy.title" :visible.sync="editDy.open" width="600px" append-to-body>
      <el-form ref="editDyForm" :model="editDyForm" :rules="editDyRules" label-width="120px">
      <div  v-hasPermi="['store:storeOrder:updateErpOrder']"  style="margin-bottom: 20px;" >
        <el-button size="mini" @click="updateErpOrder" >同步物流单号信息</el-button>
      </div>
        <el-form-item label="物流公司" prop="deliverySn" >
           <el-select style="width:220px" v-model="editDyForm.deliverySn" placeholder="请选择" clearable size="small">
            <el-option key="SF"  label="顺丰" value="SF" />
            <el-option key="EMS"  label="邮政" value="EMS" />
             <el-option key="ZTO"  label="中通" value="ZTO" />
             <el-option key="JD"  label="京东" value="JD" />
             <el-option key="DBL"  label="德邦" value="DBL" />
           </el-select>
         </el-form-item>
        <el-form-item label="物流单号" prop="deliveryId"  >
          <el-input v-model="editDyForm.deliveryId" placeholder="请输入物流单号" />
        </el-form-item>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEditDyForm">确 定</el-button>
        <el-button @click="editDy.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="expressDialog.title" :visible.sync="expressDialog.open" width="600px" append-to-body>
      <div  v-hasPermi="['store:storeOrder:syncExpress']"  >
        <el-button size="mini" @click="syncExpress()" >同步快递鸟物流状态</el-button>
      </div>
      <el-table style="margin-top: 20px;width: 100%"
                ref="orderHistoryTable"
                :data="traces" border>
        <el-table-column label="操作时间"  width="160" align="center">
          <template slot-scope="scope">
            {{scope.row.AcceptTime}}
          </template>
        </el-table-column>
         <el-table-column label="位置" align="center">
          <template slot-scope="scope">
            {{scope.row.Location}}
          </template>
        </el-table-column>
        <el-table-column label="描述" align="center">
          <template slot-scope="scope">
            {{scope.row.AcceptStation}}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog :title="erpDialog.title" :visible.sync="erpDialog.open" width="600px" append-to-body>
      <div v-if="order!=null&&order.extendOrderId!=null&&order.status==1"  v-hasPermi="['store:storeOrder:updateExpress']"  >
        <el-button size="mini" @click="updateExpress()" >同步物流发货</el-button>
      </div>
      <div class="table-layout"  v-if="erpOrder!=null">
        <el-row>
          <el-col :span="6" class="table-cell-title">订单编号</el-col>
          <el-col :span="6" class="table-cell-title">是否代收</el-col>
          <el-col :span="6" class="table-cell-title">快递编号</el-col>
          <el-col :span="6" class="table-cell-title">快递名称</el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell">
            {{erpOrder.code}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.cod?'是':'否'}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.express_code}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.express_name}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell-title">收货人</el-col>
          <el-col :span="6" class="table-cell-title">电话</el-col>
          <el-col :span="6" class="table-cell-title">地址</el-col>
          <el-col :span="6" class="table-cell-title">运单号</el-col>
        </el-row>
        <el-row>
          <el-col :span="6" class="table-cell">
            {{erpOrder.receiver_name}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.receiver_mobile}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.receiver_address}}
          </el-col>
          <el-col :span="6" class="table-cell">
            {{erpOrder.deliverys!=null&&erpOrder.deliverys.length>0?erpOrder.deliverys[0].mail_no:''}}
          </el-col>

        </el-row>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
import {auditPayRemain,addTuiMoney,syncExpress,updateExpress,getEroOrder,refundOrderMoney, editTuiMoney,getExpress,finishOrder,listStoreOrder, getStoreOrder, delStoreOrder, addStoreOrder, updateStoreOrder, exportStoreOrder,updateDeliveryId, createErpOrder,updateErp,getStoreOrderAddress,getStoreOrderPhone} from "@/api/store/storeOrder";
import { getTcmScheduleList } from "@/api/company/schedule";
export default {
  name: "order",
  data() {
    return {
      dialogVisibleImage: false,
      createTypeOptions:[],
      deliveryStatusOptions:[],
      deliveryTypeOptions:[],
      scheduleOptions:[],
      schedules:[],
      orderId:null,
      erpDialog:{
        title:"ERP订单信息",
        open:false,
      },
      expressDialog:{
        title:"物流信息",
        open:false,
      },
      edit:{
        title:"",
        open:false,
      },
      editDy:{
        title:"修改物流单号",
        open:false,
      },
      editDyForm:{
        deliverySn:null,
        deliveryId:null,
      },
      editForm:{
        orderType:null,
        status:null,
        userAddress:null,
        // extendOrderId:null,
        scheduleId:null,
        mark:"",
      },

      editDyRules:{
        deliverySn: [
          { required: true, message: "物流公司不能为空", trigger: "blur" }
        ],
        deliveryId: [
          { required: true, message: "物流单号不能为空", trigger: "blur" }
        ],
      },
      editRules:{
        userAddress: [
          { required: true, message: "收货地址不能为空", trigger: "blur" }
        ],

      },
      orderTypeOptions:[],
      payTypeOptions:[],
      statusOptions:[],
      certificates:null,
      orderStatus:null,
      order:null,
      user:{},
      logs:[],
      items:[],
      express:null,
      traces:[],
      payments:[],
      tuiMoneyLogs:[],
      erpOrder:null,
    };
  },
  created() {
    this.getDicts("store_order_delivery_status").then((response) => {
      this.deliveryStatusOptions = response.data;
    });
    this.getDicts("store_order_delivery_type").then((response) => {
      this.deliveryTypeOptions = response.data;
    });

    this.getDicts("store_order_type").then((response) => {
      this.orderTypeOptions = response.data;
    });
    this.getDicts("store_order_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("store_pay_type").then((response) => {
      this.payTypeOptions = response.data;
    });
    this.getDicts("store_order_create_type").then((response) => {
      this.createTypeOptions = response.data;
    });
    getTcmScheduleList().then(response => {
      this.scheduleOptions = response.data;
    });
  },
  methods: {
    handleAddress(){
        const id = this.order.id;
        getStoreOrderAddress(id).then(response =>{
            this.order.userAddress = response.address;
        }) 
      },
      handlePhone(){
        const id = this.order.id;
        getStoreOrderPhone(id).then(response =>{
            this.order.userPhone = response.userPhone;
        }) 
      },
    showImageDialog() {
      this.dialogVisible = true;
    },
    syncExpress(){
      var that=this;
        this.$confirm('确定同步物流状态吗', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return syncExpress(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    updateErpOrder(){
      var that=this;
        this.$confirm('确定同步物流单号信息吗', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return updateErp(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
          this.editDy.open = false
        }).catch(function() {});
    },
    updateExpress(){
      var that=this;
        this.$confirm('确定同步物流信息吗，同步后将自动发货', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return updateExpress(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    showErpOrder(){
      this.erpDialog.open=true;
      var data={extendOrderId:this.order.extendOrderId};
      getEroOrder(data).then(response => {
          this.erp = response.data;
          if(response.data.orders!=null&&response.data.orders.length==1){
            this.erpOrder=response.data.orders[0]
          }
          console.log(this.erpOrder)

      });
    },
    showExpress(){
      this.expressDialog.open=true;
      getExpress(this.orderId).then(response => {
          this.express = response.data;
          if(this.express!=null&&this.express.Traces!=null){
              this.traces=this.express.Traces
          }

      });

    },
    submitEditForm(){
        this.$refs["editForm"].validate(valid => {
        if (valid) {
          updateStoreOrder(this.editForm).then(response => {
            if (response.code === 200) {
              this.msgSuccess("操作成功");
              this.edit.open = false;
              this.getOrder(this.order.id);
            }
          });

        }
      });
    },
    submitEditDyForm(){
        this.$refs["editDyForm"].validate(valid => {
        if (valid) {
          updateDeliveryId(this.editDyForm).then(response => {
            if (response.code === 200) {
              this.msgSuccess("操作成功");
              this.editDy.open = false;
              this.getOrder(this.order.id);
            }
          });

        }
      });
    },
    editTuiMoney1(){
      var that=this;
        this.$confirm('是否冻结此订单推广佣金吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return editTuiMoney(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    editTuiMoney2(){
      var that=this;
        this.$confirm('是否解冻此订单推广佣金吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return editTuiMoney(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    addTuiMoney(){
      var that=this;
        this.$confirm('确定手动分佣金吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return addTuiMoney(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    refundOrderMoney(){
        var that=this;
        this.$confirm('确认退款吗', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return refundOrderMoney(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    finishOrder(){
        var that=this;
        this.$confirm('是否确认客户已收货?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return finishOrder(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    auditPayRemain(){
        var that=this;
        this.$confirm('是否确认已收尾款?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderId:that.order.id}
          return auditPayRemain(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    editOrder(){
        this.edit.open=true;
        this.editForm.id=this.order.id;
        this.editForm.mark=this.order.mark
        this.editForm.orderType=this.order.orderType.toString();
        this.editForm.status = this.order.status.toString();
        this.editForm.userAddress = this.order.userAddress.toString();
        this.editForm.scheduleId = this.order.scheduleId;
        // this.editForm.extendOrderId = this.order.extendOrderId.toString();
        
    },
    //推送管易按钮
    addErpOrder(){
        var that=this;
        this.$confirm('是否确认推送管易?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          var data={orderCode:that.order.orderCode}
          return createErpOrder(data);
        }).then(() => {
          this.msgSuccess("操作成功");
          this.getOrder(this.order.id);
        }).catch(function() {});
    },
    editDelivery(){
      this.editDy.open = true;
      this.editDyForm.id = this.order.id;
      this.editDyForm.deliveryId = this.order.deliveryId;
      this.editDyForm.deliverySn = this.order.deliverySn;
    },
    getOrder(orderId){
        this.orderId=orderId;
        this.certificates = null;
        getStoreOrder(orderId).then(response => {
            this.order = response.order;
            if(response.order.certificates != null){
              this.certificates = response.order.certificates;
            }
            if(response.order.status != null){
              this.orderStatus = response.order.status;
            }  
            this.user = response.user;
            this.logs = response.logs;
            this.items = response.items;
            this.payments=response.payments;
            this.tuiMoneyLogs=response.tuiMoneyLogs;
        });
     }
  }
};
</script>
<style scoped>
.order-content{
  margin: 10px;

}

.operate-container {
  background: #F2F6FC;
  height: 60px;
  margin: -20px -20px 0;
  line-height: 60px;
}

.operate-button-container {
  float: right;
  margin-right: 20px
}
</style>
