<template>
  <a-card :bordered="false" class="salesManagementList-wrap">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-item label="创建时间">
              <a-range-picker v-model="queryParam.reatDate" id="alesManagementList-creatDate"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="客户名称" :label-col="{ span:7 }" :wrapper-col="{ span:17}">
            	<a-select id="alesManagementList-customeName" placeholder="请选择客户" allowClear v-model="queryParam.dataSourceNo" :showSearch="true" option-filter-prop="children" :filter-option="filterOption">
            		<a-select-option v-for="item in customeList" :key="item.salesChannelNo" :value="item.salesChannelNo">{{ item.salesChannelName }}</a-select-option>
            	</a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="销售单号">
              <a-input id="alesManagementList-salesNo" v-model.trim="queryParam.salesNo" allowClear placeholder="请输入销售单号"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-item label="店内单号">
                <a-input id="alesManagementList-storeNo" v-model.trim="queryParam.storeNo" allowClear placeholder="请输入店内单号"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="支付方式">
                <v-select
                  v-model="queryParam.payType"
                  ref="payType"
                  id="alesManagementList-payType"
                  code="PAYMENT_TYPE"
                  placeholder="请选择支付方式"
                  allowClear></v-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="收款方式">
                <v-select
                  v-model="queryParam.paymentType"
                  ref="paymentType"
                  id="alesManagementList-paymentType"
                  code="PAYMENT_TYPE"
                  placeholder="请选择收款方式"
                  allowClear></v-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="单据状态">
                <v-select
                  v-model="queryParam.billStatus"
                  ref="billStatus"
                  id="alesManagementList-billStatus"
                  code="PAYMENT_TYPE"
                  placeholder="请选择单据状态"
                  allowClear></v-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" :disabled="disabled" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" :disabled="disabled" @click="resetSearchForm()">重置</a-button>
              <a @click="toggleAdvanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮 -->
    <div class="table-operator">
      <a-button type="primary" @click="handleEdit()">新建销售单</a-button>
    </div>
    <!-- alert -->
    <a-alert type="warning">
      <div slot="message">
        <span>总售价：14.00 元；</span>
        <span>总单数：6；</span>
        <span>总款数：3；</span>
        <span>总数量：7；</span>
      </div>
    </a-alert>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :scroll="{ x: 1500, y: 300 }"
      bordered>
      <!-- 状态 -->
      <template slot="state" slot-scope="text, record">
        <span>{{record.state == 1 ? '已启用' : '已禁用'}}</span>
      </template>
      <!-- 操作 -->
      <span slot="action" slot-scope="text, record">
        <template>
          <a href="javascript:;" id="alesManagementList-auth-btn">审核</a>
          <a-divider type="vertical" />
          <a href="javascript:;" id="alesManagementList-send-btn">发货</a>
          <a-divider type="vertical" />
        </template>
        <a-dropdown>
          <a class="ant-dropdown-link">
            更多 <a-icon type="down" />
          </a>
          <a-menu slot="overlay">
            <a-menu-item >
              <a id="alesManagementList-view-btn" href="javascript:;" @click="handleView(record)">明细</a>
            </a-menu-item>
            <a-menu-item>
              <a id="alesManagementList-edit-btn" href="javascript:;" @click="handleEdit(record)">修改</a>
            </a-menu-item>
            <a-menu-item>
              <a id="alesManagementList-del-btn" href="javascript:;" @click="handleDel(record)">删除</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
        </span>
    </s-table>
  </a-card>
</template>

<script>
import moment from 'moment'
import { STable, VSelect } from '@/components'
// import { getRoleList, getServiceList } from '@/api/manage'
export default {
  name: 'TableList',
  components: {
    STable,
    VSelect
  },
  data () {
    return {
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      disabled: false, //  查询、重置按钮是否可操作
      customeList:[],
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '创建时间',
          dataIndex: 'creatDate',
          align: 'center'
        },
        {
          title: '销售单号',
          dataIndex: 'salerNo',
          align: 'center'
        },
        {
          title: '店内单号',
          dataIndex: 'storeNo',
          align: 'center'
        },
        {
          title: '客户名称',
          dataIndex: 'custName',
          align: 'center'
        },
        {
          title: '总款数',
          dataIndex: 'totalP',
          align: 'center'
        },
        {
          title: '总数量',
          dataIndex: 'totalNums',
          align: 'center'
        },
        {
          title: '总售价',
          dataIndex: 'totalPrice',
          align: 'center'
        },
        {
          title: '支付方式',
          dataIndex: 'payType',
          align: 'center'
        },
        {
          title: '收款方式',
          dataIndex: 'mementPay',
          align: 'center'
        },
        {
          title: '审核时间',
          dataIndex: 'shDate',
          align: 'center'
        },
        {
          title: '急件',
          dataIndex: 'isJj',
          align: 'center'
        },
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center'
        },
        {
          title: '操作',
          width: '200px',
          key: 'operation',
          fixed: 'right',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return customerBundleDelayList( Object.assign(parameter, this.queryParam) ).then(res => {
        //   const data = res.data
        //   const no = (data.pageNo - 1) * data.pageSize
        //   for (var i = 0; i < data.list.length; i++) {
        //     data.list[i].no = no + i + 1
        //   }
        //   this.disabled = false
        //   return data
        // })
        const _this = this
        return new Promise(function(resolve, reject){
          const data = {
            pageNo: 1,
            pageSize: 10,
            list: [
              { id: '1', productNum: 'jgqp11111111111', productName: '产品1', productOldNum: 'jgqp111123545', productBrand: '箭冠品牌', productType: '产品分类1', inventoryNum: '5', inventoryMoney: '122' }
            ],
            count: 10
          }
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
          }
          _this.disabled = false
          resolve(data)
        })
      },
    }
  },
  created () {
  },
  methods: {
    handleEdit (record) {
      this.$emit('onEdit', record)
    },
    handleView(record){
      this.$router.push({ name: 'salesDetail', params: { id: record.id }})
    },
    handleDel(){},
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    resetSearchForm () {
      this.queryParam.orderBundleNo = ''
      this.queryParam.orderBundle.custMobile = ''
      this.queryParam.bundleName = ''
      this.queryParam.itemName = ''
      this.oldTime = undefined
      this.newTime = undefined
      this.$refs.table.refresh(true)
    },
  }
}
</script>
<style lang="less">
  .salesManagementList-wrap{
    .sTable{
      margin-top: 15px;
    }
  }
</style>