<template>
  <a-modal
    title="参照订单数据"
    v-model="referOrderDataModVis"
    :confirmLoading="confirmLoading"
    @ok="onSubmit"
    @cancel="handleCancel"
    width="76%"
  >
    <!-- tabel 加载 -->
    <a-spin :spinning="confirmLoading">
      <!-- 查询  -->
      <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.orderNumber"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="8">
              <a-form-item label="账套">
                <a-input placeholder="请输入账套" v-model="queryParam.account"></a-input>
                <!-- <a-select placeholder="请选择账套" v-model="queryParam.account">
                  <a-select-option value="">请选择</a-select-option>
                  <a-select-option :value="0">香港森语(101)</a-select-option>
                </a-select> -->
              </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>

      <!-- 勾选表  :row-key="record => record.id" { pageSize: 50 } , y: 800  -->
      <a-table
        bordered
        size="small"
        rowKey="id"
        v-if="orderListData"
        :columns="referOerderColumns"
        :data-source="orderListData"
        :loading="loading"
        :pagination="pagination"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 1500 }"
      >
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'

import { queryOrderData } from '@api/document/shipmentList'

export default {
  name: 'ReferOrderDataModal', // 参照订单数据弹框
  mixins: [JeecgListMixin],
  components: { JEllipsis, moment },

  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} /> // 省略

    return {
      selectedRowKeys: [],
      selectedRows: {}, // 勾选项
      loading: false, // 表格加载
      // 表头
      referOerderColumns: [
        {
          title: '订单号',
          dataIndex: 'orderNumber',
          width: 280,
          fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '款号',
          dataIndex: 'itemNumber',
          width: 180,
          fixed: 'left',
          className: 'replacecolor'
        },

        {
          title: '小po',
          dataIndex: 'smallPo',
          width: 100,
          className: 'replacecolor'
        },
        // 账套替换
        {
          title: '账套',
          dataIndex: 'account',
          width: 80,
          className: 'replacecolor'
        },
        //         {
        //   title: '创建时间',
        //   dataIndex: 'createTime',
        //   align: 'center',
        //   sorter: true,
        //   customRender: text => {
        //     return moment(text).format('YYYY-MM-DD')
        //   }
        // },
        {
          title: '订单日期',
          dataIndex: 'orderDate',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: 'packId',
          dataIndex: 'packId',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '分销点',
          dataIndex: 'distributionPoint',
          width: 120,
          className: 'replacecolor'
        },

         {
          title: '存货编码',
          dataIndex: 'inventoryCode',
          width: 220,
          className: 'replacecolor'
        },
        {
          title: '存货名称',
          dataIndex: 'inventoryName',
          width: 280,
          className: 'replacecolor'
        },
        {
          title: '颜色',
          dataIndex: 'colour',
          width: 160,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '尺码',
          dataIndex: 'size',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '配码规格',
          dataIndex: 'codingRules',
          width: 180,
          className: 'replacecolor'
        },
        {
          title: '数量',
          dataIndex: 'quantity',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '订单剩余数量',
          dataIndex: 'surplusNum',
          width: 120,
          className: 'replacecolor'
        },

  {
          title: '含税单价',
          dataIndex: 'unitPriceIncludingTax',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '含税单价',
          dataIndex: 'unitPriceIncludingTax',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '业务类型',
          dataIndex: 'businessTypeText',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '客户订单',
          dataIndex: 'customerOrderNumber',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '销售类型',
          dataIndex: 'salesTypeText',
          width: 100,
          className: 'replacecolor'
        },

        {
          title: '客户简称',
          dataIndex: 'customerAbbreviation',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          width: 220,
          className: 'replacecolor'
        },
        {
          title: '供应商',
          dataIndex: 'supplier',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '汇率',
          dataIndex: 'exchangeRate',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '整单合计',
          dataIndex: 'wholeOrderTotal',
          width: 100,
          className: 'replacecolor'
        },

        {
          title: '销售部门',
          dataIndex: 'salesDepartment',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '业务员',
          dataIndex: 'salesman',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '币种',
          dataIndex: 'currencyText',
          width: 100,
          className: 'replacecolor'
        },

        {
          title: '品牌方',
          dataIndex: 'brandSide',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '第三方',
          dataIndex: 'thirdParty',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '定金比例(%)',
          dataIndex: 'depositRatio',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '定金',
          dataIndex: 'deposit',
          width: 100,
          className: 'replacecolor'
        },
        {
          title: '协同路线',
          dataIndex: 'collaborativeRoute',
          width: 100,
          className: 'replacecolor'
        },

        {
          title: '付款条件',
          dataIndex: 'termOfPayment',
          width: 120,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '最终客户',
          dataIndex: 'endCustomer',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '订单备注',
          dataIndex: 'orderRemarks',
          width: 180,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },

        {
          title: '价格备注',
          dataIndex: 'priceRemarks',
          width: 120,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '订单变更说明',
          dataIndex: 'orderChangeDescription',
          width: 220,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '订单主表ID',
          dataIndex: 'syOrderDataId',
          width: 120,
          //  colSpan:0,     //隐藏表头
          //     customRender: (value, row, index) => {
          //         let obj = {
          //             children: value,
          //             attrs: {},
          //         };
          //         obj.attrs.colSpan = 0;
          //         return obj;
          //     },
          className: 'replacecolor1'
        },
        {
          title: '订单子表ID',
          dataIndex: 'syOrderDataItemId',
          width: 220,
          className: 'replacecolor'
        }
      ],
      orderListData: [],
      confirmLoading: false,
      referOrderDataModVis: false,

      // 查询条件
      queryParam: {
        orderNumber: '', // 订单号
        account: ''
        // pageNo: '', // 初始页
        // pageSize: '-1' // 每页显示条数
      },
      // 分页
      pagination: {
        // total: 0,
        // current: 0,
        // pageSize: 0
      }
    }
  },
  // 接收父组件 方法
  // props: {},

  created() {
    this.getOrderList()
  },
  methods: {
    // 参照订单数据 查询
    getOrderList() {
      this.$nextTick(() => {
        queryOrderData(this.queryParam).then(res => {
          // console.log('参照订单数据res', res)
          if (res.success) {
            this.orderListData = res.result.records
            this.pagination = {
              total: res.result.total,
              current: res.result.current,
              pageSize: res.result.size
            }
          }
        })
      })
    },

    // 弹框确定
    onSubmit() {
      if (this.selectedRowKeys.length == 0) {
        this.$message.error('请勾选订单数据')
      } else {
        // console.log('需要传给父组件的数据', this.selectedRows)
        // bao父组件指定的传数据绑定的函数 || this.selectedRows子组件给父组件传递的数据
        console.log('all?', this.selectedRows)

        this.$emit('bao', this.selectedRows)
        this.referOrderDataModVis = false
        this.selectedRowKeys = []
        this.selectedRows = []
      }
    },
    handleTableChange(pagination, filters, sorter) {
      this.queryParam.pageNo = pagination.current
      this.getOrderList()
    },

    searchQuery() {
      this.queryParam.pageNo = ''
      this.getOrderList()
    },

    // 重置
    searchReset() {
      this.queryParam.orderNumber = ''
      this.queryParam.account = ''
      this.getOrderList()
    },
    // 选中行
    onSelectChange(keys, rows) {
      this.selectedRowKeys = keys
      this.selectedRows = rows
    },

    close() {
      this.$emit('close')
      this.referOrderDataModVis = false
      this.selectedRowKeys = []
      this.orderListData = []
      this.getOrderList()
    },
    handleCancel() {
      this.close()
    }
  },
  computed: {
    // 选中项
    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
          }
        })
      }
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}
/deep/ .ant-table-tbody {
  text-align: center;
}
// /deep/ th.replacecolor1 {
// display: none;
// }
</style>
