<template>
  <div id="transferOrder">
    <div v-if="isList">
      <el-form class="search_area" label-width="120px">
        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-form-item label="调出库存组织">
              <el-select clearable size="small" v-model="queryParams.deliveryInventoryOrg" @focus="chooseRefer('ORG_PARAM', true, '调出库存组织')" style="width: 200px">
                <el-option v-for="item in chuOrgOptions" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="单据日期">
              <el-date-picker
               style="width: 200px"
               size="small"
               clearable
               value-format="yyyy-MM-dd"
                v-model="queryParams.billDate"
                type="date">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="订单类型">
              <el-select v-model="queryParams.billType" size="small" style="width: 200px" clearable>
                <el-option v-for="dict in dict.type.sys_allot_billtype" :key="dict.value" :label="dict.label" :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="调入库存组织">
              <el-select clearable size="small" v-model="queryParams.storageInventoryOrg" @focus="chooseRefer('ORG_PARAM', true, '调入库存组织')" style="width: 200px">
                <el-option v-for="item in ruOrgOptions" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="单据号">
              <el-input
                v-model.trim="queryParams.code"
                size="small"
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="1.5">
            <el-form-item label="" label-width="20px">
              <el-button type="primary" size="small" icon="el-icon-search" plain @click="searchList">搜索</el-button>
              <el-button size="small" icon="el-icon-refresh" plain @click="resetList">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <!-- <CollapseTransition>
        <div v-show="expanded">
          <el-row :gutter="10">
            <el-col :span="1.5">
              <el-form-item label="物料编码">
                <el-input
                v-model="queryParams.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="1.5">
              <el-form-item label="调入库存组织">
                <el-input
                v-model="queryParams.storageInventoryOrg"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        </CollapseTransition> -->
      </el-form>
      <!-- <el-divider class="lines"><i style="cursor: pointer;" :class="expanded?'el-icon-arrow-up':'el-icon-arrow-down'" @click="drop"></i></el-divider> -->

      <el-card>
        <div class="btn_grooup">
          <el-button type="primary" size="small" @click="addOrder">新增</el-button>
        </div>

        <el-table 
          :data="tableList" 
          fit
          show-summary
          highlight-current-row
          max-height="680"
          ref="multipleTable"
          @row-click="select"
        >
          <el-table-column show-overflow-tooltip label="调出库存" align="center" prop="deliveryInventoryOrgName" width="150px"/>
          <el-table-column show-overflow-tooltip label="订单类型" align="center" prop="billType" width="150px"/>
          <el-table-column show-overflow-tooltip label="单据号" align="center" prop="code" width="180px"/>
          <el-table-column show-overflow-tooltip label="单据日期" align="center" prop="billDate" width="150px"/>
          <el-table-column show-overflow-tooltip label="调拨方式" align="center" prop="allotType" width="150px">
            <template slot-scope="scope">
              <span>{{ scope.row.allotType == '2' ? '财务组织间调拨' : '财务组织内库存组织内调拨' }}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="调拨出库单号" align="center" prop="deliveryCode" width="150px"/>
          <el-table-column show-overflow-tooltip label="调拨入库单号" align="center" prop="storageCode" width="150px"/>
          <el-table-column show-overflow-tooltip label="调拨入库组织" align="center" prop="storageInventoryOrgName" width="150px"/>
          <el-table-column show-overflow-tooltip label="调出业务员" align="center" prop="businessPersonalName" width="150px"/>
          <el-table-column show-overflow-tooltip label="调出部门" align="center" prop="deliveryDeptName" width="150px"/>
          <el-table-column show-overflow-tooltip label="币种" align="center" prop="currencyName"/>
          <el-table-column show-overflow-tooltip label="折本汇率" align="center" prop="rate"/>
          <el-table-column show-overflow-tooltip label="在途归属" align="center" prop="onRouteAffilliation" width="150px"/>
          <el-table-column show-overflow-tooltip label="总数量" align="center" prop="qty"/>
          <el-table-column show-overflow-tooltip label="结算路径" align="center" prop="accountPath" width="150px"/>
          <el-table-column show-overflow-tooltip label="客户" align="center" prop="customerName" width="150px"/>
          <el-table-column show-overflow-tooltip label="调出仓库" align="center" prop="deliveryWarehouseName" width="180px"/>
          <el-table-column show-overflow-tooltip label="调入仓库" align="center" prop="storageWarehouseName" width="150px"/>
          <el-table-column show-overflow-tooltip label="物流项目组" align="center" prop="materialProject" width="150px"/>
          <el-table-column show-overflow-tooltip label="利润中心" align="center" prop="liacenterName" width="150px"/>
          <!-- <el-table-column show-overflow-tooltip label="已同步WMS" align="center" prop="isSendWms" width="150px"/> -->
          <el-table-column show-overflow-tooltip label="备注" align="center" prop="remark" width="150px"/>
          <el-table-column show-overflow-tooltip label="单据状态" align="center" prop="status" width="150px"/>
          <el-table-column show-overflow-tooltip label="制单人" align="center" prop="createByName" width="150px"/>
          <el-table-column show-overflow-tooltip label="制单日期" align="center" prop="createTime" width="150px"/>
          <!-- <el-table-column show-overflow-tooltip label="审批人" align="center" prop="code" width="150px"/> -->
          <!-- <el-table-column show-overflow-tooltip label="审批日期" align="center" prop="code" width="150px"/> -->
          <el-table-column show-overflow-tooltip label="最后修改人" align="center" prop="updateByName" width="150px"/>
          <el-table-column show-overflow-tooltip label="最后修改时间" align="center" prop="updateTime" width="150px"/>
          <el-table-column
          fixed="right"
          label="操作"
          align="center"
          width="150"
          >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="check(scope.row)">查看</el-button>
            <el-button type="text" size="small" v-if="scope.row.status == '0' || scope.row.status == '3'" @click="edit(scope.row)">编辑</el-button>
            <el-button type="text" size="small" v-if="scope.row.status == '0' || scope.row.status == '3'" @click="deleteids(scope.row)">删除</el-button>
          </template>
        </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="1"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
        </el-pagination>

        <el-tabs style="margin-top: 10px;">
          <el-tab-pane label="物料信息">
            <el-table
            :data="materialInfo" 
            fit
            max-height="380"
            >
            <el-table-column show-overflow-tooltip label="行号" align="center" prop="rowno"/>
            <el-table-column show-overflow-tooltip label="物料编码" align="center" prop="materialCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="物料名称" align="center" prop="materialName" width="150px"/>
            <el-table-column show-overflow-tooltip label="调拨出库单号" align="center" prop="deliveryCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="调拨入库单号" align="center" prop="storageCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="规格" align="center" prop="specification"/>
            <el-table-column show-overflow-tooltip label="生产厂家/代理人" align="center" prop="manufacturer" width="150px"/>
            <el-table-column show-overflow-tooltip label="产地" align="center" prop="originPlace" width="150px"/>
            <el-table-column show-overflow-tooltip label="型号" align="center" prop="model" width="150px"/>
            <el-table-column show-overflow-tooltip label="单位" align="center" prop="unitName" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="调出仓库" align="center" prop="deliveryWarehouseName"/> -->
            <el-table-column show-overflow-tooltip label="数量" align="center" prop="qty" width="150px"/>
            <el-table-column show-overflow-tooltip label="主单位" align="center" prop="mainUnit" width="150px"/>
            <el-table-column show-overflow-tooltip label="换算率" align="center" prop="equation" width="150px"/>
            <el-table-column show-overflow-tooltip label="主数量" align="center" prop="mainQty" width="150px"/>
            <el-table-column show-overflow-tooltip label="税率" align="center" prop="rate" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="调入仓库" align="center" prop="storageWarehouseName"/> -->
            <el-table-column show-overflow-tooltip label="批次号" align="center" prop="patchNo" width="150px"/>
            <el-table-column show-overflow-tooltip label="产品批号" align="center" prop="producBatch" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产日期" align="center" prop="manufactureDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="有效期至/失效日期" align="center" prop="periodEndDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="批准文号" align="center" prop="ratifyCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="注册证号" align="center" prop="registration" width="150px"/>
            <el-table-column show-overflow-tooltip label="商品名" align="center" prop="productCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="通用名" align="center" prop="commonCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="剂型" align="center" prop="drug" width="150px"/>
            <el-table-column show-overflow-tooltip label="调入调出结算规则明细" align="center" prop="ruleDetail" width="150px"/>
            <el-table-column show-overflow-tooltip label="上市许可持有人" align="center" prop="marketingApprovalPersonal" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产许可证号/经营许可证号/备案凭证号" align="center" prop="production" width="260px"/>
            <el-table-column show-overflow-tooltip label="pi码" align="center" prop="pi" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="无税金额" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="备注" align="center" prop="code"/> -->
            <el-table-column show-overflow-tooltip label="类别" align="center" prop="classify" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料码" align="center" prop="customerLogistic" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料名称" align="center" prop="customerLogisticName" width="150px"/>
            </el-table>
          </el-tab-pane>

          <el-tab-pane label="收发货信息">
            <el-table
            :data="receiveInfo" 
            fit
            max-height="380"
            >
            <el-table-column show-overflow-tooltip label="行号" align="center" prop="rowno"/>
            <el-table-column show-overflow-tooltip label="调拨出库单号" align="center" prop="deliveryCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="调拨入库单号" align="center" prop="storageCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产厂家/代理人" align="center" prop="manufacturer" width="150px"/>
            <el-table-column show-overflow-tooltip label="产地" align="center" prop="originPlace" width="150px"/>
            <el-table-column show-overflow-tooltip label="类别" align="center" prop="classify" width="150px"/>
            <el-table-column show-overflow-tooltip label="调出仓库" align="center" prop="deliveryWarehouseName" width="150px"/>
            <el-table-column show-overflow-tooltip label="调入仓库" align="center" prop="storageWarehouseName" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="收货利润中心" align="center" prop="code"/>
            <el-table-column show-overflow-tooltip label="发货利润中心" align="center" prop="code"/> -->
            <el-table-column show-overflow-tooltip label="调入业务员" align="center" prop="businessPersonalName" width="150px"/>
            <el-table-column show-overflow-tooltip label="产品批号" align="center" prop="productBatch" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产日期" align="center" prop="manufactureDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="有效期至/失效日期" align="center" prop="periodEndDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="批准文号" align="center" prop="ratifyCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="注册证号" align="center" prop="registration" width="150px"/>
            <el-table-column show-overflow-tooltip label="商品名" align="center" prop="productCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="通用名" align="center" prop="commonCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="剂型" align="center" prop="drug" width="150px"/>
            <el-table-column show-overflow-tooltip label="收货客户" align="center" prop="customerName" width="150px"/>
            <el-table-column show-overflow-tooltip label="收货地址" align="center" prop="addressaddress" width="150px"/>
            <el-table-column show-overflow-tooltip label="收货地区" align="center" prop="area" width="150px"/>
            <el-table-column show-overflow-tooltip label="收货地点" align="center" prop="place" width="150px"/>
            <el-table-column show-overflow-tooltip label="计划发货日期" align="center" prop="deliveryDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="计划到货日期" align="center" prop="strageDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="运输方式" align="center" prop="transportation" width="150px"/>
            <el-table-column show-overflow-tooltip label="备注" align="center" prop="remark" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料编码" align="center" prop="customerLogistic" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料名称" align="center" prop="customerLogisticName" width="150px"/>
            </el-table>
          </el-tab-pane>

          <el-tab-pane label="价格费用">
            <el-table
            :data="priceList" 
            fit
            max-height="380"
            >
            <el-table-column show-overflow-tooltip label="行号" align="center" prop="rowno"/>
            <el-table-column show-overflow-tooltip label="调拨出库单号" align="center" prop="deliveryCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="调拨入库单号" align="center" prop="storageCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产厂家/代理人" align="center" prop="manufacturer" width="150px"/>
            <el-table-column show-overflow-tooltip label="产地" align="center" prop="originPlace" width="150px"/>
            <el-table-column show-overflow-tooltip label="类别" align="center" prop="classify" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="税率" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="无税单价" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="含税单价" align="center" prop="code"/> -->
            <el-table-column show-overflow-tooltip label="产品批号" align="center" prop="productBatch" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产日期" align="center" prop="manufactureDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="有效期至/失效日期" align="center" prop="periodEndDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="批准文号" align="center" prop="ratifyCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="注册证号" align="center" prop="registration" width="150px"/>
            <el-table-column show-overflow-tooltip label="商品名" align="center" prop="productCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="通用名" align="center" prop="commonCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="剂型" align="center" prop="drug" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="询价无税价" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="询价含税价" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="税额" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="加价率" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="无税金额" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="价税合计" align="center" prop="code"/> -->
            <el-table-column show-overflow-tooltip label="客户物料码" align="center" prop="customerLogistic" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料名称" align="center" prop="customerLogisticName" width="150px"/>
            </el-table>
          </el-tab-pane>

          <el-tab-pane label="执行结果">
            <el-table
            :data="resultList" 
            fit
            max-height="380"
            >
            <el-table-column show-overflow-tooltip label="行号" align="center" prop="rowno"/>
            <el-table-column show-overflow-tooltip label="调拨出库单号" align="center" prop="deliveryCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="调拨入库单号" align="center" prop="storageCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产厂家/代理人" align="center" prop="manufacturer" width="150px"/>
            <el-table-column show-overflow-tooltip label="产地" align="center" prop="originPlace" width="150px"/>
            <el-table-column show-overflow-tooltip label="类别" align="center" prop="classify" width="150px"/>
            <el-table-column show-overflow-tooltip label="产品批号" align="center" prop="productBatch" width="150px"/>
            <el-table-column show-overflow-tooltip label="生产日期" align="center" prop="manufactureDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="有效期至/失效日期" align="center" prop="periodEndDate" width="150px"/>
            <el-table-column show-overflow-tooltip label="批准文号" align="center" prop="ratifyCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="注册证号" align="center" prop="registration" width="150px"/>
            <el-table-column show-overflow-tooltip label="商品名" align="center" prop="productCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="通用名" align="center" prop="commonCode" width="150px"/>
            <el-table-column show-overflow-tooltip label="剂型" align="center" prop="drug" width="150px"/>
            <!-- <el-table-column show-overflow-tooltip label="已调出主数量" align="center" prop="code"/>
            <el-table-column show-overflow-tooltip label="已调入主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="调拨在途主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="已发货主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="途损主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="累计退货主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="调出与调入已结算主数量" align="center" prop="code"/> -->
            <!-- <el-table-column show-overflow-tooltip label="调出与调入已结算金额" align="center" prop="code"/> -->
            <el-table-column show-overflow-tooltip label="客户物料码" align="center" prop="customerLogistic" width="150px"/>
            <el-table-column show-overflow-tooltip label="客户物料名称" align="center" prop="customerLogisticName" width="150px"/>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>

    <Add v-model="isList" v-if="!isList" :pageStu="page" :disable="disable" :row="rowDetail" @refresh="getList"/>
    <Refers ref="refer" @doSubmit="selectionsToInput" :single="true"/>
  </div>
</template>

<script>
import Add from './add.vue'
import CollapseTransition from '@/components/MyCollapse/collapse.vue'
import Refers from '@/components/Refers/refers.vue'
import {getOrderList, delOrder} from '@/api/purchase/transferOrder.js'
export default {
  name: 'transferOrder',
  dicts: ['sys_allot_billtype'],
  components: {
    Add,
    CollapseTransition,
    Refers
  },
  data() {
    return {
      expanded: false,
      // 页面配置
      isList: true,
      // 页面状态
      page: '',
      queryParams: {
        deliveryInventoryOrg: '',
        billDate: '',
        billType: '',
        storageInventoryOrg: '',
        code: '',
        pageNum: 1,
        pageSize: 5
      },
      referCondition: {
        type: '',
        isPage: true,
        title: '',
      },
      options: [{
        value: '1', label: '是',
      }, {
        value: '0', label: '否'
      }],
      chuOrgOptions: [],
      ruOrgOptions: [],
      tableList: [],
      total: 0,
      materialInfo: [],
      receiveInfo: [],
      priceList: [],
      resultList: [],
      rowDetail: {},
      disable: false,
      ids: []
    }
  },
  created() {
    this.getList(this.queryParams)
  },
  methods: {
    searchList() {
      this.getList(this.queryParams)
    },
    resetList() {
      this.queryParams = {
        deliveryInventoryOrg: '',
        billDate: '',
        billType: '',
        storageInventoryOrg: '',
        code: '',
        pageNum: 1,
        pageSize: 5
      }
      this.getList(this.queryParams)
    },
    getList(params){
      getOrderList(params).then(res => {
        if (res.code === 200) {
          this.tableList = res.rows
          this.total = res.total
          this.materialInfo = res.rows[0].stAllotMaterialList
        }
      })
    },
    addOrder() {
      this.isList = false
      this.page = 'add'
      this.disable = false
    },
    check(row) {
      this.isList = false
      this.page = 'check'
      this.rowDetail = row
      this.disable = true
    },
    edit(row) {
      this.isList = false
      this.page = 'edit'
      this.rowDetail = row
      this.disable = false
    },
    // 选中某行
    select(row) {
      console.log('选中', row)
      this.materialInfo = row.stAllotMaterialList
    },
    // 行内删除
    deleteids(row) {
      console.log('row', row)
      this.$modal.confirm('确认信息').then(() => {
        delOrder(row.id).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("删除成功");
            this.getList(this.queryParams)
          }
        })
        }).catch(() => {})
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.queryParams.pageSize = val
      this.getList(this.queryParams)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.queryParams.pageNum = val
      this.getList(this.queryParams)
    },
    drop() {
      this.expanded = !this.expanded
    },
    chooseRefer(type, isPage, title) {
      this.referCondition.type = type
      this.referCondition.isPage = isPage
      this.referCondition.title = title
      this.$refs.refer.init(this.referCondition)
    },
    selectionsToInput(selection) {
      if (this.referCondition.title == '调出库存组织') {
        this.chuOrgOptions = selection
        this.queryParams.deliveryInventoryOrg = selection[0].id
      }
      if (this.referCondition.title == '调入库存组织') {
        this.ruOrgOptions = selection
        this.queryParams.storageInventoryOrg = selection[0].id
      }
    },
  }

}
</script>

<style lang="scss" scoped>
#transferOrder {
  height: calc(100vh - 84px);
  padding: 12px;
  box-sizing: border-box;
  overflow-y: scroll;
}
.btn_grooup {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}
.lines {
  margin-top: 0;
}
</style>