<template>
  <a-card size="small" :bordered="false" class="quotationList-wrap">
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-item label="创建时间">
              <rangeDate ref="rangeDate" @change="dateChange" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="客户名称">
              <a-select
                id="quotationList-bundleName"
                placeholder="请选择"
                allowClear
                v-model="queryParam.dataSourceNo"
                :showSearch="true"
                option-filter-prop="children"
                :filter-option="filterOption">
                <a-select-option v-for="item in brandData" :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="quotationList-bundleName" v-model.trim="queryParam.bundleName" allowClear placeholder="请输入关联销售单号"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-item label="报价单号">
                <a-input id="quotationList-bundleName" v-model.trim="queryParam.bundleName" allowClear placeholder="请输入报价单号"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="quotationList-refresh">查询</a-button>
            <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="quotationList-reset">重置</a-button>
            <a @click="advanced=!advanced" style="margin-left: 8px">
              {{ advanced ? '收起' : '展开' }}
              <a-icon :type="advanced ? 'up' : 'down'"/>
            </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮 -->
    <div class="table-operator">
      <a-button id="quotationList-add" type="primary" class="button-error" @click="handleAdd">新增</a-button>
    </div>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :scroll="{ x: 1310 }"
      bordered>
      <!-- 是否转销售单 -->
      <template slot="invenstoryNum" slot-scope="text, record">
        <span>{{ record.invenstoryNum == 1 ? '是' : '否' }}</span>
      </template>
      <!-- 操作 -->
      <template slot="action" slot-scope="text, record">
        <a-button size="small" type="link" @click="handleEdit(record)" id="quotationList-edit-btn">编辑</a-button>
        <a-divider type="vertical" style="margin: 0;" />
        <a-button size="small" type="link" @click="handleDetail(record)" id="quotationList-detail-btn">详情</a-button>
        <a-divider type="vertical" style="margin: 0;" />
        <a-button size="small" type="link" @click="handleDel(record)" id="quotationList-del-btn">删除</a-button>
      </template>
    </s-table>
    <!-- 选择基本信息弹框 -->
    <basic-info-modal :openModal="openModal" @ok="handleOk" @close="openModal=false" />
  </a-card>
</template>

<script>
import { STable, VSelect } from '@/components'
import rangeDate from '@/views/common/rangeDate.vue'
import basicInfoModal from './basicInfoModal.vue'
export default {
  components: { STable, VSelect, basicInfoModal, rangeDate },
  data () {
    return {
      advanced: false, // 高级搜索 展开/关闭
      queryParam: { //  查询条件
        beginDate: '',
        endDate: '',
        bundleName: '', //  供应商名称
        state: undefined //  状态
      },
      disabled: false, //  查询、重置按钮是否可操作
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '创建时间', dataIndex: 'inventoryMoney', width: 160, align: 'center' },
        { title: '报价单号', dataIndex: 'inventosryMoney', width: 140, align: 'center' },
        { title: '关联销售单号', dataIndex: 'productType', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '客户名称', dataIndex: 'productName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
        { title: '总款数', dataIndex: 'productBrand', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '总数量', dataIndex: 'psroductBrand', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '总价格', dataIndex: 'invdentoryNum', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '是否转销售单', scopedSlots: { customRender: 'invenstoryNum' }, width: 120, align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
      ],
      // 加载数据方法 必须为 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' }
            ]
          }
          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)
        })
      },
      brandData: [],
      openModal: false // 基本信息弹框是否显示
    }
  },
  methods: {
    //  时间  change
    dateChange (date) {
      this.queryParam.beginDate = date[0]
      this.queryParam.endDate = date[1]
    },
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    },
    //  重置
    resetSearchForm () {
      this.$refs.rangeDate.resetDate()
      this.queryParam.beginDate = ''
      this.queryParam.endDate = ''
      this.queryParam.orderBundleNo = ''
      this.queryParam.orderBundle.custMobile = ''
      this.queryParam.bundleName = ''
      this.queryParam.itemName = ''
      this.oldTime = undefined
      this.newTime = undefined
      this.$refs.table.refresh(true)
    },
    //  基本信息  保存
    handleOk () {
      this.$router.push({ path: `/salesManagement/quotation/add` })
    },
    //  新增
    handleAdd () {
      this.openModal = true
    },
    //  编辑
    handleEdit (row) {
      this.$router.push({ path: `/salesManagement/quotation/edit/${row.id}` })
    },
    //  详情
    handleDetail (row) {
      this.$router.push({ path: `/salesManagement/quotation/detail/${row.id}` })
    },
    //  删除
    handleDel (row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '删除后不可恢复，确定要进行删除吗？',
        centered: true,
        onOk () {
          // warehouseDel({
          //   id: row.id
          // }).then(res => {
          //   if (res.status == 200) {
          //     _this.$message.success(res.message)
          //     _this.$refs.table.refresh()
          //   }
          // })
        }
      })
    }
  }
}
</script>
