<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="会员手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入会员手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="会员" prop="userId">-->
<!--        <el-select v-model="queryParams.userId" filterable placeholder="请选择">-->
<!--          <el-option-->
<!--            v-for="(item,index) in memberUserList"-->
<!--            :key="index"-->
<!--            :label="item.name+item.phone"-->
<!--            :value="item.id">-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="会员名称" prop="memberUserName">
        <el-input
          v-model="queryParams.memberUserName"
          placeholder="请输入会员名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员" prop="salesmanId">
        <el-select v-model="queryParams.salesmanId" filterable placeholder="请选择">
          <el-option
            v-for="(item,index) in salesmanList"
            :key="index"
            :label="item.name+item.phone"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable size="small">
          <el-option label="普通订单" :value="0" />
          <el-option label="拼团订单" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="配送方式" prop="deliveryType">
        <el-select v-model="queryParams.deliveryType" placeholder="请选择配送方式" clearable size="small">
          <el-option label="快递" :value="0" />
          <el-option label="自提" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付类型" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付类型" clearable size="small">
          <el-option label="未支付" :value="0" />
          <el-option label="微信" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="下单时间" prop="createAt">
        <el-date-picker
          v-model="createAtRange"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['mall:mallOrderOrder:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mall:mallOrderOrder:edit']"
        >修改</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['mall:mallOrderOrder:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['mall:mallOrderOrder:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="deliveryByOrderIds"
          v-hasPermi="['mall:mallOrderOrder:edit']"
        >批量配送</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-monitor"
          size="mini"
          :loading="exportLoading"
          @click="batchPrintDataButton"
          v-hasPermi="['mall:mallOrderOrder:print']"
        >批量打印</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallOrderOrderList"  @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="主键ID" align="center" prop="id" />-->
      <el-table-column label="订单号" align="center" prop="orderNo" width="110px" />
      <el-table-column label="会员名称" align="center" prop="memberUserName" />
      <el-table-column label="会员手机号" align="center" prop="phone" />
      <el-table-column label="业务员名称" align="center" prop="salesmanName" />
      <el-table-column label="订单类型" align="center" prop="orderType" >
        <template slot-scope="scope">
          <div v-if="scope.row.orderType == 0">普通订单</div>
          <div v-if="scope.row.orderType == 2">拼团订单</div>
        </template>
      </el-table-column>
      <el-table-column label="配送方式" align="center" prop="deliveryType" >
        <template slot-scope="scope">
          <div v-if="scope.row.deliveryType == 0">快递</div>
          <div v-if="scope.row.deliveryType == 1">自提</div>
        </template>
      </el-table-column>
      <el-table-column label="订单原价" align="center" prop="orderPrice" />
      <el-table-column label="实付金额" align="center" prop="payment" />
      <el-table-column label="订单状态" align="center" prop="status" >
      <template slot-scope="scope">
        <dict-tag :options="statusOptions" :value="scope.row.status"/>
      </template>
      </el-table-column>
      <el-table-column label="支付类型" align="center" prop="payType" >
        <template slot-scope="scope">
          <div v-if="scope.row.payType == 0">未支付</div>
          <div v-if="scope.row.payType == 1">微信</div>
          <div v-if="scope.row.payType == 2">支付宝</div>
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createAt" />
      <el-table-column label="支付时间" align="center" prop="payAt" />
      <el-table-column label="买家留言" align="center" prop="buyerMsg" />
      <el-table-column label="所属商家" align="center" prop="shopName" />
      <!--<el-table-column label="是否申请退款" align="center" prop="isRefund" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-monitor"
            @click="printDialogOpen(scope.row)"
          >打印</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:mallOrderOrder:edit']"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['mall:mallOrderOrder:remove']"-->
<!--          >删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleChackDetail(scope.row)"
            v-hasPermi="['mall:mallOrderOrder:chackDetail']"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单状态" v-if="form.status == '1' || form.status == '2'">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusTwoOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="收件人" prop="receiverName">
          <el-input v-model="form.receiverName" placeholder="请输入收件人" disabled />
        </el-form-item>
        <el-form-item label="电话" prop="receiverPhone">
          <el-input v-model="form.receiverPhone" placeholder="请输入电话" disabled />
        </el-form-item>
        <el-form-item label="省份" prop="receiverProvince">
          <el-input v-model="form.receiverProvince" placeholder="请输入省份" disabled />
        </el-form-item>
        <el-form-item label="城市" prop="receiverCity">
          <el-input v-model="form.receiverCity" placeholder="请输入城市" disabled />
        </el-form-item>
        <el-form-item label="区县" prop="receiverArea">
          <el-input v-model="form.receiverArea" placeholder="请输入区县" disabled />
        </el-form-item>
        <el-form-item label="地址" prop="receiverAddress">
          <el-input v-model="form.receiverAddress" placeholder="请输入地址" disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

<!--    订单详情-->
    <el-dialog  :visible.sync="menuRoleVisible" append-to-body>
      <el-form label-width="90px">
        <el-row>
          <el-col :span="parseInt(12)">
            <el-form-item label="收件人" prop="receiverName" v-if="form.deliveryType === 0" >
              <el-input v-model="form.receiverName" placeholder="" disabled />
            </el-form-item>
            <el-form-item label="自提点名" prop="receiverName" v-if="form.deliveryType === 1" >
              <el-input v-model="form.receiverName" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="parseInt(12)">
            <el-form-item label="手机号" prop="receiverPhone" v-if="form.deliveryType === 0">
              <el-input v-model="form.receiverPhone" placeholder="" disabled />
            </el-form-item>
            <el-form-item label="自提点电话" prop="receiverPhone" v-if="form.deliveryType === 1">
              <el-input v-model="form.receiverPhone" placeholder="" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="parseInt(8)">
            <el-form-item label="省份" prop="receiverProvince">
              <el-input v-model="form.receiverProvince" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="parseInt(8)">
            <el-form-item label="城市" prop="receiverCity">
              <el-input v-model="form.receiverCity" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="parseInt(8)">
            <el-form-item label="区县" prop="receiverArea">
              <el-input v-model="form.receiverArea" placeholder="" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="地址" prop="receiverAddress">
            <el-input v-model="form.receiverAddress" placeholder="" disabled />
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="parseInt(12)">
            <el-form-item label="总价" prop="totalPrice">
              <el-input v-model="form.totalPrice" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="parseInt(12)">
            <el-form-item label="总数量" prop="totalCount">
              <el-input v-model="form.totalCount" placeholder="" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="parseInt(12)" v-if="form.isCar === '1' && form.carVideo != null">
            <el-form-item label="装车视频" prop="carVideo">
              <video style="width: 200px; height: 200px" :src="form.carVideo" disabled controls />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <order-goods v-if="menuRoleVisible" :page-type="1" :order-id="this.orderGoodsOrderId"  ref="OrderGoods"></order-goods>
    </el-dialog>

<!--    打印配置-->
    <el-dialog  :visible.sync="printSettingOpen" append-to-body>
      <!-- 添加或修改订单打印设置对话框 -->
      <el-form ref="form" :model="printForm" :rules="printRules" label-width="80px">
        <el-form-item label="制单人" prop="preparer">
          <el-input v-model="printForm.preparer" placeholder="请输入制单人" />
        </el-form-item>
        <el-form-item label="审核人" prop="checker">
          <el-input v-model="printForm.checker" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="打印人" prop="printed">
          <el-input v-model="printForm.printed" placeholder="请输入打印人" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="printForm.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="printForm.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPrintSettingForm">确 定</el-button>
      </div>
    </el-dialog>
<!--    订单详情-->
    <el-dialog  :visible.sync="printOpen" title="打印订单" append-to-body width="500px">
      <el-row style="margin-bottom: 10px">
        <el-col :span="parseInt('3')">
          <el-button type="primary" v-print="'#printMe'">打印</el-button>
        </el-col>
        <el-col :span="parseInt('5')">
          <el-button type="warning" @click="printSettingDialog()">打印配置</el-button>
        </el-col>
      </el-row>
      <el-row style="margin-bottom: 10px">
      </el-row>
      <div id="printMe" >
        <el-form v-if="!isPrintBatch">
          <el-form-item>
            <el-row class="printElRow">
              <div style="text-align: center;font-size: 17px;">郑州千冻实业发展有限公司出库单</div>
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">日期:</span>
              <el-input style="width: 60%" v-text="parseTime(printData.orderObj.createAt,'{y}年{m}月{d}日')" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">编号:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.orderNo" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">业务员:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.salesmanName" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">配送方式:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.deliveryType === 0 ? '快递':'自提'" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph" v-if="printData.orderObj.deliveryType === 0">收件人:</span>
              <span style="margin-left: 10px;margin-right: 10px" class="ph" v-if="printData.orderObj.deliveryType === 1">自提点名:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.receiverName" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph" v-if="printData.orderObj.deliveryType === 0">手机号:</span>
              <span style="margin-left: 10px;margin-right: 10px" class="ph" v-if="printData.orderObj.deliveryType === 1">自提点电话:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.receiverPhone" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">地区:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.receiverProvince + printData.orderObj.receiverCity + printData.orderObj.receiverArea" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">地址:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.receiverAddress" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">备注:</span>
              <el-input style="width: 60%" v-text="printObj.remark" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">合计:</span>
              <el-input style="width: 60%" v-text="printData.orderObj.orderPrice" :disabled="true" />
            </el-row>
          </el-form-item>
          <table border="1" style="width: 380px">
            <!--    第四行-->
            <tr>
              <td align="center">序号</td>
              <td align="center">商品名称</td>
              <td align="center">规格</td>
<!--              <td align="center">单位</td>-->
              <td align="center">单价</td>
              <td align="center">数量</td>
              <td align="center">小计</td>
            </tr>
            <!--    遍历表格数据-->
            <tr v-for="(item,index) in printData.orderGoodsList">
              <td align="center">{{ index+1 }}</td>
              <td align="center">{{ item.goodsName }}</td>
              <td align="center">{{ item.productName }}</td>
<!--              <td align="center">/</td>-->
              <td align="center">{{ item.price }}</td>
              <td align="center">{{ item.total }}</td>
              <td align="center">{{ item.totalPrice }}</td>
            </tr>
          </table>
        </el-form>
        <el-form v-if="isPrintBatch" v-for="printData in printDataList" :key="index" style="margin-bottom: 20px">
          <el-form-item>
            <el-row class="printElRow">
              <div style="text-align: center;font-size: 17px;">郑州千冻实业发展有限公司销售出库单</div>
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">日期:</span>
              <el-input style="width: 25%" v-text="parseTime(printData.orderObj.createAt,'{y}年{m}月{d}日')" :disabled="true" />
              <span style="margin-left: 10px;margin-right: 10px" class="ph">编号:</span>
              <el-input style="width: 25%" v-text="printData.orderObj.orderNo" :disabled="true" />
              <span style="margin-left: 10px;margin-right: 10px" class="ph">业务员:</span>
              <el-input style="width: 25%" v-text="printData.orderObj.salesmanName" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">客户:</span>
              <el-input style="width: 25%" v-text="printData.orderObj.memberUserName" :disabled="true" />
              <span style="margin-left: 10px;margin-right: 10px" class="ph">客户手机号:</span>
            <el-input style="width: 25%" v-text="printData.orderObj.memberUserPhone" :disabled="true" />
            </el-row>
            <el-row class="printElRow">
              <span style="margin-left: 10px;margin-right: 10px" class="ph">备注:</span>
              <el-input style="width: 25%" v-text="printObj.remark" :disabled="true" />
            </el-row>
          </el-form-item>
          <table border="1" >
            <!--    第四行-->
            <tr>
              <td align="center">序号</td>
              <td align="center">商品名称</td>
              <td align="center">规格型号</td>
              <td align="center">单位</td>
              <td align="center">数量</td>
            </tr>
            <!--    遍历表格数据-->
            <tr v-for="(item,index) in printData.orderGoodsList" :key="index">
              <td align="center">{{ index+1 }}</td>
              <td align="center">{{ item.goodsName }}</td>
              <td align="center">{{ item.productName }}</td>
              <td align="center">/</td>
              <td align="center">{{ item.total }}</td>
            </tr>
          </table>
        </el-form>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  batchPrintData,
  deliveryByOrderIds,
  listMallOrderOrder,
  getMallOrderOrder,
  delMallOrderOrder,
  addMallOrderOrder,
  updateMallOrderOrder,
  exportMallOrderOrder,
  exportOrder
} from "@/api/mall/mallOrderOrder";
import { listMallOrderGoods } from "@/api/mall/mallOrderGoods";
import OrderGoods from "./orderGoods";
import { selectList } from "@/api/mall/mallSalesman";
import { mallMemberUserselectList } from "@/api/mall/mallMemberUser";
import { getPrintSetting, updatePrintSetting} from "@/api/mall/printSetting";
import {exportMallSalesmanAchievement} from "@/api/mall/mallSalesmanAchievement";

export default {
  name: "MallOrderOrder",
  components:{
    OrderGoods
  },
  data() {
    return {
      /** 是否批量打印 */
      isPrintBatch: false,
      /** 配置表单 */
      printForm:{},
      printRules: {
        // preparer: [
        //   { required: true, message: "制单人不能为空", trigger: "blur" }
        // ],
        // checker: [
        //   { required: true, message: "审核人不能为空", trigger: "blur" },
        //   { min: 2, max: 20, message: '名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        // ],
        // printed: [
        //   { required: true, message: "打印人不能为空", trigger: "blur" }
        // ],
        // phone: [
        //   { required: true, message: "电话不能为空", trigger: "blur" }
        // ],
      },
      /** 打印配置 */
      printSettingOpen: false,
      // 打印遮罩层
      printOpen: false,
      menuRoleVisible : false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      mallOrderOrderList: [],
      statusOptions: [
        // {isEnable: false,dictLabel: "待支付",dictValue: "0"},
        // {isEnable: true,dictLabel: "待配送",dictValue: "1"},
        // {isEnable: true,dictLabel: "配送中",dictValue: "2"},
        // {isEnable: false,dictLabel: "已完成",dictValue: "4"},
        // {isEnable: false,dictLabel: "退款中",dictValue: "5"},
        // {isEnable: false,dictLabel: "退款成功",dictValue: "6"},
        // {isEnable: false,dictLabel: "取消订单",dictValue: "8"}
      ],
      statusTwoOptions: [
        // {isEnable: false,dictLabel: "待支付",dictValue: "0"},
        {isEnable: true,dictLabel: "待配送",dictValue: "1"},
        {isEnable: true,dictLabel: "配送中",dictValue: "2"},
        // {isEnable: false,dictLabel: "已完成",dictValue: "4"},
        // {isEnable: false,dictLabel: "退款中",dictValue: "5"},
        // {isEnable: false,dictLabel: "退款成功",dictValue: "6"},
        // {isEnable: false,dictLabel: "取消订单",dictValue: "8"}
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: null,
        status: null,
        createAt: null,
        salesmanId: null,
        userId: null,
        orderType: null,
        orderNo: null,
        params:{
          beginCreateAt: null,
          endCreateAt: null
        }
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        payment: [
          { required: true, message: "实付金额不能为空", trigger: "blur" }
        ],
      },
      salesmanList:[],
      memberUserList:[],
      orderGoodsOrderId:0,
      createAtRange:[],
      printObj:{},
      printData:{
        orderObj:{},
        orderGoodsList:[]
      },
      printDataList:[]
    };
  },

  created() {
    this.getList();
    this.getDicts("mall_order_status").then(response => {
      this.statusOptions = response.data;
      console.log(this.statusOptions)
    });
    selectList().then(res =>{
      this.salesmanList = res.data
    })
    mallMemberUserselectList().then(res =>{
      this.memberUserList = res.data
    })
  },
  methods: {
    batchPrintDataButton(){
      this.printDataList = []
      // 打印配置信息
      this.getPrintSetting();
      this.printOpen = true
      // 是否批量打印
      this.isPrintBatch = true;
      const ids = this.ids;
      this.exportLoading= true
      batchPrintData(ids).then(res =>{
        console.log(res)
        this.printDataList = res.data
        this.exportLoading= false
      })

    },
    /** 打印配置信息 */
    getPrintSetting() {
      getPrintSetting('1').then(response => {
        this.printForm = response.data;
        console.log(response.data)
        this.printObj.preparer = this.printForm.preparer
        this.printObj.checker = this.printForm.checker
        this.printObj.printed = this.printForm.printed
        this.printObj.phone = this.printForm.phone
        this.printObj.remark = this.printForm.remark
        this.printSettingOpen = false
      });
    },
    /** 打印弹窗 */
    printDialogOpen(row){
      this.isPrintBatch = false
      this.printData =  {
        orderObj:{},
        orderGoodsList:[]
      }
      this.printObj =  {}
      this.printOpen = true
      var orderId = row.id
      var _this = this
      this.getPrintSetting();
      getMallOrderOrder(orderId).then(res =>{
        if (res.code == 200){
          _this.printData.orderObj = res.data;
        }else {
          _this.msgError('订单信息获取失败');
        }
      });
      listMallOrderGoods({
        orderId: orderId
      }).then(res =>{
        if (res.code == 200){
          _this.printData.orderGoodsList = res.rows;
        }else {
          _this.msgError('订单信息获取失败');
        }
      });
    },
    /** 提交按钮 */
    submitPrintSettingForm() {
      // this.$refs["printForm"].validate(valid => {
      //   if (valid) {
          updatePrintSetting(this.printForm).then(response => {
            this.msgSuccess("修改成功");
            this.getPrintSetting();
        //   });
        // }
      });
    },
    printSettingDialog(){
      this.printSettingOpen = true
    },
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      if (null != this.createAtRange && '' != this.createAtRange) {
        this.queryParams.params["beginCreateAt"] = this.createAtRange[0];
        this.queryParams.params["endCreateAt"] = this.createAtRange[1];
      }
      console.log(this.queryParams.userId)
      listMallOrderOrder(this.queryParams).then(response => {
        this.mallOrderOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }

        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value)) && ("payment" == column.property || "orderPrice" == column.property)) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          var temp = parseFloat(sums[index]).toFixed(3)
          sums[index] = temp.substring(0,temp.length-1);
          sums[index] += ' 元';
        } else {
          sums[index] = '';
        }
      });

      return sums;
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        userId: null,
        postFee: null,
        orderPrice: null,
        payment: null,
        status: "0",
        createAt: null,
        payAt: null,
        payType: null,
        consignAt: null,
        enterAt: null,
        returnAt: null,
        completeAt: null,
        shippingMark: null,
        shippingName: null,
        shippingCode: null,
        buyerMsg: null,
        isRefund: null,
        receiverName: null,
        receiverPhone: null,
        receiverProvince: null,
        receiverCity: null,
        receiverArea: null,
        receiverAddress: null,
        year: null,
        month: null,
        day: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createAtRange = []
      this.queryParams.params["beginCreateAt"] = '';
      this.queryParams.params["endCreateAt"] = '';
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMallOrderOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    handleChackDetail(row){
      let orderId = row.id;
      this.form = {}
      getMallOrderOrder(orderId).then(response => {
        this.form = response.data;
      });
      this.menuRoleVisible = true;
      this.orderGoodsOrderId = orderId
    //   this.$nextTick(()=>{
    //     this.$refs.OrderGoods.getInit(orderId);
    // })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMallOrderOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallOrderOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 批量发货
    deliveryByOrderIds(){
      const ids = this.ids;
      var that = this
      if (ids.length == 0){
        this.msgWarning("请勾选订单");
      }else {
        this.$confirm('是否确认批量发货?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          callback(action, instance){
            // function(action, instance)，action 的值为'confirm', 'cancel'或'close',
            // instance 为 MessageBox 实例，可以通过它访问实例上的属性和方法
            if (action == 'confirm'){
              deliveryByOrderIds(ids).then(res =>{
                if (res.code == 200){
                  that.getList();
                  that.msgSuccess(res.msg);
                }
              })
            }
          },
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单编号为"' + row.orderNo + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMallOrderOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // const queryParams = this.queryParams;
      // this.$confirm('是否确认导出满足筛选条件的订单?', "警告", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning"
      // }).then(() => {
      //   this.exportLoading = true;
      //   return exportMallOrderOrder(queryParams);
      // }).then(response => {
      //   this.download(response.msg);
      //   this.exportLoading = false;
      // }).catch(() => {});
      const orderIds = this.ids;
      var that = this
      if (orderIds.length === 0){
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出满足筛选条件的订单?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportMallOrderOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }else {
        // const queryParams = this.queryParams;
        this.$confirm('是否确认导出勾选的订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          that.exportLoading = true;
          return exportOrder(orderIds);
        }).then(response => {
          that.download(response.msg);
          that.exportLoading = false;
        }).catch(() => {});
      }

    }
  }
};
</script>
<style scoped>
.el-input.is-disabled /deep/ .el-input__inner {
  color: #606266;
}
a:hover{
  color: #069af8;
  text-decoration: underline;
}
table {
  border-collapse: collapse;
  /*width: 750px;*/
}
table,table tr, table tr td {
  border:1px solid #000000;
  height: 30px;
}
.printElRow{
  height: 28px;
}
</style>

