<template>
  <div class="bulkWarehousingOrderEdit-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <!-- 内容 -->
      <a-page-header :ghost="false" :backIcon="false" class="bulkWarehousingOrderEdit-cont" >
        <!-- 自定义的二级文字标题 -->
        <template slot="subTitle">
          <a id="bulkWarehousingOrderEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
          <p style=" display: inline-block;margin: 0 0 0 60px;color: #000;font-size: 16px;font-weight: 600;">单号：{{ (basicInfoData&&basicInfoData.sparePartsPurchaseNo) || '' }}</p>
        </template>
        <!-- 操作区，位于 title 行的行尾 -->
        <template slot="extra">
          <a-radio-group key="3" v-model="printerType">
            <a-radio value="NEEDLE">针式</a-radio>
            <a-radio value="INK">喷墨</a-radio>
          </a-radio-group>
          <a-button key="2" id="bulkWarehousingOrderEdit-preview-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('preview')">打印预览</a-button>
          <a-button key="1" type="primary" id="bulkWarehousingOrderEdit-print-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('print')">快捷打印</a-button>
        </template>
      </a-page-header>
      <!-- 基础信息 -->
      <a-card size="small" :bordered="false" class="bulkWarehousingOrderEdit-cont">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1">
            <template slot="header">
              基础信息
              <!-- <a-button type="primary" shape="circle" size="small" icon="edit" class="edit-circle-btn" id="bulkWarehousingOrderEdit-edit-circle-btn" @click.stop="handleEditInfo" /> -->
            </template>
            <a-descriptions :column="3">
              <a-descriptions-item label="供应商">{{ (basicInfoData&&basicInfoData.supplierName) || '--' }}</a-descriptions-item>
              <a-descriptions-item label="散件入库类型">{{ (basicInfoData&&basicInfoData.sparePartsTypeName) || '--' }}</a-descriptions-item>
              <a-descriptions-item label="备注">{{ (basicInfoData&&basicInfoData.remarks) || '--' }}</a-descriptions-item>
            </a-descriptions>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
      <!-- 选择产品 -->
      <a-card size="small" :bordered="false" class="bulkWarehousingOrderEdit-cont">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1">
            <template slot="header">
              选择产品<span class="sub-title">①输入查询条件--->②查找到需要入库的配件--->③录入成本价、数量、仓库、仓位--->④点击“添加”</span>
            </template>
            <!-- 选择产品 -->
            <div>
              <!-- 搜索条件 -->
              <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="关键词">
                        <a-input id="bulkWarehousingOrderEdit-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="产品名称/产品编码/原厂编码"/>
                      </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="24">
                      <a-form-item label="产品品牌">
                        <a-select
                          placeholder="请选择产品品牌"
                          id="bulkWarehousingOrderEdit-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-item>
                    </a-col>
                    <a-col :md="6" :sm="24">
                      <a-form-item label="产品分类">
                        <a-cascader
                          @change="changeProductType"
                          change-on-select
                          v-model="productType"
                          expand-trigger="hover"
                          :options="productTypeList"
                          :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
                          id="productInfoList-productType"
                          placeholder="请选择产品分类"
                          allowClear />
                      </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="24">
                      <a-button style="margin-bottom: 18px;" type="primary" @click="getDealerProductList(1)" :disabled="disabled" id="bulkWarehousingOrderEdit-refresh">查询</a-button>
                      <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="bulkWarehousingOrderEdit-reset">重置</a-button>
                    </a-col>
                  </a-row>
                </a-form>
              </div>
              <!-- 列表 -->
              <a-table
                class="sTable"
                ref="table"
                size="small"
                :rowKey="(record) => record.id"
                :columns="columns"
                :customRow="handleClickRow"
                :dataSource="loadData"
                :scroll="{ x: 1600, y: 300 }"
                :pagination="paginationProps"
                @change="onTableChange"
                bordered>
                <!-- 成本价 -->
                <template slot="putCost" slot-scope="text, record">
                  <a-input-number
                    id="bulkWarehousingOrderEdit-putCost"
                    v-model="record.putCost"
                    :precision="2"
                    :min="1"
                    :max="999999"
                    placeholder="请输入"
                    style="width: 100%;" />
                </template>
                <!-- 数量 -->
                <template slot="putQty" slot-scope="text, record">
                  <a-input-number
                    id="bulkWarehousingOrderEdit-putQty"
                    v-model="record.putQty"
                    :precision="0"
                    :min="1"
                    :max="999999"
                    placeholder="请输入"
                    style="width: 100%;" />
                </template>
                <!-- 仓库仓位 -->
                <template slot="warehouse" slot-scope="text, record, index">
                  <a-cascader
                    @change="e => changeWarehouseCascade(e, record, index, 'dealerProduct')"
                    v-model="record.warehouseCascade"
                    expand-trigger="hover"
                    :allowClear="false"
                    :options="warehouseCascadeData"
                    :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
                    id="bulkWarehousingOrderEdit-warehouseCascade"
                    placeholder="请选择仓库仓位"
                    style="width: 100%;" />
                </template>
                <!-- 操作 -->
                <template slot="action" slot-scope="text, record">
                  <a-button size="small" type="primary" class="button-primary" @click="handleAdd(record)" id="bulkWarehousingOrderEdit-add-btn">添加</a-button>
                </template>
              </a-table>
            </div>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
      <!-- 已选产品 -->
      <a-card size="small" :bordered="false" class="bulkWarehousingOrderEdit-cont">
        <a-collapse :activeKey="['1']">
          <a-collapse-panel key="1">
            <template slot="header">
              已选产品
              <a-button size="small" class="import-btn" id="bulkWarehousingOrderEdit-import-btn" @click.stop="handleImport">导入明细</a-button>
            </template>
            <!-- 已选产品 -->
            <div>
              <!-- 总计 -->
              <a-alert type="info" showIcon style="margin-bottom:15px">
                <div slot="message">总款数 <strong>{{ (productTotal&&productTotal.productTotalCategory) || 0 }}</strong> ，总数量 <strong>{{ (productTotal&&productTotal.productTotalQty) || 0 }}</strong> ，总成本￥<strong>{{ (productTotal&&productTotal.productTotalCost) || 0 }}</strong></div>
              </a-alert>
              <!-- 列表 -->
              <a-table
                class="sTable"
                ref="chooseTable"
                size="small"
                :rowKey="(record) => record.id"
                :columns="chooseColumns"
                :dataSource="chooseLoadData"
                :scroll="{ x: 1700, y: 300 }"
                :pagination="choosePaginationProps"
                @change="onChooseTableChange"
                bordered>
                <!-- 成本价 -->
                <template slot="putCost" slot-scope="text, record">
                  <a-input-number
                    id="bulkWarehousingOrderEdit-choose-putCost"
                    v-model="record.putCost"
                    :precision="2"
                    :min="1"
                    :max="999999"
                    placeholder="请输入"
                    @blur="e => putCostBlur(e.target.value, record)"
                    style="width: 100%;" />
                </template>
                <!-- 数量 -->
                <template slot="putQty" slot-scope="text, record">
                  <a-input-number
                    id="bulkWarehousingOrderEdit-choose-putQty"
                    v-model="record.putQty"
                    :precision="0"
                    :min="1"
                    :max="999999"
                    placeholder="请输入"
                    @blur="e => putQtyBlur(e.target.value, record)"
                    style="width: 100%;" />
                </template>
                <!-- 仓库仓位 -->
                <template slot="warehouse" slot-scope="text, record, index">
                  <a-cascader
                    @change="e => changeWarehouseCascade(e, record, index, 'sparePartsPurDetail')"
                    v-model="record.warehouseCascade"
                    expand-trigger="hover"
                    :allowClear="false"
                    :options="warehouseCascadeData"
                    :fieldNames="{ label: 'name', value: 'sn', children: 'warehouseLocationList' }"
                    id="bulkWarehousingOrderEdit-choose-warehouseCascade"
                    placeholder="请选择仓库仓位"
                    style="width: 100%;" />
                </template>
                <!-- 操作 -->
                <template slot="action" slot-scope="text, record">
                  <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="bulkWarehousingOrderEdit-del-btn">删除</a-button>
                </template>
              </a-table>
            </div>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
      <a-affix :offset-bottom="0">
        <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
          <a-button
            type="primary"
            id="bulkWarehousingOrderEdit-submit"
            size="large"
            class="button-primary"
            @click="handleSubmit"
            style="padding: 0 60px;">提交</a-button>
        </div>
      </a-affix>
    </a-spin>
    <!-- 选择基本信息弹框 -->
    <basic-info-modal :openModal="openModal" @ok="handleOk" @close="openModal=false" />
    <!-- 打印 -->
    <div id="print"></div>
  </div>
</template>

<script>
import { STable, VSelect } from '@/components'
import basicInfoModal from './basicInfoModal.vue'
import { getOperationalPrecision } from '@/libs/tools.js'
import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
import { dealerProductTypeList } from '@/api/dealerProductType'
import { sparePartsPurDetail, sparePartsPurDetailList, sparePartsPurDetailCount, sparePartsPurDetailSave, sparePartsPurDetailDel, sparePartsPurSubmit, sparePartsPurDetailPrint } from '@/api/sparePartsPur'
import { dealerProductList } from '@/api/dealerProduct'
import { warehouseCascadeList } from '@/api/warehouse'
export default {
  components: { STable, VSelect, basicInfoModal },
  data () {
    return {
      spinning: false,
      queryParam: {
        queryWord: '',
        productBrandSn: undefined,
        productTypeSn1: undefined,
        productTypeSn2: undefined,
        productTypeSn3: undefined
      },
      productBrandList: [], //  产品品牌  下拉数据
      productTypeList: [], //  产品分类  下拉数据
      productType: [],
      warehouseCascadeData: [], //  仓库仓位
      disabled: false, //  查询、重置按钮是否可操作
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '产品编码', dataIndex: 'code', width: 220, align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '原厂编码', dataIndex: 'origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品品牌', dataIndex: 'productBrandName', width: 200, align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
        { title: '单位', dataIndex: 'unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '成本价', scopedSlots: { customRender: 'putCost' }, width: 140, align: 'center' },
        { title: '数量', scopedSlots: { customRender: 'putQty' }, width: 140, align: 'center' },
        { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: 200, align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
      ],
      loadData: [],
      pageNo: 1, //  分页页码
      pageSize: 10, //  分页 每页多少条
      paginationProps: {
        showSizeChanger: true, //  是否可以改变 pageSize
        total: 0, //  分页总条数
        current: 1,
        onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize),
        onChange: (current) => this.changePage(current)
      },
      // 表头
      chooseColumns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', sorter: true },
        { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品品牌', dataIndex: 'brandName', width: 200, align: 'center', sorter: true, customRender: function (text) { return text || '--' } },
        { title: '单位', dataIndex: 'productUnit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
        { title: '成本价', scopedSlots: { customRender: 'putCost' }, width: 140, align: 'center' },
        { title: '数量', scopedSlots: { customRender: 'putQty' }, width: 140, align: 'center' },
        { title: '成本小计', dataIndex: 'costSubtotal', width: 100, align: 'center' },
        { title: '仓库仓位', scopedSlots: { customRender: 'warehouse' }, width: 200, align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
      ],
      chooseLoadData: [],
      choosePageNo: 1, //  分页页码
      choosePageSize: 10, //  分页 每页多少条
      choosePaginationProps: {
        showSizeChanger: true, //  是否可以改变 pageSize
        total: 0, //  分页总条数
        current: 1,
        onShowSizeChange: (current, pageSize) => this.changeChoosePageSize(current, pageSize),
        onChange: (current) => this.changeChoosePage(current)
      },
      openModal: false, // 选择基本信息弹框是否显示
      warehouseList: [], //  仓库  下拉数据
      warehouseLocList: {}, //  仓位  下拉数据
      defaultWarehouseCascade: [], //  默认仓库仓位
      chooseWarehouseList: [], //  已选产品 仓库  下拉数据
      chooseWarehouseLocList: {}, //  已选产品 仓位  下拉数据
      basicInfoData: null, //  基本信息
      productTotal: null, //  合计
      printerType: 'NEEDLE' //  打印机类型
    }
  },
  methods: {
    //  重置
    resetSearchForm () {
      this.queryParam.queryWord = ''
      this.queryParam.productBrandSn = undefined
      this.queryParam.productTypeSn1 = ''
      this.queryParam.productTypeSn2 = ''
      this.queryParam.productTypeSn3 = ''
      this.productType = []
      this.pageNo = 1
      this.pageSize = 10
      this.paginationProps.total = 0
      this.paginationProps.current = 1
      this.getDealerProductList(1)
    },
    // 打印预览/快捷打印
    handlePrint (type) {
      const _this = this
      _this.spinning = true
      sparePartsPurDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
        _this.spinning = false
        if (res.type == 'application/json') {
          var reader = new FileReader()
          reader.addEventListener('loadend', function () {
            const obj = JSON.parse(reader.result)
            _this.$notification.error({
              message: '提示',
              description: obj.message
            })
          })
          reader.readAsText(res)
        } else {
          this.print(res, type)
        }
      })
    },
    print (data, type) {
      if (!data) {
        return
      }
      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
      document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
      if (type == 'preview') { //  预览
        window.open(url)
      } else if (type == 'print') { //  打印
        window.frames['printf'].focus()
        window.frames['printf'].print()
      }
    },
    // 双击快速添加
    handleClickRow (record) {
      return {
        on: {
          dblclick: (event) => {
            this.handleAdd(record)
          }
        }
      }
    },
    //  分页  一页多少条change
    changePageSize (current, pageSize) {
      this.pageNo = current
      this.pageSize = pageSize
      this.getDealerProductList()
    },
    //  分页 页码change
    changePage (current) {
      this.pageNo = current
      this.getDealerProductList()
    },
    //  已选产品 分页  一页多少条change
    changeChoosePageSize (current, pageSize) {
      this.choosePageNo = current
      this.choosePageSize = pageSize
      this.getChooseDealerProductList()
    },
    //  已选产品 分页 页码change
    changeChoosePage (current) {
      this.choosePageNo = current
      this.getChooseDealerProductList()
    },
    // 基本信息
    getDetail () {
      sparePartsPurDetail({ id: this.$route.params.id }).then(res => {
        if (res.status == 200) {
          this.basicInfoData = res.data
        } else {
          this.basicInfoData = null
        }
      })
    },
    //  添加/编辑
    handleAdd (row, isEdit) {
      if (!isEdit && !row.putCost) {
        this.$message.warning('请输入成本价后再添加！')
        return
      }
      if (!isEdit && !row.putQty) {
        this.$message.warning('请输入数量后再添加！')
        return
      }
      if (!isEdit && !row.warehouseSn) {
        this.$message.warning('请选择仓库后再添加！')
        return
      }
      if (!isEdit && !row.warehouseLocationSn) {
        this.$message.warning('请选择仓位后再添加！')
        return
      }
      const params = {
        id: isEdit ? row.id : undefined,
        sparePartsPurchaseSn: this.$route.params.sn,
        putCost: row.putCost,
        putQty: row.putQty,
        productCode: isEdit ? row.productCode : row.code,
        productOrigCode: (isEdit ? row.productOrigCode : row.origCode) || undefined,
        productSn: row.productSn,
        productTypeSn1: row.productTypeSn1,
        productTypeSn2: row.productTypeSn2,
        productTypeSn3: row.productTypeSn3,
        brandSn: isEdit ? row.brandSn : row.productBrandSn,
        warehouseLocationSn: row.warehouseLocationSn,
        warehouseSn: row.warehouseSn
      }
      if (isEdit) { // 编辑
        // 清空成本价或数量时,值应保持未清空前的值，因成本价和数量都不可为空
        if (!row.putCost) {
          row.putCost = row.putCostBackups
          return
        }
        if (!row.putQty) {
          row.putQty = row.putQtyBackups
          return
        }
      }
      this.spinning = true
      sparePartsPurDetailSave(params).then(res => {
        if (res.status == 200) {
          this.$message.success(res.message)
          this.getChooseDealerProductList()
          this.spinning = false
        } else {
          this.spinning = false
        }
      })
    },
    //  提交
    handleSubmit () {
      const _this = this
      _this.spinning = true
      sparePartsPurSubmit({ id: this.$route.params.id }).then(res => {
        if (res.status == 200) {
          this.$message.success(res.message)
          setTimeout(() => {
            _this.handleBack()
            _this.spinning = false
          }, 1000)
        } else {
          _this.spinning = false
        }
      })
    },
    //  删除
    handleDel (row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '删除后不可恢复，确定要进行删除吗？',
        centered: true,
        onOk () {
          _this.spinning = true
          sparePartsPurDetailDel({ id: row.id }).then(res => {
            if (res.status == 200) {
              _this.$message.success(res.message)
              _this.getChooseDealerProductList()
              _this.spinning = false
            }else{
              _this.spinning = false
            }
          })
        }
      })
    },
    //  编辑基本信息
    handleEditInfo () {
      this.openModal = true
    },
    //  基本信息  保存
    handleOk () {},
    //  导入明细
    handleImport () {
      console.log(333)
    },
    //  返回列表
    handleBack () {
      this.$router.push({ path: '/bulkManagement/bulkWarehousingOrder/list' })
    },
    // 合计
    getDetailCount (params) {
      sparePartsPurDetailCount(params).then(res => {
        if (res.status == 200) {
          this.productTotal = res.data
        } else {
          this.productTotal = null
        }
      })
    },
    changeWarehouseCascade (val, opt, ind, type) {
      let loadData
      if (type == 'dealerProduct') { //  全部产品
        loadData = this.loadData[ind]
      } else if (type == 'sparePartsPurDetail') { //  已选产品
        loadData = this.chooseLoadData[ind]
      }
      if (val.length < 2) {
        this.$message.warning('当前仓库无仓位，请选择其他仓库')
        const warehouseSnBackups = loadData.warehouseSnBackups || undefined
        const warehouseLocationSnBackups = loadData.warehouseLocationSnBackups || undefined
        loadData.warehouseSn = warehouseSnBackups
        loadData.warehouseLocationSn = warehouseLocationSnBackups
        if (warehouseSnBackups || warehouseLocationSnBackups) {
          loadData.warehouseCascade = [warehouseSnBackups, warehouseLocationSnBackups]
        } else {
          loadData.warehouseCascade = undefined
        }
      } else {
        loadData.warehouseSn = val[0] ? val[0] : ''
        loadData.warehouseLocationSn = val[1] ? val[1] : ''
        if (type == 'sparePartsPurDetail') { //  已选产品
          loadData = this.chooseLoadData[ind]
          this.handleAdd(loadData, 'edit')
        }
      }
    },
    // 已选产品 成本价  blur
    putCostBlur (val, record) {
      //  光标移出，值发生改变再调用编辑接口
      if (val != record.putCostBackups) {
        this.handleAdd(record, 'edit')
      }
    },
    // 已选产品 数量  blur
    putQtyBlur (val, record) {
      if (val != record.putQtyBackups) {
        this.handleAdd(record, 'edit')
      }
    },
    //  产品分类  change
    changeProductType (val, opt) {
      this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
      this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
      this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
    },
    // 产品列表数据
    getDealerProductList (pageNo, sorter) {
      this.disabled = true
      this.pageNo = pageNo || this.pageNo
      const params = Object.assign({ pageNo: this.pageNo, pageSize: this.pageSize }, this.queryParam)
      params.enabledFlag = 1
      params.sysFlag = 0
      if (sorter) {
        params.sortField = sorter.field
        params.sortOrder = sorter.order
        params.sortAlias = 'dp'
      }
      dealerProductList(params).then(res => {
        if (res.status == 200) {
          const data = res.data
          this.paginationProps.total = Number(res.data.count) || 0
          this.paginationProps.current = this.pageNo
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
            if (this.defaultWarehouseCascade.length > 0) {
              data.list[i].warehouseCascade = this.defaultWarehouseCascade
              data.list[i].warehouseSn = this.defaultWarehouseCascade[0]
              data.list[i].warehouseLocationSn = this.defaultWarehouseCascade[1]
            } else {
              data.list[i].warehouseCascade = undefined
            }
          }
          this.loadData = data.list
          this.disabled = false
        } else {
          this.paginationProps.total = 0
          this.paginationProps.current = 1
          this.loadData = []
        }
      })
    },
    // 已选产品列表数据
    getChooseDealerProductList (pageNo, sorter) {
      this.choosePageNo = pageNo || this.choosePageNo
      const params = {
        pageNo: this.choosePageNo,
        pageSize: this.choosePageSize,
        sparePartsPurchaseSn: this.$route.params.sn
      }
      if (sorter) {
        params.sortField = sorter.field == 'brandName' ? 'productBrandName' : 'productCode'
        params.sortOrder = sorter.order
        params.sortAlias = sorter.field == 'brandName' ? 'dp' : 'sppd'
      }
      sparePartsPurDetailList(params).then(res => {
        if (res.status == 200) {
          this.getDetailCount(params)
          const data = res.data
          this.choosePaginationProps.total = Number(res.data.count) || 0
          this.choosePaginationProps.current = data.pageNo
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
            data.list[i].putCostBackups = data.list[i].putCost
            data.list[i].putQtyBackups = data.list[i].putQty
            const warehouseSn = data.list[i].warehouseSn || undefined
            const warehouseLocationSn = data.list[i].warehouseLocationSn || undefined
            if (warehouseSn || warehouseLocationSn) {
              data.list[i].warehouseSnBackups = warehouseSn
              data.list[i].warehouseLocationSnBackups = warehouseLocationSn
              data.list[i].warehouseCascade = [warehouseSn, warehouseLocationSn]
            } else {
              data.list[i].warehouseCascade = undefined
            }
            // 成本小计  由于数据库内小数位数为4位，页面则需显示2位。因此会做小数运算精度处理
            data.list[i].costSubtotal = getOperationalPrecision(data.list[i].putCost, data.list[i].putQty)
          }
          this.chooseLoadData = data.list
        } else {
          this.choosePaginationProps.total = 0
          this.choosePaginationProps.current = 1
          this.chooseLoadData = []
        }
      })
    },
    //  仓库仓位  级联  列表
    getWarehouseCascade () {
      const _this = this
      warehouseCascadeList({}).then(res => {
        if (res.status == 200) {
          res.data.filter(item => {
            // 过滤默认仓库
            if (item.defaultFlag == 1 && item.wasteFlag == 0) { //  defaultFlag为1,且不是废品仓
              _this.defaultWarehouseCascade[0] = item.warehouseSn
              // 过滤默认仓位
              item.warehouseLocationList.filter(subItem => {
                if (subItem.defaultFlag == 1 && subItem.wasteFlag == 0) {
                  _this.defaultWarehouseCascade[1] = subItem.warehouseLocationSn
                  _this.getDealerProductList(1)
                  _this.getChooseDealerProductList(1)
                }
              })
            }
          })
          res.data.map(item => {
            item.sn = item.warehouseSn
            if (item.warehouseLocationList) {
              item.warehouseLocationList.map(subItem => {
                subItem.sn = subItem.warehouseLocationSn
              })
            }
          })
          this.warehouseCascadeData = res.data
        } else {
          this.warehouseCascadeData = []
        }
      })
    },
    //  产品品牌  列表
    getProductBrand () {
      // sysFlag传0,表示只查自建产品
      dealerProductBrandQuery({ 'sysFlag': '0' }).then(res => {
        if (res.status == 200) {
          this.productBrandList = res.data
        } else {
          this.productBrandList = []
        }
      })
    },
    //  产品分类  列表
    getProductType () {
      dealerProductTypeList({ 'sysFlag': '0' }).then(res => {
        if (res.status == 200) {
          this.productTypeList = res.data
        } else {
          this.productTypeList = []
        }
      })
    },
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    },
    // 选择产品 表格  change
    onTableChange (pagination, filters, sorter) {
      this.getDealerProductList(this.pageNo, sorter)
    },
    // 已选产品 表格  change
    onChooseTableChange (pagination, filters, sorter) {
      this.getChooseDealerProductList(this.choosePageNo, sorter)
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.openModal = false
      vm.getChooseDealerProductList(1)
      vm.getWarehouseCascade()
      vm.getDetail()
      vm.getProductBrand()
      vm.getProductType()
    })
  }
}
</script>

<style lang="less">
  .bulkWarehousingOrderEdit-wrap{
    .bulkWarehousingOrderEdit-cont{
      margin-bottom: 15px;
      .sub-title{
        font-size: 12px;
        color: #808695;
        margin-left: 10px;
      }
      .tag-txt{
        font-size: 12px;
        color: #ed1c24;
      }
      .edit-circle-btn{
        margin-left: 15px;
        i{
          vertical-align: text-bottom;
        }
      }
      .import-btn{
        margin-left: 15px;
      }
    }
  }
</style>
