<template>
  <div class="mod-order-order">
    <div class="search-bar">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList(this.page)"
        size="small">
        <div class="input-row">
          <el-form-item :label="this.$i18n.t('order.number') + ':'" :label-width=" lang === 'en' ? '145px' : '85px'">
            <el-input
              v-model="dataForm.orderNumber"
              :placeholder="this.$i18n.t('order.number')"
              clearable
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item label="订单状态"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <el-select
              v-model="dataForm.status"
              clearable
              placeholder="请选择订单状态"
              size="small"
              @change="orderStatus">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="产品名称"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <template>
              <el-select
                v-model="dataForm.prodName"
                size="small"
                clearable
                placeholder="产品名称">
                <el-option key="yjxk" label="圆角小卡" value="圆角小卡"></el-option>
                <el-option key="zjxk" label="直角小卡" value="直角小卡"></el-option>
                <el-option key="pld" label="拍立得" value="拍立得"></el-option>
                <el-option key="zpfm" label="直拍封面" value="直拍封面"></el-option>
                <el-option key="sq" label="书签" value="书签"></el-option>
                <el-option key="mxp" label="明信片" value="明信片"></el-option>
                <el-option key="fk" label="方卡" value="方卡"></el-option>
                <el-option key="hz" label="徽章" value="徽章"></el-option>
                <el-option key="sf" label="手幅" value="手幅"></el-option>
                <el-option key="pg" label="票根" value="票根"></el-option>
              </el-select>
            </template>
          </el-form-item>
          <el-form-item label="覆膜工艺"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <template>
              <el-select
                v-model="dataForm.skuName"
                size="small"
                clearable
                placeholder="覆膜工艺">
                <el-option key="lm" label="亮膜" value="亮膜"></el-option>
                <el-option key="ym" label="哑膜" value="哑膜"></el-option>
                <el-option key="ls" label="镭射" value="镭射"></el-option>
                <el-option key="mtx" label="满天星" value="满天星"></el-option>
                <el-option key="axm" label="玻璃碎" value="玻璃碎"></el-option>
                <el-option key="axm" label="爱心膜" value="爱心膜"></el-option>
                <el-option key="xx" label="星星" value="星星"></el-option>
                <el-option key="zgz" label="珠光" value="珠光纸"></el-option>
              </el-select>
            </template>
          </el-form-item>
          <el-form-item :label="this.$i18n.t('order.theRecipientSName') + ':'"  :label-width=" lang === 'en' ? '145px' : '100px'">
            <el-input
              v-model="dataForm.receiverName"
              :placeholder="this.$i18n.t('order.pleaseEnRecipName')"
              clearable
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item label="运单号:" :label-width=" lang === 'en' ? '145px' : '85px'">
            <el-input
              v-model="dataForm.deliveryNo"
              placeholder="运单号"
              clearable
              size="small"></el-input>
          </el-form-item>
          <el-form-item :label="this.$i18n.t('shop.contactTel') + ':'"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <el-input
              v-model="dataForm.receiverMobile"
              :placeholder="this.$i18n.t('order.pleaseEnterNumber')"
              clearable
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item label="是否优先"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <template>
              <el-select
                v-model="dataForm.isPromotion"
                clearable
                size="small"
              >
                <el-option key="0" label="正常" value="0"></el-option>
                <el-option key="1" label="优先" value="1"></el-option>
              </el-select>
            </template>
          </el-form-item>
          <el-form-item label="是否合单"  :label-width=" lang === 'en' ? '145px' : '85px'">
            <template>
              <el-select
                v-model="dataForm.isMerge"
                clearable
                size="small">
                <el-option key="1" label="否" value="1"></el-option>
                <el-option key="2" label="是" value="2"></el-option>
              </el-select>
            </template>
          </el-form-item>
          <el-form-item label="张数：" :label-width=" lang === 'en' ? '145px' : '85px'">
            <InputNumberRange v-model="productNumsRange"></InputNumberRange>
          </el-form-item>
          <el-form-item :label="this.$i18n.t('order.createTime') + ':' "   :label-width=" lang === 'en' ? '145px' : '85px'">
            <el-date-picker
              size="small"
              v-model="dateRange"
              type="datetimerange"
              :range-separator="this.$i18n.t('time.tip')"
              value-format="yyyy-MM-dd HH:mm:ss"
              :start-placeholder="this.$i18n.t('time.start')"
              :end-placeholder="this.$i18n.t('time.end')"
            ></el-date-picker
            >
          </el-form-item>
          <el-form-item>
            <div v-for="(item, index) in numList" class="default-btn" style="margin-left: 1px;font-size: 15px;" :class="{ 'is-active': numActive === index }"
                 @click="setNumRange(index)">{{item}}</div>
          </el-form-item>
          <el-form-item>
            <div class="default-btn" :class="{ 'is-active': timeActive === 1 }" @click="setDateRange(1)">{{
              $t("time.t")
              }}</div>
            <div class="default-btn" :class="{ 'is-active': timeActive === 2 }" @click="setDateRange(2)">{{
              $t("time.y")
              }}</div>
            <div class="default-btn" :class="{ 'is-active': timeActive === 3 }" @click="setDateRange(3)">{{
              $t("time.n")
              }}</div>
            <div class="default-btn" :class="{ 'is-active': timeActive === 4 }" @click="setDateRange(4)">{{
              $t("temp.m")
              }}</div>
            <div class="default-btn primary-btn" @click="searchChange(true)">{{ $t("order.query") }}</div>
            <div class="default-btn" @click="clear()">{{ $t("shop.resetMap") }}</div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="main">
      <div class="content">
        <div style="margin-bottom: 20px">
          <el-checkbox @change="checked=>handleSelectAll(checked)" class="all-check-btn" v-model="selectAll">全选 </el-checkbox>
          <span v-if="dataListSelections.size" class="had-selected">已选 {{dataListSelections.size}}</span>
          <span v-if="dataListSelections.size" class="had-selected" style="font-weight: bold;color: red;font-size: 20px"> {{selectSheets}}张</span>
          <el-button size="small" type="primary" icon="el-icon-plus" @click="openGenerateWaveDialog">生成波次</el-button>
          <el-button size="small" icon="el-icon-upload2" @click="openAddToWaveDialog">添加已有波次</el-button>
<!--          <el-button size="small" type="success" @click="checkAndAutoCreateWave">自动生成波次</el-button>-->
        </div>
        <!-- 列标题 -->
        <div :class="['tit', showHeadScroll ? 'fixed-top' : '']">
          <el-row style="width: 100%">
            <el-col :span="7" id="prod-info-title">
              <span class="item product">订单信息</span>
            </el-col>
            <el-col :span="4" class="column-title">
              <span class="item">产品材质</span>
            </el-col>
            <el-col :span="2" class="column-title">
              <span class="item">张数</span>
            </el-col>
            <el-col :span="1" class="column-title">
              <span class="item">合单</span>
            </el-col>
            <el-col :span="3" class="column-title">
              <span class="item">买家/收货人</span>
            </el-col>
            <el-col :span="2" class="column-title">
              <span class="item">订单状态</span>
            </el-col>
            <el-col :span="2" class="column-title">
              <span class="item">是否优先</span>
            </el-col>
            <el-col :span="3" class="column-title">
              <span class="item">{{ $t("publics.operating") }}</span>
            </el-col>
          </el-row>
        </div>
        <div
          class="prod"
          v-for="(order, index) in dataList"
          :key="order.printOrderId">
          <div class="prod-tit">
            <el-checkbox v-model="order.checkStatus" :ref="'checkbox' + index" @change="checked=>handleSelectionChange(checked, order)"></el-checkbox>
            <span class="order-number">{{ $t("order.number") }}:{{ order.orderNumber }}</span>
            <span class="order-number">第三方单号:{{ order.orderNo }}</span>
            <span class="order-time">用户下单时间:{{ order.orderTime }}</span>
            <span class="order-time">推送时间:{{ order.createTime }}</span>
            <span class="order-time">运单号:{{ order.deliveryNo }}</span>
            <el-tag effect="dark" v-if="order.isPromotion === 1" type="danger">优先</el-tag>
          </div>
          <div class="prod-cont">
            <el-row style="width: 100%">
              <el-col :span="7" style="height: 100%">
                <div class="item prod-item">
                  <!-- 订单信息 -->
                  <div class=" items name">
                    <div class="order-prod-item-info">
                      <div class="info">
                        <div class="prod-image">
                          <prod-pic
                            height="60"
                            width="60"
                            :pic="order.pic"
                          ></prod-pic>
                        </div>
                        <div class="prod-name">
                          <div class="prod-con">
                            <div class="prod-name-txt">
                              {{ order.prodName }}
                            </div>
                            <div class="order-status" v-if="order.waveNo" style="cursor: pointer" @click="jumpToWave(order.orderNumber, order.waveId)">
                              所属波次号: {{order.waveNo}}
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </el-col>
              <el-col :span="4" style="height: 100%">
                <div class="item prod-item">
                  <span>{{order.prodName}}</span>
                  <!--<el-tooltip placement="top">
                    <div
                      slot="content"
                      style="font-size: 8px"
                      v-for="orderItem in order.orderItemList"
                      :key="orderItem.orderItemId">
                      <div>{{orderItem.prodName}}</div>
                    </div>
                    <span v-if="order.orderItemList.length > 1">{{order.orderItemList[0].prodName}} <br/>......</span>
                    <span v-else>{{order.orderItemList[0].prodName}}</span>
                  </el-tooltip>-->
                </div>
              </el-col>
              <!-- 张数 -->
              <el-col :span="2" style="height: 100%">
                <div class="item">
                  <span style="font-size: 24px; color: red">{{order.prodNums}} 张</span>
                </div>
              </el-col>
              <!-- 是否合单 -->
              <el-col :span="1" style="height: 100%">
                <div class="item">
                 <el-tag type="info" effect="dark" v-if="order.isMerge == 1">否</el-tag>
                 <el-tag type="danger" effect="dark" v-if="order.isMerge == 2">是</el-tag>
                </div>
              </el-col>
              <!-- 买家信息 -->
              <el-col :span="3" style="height: 100%">
                <div class="item">
                  <div class="buyer-info">
                    <div>
                      <el-tooltip placement="top">
                        <div slot="content" style="font-size: 8px">
                          <span>{{order.userAddrOrder.province }}</span>
                          <span>{{order.userAddrOrder.city }}</span>
                          <span>{{order.userAddrOrder.area }}</span>
                          <span>{{order.userAddrOrder.street }}</span>
                          <span>{{order.userAddrOrder.addr }}</span>
                        </div>
                        <div>
                          <span>{{order.userAddrOrder.receiver }}</span>
                          <br/>
                          <span>{{order.userAddrOrder.mobile }}</span>
                        </div>
                      </el-tooltip>
                    </div>
                    <!--<div class="buyer-name">{{ order.receiverName }}</div>
                    <div class="buyer-phone">{{ order.receiverMobile }}</div>-->
                  </div>
                </div>
              </el-col>
              <!-- 订单状态 -->
              <el-col :span="2" style="height: 100%">
                <div class="item">
                  <span>
                    <el-tag
                      v-if="order.status === 1"
                      type="primary"
                    >待打印</el-tag
                    >
                    <el-tag
                      v-else-if="order.status === 2"
                      type="danger"
                    >待发货</el-tag
                    >
                    <el-tag
                      v-else-if="order.status === 3"
                      type="success"
                    >已发货</el-tag>
                    <el-tag
                      v-else-if="order.status === 4"
                      type="warning"
                    >异常</el-tag>
                    <el-tag
                      v-else-if="order.status === 11"
                      type="info"
                    >已取消</el-tag>
                  </span>
                </div>
              </el-col>
              <el-col :span="2" style="height: 100%">
                <div class="item">
                  <span v-if="order.isPromotion === 0">正常</span>
                  <span v-else-if="order.isPromotion === 1">优先</span>
                  <span v-else>正常</span>
                </div>
              </el-col>
              <el-col :span="3" style="height: 100%">
                <div class="item">
                  <div class="operate">
                    <div
                      class="default-btn text-btn operate-btn"
                      @click="openPrintOrderDialog(order.orderNumber)">详情</div>
                    <div
                      class="default-btn text-btn operate-btn"
                      @click="updateStatus(order, 4)"
                      v-if="order.status === 1">标记异常</div>
                    <div
                      class="default-btn text-btn operate-btn"
                      @click="updateStatus(order, 1)"
                      v-if="order.status === 4">标记正常</div>
                    <div
                      class="default-btn text-btn operate-btn"
                      @click="updateStatus(order, 11)">取消订单
                    </div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
        <div class="empty" v-if="!dataList.length">
          {{ $t("order.noData") }}
        </div>
      </div>
    </div>
    <el-pagination
      ref="orderListTable"
      v-if="dataList.length"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page.currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="page.total"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>

    <!-- 生成波次弹窗 -->
    <el-dialog
      title="生成波次"
      :visible.sync="generateWaveDialogVisible"
      width="40%"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form :model="wave">
        <el-form-item label="波次号" label-width="100px">
          <span autocomplete="off">{{wave.waveNo}}</span>
        </el-form-item>
        <el-form-item label="备注名" label-width="100px">
          <el-input v-model="wave.waveName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="订单数" label-width="100px">
          <span autocomplete="off">{{dataListSelections.size}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="createWave">生 成</el-button>
      </div>
    </el-dialog>
    <!-- 添加到已有波次弹窗 -->
    <el-dialog
      title="添加到已有波次"
      :visible.sync="addToWaveDialogVisible"
      width="40%"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      @close="handleAddToWaveDialogClose"
    >
      <el-form :model="wave">
        <el-form-item label="波次" label-width="100px">
          <el-select v-model="wave.selectWaveId" clearable placeholder="请选择波次" @change="handleWaveChange" style="width: 300px">
            <el-option-group
              label="波次号|备注名">
              <el-option
                v-for="(item, index) in wave.latestWaveList"
                :key="item.waveId"
                :label="item.waveNo + '|' + item.waveName"
                :value="item.waveId">
              </el-option>
            </el-option-group>
          </el-select>
        </el-form-item>
        <el-form-item label="原订单数" label-width="100px">
          <span autocomplete="off">{{wave.orderNum}}</span>
        </el-form-item>
        <el-form-item label="添加数" label-width="100px">
          <span autocomplete="off">{{dataListSelections.size}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addToWave">添 加</el-button>
      </div>
    </el-dialog>
    <!-- 订单详情 -->
    <print-order-info ref="printOrderInfo" v-if="printOrderDialogVisible" @printOrderClose="printOrderClose"></print-order-info>
    <!-- 波次订单 -->
    <wave-print-order ref="wavePrintOrder"></wave-print-order>

  </div>
</template>

<script>
  import ProdPic from '@/components/prod-pic'
  import InputNumberRange from '@/components/input-number-range';
  import PrintOrderInfo from './print-order-info';
  import WavePrintOrder from './wave-print-order';
  import moment from 'moment'

  export default {
    data () {
      return {
        // 是否全选
        selectAll: false,
        showHeadScroll: false, // 修改物流相关
        logVisible: false,
        radio: '1',
        logisticsInfo: [],  // 包裹列表
        logDataForm: {
          dvyId: '', // 当前物流公司id
          dvyFlowId: '',  // 物流单号
          dvyNames: []  // 物流公司列表
        },
        uploadVisible: false,
        lang: localStorage.getItem('lang'),
        errorNum: 0,
        // 确认修改弹窗
        isReviseLog: true,  // 是否正在修改物流信息
        confirmList: [],  // 确认修改信息
        dataForm: {status:1},
        sts: 0,
        dateRange: [],
        productNumsRange:[],
        status: null,
        options: [
          {
          value: 1,
          label: "待打印"
          },
          {
            value: 2,
            label: "待发货"
          },
          {
            value: 3,
            label: "已发货"
          },
          {
            value: 4,
            label: "异常"
          },
          {
            value: 11,
            label: "已取消"
          },
          ],
        refund: [
          {
          value: 0,
          label: this.$i18n.t('order.noAfterSales')},
          {
            value: 1,
            label: this.$i18n.t('order.requestARefund')
          },
          {
            value: 2,
            label: this.$i18n.t('order.refundsuccessfully')
          },
          {
            value: 3,
            label: this.$i18n.t('order.partialRefundSucc')
          },
          {
            value: 4,
            label: this.$i18n.t('order.refundFailed')
          }],
        resourcesUrl: process.env.VUE_APP_RESOURCES_URL,
        dataList: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 50 // 每页显示多少条
        },
        numList: [10, 20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,'更多'],
        dataListLoading: false,
        dataListSelections: new Set(),
        selectSheets: 0,
        generateWaveDialogVisible: false,
        timeActive: null,
        numActive: null,
        priceWidth: '109px',
        infoWidth: '400px',
        orderCreateBatchVisible: false,
        orderCreateBatchLoading: false,
        wavePrintOrderVisible: false,
        newWaveNo: null,
        wave:{
          waveNo:null,
          waveName:null,
          orderNumberList: null,
          latestWaveList: null,
          selectWaveId: null,
          orderNum: 0,
          sheets:0
        },
        printChannel: "KuaiYin",
        addToWaveDialogVisible: false,
        printOrderDialogVisible: false
      }
    },
    components: {
      ProdPic,
      InputNumberRange,
      PrintOrderInfo,
      WavePrintOrder
    },
    computed: {
      // 二级菜单折叠状态
      sidebarFold: {
        get () { return this.$store.state.common.sidebarFold },
        set (val) { this.$store.commit('common/updateSidebarFold', val) }
      }
    },
    created () {

      // 携带参数查询
      this.getDataList(this.page, this.$route.query)

      // // 请求物流公司
      // this.getLogisticsList()
    },
    activated () {
      // 携带参数查询
      var query = this.$route.query
      if (Object.keys(query).length > 0) {
        this.getDataList(this.page, query)
      }
    },
    mounted () {
      // 监听页面滚动
      // window.addEventListener('scroll', this.scrollToTop)
    },
    watch: {

    },
    methods: {
      printOrderClose(){
        this.printOrderDialogVisible = false;
      },

      wavePrintOrderClose(){
        this.wavePrintOrderVisible = false;
      },
      jumpToWave(orderNumber, waveId){
        this.$refs.wavePrintOrder.openAndQueryPrintOrder({orderNumber: orderNumber, waveId: waveId})
      },
      openPrintOrderDialog(orderNumber){
        this.printOrderDialogVisible = true;
        this.$nextTick(() => {
          this.$refs.printOrderInfo.init({
            orderNumber: orderNumber,
          })
        });
      },
      openGenerateWaveDialog(){
        if(this.dataListSelections.size === 0){
          this.$message.error("请至少选择一个订单");
          return ;
        }
        this.$http({
          url: this.$http.adornUrl(`/wave/wave/getLatestWaveNo`),
          method: 'GET',
          params: this.$http.adornParams({printChannel:this.printChannel})
        }).then(({data}) => {
          if(data.status == "success"){
            this.generateWaveDialogVisible = true;
            this.wave.waveNo = data.result;
          }
        })
      },
      openAddToWaveDialog(){
        if(this.dataListSelections.size === 0){
          this.$message.error("请至少选择一个订单");
          return ;
        }
        this.$http({
          url: this.$http.adornUrl(`/wave/wave/getLatestWave`),
          method: 'GET',
          params: this.$http.adornParams({printChannel:this.printChannel, queryLimit: 30})
        }).then(({data}) => {
          if(data.status == "success"){
            this.addToWaveDialogVisible = true;
            this.wave.latestWaveList = data.result;
          }
        })
      },
      checkAndAutoCreateWave(){
        this.$confirm('确定要自动生成波次吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/wave/wave/checkAndAutoCreateWave`),
            method: 'POST',
            data: this.$http.adornData()
          }).then(({data}) => {
            if(data){
              this.$message({
                type: "success",
                message: "波次生成成功"
              })
            }else{
              this.$message({
                type: "warning",
                message: "无波次生成"
              })
            }
          }).catch(() => {
            this.$message({
              type: "error",
              message: "波次生成失败"
            })
          })
        });

      },
      handleWaveChange(val){
        this.wave.latestWaveList.forEach(item =>{
          if(item.waveId == val){
            this.wave.orderNum = item.orderNum;
            return;
          }
        })
      },
      handleAddToWaveDialogClose(){
        this.wave.selectWaveId = null;
        this.wave.orderNum = 0;
      },
      updateStatus(row, status){
        this.$http({
          url: this.$http.adornUrl(`/printOrder/printOrder/updateStatus`),
          method: 'POST',
          data: this.$http.adornData({printOrderId: row.printOrderId, status: status})
        }).then(({data}) => {
          if(data){
            this.$message({
              message: "标记成功",
              type: 'success'
            })
            this.getDataList(this.page, null, false);
          }else{
            this.$message({
              message: "标记失败",
              type: 'error'
            })
          }
        })
      },
      createWave(){
        let dataBody = {waveName: this.wave.waveName, "orderNumberList": [...this.dataListSelections], "printChannel": this.printChannel};
        this.$http({
          url: this.$http.adornUrl(`/wave/wave/create`),
          method: 'POST',
          data: this.$http.adornData(dataBody)
        }).then(({data}) => {
          if(data){
            this.generateWaveDialogVisible = false;
            this.$message({
              message: "生成波次成功",
              type: 'success'
            })
            this.getDataList(this.page);
            let it = this;
            this.dataList.forEach((item, index) => {
              it.$set(item,'checkStatus',false)
              it.dataListSelections.delete(item.orderNumber);
              it.selectAll = false;
            })
          }else{
            this.$message({
              message: "生成波次失败",
              type: 'error'
            })
          }
        })
      },
      addToWave(){
        if(!this.wave.selectWaveId){
          this.$message({
            message: "请选择波次",
            type: 'error'
          })
          return;
        }
        let dataBody = {waveId: this.wave.selectWaveId, "orderNumberList": [...this.dataListSelections], "printChannel": this.printChannel};
        this.$http({
          url: this.$http.adornUrl(`/wave/wave/addToWave`),
          method: 'POST',
          data: this.$http.adornData(dataBody)
        }).then(({data}) => {
          if(data.status == "success"){
            this.addToWaveDialogVisible = false;
            this.$message({
              message: data.msg,
              type: 'success'
            })
            this.getDataList(this.page);
            let it = this;
            this.dataList.forEach((item, index) => {
              it.$set(item,'checkStatus',false)
              it.dataListSelections.delete(item.orderNumber);
              it.selectAll = false;
              });
          }else{
            this.$message({
              message: data.msg,
              type: 'error'
            })
          }
        })
      },
      openCreateOrderBatchDialog(){
        this.orderCreateBatchVisible = true;
      },
      handleOrderAuditStatusUpdate(auditStatusReturn){
        let it = this;
        this.dataList.forEach((item, index) => {
          if(item.orderNumber == auditStatusReturn.orderNumber){
            it.$set(item,'auditStatus',auditStatusReturn.auditStatus)
            return;
          }
        })
      },
      /**
       * 全选按钮
       */
      handleSelectAll (checked) {
        let it = this;
        it.selectSheets = 0;
        if(checked){
          it.selectAll = true;
          this.dataList.forEach((item, index) => {
            it.$set(item,'checkStatus',true)
            it.dataListSelections.add(item.orderNumber);
            it.selectSheets = it.selectSheets + item.prodNums;
          })
        }else{
          this.dataList.forEach((item, index) => {
            it.$set(item,'checkStatus',false)
            it.dataListSelections.delete(item.orderNumber);
          })
          it.selectAll = false;
          this.selectSheets = 0;
        }

      },
      handleSelectionChange(checked, order){
        if(checked){
          this.dataListSelections.add(order.orderNumber);
          this.selectSheets = this.selectSheets + order.prodNums;
          if(this.dataListSelections.size === this.dataList.length){
            this.selectAll = true;
          }
        }else{
          this.dataListSelections.delete(order.orderNumber);
          this.selectSheets = this.selectSheets - order.prodNums;
          if(this.dataListSelections.size == 0){
            this.selectAll = false;
            this.selectSheets = 0;
          }
        }
      },
      /**
       * 页面滚动事件
       */
      scrollToTop () {
        // let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        // this.showHeadScroll = scrollTop > 400
      },



      /**
       * 获取数据列表
       */
      getDataList (page, params, newData = false) {
        page = (page === undefined ? this.page : page)
        this.dataListLoading = true
        if (newData || !this.theData) {
          this.theData = {
            current: page == null ? this.page.currentPage : page.currentPage,
            size: page == null ? this.page.pageSize : page.pageSize,
            'orderNumber': this.dataForm.orderNumber,
            'receiverName': this.dataForm.receiverName,
            'receiverMobile': this.dataForm.receiverMobile,
            'status': this.dataForm.status,
            'refundStatus': this.dataForm.refundStatus,
            'startTime': this.dateRange === null ? null : this.dateRange[0], // 开始时间
            'endTime': this.dateRange === null ? null : this.dateRange[1], // 结束时间
            'startProductNums': this.productNumsRange === null ? null : this.productNumsRange[0], // 订购数量起
            'endProductNums': this.productNumsRange === null ? null : this.productNumsRange[1], // 订购数量起
            'prodName': this.dataForm.prodName, // 产品名称
            'isMerge': this.dataForm.isMerge, // 是否合单
            'printChannel': this.printChannel,
            'skuName': this.dataForm.skuName,
            'prodNums': this.dataForm.prodNums,
            'deliveryNo': this.dataForm.deliveryNo,
            'isPromotion': this.dataForm.isPromotion
          }
        } else {
          this.theData.current = page == null ? this.page.currentPage : page.currentPage
          this.theData.size = page == null ? this.page.pageSize : page.pageSize
          this.theData.status = this.dataForm.status
        }
        this.$http({
          url: this.$http.adornUrl('/printOrder/printOrder/page'),
          method: 'get',
          params: this.$http.adornParams(
            Object.assign(this.theData, params
            ), false
          )
        }).then(({ data }) => {
          this.dataList = data.records;
          this.page.total = data.total
          this.sts = !this.status ? 0 : this.status
          this.dataListLoading = false
          this.activeName = !this.status ? '0' : this.status + '';
          let it = this;
          this.dataList.forEach((item, index) => {
            it.$set(item,'checkStatus',false)
            it.dataListSelections.delete(item.orderNumber);
          })
          this.dataListSelections = new Set();
          this.selectAll = false;
          this.selectSheets = 0;
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.page.pageSize = val
        this.page.currentPage = 1
        this.getDataList(this.page)
      },
      // 当前页
      currentChangeHandle (val) {
        this.dataListSelections = new Set();
        this.page.currentPage = val
        this.getDataList(this.page, null, false);
      },

      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      orderStatus (val) {
        this.status = val
        this.activeName = val + ''
        this.getDataList(this.page)
      },
      /**
       * 根据选项设置时间
       * 1:今天 2:昨天 3: 近七天 4:近30天 5:近60天
       */
      setDateRange (val) {
        this.timeActive = val
        var startDay = null
        var endDay = null
        if (val === 1) {
          startDay = 0
          endDay = 0
        } else if (val === 2) {
          startDay = -1
          endDay = -1
        } else if (val === 3) {
          startDay = -7
          endDay = -1
        } else if (val === 4) {
          startDay = -30
          endDay = -1
        } else {
          return
        }
        // 开始时间
        let startTime = moment().add(startDay, 'days').startOf('days').format('LL')
        // 结束时间
        let endTime = moment().add(endDay, 'days').endOf('days').format('LL')
        this.dateRange = [startTime, endTime]
      },
      setNumRange(val){
        this.numActive = val;
        if(val == this.numList.length - 1){
          this.dataForm.prodNums = -1;
        }else{
          this.dataForm.prodNums = this.numList[val];
        }
        this.getDataList(this.page, null, true);
      },
      // 查看订单
      addOrUpdateHandle (orderNumber, shopId, status) {
        this.$refs.orderInfo.init({
          orderNumber: orderNumber,
          shopId: shopId,
          status: status
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.orderId
        })
        this.$confirm(`${this.$i18n.t('sys.makeSure')}[${id ? this.$i18n.t('text.delBtn') : this.$i18n.t('sys.batchDelete')}]${this.$i18n.t('text.menu')}?`, this.$i18n.t('text.tips'), {
          confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
          cancelButtonText: this.$i18n.t('crud.filter.cancelBtn'),
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/prod/spec/${ids}`),
            method: 'delete',
            data: this.$http.adornData(ids, false)
          }).then(({ data }) => {
            this.$message({
              message: this.$i18n.t('publics.operation'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        }).catch(() => { })
      },
      // 清空按钮
      clear () {
        this.dataForm = {};
        this.dateRange = [];
        this.status = null;
        this.timeActive = null;
        this.numActive = null;
        this.getDataList(this.page, null, false)
      },
      // 搜索查询
      searchChange (newData = false) {
        this.page.currentPage = 1;
        this.getDataList(this.page, null, newData)
      },
    },
    destroyed () {
      // 页面销毁时移除监听
      window.removeEventListener('scroll', this.handleScroll)
    }
  }
</script>
<style lang="scss" scoped>
  .mod-order-order {
    .search-bar {
      .input-row {
        .select-time-btn {
          margin-right: 20px;
          display: inline-block;
          color: #AAAAAA;
          font-size: 14px;
          cursor:pointer;
          &:last-child {
            margin-right: 0;
          }
        }
        .select-time-btn.is-active {
          color: #155BD4;
        }

      }
    }
    .main {
      .content {
        .all-check-btn {
          margin-right: 10px;
        }
        .had-selected {
          font-size: 12px;
          margin-right: 10px;
        }
      }
      .order-status-nav {
        position: relative;
        display: block;
        width: 100%;
        margin-bottom: 15px;
        height: 40px;
        line-height: 40px;
        border-bottom: 1px solid #ddd;
        ul,
        li {
          list-style: none;
          padding: 0;
          margin: 0;
        }
        .nav-item {
          float: left;
          height: 40px;
          line-height: 40px;
          background: #f7f8fa;
          border: 1px solid #ddd;
          padding: 0 20px;
          margin: 0 -1px -1px 0;
          cursor: pointer;
        }

        .selected {
          background: #fff;
          border-bottom: 1px solid #fff;
        }
      }
      .status-nav {
        ::v-deep .el-tabs__item {
          padding: 0 20px ;
          min-width: 68px;
          width: auto;
          text-align: center;
        }
        ::v-deep .el-tabs__nav-wrap::after{
          height: 1px;
        }
      }
      .tit {
        display: flex;
        align-items: center;
        margin-bottom: 15px;
        background: #F7F8FA;
        z-index: 11;
        height: 57px;
        font-weight: bold;
        .column-title {
          text-align: center;
        }
        .item {
          padding: 0 10px;
          width: 10%;
          text-align: center;
        }
        .product {
          width: 25%;
          margin-bottom: 15px;
          text-align: left !important;
        }
      }
      .fixed-top {
        position: fixed;
        width: calc(83.5% + var(--tit-width-incremental));
        top: 90px;
      }
      .prod {
        margin-bottom: 15px;
        .prod-tit {
          padding: 10px;
          background: #F7F8FA;
          height: 49px;
          display: flex;
          align-items: center;
          border-left: 1px solid #EBEDF0;
          border-top: 1px solid #EBEDF0;
          border-right: 1px solid #EBEDF0;
          .order-number{
            color: #333333;
            font-size: 14px
          }
          .order-index{
            color: red;
            font-size: 14px;
            font-weight: bold;
          }
          .order-time{
            color: #999999;
            font-size: 14px
          }
          span {
            margin-right: 15px;
          }
        }
        .prod-cont {
          display: flex;
          border: 1px solid #EBEDF0;
          color: #495060;
          .item {
            display: flex;
            display: -webkit-flex;
            align-items: center;
            padding: 10px;
            text-align: center;
            justify-content: center !important;
            height: 100%;
            border-right: 1px solid #eee;
            .totalprice {
              color: #ff4141;
              margin-bottom: 10px;
            }
            .operate {
              color: #2d8cf0;
              .operate-btn {
                margin: 0 !important;
                height: auto;
              }
              .default-btn + .default-btn {
                display: block;
                margin-top: 10px;
                margin-left: 0;
              }
            }
            .buyer-info {
              .buyer-name {
                margin-bottom: 4px;
              }
            }
            span {
              display: block;
            }
          }
          .prod-item {
            padding: 0;
            display: flex;
            flex-direction: column !important;
            height: 100%;
            border-right: 1px solid #eee;
            .items.name {
              width: 100%;
              display: flex;
              align-items: center;
              border-bottom: 1px solid #EBEDF0;
              padding: 10px !important;
              text-align: left;
              &:last-child {
                border-bottom: none;
              }
              .order-prod-item-info {
                width: 100%;
                display: flex;
                flex-direction: column;
                .info {
                  display: flex;
                  align-items: center;
                  .prod-image {
                    min-height: 80px;
                    width: 80px;
                    height: auto;
                    margin-right: 20px;
                    padding: 0;
                    line-height: 80px;
                    img {
                      width: 100%;
                      height: 100%;
                      object-fit: contain;
                    }
                  }
                  .prod-name {
                    width: 100% !important;
                    .prod-con {
                      width: 85% !important;
                      display: block;
                      padding: 0 !important;
                      .prod-name-txt {
                        padding-right: 10px;
                        box-sizing: border-box;
                        display: -webkit-box;
                        -webkit-box-orient: vertical;
                        -webkit-line-clamp: 2;
                        overflow: hidden;
                      }
                      .order-status {
                        display: inline-block;
                        margin-top: 15px;
                        margin-right: 10px;
                        padding: 2px 4px;
                        border: 1px solid #e43130;
                        border-radius: 2px;
                        color: #e43130;
                        font-size: 14px;
                      }
                    }
                  }
                }
                // 赠品盒子
                .order-prod-item-give-con {
                  width: 100%;
                  padding: 10px 50px 0 10px;
                  box-sizing: border-box;
                  .giveaway-item {
                    display: flex;
                    margin-bottom: 10px;
                    &:last-child {
                      margin-bottom: 0;
                    }
                  }
                  .giveaway-item-name {
                    box-sizing: border-box;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                    -webkit-line-clamp: 1;
                    overflow: hidden;
                  }
                  .giveaway-item-sku-count {
                    margin-left: 10px;
                    color: #999;
                    width: 20px;
                  }
                }
              }
              .prod-price {
                width: 28%;
                display: flex;
                justify-content: flex-start;
                flex-direction: column;
                overflow: hidden;
                position: relative;
                right: 0 !important;
                span {
                  display: block;
                  text-align: left;
                  word-break: keep-all;
                  &:first-child {
                    margin-bottom: 10px;
                  }
                }
              }
            }
          }
        }
      }
      .empty {
        display: block;
        height: 200px;
        line-height: 200px;
        text-align: center;
        color: #aaa;
      }
      .transaction-price {
        text-align: center;
      }
    }
    // 修改物流弹窗
    .change-logistics {
      color: #333;
      padding: 0 20px;
      .warning {
        padding: 10px;
        border: 1px solid #f1924e;
        background: #fff5ed;
      }
      .log-list {
        max-height: 600px;
        margin-top: 30px;
        overflow-y: auto;
        .item {
          padding-bottom: 20px;
          .i-tit {
            display: flex;
            align-items: center;
            .big {
              font-weight: 600;
              margin-right: 15px;
            }
          }
          .item-goods {
            position: relative;
            width: 100%;
            height: 110px;
            overflow-x: auto;
            .goods-box {
              position: absolute;
              left: 0;
              display: flex;
              margin-top: 0;
              -webkit-transition: all 0.3s;
              -moz-transition: all 0.3s;
              transition: all 0.3s;
              .item {
                margin-right: 10px;
                font-size: 12px;
                cursor: pointer;
                .img {
                  width: 60px;
                  height: 60px;
                  font-size: 0;
                  margin-bottom: 4px;
                  margin-top: 4px;
                  position: relative;
                  img {
                    width: 100%;
                    height: 100%;
                  }
                  .number {
                    position: absolute;
                    bottom: 0;
                    right: 0;
                    background: rgba(0, 0, 0, 0.3);
                    color: #fff;
                    border-radius: 6px 0 6px 0;
                    font-size: 12px;
                    height: 16px;
                    line-height: 16px;
                    padding: 0 5px;
                  }
                }
                .name {
                  width: 60px;
                  height: 16px;
                  line-height: 16px;
                  white-space: nowrap;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  color: #999;
                }
              }
              .item:last-child {
                margin: 0;
              }

            }
          }
          .info-int {
            &.el-form-item__content,
            &.el-form-item__label,
            .el-input__suffix-inner,
            .el-input__icon {
              height: 32px;
              line-height: 32px;
            }
            display: flex;
            .form-item {
              margin-right: 15px;
            }
          }
        }
      }
      .log-info-table {
        margin-top: 20px;
        max-height: 600px;
        overflow-y: auto;
      }
    }
    @media (max-width:1660px) {
      .fixed-top {
        width: calc(79.5% + var(--tit-width-incremental)) !important;
      }
    }
    @media (max-width:1360px) {
      .fixed-top {
        width: calc(75.5% + var(--tit-width-incremental)) !important;
      }
    }
  }
</style>
