<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.order_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="primary"
                   size="small"
                   icon="el-icon-receiving"
                   plain
                   @click="handleExport">导 出
        </el-button>
        <el-button type="primary"
                   size="small"
                   icon="el-icon-receiving"
                   plain
                   @click="handleBind">绑定物流单号
        </el-button>
      </template>

      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          size="small"
          @click="viewDialogShow(scope.row)"
        >详 情
        </el-button>
        <el-button
          v-if="scope.row.payFlag == 6 || scope.row.payFlag == 6"
          type="text"
          size="small"
          @click="refund(scope.row)"
        >退款
        </el-button>
      </template>
    </avue-crud>

    <el-dialog title="详情"
               append-to-body
               :visible.sync="viewDetail"
               :before-close="handleClose"
               width="800px"
               heigh="40%">
      <!-- 订单信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">订单信息</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span class="d_context">订单号:</span>
          <span>{{form.outTradeNo}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">下单时间:</span>
          <span>{{form.createTime}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">订单类型:</span>
          <span>{{form.orderTypeDisplayName}}</span>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span class="d_context">订单状态:</span>
          <span>{{form.payFlagDisplayName}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">下单人:</span>
          <span>{{form.userName}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">到账类型:</span>
          <span>{{form.settleTypeDisplayName}}</span>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8" v-if="form.payFlag > 1">
          <span class="d_context">支付时间:</span>
          <span>{{form.payTime}}</span>
        </el-col>
        <el-col :span="8" v-if="form.payFlag == 6 || form.payFlag == 7">
          <span class="d_context">申请退款时间:</span>
          <span>{{form.refundApplyTime}}</span>
        </el-col>
        <el-col :span="8" v-if="form.payFlag == 7">
          <span class="d_context">退款时间:</span>
          <span>{{form.refundTime}}</span>
        </el-col>
        <el-col :span="8" v-if="form.payFlag == 4">
          <span class="d_context">确认收货时间:</span>
          <span>{{form.recordTime}}</span>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <!-- 商品信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">商品信息</div></el-col>
        <el-col :span="5">
          <el-image
            style="width: 90px; height: 90px"
            :src="form.goodsInfo.goodsCover"
            fit="cover"></el-image>
        </el-col>
        <el-col :span="19">
          <el-col :span="12">
            <span class="d_context">商品名称:</span>
            <span>{{form.goodsInfo.goodsName}}</span>
          </el-col>
          <el-col :span="12">
            <span class="d_context">规格:</span>
            <span>{{form.goodsSpec.spceName}}</span>
          </el-col>
          <el-col :span="12">
            <span class="d_context">价格:</span>
            <span>{{form.orderGood.goodsPrice}}</span>
          </el-col>
          <el-col :span="12">
            <span class="d_context">数量:</span>
            <span>{{form.orderGood.goodsNum}}</span>
          </el-col>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <!-- 费用信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">费用信息</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span class="d_context">支付总价:</span>
          <span>{{form.payFee}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">商品总购买价:</span>
          <span>{{form.totalFee}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">邮费:</span>
          <span>{{form.wlPrice}}</span>
        </el-col>
        <el-col :span="8" v-if="form.payFlag == 7">
          <span class="d_context">退款金额:</span>
          <span>{{form.refundAmount}}</span>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <!-- 积分信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">积分信息</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span class="d_context">获得积分:</span>
          <span>{{form.totalTicket}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">抵扣积分:</span>
          <span v-if="form.needIntegral == -1">暂无</span>
          <span v-else>{{form.needIntegral}}</span>
        </el-col>
        <el-col :span="8" v-if="form.payFlag == 7">
          <span class="d_context">退款扣除:</span>
          <span>{{form.deductIntegral}}</span>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <!-- 收货人信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">收货人信息</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span class="d_context">收件人:</span>
          <span>{{form.receivingName}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">收件人电话:</span>
          <span>{{form.telPhone}}</span>
        </el-col>
        <el-col :span="8">
          <span class="d_context">收货地址:</span>
          <span>{{form.userAddress}}</span>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <!-- 物流信息 -->
      <el-row>
        <el-col :span="24"><div class="d_title">物流信息</div></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-row>
            <el-col :span="24">
              <span class="d_context">配送方式:</span>
              <span v-if="form.distributeModeDisplayName == ''">暂无</span>
              <span v-else>{{form.distributeModeDisplayName}}</span>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <span class="d_context">快递公司:</span>
              <span v-if="form.wlName == ''">暂无</span>
              <span v-else>{{form.wlName}}</span>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <span class="d_context">物流单号:</span>
              <span v-if="form.wlName == ''">暂无</span>
              <span v-else>{{form.wlNum}}</span>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="16">
          <avue-empty desc="暂无物流信息" v-if="logisticList.length == 0"></avue-empty>
          <div style="height: 270px; display: flex" class="cab" v-else>
            <el-scrollbar style="height:100%">
              <el-timeline>
                <el-timeline-item
                  v-for="(activity, index) in logisticList"
                  :key="index"
                  :timestamp="activity.time" color="#0bbd87">
                  {{activity.message}}
                </el-timeline-item>
              </el-timeline>
            </el-scrollbar>
          </div>

        </el-col>
      </el-row>


    </el-dialog>

    <el-dialog title="绑定物流单号" @close="refreshChange"
               append-to-body
               :visible.sync="bindBox"
               :before-close="handleClose"
               width="500px"
               heigh="40%">
      <el-form :model="form" label-width="80px">
        <el-form-item label="物流公司:" placeholder="请选择物流公司">
          <el-select v-model="wlCompany" filterable placeholder="请选择物流公司">
            <el-option
              v-for="item in WL_COMPANY"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="物流单号:">
          <el-input v-model="wlNo" autocomplete="off" placeholder="请输入物流单号"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="bindLogisticsInfo">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="共富1580订单录入" @close="refreshChange"
               append-to-body
               :visible.sync="orderLinkedBox"
               :before-close="handleClose"
               width="30%"
               heigh="40%">
      <el-form label-position='top' :model="orderLinkedForm" :rules="orderLinkedRule" ref="ruleForm" label-width="80px">
        <el-form-item label="手机号:" prop="phone">
          <el-input v-model="orderLinkedForm.phone" autocomplete="off" placeholder="请输入手机号"></el-input>
        </el-form-item>

        <el-form-item label="姓名:" prop="username">
          <el-input v-model="orderLinkedForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
        </el-form-item>

        <el-form-item label="推荐人手机号:" prop="recommendPhone">
          <el-input v-model="orderLinkedForm.recommendPhone" autocomplete="off" placeholder="请输入推荐人手机号"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="addLinkedOrder">确 定</el-button>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
import log from "../redpacket/log";

var DIC = {
  INTEGRAL_TYPE: [{
    label: '红色积分',
    value: '1'
  }, {
    label: '绿色积分',
    value: '2'
  }],
  PAY_YES_NO: [{
    label: '已支付',
    value: '1'
  }, {
    label: '未支付',
    value: '2'
  }],
}

  /* update*/
  import {getDetail, add, deliver, remove, getGoodsOrder, exportData, bindLogisticsInfo, refundCart, linkedOrderAdd} from "@/api/finance/order";
  import {mapGetters} from "vuex";
import {remove as removeSpec} from "../../api/redenvelopemall/goodsspec";

  export default {
    data() {
      return {
        orderLinkedForm: {
          recommendPhone: '',
          phone: '',
          username: ''
        },
        orderLinkedRule: {
          phone: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
          ],
          username: [
            { required: true, message: '请输入姓名', trigger: 'blur' },
          ],
        },
        orderLinkedBox: false,
        WL_COMPANY: [{
          label: '圆通速递',
          value: 'yuantong'
        }, {
          label: '韵达快递',
          value: 'yunda'
        },{
          label: '申通快递',
          value: 'shentong'
        },{
          label: '中通快递',
          value: 'zhongtong'
        },{
          label: '极兔速递',
          value: 'jtexpress'
        },{
          label: '邮政快递包裹',
          value: 'youzhengguonei'
        },{
          label: '顺丰速运',
          value: 'shunfeng'
        },{
          label: '京东物流',
          value: 'jd'
        },{
          label: '百世快递',
          value: 'huitongkuaidi'
        },{
          label: '德邦快递',
          value: 'debangkuaidi'
        },{
          label: '邮政标准快递',
          value: 'youzhengbk'
        }],
        activities: [{
          content: '活动按期开始',
          timestamp: '2018-04-15'
        }, {
          content: '通过审核',
          timestamp: '2018-04-13'
        }, {
          content: '创建成功',
          timestamp: '2018-04-11'
        }],
        wlCompany: '',
        wlNo: '',
        viewDetail: false,
        bindBox: false,
        form: {
          goodsInfo: {
            goodsCover : ''
          },
          goodsSpec: {},
          orderGood: {}
        },
        logisticList: [],
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0,
          pageSizes: [10, 30, 50, 100, 200, 400]
        },
        selectionList: [],
        option: {
          searchIcon: true,
          searchIndex: 3,
          height:'auto',
          calcHeight: 30,
          // searchShow: true,
          // searchMenuSpan: 6,
          border: true,
          viewBtn: false,
          editBtn: false,
          delBtn: false,
          menuWidth: 100,
          selection: true,
          dialogClickModal: false,
          labelWidth: 120,
          excelBtn:true,
          column: [
            {
              label: "主键ID",
              prop: "id",
              hide: true,
              display: false,
            },
            {
              label: "用户ID",
              prop: "userId",
              hide: true,
              display: false,
            },
            {
              label: "订单号",
              prop: "outTradeNo",
              overHidden: true,
              display: false,
              search: true,
              width: 170,
            },
            {
              label: "收款方",
              prop: "settlementAccount",
              overHidden: true,
              display: false,
              formatter:(val,value,label)=>{
                if (value == '2088441218763712') {
                  return "正道乾";
                } else if (value == '2088341967443472'){
                  return "中宏科技"
                } else if (value == '1633748877' || value == '2088541242921565'){
                  return "中宏咨询"
                } else {
                  return "暂无";
                }
              },
            },
            {
              label: "商品名称",
              prop: "goodsName",
              display: false,
              width: 200,
              search: true
            },
            {
              label: "规格名称",
              prop: "specName",
              display: false,
              width: 100,
              search: true
            },
            {
              label: "商品来源",
              prop: "source",
              display: false,
              search: true,
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=third_source",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dataType: "number",
              // formatter:(val,value,label)=>{
              //   if (value == '1') {
              //     return "胜天半子";
              //   } else if (value == '2'){
              //     return "唯品尚"
              //   } else {
              //     return "中宏";
              //   }
              // },
            },
            {
              label: "订单类型",
              prop: "orderType",
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=goods_order_type",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dataType: "number",
              search: true,
              display: false,
              rules: [{
                required: true,
                message: "订单类型",
                trigger: "blur"
              }]
            },
            {
              label: "下单人",
              prop: "userName",
              search: true,
              display: false,
              overHidden: true,
              width: 65,
              hide: true
            },
            {
              label: "支付方式",
              prop: "payCodeDesc",
              display: false,
            },
            {
              label: "支付总价",
              prop: "payFee",
              display: false,
            },
            {
              label: "商品总购买价",
              prop: "totalFee",
              display: false,
              formatter:(val,value,label)=>{
                return Number(value).toFixed(2);
              },
            },
            {
              label: "数量",
              prop: "goodsNum",
              display: false,
            },
            {
              label: "邮费",
              prop: "wlPrice",
              display: false,
              width: 60,
            },
            {
              label: "协议价",
              prop: "agreementPrice",
              display: false,
              formatter:(val,value,label)=>{
                return Number(value).toFixed(2);
              },
            },
            {
              label: "商品售价",
              prop: "salePrice",
              display: false,
              formatter:(val,value,label)=>{
                return Number(value).toFixed(2);
              },
            },

            {
              label: "抵扣积分",
              prop: "needIntegral",
              display: false,
              formatter:(val,value,label)=>{
                return Number(value).toFixed(2);
              },
            },
            {
              label: "订单状态",
              prop: "payFlag",
              type: "select",
              dicUrl: "/api/blade-system/dict-biz/dictionary?code=pay_flag",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              dataType: "number",
              search: true,
              // hide: true,
              display: false,
              rules: [{
                required: true,
                message: "订单状态",
                trigger: "blur"
              }]
            },
            {
              label: "付款状态",
              prop: "orderState",
              type: "select",
              hide: true,
              search: true,
              display: false,
              dicData: DIC.PAY_YES_NO
            },
            {
              label: "配送方式",
              prop: "distributeModeDisplayName",
              display: false,
              hide: true
            },
            {
              label: "配送信息",
              prop: "deliveryStaff",
              display: false,
              hide: true,
            },
            // {
            //   label: "支付方式",
            //   prop: "payCode",
            //   display: false,
            // },
            {
              label: "收件人",
              prop: "receivingName",
              search: true,
              display: false,
            },
            {
              label: "电  话",
              prop: "telPhone",
              display: false,
              search: true,
              span: 8,
              width: 110,
            },
            {
              label: "收货地址",
              prop: "userAddress",
              overHidden: true,
              span: 24,
              display: false,
              width: 160,
            },
            {
              label: "是否退款",
              prop: "isRefundDisplayName",
              hide: true,
              display: false,
            },
            {
              label: "物流公司名称",
              prop: "wlName",
              span: 24,
              display: false,
              hide: true,
            },
            {
              label: "物流公司",
              hide: true,
              prop: "wlCode",
              type: "select",
              dicUrl: "/api/platform/express/selectList",
              props: {
                label: "expressName",
                value: "expressCode"
              },
              dataType: "text",
              viewDisplay: false,
              rules: [{
                required: true,
                message: "请选择物流公司",
                trigger: "blur"
              }]
            },
            {
              label: "物流单号",
              prop: "wlNum",
              overHidden: true,
              viewDisplay: false,
              hide: true,
              search: true
            },
            {
              label: "下单时间",
              prop: "createTime",
              display: false,
              width: 150,
            },
            {
              label: "支付时间",
              prop: "payTime",
              width: 140,
              display: false,
              hide: true
            },
            {
              label: "发货时间",
              prop: "sendTime",
              hide: true,
              width: 140,
              display: false,
            },
            {
              label: "收货时间",
              prop: "recordTime",
              width: 140,
              display: false,
              hide: true,
            },
            {
              label: "更新时间",
              prop: "updateTime",
              hide: true,
              display: false,
            },
            {
              label: "备注",
              prop: "remark",
              span: 24,
              hide: true,
              display: false,
            },
            {
              label: "积分类型",
              display: false,
              hide: true,
              search: true,
              prop: "integralType",
              type: "select",
              dicData: DIC.INTEGRAL_TYPE
            },
            {
              label: "下单时间",
              display: false,
              hide: true,
              search: true,
              type: 'datetimerange',
              prop:'orderTimeRange',
              searchRange:true,
              defaultTime:['00:00:00', '23:59:59'],
              format:'yyyy-MM-dd HH:mm:ss',
              valueFormat:'yyyy-MM-dd HH:mm:ss',
              startPlaceholder: '开始时间',
              endPlaceholder: '结束时间',
            }
          ],

          group: [
            {
              label: '订单信息',
              prop: 'orderInfo',
              column: [
                {
                  label: '订单号',
                  prop: 'outTradeNo',
                  span: 12
                },
                {
                  label: '下单时间',
                  prop: 'createTime',
                  span: 12
                },
                {
                  label: '订单类型',
                  prop: 'orderTypeDisplayName',
                  span: 12
                },
                {
                  label: '订单状态',
                  prop: 'payFlagDisplayName',
                  span: 12
                },
                {
                  label: '下单人',
                  prop: 'userName',
                  span: 12
                },
                {
                  label: '到账类型',
                  prop: 'settleTypeDisplayName',
                  span: 12
                },
              ]
            },
            {
              label: '费用信息',
              prop: 'amountInfo',
              column: [
                {
                  label: '支付总价',
                  prop: 'payFee',
                  span: 12
                },
                {
                  label: '商品总购买价',
                  prop: 'totalFee',
                  span: 12
                },
              ]
            },
            {
              label: '积分信息',
              prop: 'integralInfo',
              column: [
                {
                  label: '获得积分',
                  prop: 'totalTicket',
                  span: 12
                },
                {
                  label: '抵扣积分',
                  prop: 'needIntegral',
                  span: 12
                },
              ]
            },
            {
              label: '收货人信息',
              prop: 'receivingInfo',
              editDisplay: false,
              column: [
                {
                  label: "收件人",
                  prop: "receivingName",
                  span: 12
                },
                {
                  label: "收件人电话",
                  prop: "telPhone",
                  span: 12
                },
                {
                  label: "收货地址",
                  prop: "userAddress",
                  span: 24
                }
              ],
            },
            {
              label: '物流信息',
              prop: 'wlInfo',
              editDisplay: false,
              column: [
                {
                  label: "物流公司名称",
                  prop: "wlName",
                  span: 12,
                },
                {
                  label: "物流单号",
                  prop: "wlNum",
                  span: 12,
                },
              ],
            },
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.order_add, false),
          viewBtn: this.vaildData(this.permission.order_view, false),
          delBtn: this.vaildData(this.permission.order_delete, false),
          editBtn: this.vaildData(this.permission.order_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        deliver(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        const orderTimeRange = this.query.orderTimeRange;
        if (orderTimeRange) {
          this.query.orderStartTime = orderTimeRange[0];
          this.query.orderEndTime = orderTimeRange[1];
        }
        this.loading = true;
        getGoodsOrder(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      },
      handleExport() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        const loading = this.$loading({
          lock: true,
          text: '导出中，请稍等...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        exportData(this.selectionList, this.query.orderStartTime, this.query.orderEndTime).then(res => {
          loading.close();
          this.selectionClear();
          var filename = "订单数据.xlsx";
          var blob = new Blob([res.data])
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.href = href;
          downloadElement.download = filename
          //此处也可以将filename写死 "filename.xlsx"
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象

          // window.open(`/api/blade-system/region/export-region?${this.website.tokenHeader}=${getToken()}`);
        }).catch(() => {
          loading.close();
        });
      },
      handleBind() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择一条数据");
          return;
        }
        if (this.selectionList.length > 1) {
          this.$message.warning("只能选择一条数据");
          return;
        }
        if (this.selectionList[0].businessType != 1) {
          this.$message.warning("非自营类型不支持绑定");
          return;
        }
        this.bindBox = true;
      },
      handleClose() {
        this.bindBox = false;
        this.wlNo = '';
        this.wlCompany = '';
        this.viewDetail = false;
        this.form = {
          goodsInfo: {
            goodsCover : ''
          },
          goodsSpec: {},
          orderGood: {}
        };
        this.orderLinkedBox = false;
        this.orderLinkedForm = {phone: "",username: ""}
      },
      bindLogisticsInfo() {
        let wlCompanyName = '';
        this.WL_COMPANY.map(e => {
          if (this.wlCompany == e.value) {
            wlCompanyName = e.label;
          }
        })
        const loading = this.$loading({
          lock: true,
          text: '绑定中，请稍等...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        bindLogisticsInfo(this.selectionList[0].outTradeNo, this.wlNo, wlCompanyName, this.wlCompany).then(res => {
          loading.close();
          this.selectionClear();
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.handleClose();
        }).catch(() => {
          loading.close();
        });
      },
      addLinkedOrder() {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            const loading = this.$loading({
              lock: true,
              text: '录入中，请稍等...',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            });
            linkedOrderAdd(this.orderLinkedForm.phone, this.orderLinkedForm.username, this.orderLinkedForm.recommendPhone).then(res => {
              loading.close();
              this.$message({
                type: "success",
                message: "录入成功!"
              });
              this.handleClose();
            }).catch(() => {
              loading.close();
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      viewDialogShow(row) {
        const loading = this.$loading({
          lock: true,
          text: '加载中...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        getDetail(row.id).then(res => {
          this.form = res.data.data;
          this.logisticList = res.data.data.logisticList
          loading.close();
          this.viewDetail = true;
        }).catch(() => {
          loading.close();
        });
      },
      refund(row) {
        this.$confirm("确定退款？", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            const loading = this.$loading({
              lock: true,
              text: '退款中...',
              spinner: 'el-icon-loading',
              background: 'rgba(0, 0, 0, 0.7)'
            });
            refundCart(row.outTradeNo, row.payFee, row.totalTicket).then(res => {
              loading.close();
              this.$message({
                type: "success",
                message: "退款成功!"
              });
              this.refreshChange();
            }).catch(() => {
              loading.close();
            });
          });
      }
    }
  };
</script>

<style>
.d_title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
}
.d_context {
  margin-right: 10px;
}
.el-col {
  margin-bottom: 12px;
}
</style>
