<template>
  <div class="app-container">
    <div v-loading.fullscreen.lock="loadingFull" />
    <div style="margin-bottom:15px">
      <el-date-picker v-model="listQuery.time" value-format="yyyy-MM-dd HH:mm" format="yyyy-MM-dd HH:mm" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="filter-item" style="width:400px" />
      <el-input v-model="listQuery.order_no" placeholder="订单编号" class="filter-item filter-input" style="display: inline-block; width: 240px;" @keydown.native.enter="listQuery.page_index = 1;getList()" />
      <el-input v-model="listQuery.search_name" placeholder="备注昵称/姓名/手机号" class="filter-item filter-input" style="display: inline-block; width: 240px;" @keydown.native.enter="listQuery.page_index = 1;getList()" />
      <el-select
        v-model="listQuery.store_id"
      >
        <el-option label="全部" value="" />
        <el-option v-for="item in storeList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="listQuery.activity_id" style="width: 400px">
        <el-option label="全部" value="" />
        <el-option v-for="item in activitys" :key="item.id" :label="item.title" :value="item.id" />
      </el-select>
      <el-button type="primary" icon="el-icon-search" class="filter-item" @click="listQuery.page_index = 1;getList()">搜索</el-button>
      <el-popover
        placement="bottom"
        width="350"
        trigger="hover"
      >
        <el-button type="primary" @click="exportOrder">订单明细</el-button>
        <el-button type="primary" @click="exporOrdertOrder">拆单明细</el-button>
        <el-button type="primary" @click="exportMoney">订单金额</el-button>
        <el-button slot="reference" type="primary" :loading="downloadLoading" icon="el-icon-document" class="filter-item">导出</el-button>
      </el-popover>
    </div>
    <el-table :data="tableList" :header-cell-style="{ background: '#f8fbfc' }" border stripe @selection-change="orderMulSelect">
      <el-table-column type="selection" width="50" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="order_num" label="订单编号" width="210">
        <template slot-scope="{ row }">
          <el-button type="text" @click="toOrderWxamine(row)">{{ row.order_num }}</el-button>
          <!-- <span>{{ row.order_num }}</span> -->
          <br>
          <p v-if="row.order_type === 1" class="tag sub-tag">代下单</p>
          <p v-if="row.is_back === 1" class="tag return-tag">退回</p>
        </template>
      </el-table-column>
      <el-table-column prop="get_user" label="备注昵称" align="center" width="150" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">{{ row.get_user.name }}</template>
      </el-table-column>
      <el-table-column prop="get_user" label="下单人姓名" align="center" width="120" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">{{ row.get_user.realname }}</template>
      </el-table-column>
      <el-table-column prop="created_at" align="center" label="下单时间" width="160" :show-overflow-tooltip="true" />
      <el-table-column prop="status" align="center" label="订单状态" width="110" :show-overflow-tooltip="true">
        <template slot-scope="{ row: { is_deleted, status } }">
          <el-tag v-if="is_deleted === 1" type="info">已作废</el-tag>
          <el-tag v-else :color="orderStatus(status).color" style="color:#ffffff;">{{ orderStatus(status).name }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="get_store"
        label="体验店订单"
        width="150"
        align="center"
      >
        <span slot-scope="{ row: { get_store } }">{{ (get_store && get_store.name) || '' }}</span>
      </el-table-column>
      <el-table-column prop="pay_status" align="center" label="支付状态" width="90" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">
          <span :style="`color: ${payStatus(row.pay_status).color}`">{{ payStatus(row.pay_status).name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="total" label="数量合计" align="center" width="80" :show-overflow-tooltip="true" />
      <el-table-column prop="money" label="订单总额" align="censtoreter" width="120" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">{{ `￥${row.money}` }}</template>
      </el-table-column>
      <el-table-column prop="get_address" label="收货人" align="center" width="120" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">{{ row.get_address && row.get_address.username }}</template>
      </el-table-column>
      <el-table-column prop="get_address" label="联系方式" align="center" width="120" :show-overflow-tooltip="true">
        <template slot-scope="{ row }">{{ row.get_address && row.get_address.mobile }}</template>
      </el-table-column>
      <el-table-column prop="get_address" label="收货地址" align="center" width="200" :show-overflow-tooltip="true">
        <template slot-scope="{ row: { get_address } }">{{ get_address && get_address.province+get_address.city+get_address.town+get_address.address }}</template>
      </el-table-column>
      <el-table-column prop="remark" label="订单备注" align="center" width="160" :show-overflow-tooltip="true" />
    </el-table>
    <!-- 分页 -->
    <pagination :total="tableTotal" :limit="listQuery.page_size" :page="listQuery.page_index" @pagination="changePagination" @update:limit="changePagination" />
    <el-dialog title="导出数据" :visible.sync="export_order" width="520px">
      <el-form label-width="120">
        <el-form-item label="导出类型">
          <el-button type="primary" @click="exportOrder">订单明细</el-button>
          <el-button type="primary" @click="exporOrdertOrder">拆单明细</el-button>
          <el-button type="primary" @click="exportMoney">订单金额</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { getList, BreakUpOrder, downOrder, list_down } from '@/api/order/store'
import { getStore } from '@/api/order/list'
import { orderStatus, payStatus } from '@/filters/common'
import { formatter } from '@/filters/index'
import { activityList } from '@/api/giftB'
const moduleList = {
  '订单编号': '',
  '下单时间': '',
  '所属政委': '',
  '寄件人': '大卫博士',
  '联系方式': '4006867733',
  '发件人详细地址': '河南省郑州市经开区',
  '备注昵称': '',
  '下单人姓名': '',
  '下单人手机号': '',
  '收件人': '',
  '电话': '',
  '收件人省': '',
  '收件人市': '',
  '收件人区': '',
  '收件人街道地址': '',
  'L': '',
  'XL': '',
  'XXL': '',
  'XXXL': '',
  '女M': '',
  '女L': '',
  '女XL': '',
  '女XXL': '',
  '女XXXL': '',
  '5XL': '',
  '数据求和': '',
  '所属': '',
  '备注': '',
  '赠品': '',
  '快递单号': '',
  '快递公司': '',
  '快递公司代码': '',
  '发货状态': ''
}
export default {
  data() {
    return {
      roles: this.$route.meta.buttonAuthList ? this.$route.meta.buttonAuthList : [],
      authList: this.$route.meta.authList,
      loadingFull: false,
      downloadLoading: false,
      export_order: false,
      listQuery: {
        order_no: '',
        page_index: 1,
        page_size: 20,
        time: '',
        search_name: '',
        store_id: '',
        activity_id: ''
      },
      expressData: [],
      storeList: [],
      tableList: [],
      tableTotal: 0,
      chooseList: [],
      activitys: []
    }
  },
  created() {
    this.orderStatus = orderStatus
    this.payStatus = payStatus
    this.getStore()
    this.activityList(() => {
      this.getList()
    })
  },
  methods: {
    // 订单编号
    toOrderWxamine(row) {
      this.$router.push({
        name: 'order_examine',
        params: { order: row.order_num }
      })
    },
    async getList() {
      this.loadingFull = true
      const { page_index, page_size, order_no, search_name, store_id, time, activity_id } = this.listQuery
      await getList({
        page_index, page_size, order_no, search_name, store_id, activity_id,
        start_time: time && time.length > 0 ? time[0] : '',
        end_time: time && time.length > 0 ? time[1] : ''
      }).then(res => {
        this.loadingFull = false
        if (res.code === 200) {
          this.tableList = res.data.list
          this.tableTotal = res.data.total
        } else {
          this.$message.error(res.message)
        }
      }).catch(e => {
        this.loadingFull = false
      })
    },
    async getStore() {
      this.loadingFull = true
      await getStore().then(res => {
        this.loadingFull = false
        if (res.code === 200) {
          this.storeList = res.data.list
        }
      }).catch(e => {
        this.loadingFull = false
      })
    },
    // 分页页码变化
    changePagination(data) {
      const { page, limit } = data
      this.listQuery.page_size = limit
      this.listQuery.page_index = page
      this.getList()
    },
    // 订单金额
    exportMoney() {
      if (this.chooseList.length) {
        // this.$request(downList({ id: this.chooseList.map(e => e.id) }), (res) => {
        //   this.expressData = res
        //   const exportData = this.getExportModule()
        //   import('@/vendor/Export2Excel').then(excel => {
        //     excel.export_json_to_excel({
        //       header: Object.keys(moduleList),
        //       data: exportData.map(listItem => Object.keys(exportData[0]).map(j => listItem[j])),
        //       filename: `${new Date().toLocaleDateString()}快递单导出`,
        //       bookType: 'xlsx',
        //       isCSV: true
        //     })
        //     this.dialog.export_order = false
        //   })
        // })
        this.$request(list_down({ id: this.chooseList.map(e => e.id) }), (res) => {
          const exportData = res.list
          import('@/vendor/Export2Excel').then(excel => {
            const header = ['序号', '订单编号', '下单时间', '所属政委', '备注昵称', '下单人姓名', '订单状态', '支付状态', '数量合计', '订单总额', '所属者姓名', '所属者手机号', '所属体验店', '收货人', '联系方式', '收货地址', '订单备注']
            const exportK = ['index', 'order_num', 'created_at', 'admin_name', 'nickname', 'realname', 'status', 'pay_status', 'total', 'money', 'belong_realname', 'belong_mobile', 'get_store', 'username', 'mobile', 'address', 'remark']
            const exportV = exportData.map((item, i) => {
              const obj = {
                index: i + 1,
                created_at: item.created_at || '',
                admin_name: item.get_user && item.get_user.warea && item.get_user.warea.admin_name,
                nickname: item.get_user.nickname || '',
                realname: item.get_user.realname || '',
                order_num: item.order_num || '',
                get_store: item.get_store && item.get_store.name,
                status: orderStatus(item.status).name || '',
                pay_status: payStatus(item.pay_status).name,
                total: item.total || '',
                money: item.money || '',
                username: item.get_address.username || '',
                mobile: +item.get_address.mobile,
                belong_realname: item.belong_user && item.belong_user.realname,
                belong_mobile: item.belong_user && item.belong_user.mobile,
                address: item.get_address.province + item.get_address.city + item.get_address.town + item.get_address.address,
                remark: item.remark || ''
              }
              return obj
            })
            const exportD = exportV.map(item => exportK.map(k => item[k]))
            excel.export_json_to_excel({
              header,
              data: exportD,
              filename: `${formatter(new Date(), 'yyyy-MM-dd')}订单金额`,
              autoWidth: true,
              bookType: 'xlsx'
            })
            this.export_order = false
          })
        })
      } else {
        if (this.tableList.length === 0) {
          this.$message.error('没有可导出的数据')
          return false
        }
        let query = {}
        if (!this.highSearchFlag) {
          const { order_status, order_no, page_index, page_size, store_id, search_name, time, activity_id } = this.listQuery
          query = {
            order_status, order_no, page_index, page_size, search_name, store_id,
            start_time: time.length > 0 ? time[0] : '',
            end_time: time.length > 0 ? time[1] : '',
            activity_id
          }
        } else {
          let order_status
          let pay_status
          try {
            order_status = this.$refs.status_tree.getCheckedKeys()
            if (order_status.indexOf(-1) !== -1) order_status = [-1]
            pay_status = this.$refs.pay_status_tree.getCheckedKeys()
            if (pay_status.indexOf(-1) !== -1) pay_status = [-1]
          } catch (e) {
            order_status = []
            pay_status = []
          }
          const { page_index, page_size, order_num, time, name, address, good, type, provice, city, area, activity_id } = this.exportForm
          query = {
            page_index,
            page_size,
            order_no: order_num,
            start_time: time.length > 0 ? time[0] : '',
            end_time: time.length > 0 ? time[1] : '',
            user_name: name,
            receive_info: address,
            goods_info: good,
            order_status,
            pay_status,
            order_type: type,
            provice: provice || '',
            city: city || '',
            area: area || '',
            activity_id
          }
        }
        this.$request(list_down(query), (res) => {
          // console.log(res.data)
          const exportData = res.list
          // console.log(exportData)
              import('@/vendor/Export2Excel').then(excel => {
                const header = ['序号', '订单编号', '下单时间', '所属政委', '备注昵称', '下单人姓名', '订单状态', '支付状态', '数量合计', '订单总额', '所属者姓名', '所属者手机号', '所属体验店', '收货人', '联系方式', '收货地址', '订单备注']
                const exportK = ['index', 'order_num', 'created_at', 'admin_name', 'nickname', 'realname', 'status', 'pay_status', 'total', 'money', 'belong_realname', 'belong_mobile', 'get_store', 'username', 'mobile', 'address', 'remark']
                // if(+this.collect == false) {
                //     header.splice(12,1)
                //     exportK.splice(12,1)
                //   }
                const exportV = exportData.map((item, i) => {
                  const obj = {
                    index: i + 1,
                    created_at: item.created_at || '',
                    order_num: item.order_num,
                    get_store: item.get_store && item.get_store.name,
                    admin_name: item.get_user && item.get_user.warea && item.get_user.warea.admin_name,
                    nickname: item.get_user.nickname || '',
                    realname: item.get_user.realname || '',
                    status: orderStatus(item.status).name || '',
                    pay_status: payStatus(item.pay_status).name,
                    total: item.total || '',
                    money: item.money || '',
                    username: item.get_address.username || '',
                    mobile: +item.get_address.mobile,
                    belong_realname: item.belong_user && item.belong_user.realname,
                    belong_mobile: item.belong_user && item.belong_user.mobile,
                    address: item.get_address.province + item.get_address.city + item.get_address.town + item.get_address.address,
                    remark: item.remark || ''
                  }
                  return obj
                })
                const exportD = exportV.map(item => exportK.map(k => item[k]))
                excel.export_json_to_excel({
                  header,
                  data: exportD,
                  filename: `${formatter(new Date(), 'yyyy-MM-dd')}订单金额`,
                  autoWidth: true,
                  bookType: 'xlsx'
                })
                this.export_order = false
              })
        })
      }
    },
    // 订单明细
    async exportOrder() {
      if (this.chooseList.length) {
        this.$request(downOrder({ id: this.chooseList.map(e => e.id) }), ({ list }) => {
          import('@/vendor/Export2Excel').then(excel => {
            excel.export_json_to_excel({
              header: Object.keys(list[0]),
              data: list.map(listItem => Object.keys(list[0]).map(j => listItem[j])),
              filename: `${formatter(new Date(), 'yyyy-MM-dd')}订单`,
              bookType: 'xlsx'
            })
          })
        })
        this.export_order = false
      } else {
        if (this.tableList.length === 0) {
          this.$message.error('没有可导出的数据')
          return false
        }
        let query = {}
        const { order_no, page_index, page_size, search_name, time, store_id, activity_id } = this.listQuery
        query = {
          order_no, page_index, page_size, search_name, store_id,
          start_time: time.length > 0 ? time[0] : '',
          end_time: time.length > 0 ? time[1] : '',
          activity_id: activity_id
        }
        this.$request(downOrder(query), ({ list }) => {
          import('@/vendor/Export2Excel').then(excel => {
            excel.export_json_to_excel({
              header: Object.keys(list[0]),
              data: list.map(listItem => Object.keys(list[0]).map(j => listItem[j])),
              filename: `${formatter(new Date(), 'yyyy-MM-dd')}体验店订单`,
              bookType: 'xlsx'
            })
          })
        })
        this.export_order = false
      }
    },
    // 导出拆单
    async exporOrdertOrder() {
      if (this.chooseList.length) {
        this.$request(BreakUpOrder({ id: this.chooseList.map(e => e.id) }), (res) => {
          this.expressData = res
          const exportData = this.getExportModule()
          import('@/vendor/Export2Excel').then(excel => {
            excel.export_json_to_excel({
              header: Object.keys(moduleList),
              data: exportData.map(listItem => Object.keys(exportData[0]).map(j => listItem[j])),
              filename: `${new Date().toLocaleDateString()}快递单导出`,
              bookType: 'xlsx',
              isCSV: true
            })
            this.export_order = false
          })
        })
      } else {
        if (this.tableList.length === 0) {
          this.$message.error('没有可导出的数据')
          return false
        }
        let query = {}
        if (!this.highSearchFlag) {
          const { order_status, order_no, page_index, page_size, search_name, time, activity_id, store_id } = this.listQuery
          query = {
            order_status, order_no, page_index, page_size, search_name, store_id,
            start_time: time.length > 0 ? time[0] : '',
            end_time: time.length > 0 ? time[1] : '',
            activity_id
          }
        } else {
          let order_status
          let pay_status
          try {
            order_status = this.$refs.status_tree.getCheckedKeys()
            if (order_status.indexOf(-1) !== -1) order_status = [-1]
            pay_status = this.$refs.pay_status_tree.getCheckedKeys()
            if (pay_status.indexOf(-1) !== -1) pay_status = [-1]
          } catch (e) {
            order_status = []
            pay_status = []
          }
          const { page_index, page_size, order_num, time, name, address, good, type, provice, city, area, activity_id, store_id } = this.exportForm
          query = {
            page_index,
            page_size,
            store_id,
            order_no: order_num,
            start_time: time.length > 0 ? time[0] : '',
            end_time: time.length > 0 ? time[1] : '',
            user_name: name,
            receive_info: address,
            goods_info: good,
            order_status,
            pay_status,
            order_type: type,
            provice: provice || '',
            city: city || '',
            area: area || '',
            activity_id
          }
        }
        this.$request(BreakUpOrder(query), (res) => {
          this.expressData = res
          const exportData = this.getExportModule()
          import('@/vendor/Export2Excel').then(excel => {
            excel.export_json_to_excel({
              header: Object.keys(moduleList),
              data: exportData.map(listItem => Object.keys(exportData[0]).map(j => listItem[j])),
              filename: `${new Date().toLocaleDateString()}快递单导出`,
              bookType: 'xlsx',
              isCSV: true
            })
            this.export_order = false
          })
        })
      }
    },
    getExportModule() {
      const data = this.expressData
      const out = []
      for (const i in data) {
        const item = data[i]
        const info = item.data
        let a = 0
        let b = 0
        let c = 0
        let d = 0
        while (a < item['精装'].length) {
          const obj = Object.assign({}, moduleList)
          obj['订单编号'] = i
          obj['下单时间'] = info.created_at
          obj['所属政委'] = info.admin_name
          obj['备注昵称'] = info.u_nickname
          obj['下单人姓名'] = info.u_name
          obj['下单人手机号'] = info.u_mobile
          obj['收件人'] = info.username
          obj['电话'] = info.mobile
          obj['收件人省'] = info.province
          obj['收件人市'] = info.city
          obj['收件人区'] = info.town
          obj['收件人街道地址'] = info.address
          obj['备注'] = info.remark
          obj['所属'] = info.belong
          obj['赠品'] = info.gift.map(item => `${item.name}${item.num}`).join(';')
          let num_all = 0
          if (item['精装'][a].sec_attr === '男女款') {
            const sex = item['精装'][a].size.split('-')[0]
            let size = item['精装'][a].size.split('-')[1]
            size = size === '3XL' ? 'XXXL' : size
            if (sex === '男款') {
              obj[size] = `${item['精装'][a].num}${item['精装'][a].main_attr}`
              num_all += item['精装'][a].num
            } else {
              obj['女' + size] = `${item['精装'][a].num}${item['精装'][a].main_attr}`
              num_all += item['精装'][a].num
            }
          } else {
            if (item['精装'][a].size === '3XL') {
              item['精装'][a].size = 'XXXL'
            }
            if (item['精装'][a].sec_attr === '男款') {
              obj[item['精装'][a].size] = `${item['精装'][a].num}${item['精装'][a].main_attr}`
              num_all += item['精装'][a].num
            }
            if (item['精装'][a].sec_attr === '女款') {
              obj['女' + item['精装'][a].size] = `${item['精装'][a].num}${item['精装'][a].main_attr}`
              num_all += item['精装'][a].num
            }
          }
          obj['数据求和'] = num_all
          out.push(obj)
          a++
        }
        while (b < item['普通'].length) {
          const obj = Object.assign({}, moduleList)
          obj['订单编号'] = i
          obj['下单时间'] = info.created_at
          obj['所属政委'] = info.admin_name
          obj['备注昵称'] = info.u_nickname
          obj['下单人姓名'] = info.u_name
          obj['下单人手机号'] = info.u_mobile
          obj['收件人'] = info.username
          obj['电话'] = info.mobile
          obj['收件人省'] = info.province
          obj['收件人市'] = info.city
          obj['收件人区'] = info.town
          obj['收件人街道地址'] = info.address
          obj['备注'] = info.remark
          obj['所属'] = info.belong
          obj['赠品'] = info.gift.map(item => `${item.name}${item.num}`).join(';')
          let num_all = 0
          if (item['普通'][b].sec_attr === '男女款') {
            const sex = item['普通'][b].size.split('-')[0]
            let size = item['普通'][b].size.split('-')[1]
            size = size === '3XL' ? 'XXXL' : size
            if (sex === '男款') {
              obj[size] = `${item['普通'][b].num}${item['普通'][b].main_attr}`
              num_all += item['普通'][b].num
            } else {
              obj['女' + size] = `${item['普通'][b].num}${item['普通'][b].main_attr}`
              num_all += item['普通'][b].num
            }
          } else {
            if (item['普通'][b].size === '3XL') {
              item['普通'][b].size = 'XXXL'
            }
            if (item['普通'][b].sec_attr === '男款') {
              obj[item['普通'][b].size] = `${item['普通'][b].num}${item['普通'][b].main_attr}`
              num_all += item['普通'][b].num
            }
            if (item['普通'][b].sec_attr === '女款') {
              obj['女' + item['普通'][b].size] = `${item['普通'][b].num}${item['普通'][b].main_attr}`
              num_all += item['普通'][b].num
            }
          }
          obj['数据求和'] = num_all
          out.push(obj)
          b++
        }
        while (c < item['精装混合'].length) {
          const obj = Object.assign({}, moduleList)
          obj['订单编号'] = i
          obj['下单时间'] = info.created_at
          obj['所属政委'] = info.admin_name
          obj['备注昵称'] = info.u_nickname
          obj['下单人姓名'] = info.u_name
          obj['下单人手机号'] = info.u_mobile
          obj['收件人'] = info.username
          obj['电话'] = info.mobile
          obj['收件人省'] = info.province
          obj['收件人市'] = info.city
          obj['收件人区'] = info.town
          obj['收件人街道地址'] = info.address
          obj['备注'] = info.remark
          obj['所属'] = info.belong
          obj['赠品'] = info.gift.map(item => `${item.name}${item.num}`).join(';')
          let num_all = 0
          for (let j = 0; j < item['精装混合'][c].length; j++) {
            if (item['精装混合'][c][j].sec_attr === '男女款') {
              const sex = item['精装混合'][c][j].size.split('-')[0]
              let size = item['精装混合'][c][j].size.split('-')[1]
              size = size === '3XL' ? 'XXXL' : size
              if (sex === '男款') {
                obj[size] += `${item['精装混合'][c][j].num}${item['精装混合'][c][j].main_attr}`
                num_all += item['精装混合'][c][j].num
              } else {
                obj['女' + size] += `${item['精装混合'][c][j].num}${item['精装混合'][c][j].main_attr}`
                num_all += item['精装混合'][c][j].num
              }
            } else {
              if (item['精装混合'][c][j].size === '3XL') {
                if (item['精装混合'][c][j].sec_attr === '男款') {
                  obj['XXXL'] += `${item['精装混合'][c][j].num}${item['精装混合'][c][j].main_attr}`
                  num_all += item['精装混合'][c][j].num
                }
              } else {
                if (item['精装混合'][c][j].sec_attr === '男款') {
                  obj[item['精装混合'][c][j].size] += `${item['精装混合'][c][j].num}${item['精装混合'][c][j].main_attr}`
                  num_all += item['精装混合'][c][j].num
                }
                if (item['精装混合'][c][j].sec_attr === '女款') {
                  obj['女' + item['精装混合'][c][j].size] += `${item['精装混合'][c][j].num}${item['精装混合'][c][j].main_attr}`
                  num_all += item['精装混合'][c][j].num
                }
              }
            }
          }
          obj['数据求和'] = num_all
          out.push(obj)
          c++
        }
        while (d < item['普通混合'].length) {
          const obj = Object.assign({}, moduleList)
          obj['订单编号'] = i
          obj['下单时间'] = info.created_at
          obj['所属政委'] = info.admin_name
          obj['备注昵称'] = info.u_nickname
          obj['下单人姓名'] = info.u_name
          obj['下单人手机号'] = info.u_mobile
          obj['收件人'] = info.username
          obj['电话'] = info.mobile
          obj['收件人省'] = info.province
          obj['收件人市'] = info.city
          obj['收件人区'] = info.town
          obj['收件人街道地址'] = info.address
          obj['备注'] = info.remark
          obj['所属'] = info.belong
          obj['赠品'] = info.gift.map(item => `${item.name}${item.num}`).join(';')
          let num_all = 0
          for (let j = 0; j < item['普通混合'][d].length; j++) {
            if (item['普通混合'][d][j].sec_attr === '男女款') {
              const sex = item['普通混合'][d][j].size.split('-')[0]
              let size = item['普通混合'][d][j].size.split('-')[1]
              size = size === '3XL' ? 'XXXL' : size
              if (sex === '男款') {
                obj[size] += `${item['普通混合'][d][j].num}${item['普通混合'][d][j].main_attr}`
                num_all += item['普通混合'][d][j].num
              } else {
                obj['女' + size] += `${item['普通混合'][d][j].num}${item['普通混合'][d][j].main_attr}`
                num_all += item['普通混合'][d][j].num
              }
            } else {
              if (item['普通混合'][d][j].size === '3XL') {
                if (item['普通混合'][d][j].sec_attr === '男款') {
                  obj['XXXL'] += `${item['普通混合'][d][j].num}${item['普通混合'][d][j].main_attr}`
                  num_all += item['普通混合'][d][j].num
                }
              } else {
                if (item['普通混合'][d][j].sec_attr === '男款') {
                  obj[item['普通混合'][d][j].size] += `${item['普通混合'][d][j].num}${item['普通混合'][d][j].main_attr}`
                  num_all += item['普通混合'][d][j].num
                }
                if (item['普通混合'][d][j].sec_attr === '女款') {
                  obj['女' + item['普通混合'][d][j].size] += `${item['普通混合'][d][j].num}${item['普通混合'][d][j].main_attr}`
                  num_all += item['普通混合'][d][j].num
                }
              }
            }
          }
          obj['数据求和'] = num_all
          out.push(obj)
          d++
        }
      }
      return out
    },
    orderMulSelect(val) {
      this.chooseList = val
    },
    async activityList(cb) {
      this.loadingFull = true
      await activityList().then(res => {
        this.loadingFull = false
        if (res.code === 200) {
          this.activitys = res.data
          res.data.map(item => {
            if (item.is_ing === 1) {
              this.listQuery.activity_id = item.id
            }
          })
        }
        cb && cb()
      }).catch(e => {
        this.loadingFull = false
        cb && cb()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .tag {
    padding: 2px;
    margin-right: 2px;
    font-size: 12px;
    line-height: 1;
    border-radius: 2px;
    font-family: simsun;
    color: #fff;
    display: inline;
    cursor: pointer;
  }

  .sub-tag {
    font-size: 12px;
    color: #00a7f2;
    border: 1px solid rgba(0,167,242,.4);
  }

  .return-tag {
    color: #8c7ee4;
    border: 1px solid rgba(140,123,231,.4);
    display: inline-block;
  }
</style>
