<template>
  <a-card size="small" :bordered="false" class="salesDetailsList-wrap">
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-form-model
        ref="ruleForm"
        class="form-model-con"
        layout="inline"
        :model="queryParam"
        :rules="rules"
        @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-model-item label="销售日期" prop="time">
              <rangeDate ref="rangeDate" :value="queryParam.time" @change="dateChange" />
            </a-form-model-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-model-item label="销售单号">
              <a-input id="salesDetailsList-productCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入销售单号"/>
            </a-form-model-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-model-item label="产品编码">
              <a-input id="salesDetailsList-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="请输入产品编码"/>
            </a-form-model-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="区域">
                <a-select id="salesDetailsList-allocateTypeSn" v-model="queryParam.allocateTypeSn" placeholder="请选择区域" allowClear >
                  <a-select-option v-for="item in allocateTypeList" :key="item.allocateTypeSn" :value="item.allocateTypeSn">{{ item.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="省份">
                <a-select id="salesDetailsList-state" v-model="queryParam.state" placeholder="请选择省份" allowClear >
                  <a-select-option v-for="item in allocateTypeList" :key="item.allocateTypeSn" :value="item.allocateTypeSn">{{ item.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="产品名称">
                <a-input id="salesDetailsList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="客户名称">
                <a-input id="salesDetailsList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入客户名称"/>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="产品品牌">
                <a-select
                  placeholder="请选择"
                  id="salesDetailsList-productBrandSn"
                  allowClear
                  v-model="queryParam.productBrandSn"
                  :showSearch="true"
                  option-filter-prop="children"
                  :filter-option="filterOption">
                  <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="客户级别">
                <a-select
                  placeholder="请选择"
                  id="salesDetailsList-productBrandSn"
                  allowClear
                  v-model="queryParam.productBrandSn"
                  :showSearch="true"
                  option-filter-prop="children"
                  :filter-option="filterOption">
                  <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="品牌类别">
                <v-select code="BRAND_TYPE" id="salesDetailsList-brandType" v-model="queryParam.brandType" allowClear placeholder="请选择品牌分类"></v-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="二级分类">
                <a-select
                  placeholder="请选择"
                  id="salesDetailsList-productBrandSn"
                  allowClear
                  v-model="queryParam.productBrandSn"
                  :showSearch="true"
                  option-filter-prop="children"
                  :filter-option="filterOption">
                  <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="三级分类">
                <a-select
                  placeholder="请选择"
                  id="salesDetailsList-productBrandSn"
                  allowClear
                  v-model="queryParam.productBrandSn"
                  :showSearch="true"
                  option-filter-prop="children"
                  :filter-option="filterOption">
                  <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="盘点区间日期">
                <a-checkbox @change="onChange"></a-checkbox>
              </a-form-model-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
            <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="salesDetailsList-refresh">查询</a-button>
            <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="salesDetailsList-reset">重置</a-button>
            <a @click="advanced=!advanced" style="margin-left: 5px">
              {{ advanced ? '收起' : '展开' }}
              <a-icon :type="advanced ? 'up' : 'down'"/>
            </a>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="small"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :scroll="{ x: 3500 }"
      bordered>
      <template slot="footer" slot-scope="currentPageData">
        <a-row :gutter="15">
          <a-col :md="4" :sm="24">
            数量：69
          </a-col>
          <a-col :md="4" :sm="24">
            实售价：1130.36
          </a-col>
          <a-col :md="4" :sm="24">
            开单价：1187.11
          </a-col>
          <a-col :md="4" :sm="24">
            成本：1052.30
          </a-col>
          <a-col :md="4" :sm="24">
            折后金额：1187.11
          </a-col>
        </a-row>
      </template>
    </s-table>
  </a-card>
</template>

<script>
import getDate from '@/libs/getDate.js'
import { STable, VSelect } from '@/components'
import reportData from '@/libs/reportData'
import rangeDate from '@/views/common/rangeDate.vue'
// import { allocateBillList, allocateBillDel, allocateBillAudit, allocateBillExport } from '@/api/allocateBill'
// import { allocateTypeAllList } from '@/api/allocateType'
export default {
  components: { STable, VSelect, rangeDate },
  data () {
    return {
      advanced: false, // 高级搜索 展开/关闭
      tableHeight: 0,
      queryParam: { //  查询条件
        time: [
          getDate.getCurrMonthDays().starttime,
          getDate.getCurrMonthDays().endtime
        ],
        beginDate: getDate.getCurrMonthDays().starttime,
        endDate: getDate.getCurrMonthDays().endtime,
        targetName: '', //  调往对象
        allocateTypeSn: undefined, //  调拨类型
        state: undefined, //  业务状态
        allocateNo: '' //  调拨单号
      },
	  rules: {
	    'time': [{ required: true, message: '请选择调拨开单日期', trigger: 'change' }]
	  },
      disabled: false, //  查询、重置按钮是否可操作
      exportLoading: false,
      checkVal: '',
      reportData: reportData.reportDataList,
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center', fixed: 'left' },
        { title: '区域', dataIndex: 'data1', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '销售单号', dataIndex: 'data2', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '省份', dataIndex: 'data3', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '客户名称', dataIndex: 'data4', width: 220, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '客户级别', dataIndex: 'data5', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '直接绑定客户级别', dataIndex: 'data6', width: 200, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '间接绑定客户级别', dataIndex: 'data7', width: 200, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '开单日期', dataIndex: 'data8', width: 160, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '销售日期', dataIndex: 'data9', width: 160, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '品牌', dataIndex: 'data10', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '二级类别', dataIndex: 'data11', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '产品名称', dataIndex: 'data12', width: 120, align: 'center', ellipsis: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '产品编码', dataIndex: 'data13', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '单位', dataIndex: 'data14', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '产品批次', dataIndex: 'data15', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '销售数量', dataIndex: 'data16', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '成本价', dataIndex: 'data17', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '实售价', dataIndex: 'data18', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '开单价', dataIndex: 'data19', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '市级价', dataIndex: 'data20', width: 140, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '直接差价', dataIndex: 'data21', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '间接差价', dataIndex: 'data22', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '操作员', dataIndex: 'data23', width: 120, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return allocateBillList(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: reportData.salesDetailsList,
            count: 10
          }
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = i + 1
          }
          _this.disabled = false
          resolve(data)
        })
      },
      allocateTypeList: [], //  调拨类型
      openModal: false //  新增编辑  弹框
    }
  },
  methods: {
    handleFooterShow (currentPageData) {
      console.log(currentPageData, '[=currentPageData]')
    },
    //  创建时间  change
    dateChange (date) {
      this.queryParam.time = date
      this.queryParam.beginDate = date[0] || ''
      this.queryParam.endDate = date[1] || ''
    },
    // 选择盘点日期
    onChange (e) {
      console.log(e)
      // this.checkVal
    },

    //  重置
    resetSearchForm () {
      this.queryParam.time = [
        getDate.getCurrMonthDays().starttime,
        getDate.getCurrMonthDays().endtime
      ]
      this.$refs.rangeDate.resetDate(this.queryParam.time)
      this.queryParam.beginDate = getDate.getCurrMonthDays().starttime
      this.queryParam.endDate = getDate.getCurrMonthDays().endtime
      this.queryParam.targetName = ''
      this.queryParam.allocateTypeSn = undefined
      this.queryParam.state = undefined
      this.queryParam.allocateNo = ''
      this.$refs.table.refresh(true)
    }
  },
  activated () {
    // 如果是新页签打开，则重置当前页面
    if (this.$store.state.app.isNewTab) {
      this.resetSearchForm()
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {})
  }
}
</script>
