<template>
    <!-- 往来单位管理页面 -->
    <div class="app-container">
        <PageHeader
          v-if="isShowComponent !== 'Index'"
          :pageContent="pageContent"
          @goBack="goBack"
        />
        <!-- 列表 -->
        <TableModel
          :formLabel="formLabel"
          :columnsList="columnsList"
          :request-api="queryPurchaseReceiveListApi"
          ref="tableRef"
          v-if="isShowComponent === 'Index'"
        >
            <template slot="btn" slot-scope="{ queryParams }">
                <el-button type="success" @click="handleAddData()"
                    >验收合格</el-button
                >
                <el-button @click="handleExportData(queryParams, 'base/customer/export', '往来单位清单')"
                    >导出</el-button
                >
            </template>

            <template slot="handle" slot-scope="{ data }">
<!--                <el-button
                  type="warning"
                  size="mini"
                >解绑</el-button
                >-->
<!--              <el-button
                type="primary"
                size="mini"
              >查看</el-button
              >-->
                <el-button
                    type="primary"
                    size="mini"
                    @click="toggleDetail(data)"
                    >验收</el-button
                >
<!--                <el-button
                    type="danger"
                    size="mini"
                    @click="handleDeleteData(data.id, delStorageConfigListApi)"
                    >删除</el-button
                >-->
            </template>
<!--            <template slot="isActive" slot-scope="{ data }">
              {{ data.isActive == '1' ? '启用' : '不启用' }}
            </template>
            <template slot="phone" slot-scope="{ data }">
              {{ phoneCrypto(data.phone) }}
            </template>-->
            <template slot="purchaseNum" slot-scope="{ data }">
              {{ data.purchaseNum / storageDex }}
            </template>
            <template slot="purchasePrice" slot-scope="{ data }">
              {{ data.purchasePrice / priceDex }}
            </template>
            <template slot="notaxPrice" slot-scope="{ data }">
              {{ data.notaxPrice / priceDex }}
            </template>
            <template slot="status" slot-scope="{ data }">
              <span style="color: #D9001B">
                {{ data.statusName }}
              </span>
            </template>
        </TableModel>

        <!-- 新增以及修改时的弹框 -->
<!--        <DialogModel
            :dialogConfig="dialogConfig"
            @closeDialogOuter="closeDialogOuter"
        >
            <template slot="outerContent">
                &lt;!&ndash; 新增以及修改数据的表单组件 &ndash;&gt;
                <FormReceive
                    @closeDialog="closeDialog"
                    :editParams="editParams"
                />
            </template>
        </DialogModel>-->

      <receive-detail
        v-if="isShowComponent === 'receive-detail'"
        :send-params="transParams"
        :send-range="factoryRange"
        :send-cascader="cascaderRange"
      >

      </receive-detail>

    </div>
</template>

<script>
import { formLabel, columnsList, dialogConfig, queryStatusSelData } from './config'
import { commonMixin } from '../mixins/common'
import ReceiveDetail from './components/receive-detail.vue'
import {
  queryPurchaseReceiveListApi,
  queryStatusSelApi
} from '@/api/purchase/receive'
import {
  querySupplierListApi
} from '@/api/material/masupplier'
import {
  queryTypeListApi
} from '@/api/purchase/arrival'
import PageHeader from '@/components/pageHeader/index.vue'
import TableConfirm from '@/views/purchase/confirm/components/table-confirm.vue'
export default {
    name: 'arrivalReceiveManage',
    mixins: [commonMixin], // 混入公共方法和数据
    components: { TableConfirm, PageHeader, ReceiveDetail },
    methods: {
      queryPurchaseReceiveListApi,
      goBack() {
        this.isShowComponent = 'Index'
      },
      toggleDetail(data) {
        console.log(data)
        this.transParams = data
        this.isShowComponent = 'receive-detail'
      }
    },
    created() {
       queryStatusSelData()
      // 查询厂家
      querySupplierListApi().then(res => {
        this.factoryRange = res.rows.map(item => {
          return {
            label: item.name,
            value: item.id
          }
        })
      }).catch(err => {})
      // 查询物资规格
      queryTypeListApi().then(res => {
        res.data.forEach(lv1 => {
          if(!lv1.children) {
            lv1.disabled = true
          } else {
            lv1.children.forEach(lv2 => {
              if(!lv2.children) {
                lv2.disabled = true
              } else {
                lv2.children.forEach(lv3 => {
                  if(!lv3.children) {
                    lv3.disabled = true
                  }
                })
              }
            })
          }
        })
        this.cascaderRange = res.data
      }).catch(err => {})
    },
    data() {
        return {
            isShowComponent: 'Index',
            pageContent: '验收详情',
            formLabel,
            columnsList,
            dialogConfig,
            addDialogTitle: '新建仓库', // 新建时弹框标题
            editDialogTitle: '修改仓库', // 修改时弹框标题
            storageDex: 1000,
            priceDex: 100,
            transParams: undefined,
            factoryRange: [],
            cascaderRange: []
        }
    },
}
</script>
