<template>
  <!-- 预装箱单-成衣 -->
  <a-card :bordered="false">
    <!-- 查询 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="订单号">
              <!--  -->
              <a-input placeholder="请输入订单号" v-model="queryParam.orderNum"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="款号">
              <a-input placeholder="请输入款号" v-model="queryParam.styleNum"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="品名">
              <a-input placeholder="请输入品名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 导出 导入 新增-->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('预装箱单-成衣')">导出</a-button>

      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>

      <a-button type="primary" @click="addAdpackingDrawer" icon="plus">新增</a-button>
    </div>

    <!-- table rowKey="id" -->
    <div>
      <a-table
        bordered
        :columns="adPaListClothesColumns"
        :data-source="adPaListClothesData"
        :loading="loading"
        :pagination="ipagination"
        :row-key="record => record.id"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 1500 }"
      >
        <!-- 推送状态 -->
        <!-- slot-scope="text, record" -->
        <span slot="pushStateSlot">
          <!-- v-if="record.isRelease == '0'" -->
          <a-tag color="#f50">未推送</a-tag>
          <!-- <a-tag color="#87d068" v-else>已发布</a-tag> -->
        </span>

        <!-- 单据状态 -->
        <span slot="documentStateSlot">
          <a-tag color="#2db7f5">已保存</a-tag>
        </span>

        <!-- 操作 -->
        <span slot="operationSlot" slot-scope="text, record">
          <a @click="derive(record)" style="color:green;">导出</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item><a @click="submit(record)">提交</a></a-menu-item>
              <a-menu-item><a @click="details(record)">详情</a></a-menu-item>
              <a-menu-item><a @click="edit(record)">编辑</a></a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
                  <a href="javascript:void(0);" style="color:red;">删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item><a @click="copy(record)">复制</a></a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <!-- 抽屉 -->
    <div>
      <addAdpacking-drawer ref="addAdpackingDrawer" :father="aa" @ok="modalFormOk"></addAdpacking-drawer>
      <detailsAdpacking-drawer ref="detailsAdpackingDrawer" :father="bb" @ok="modalFormOk"></detailsAdpacking-drawer>
      <editAdpacking-drawer ref="editAdpackingDrawer" :father="cc" @ok="modalFormOk"></editAdpacking-drawer>
    </div>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'
import addAdpackingDrawer from '@views/advance-packingList/addAdpackingDrawer.vue'
import detailsAdpackingDrawer from '@views/advance-packingList/detailsAdpackingDrawer.vue'
import editAdpackingDrawer from '@views/advance-packingList/editAdpackingDrawer.vue'

export default {
  name: 'AdPaListClothes', // 预装线单-成衣
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment, addAdpackingDrawer, detailsAdpackingDrawer, editAdpackingDrawer },

  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略
    return {
      // 表头
      adPaListClothesColumns: [
        {
          title: '款号',
          dataIndex: 'styleNum',
          width: 120,
          fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '客户简称',
          dataIndex: 'customerShortName',
          width: 120,
          fixed: 'left',
          className: 'replacecolor'
        },
        //         {
        //   title: '创建时间',
        //   dataIndex: 'createTime',
        //   align: 'center',
        //   sorter: true,
        //   customRender: text => {
        //     return moment(text).format('YYYY-MM-DD')
        //   }
        // },
        {
          title: '预发货日期',
          dataIndex: 'scheduledShipDate',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '小po',
          dataIndex: 'smallPo',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '分销点',
          dataIndex: 'distributionPoint',
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '存货名称',
          dataIndex: 'inventoryName',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '颜色',
          dataIndex: 'color',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '采购/委外订单号',
          dataIndex: 'purchaseAboardOrderNum',
          width: 160,
          className: 'replacecolor'
        },
        {
          title: '订单类型',
          dataIndex: 'orderType',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '原因',
          dataIndex: 'reason',
          width: 120,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '推送状态',
          dataIndex: 'pushState',
          width: 90,
          scopedSlots: { customRender: 'pushStateSlot' },
          fixed: 'right',
          className: 'replacecolor'
        },

        {
          title: '单据状态',
          dataIndex: 'documentState',
          width: 90,
          scopedSlots: { customRender: 'documentStateSlot' },
          fixed: 'right',
          className: 'replacecolor'
        },

        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operationSlot' },
          width: 160,
          fixed: 'right',
          className: 'replacecolor'
        }
      ],
      adPaListClothesData: [{}, {}, {}, {}],
      selectedRowKeys: [], // 勾选航
      loading: false, // 表格加载

      // 查询条件
      queryParam: {
        orderNum: '',
        styleNum: '',
        name: '' // 品名
      },
      url: {
        // syncUser: '/act/process/extActProcess/doSyncUser',
        list: '/sys/user/list',
        // delete: '/sys/user/delete',
        // deleteBatch: '/sys/user/deleteBatch',
        exportXlsUrl: '/sys/user/exportXls', // 导出
        importExcelUrl: 'sys/user/importExcel' // 导入
      }
    }
  },
  created() {
    // this.getAdPaListClothes()
  },
  methods: {
    // 第一行导出
    handleExportXls() {},

    // 新增 预装箱单
    addAdpackingDrawer() {
      console.log('新增预装箱单')
      this.$refs.addAdpackingDrawer.visible = true
    },

    // 第二行 查询按钮
    searchQuery() {
      // this.getAnnList() // 渲染公告
    },
    // 重置
    searchReset() {
      // console.log('>>>>重置')
      this.queryParam = {}
      // this.getAnnList()
    },

    // 操作 导出
    derive() {},
    // 操作 提交
    submit() {},
    // 操作 详情
    details(record) {
      console.log('详情')
      console.log('点击的record', record.id)
      this.$refs.detailsAdpackingDrawer.visible = true
    },

    // 操作 编辑
    edit(record) {
      console.log('编辑')
      this.$refs.editAdpackingDrawer.visible = true
    },

    // 操作 删除
    handleDelete() {},

    // 选中行
    onSelectChange(keys, rows) {
      this.selectedRowKeys = keys
      this.selectedRows = rows
    },
    // --------------------------------------
    aa() {},
    bb() {},
    cc() {}
    // 分页、排序、筛选变化时触发
    // handleTableChange(pagination, filters, sorter) {
    //   // console.log('当前页信息>>>>',pagination)
    //   this.queryParam.pageNo = pagination.current
    //   // this.getAnnList()
    // }
  },
  computed: {
    // 导入
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    // 选中项
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
        },
        getCheckboxProps: record => ({
          props: {
            disabled: record.title === 'Disabled User',
            // Column configuration not to be checked
            title: record.title
          }
        })
      }
    }
  },
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '~@assets/less/overwriter.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}

/deep/ .ant-table-tbody {
  text-align: center;
}

// /deep/ th.replacecolor {
//   background-color: #ccc;
// }
</style>
