<template>
  <basic-container>
    <el-row :gutter="24">
      <el-col :span="24">
        <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" :page.sync="page"
          :permission="permissionList" @row-del="rowDel" @search-change="searchChange" @search-reset="searchReset"
          @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
          @refresh-change="refreshChange" @on-load="onLoad" @row-click="rowSelect">
          <template slot-scope="scope" slot="menuLeft">
            <el-button size="small" plain @click.stop="handleDesign()">新增出库单
            </el-button>
            <el-button size="small" plain @click.stop="handleExport()">出库单导出
            </el-button>
          </template>
          <template slot-scope="scope" slot="xuqiudanmingcheng">
            <el-button type="text" @click.stop="purchaseFn(scope.row)" v-if="scope.row.xuqiudanmingcheng!=''">{{scope.row.xuqiudanmingcheng}}</el-button>
              <span v-else>无</span>
          </template>
        </avue-crud>
      </el-col>
    </el-row>

    <outDialog v-if="outDialogVisible" :repairVisible='outDialogVisible' :outDialogTiltle="outDialogTiltle"
      :outDialogType="outDialogType" @handleCloseDetail="handleCloseDetail" type="二级库">
    </outDialog>

<!-- 需求单明细 -->
<needDialog :showDialog="purchaseOpen" v-if="purchaseOpen" @closeDialog="closeDialog" :purchaseTitle="purchaseTitle"></needDialog>
  </basic-container>
  </basic-container>
</template>

<script>
import { getList, remove } from "@/api/report/report";
import { mapGetters } from "vuex";
import outDialog from './components/outDialog.vue';
import needDialog from './components/needDialog.vue';

export default {
  components: {
    outDialog,
    needDialog
  },
  data() {
    return {
      purchaseOpen:false,
      purchaseTitle:'',
      treeData: [],//组织树
      defaultProps: {
        children: 'children',
        label: 'label'
      },

      form: {},
      selectionList: [],
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        selection: true,
        viewBtn: true,
        dialogClickModal: false,
        selection: false,
        printBtn: false,
        refreshBtn: false,
        gridBtn: false,
        gridBackgroundImage: false,
        gridSpan: false,
        filterBtn: false,
        columnBtn: false,
        menu: false,
        column: [
           {
            label: "需求单名称",
            prop: "xuqiudanmingcheng",
            width:180,
          },
          {
            label: "部门",
            prop: "bumen",
          },
          {
            label: "仓库类型",
            prop: "str1",
          },
          {
            label: "出库单号",
            prop: "str2",
          },
          {
            label: "出库时间",
            prop: "str3",
            search: true,
            type: "datetime",
          },
          {
            label: "出库人",
            prop: "str4",
            search: true,
          },
          {
            label: "部门",
            prop: "str8",
            search: true,
            type: 'select',
            dicData: [{
              label: '部门一',
              value: 0
            }, {
              label: '部门二',
              value: 1
            }]
          },
          {
            label: "审批人",
            prop: "str5",
          },
          {
            label: "来源",
            prop: "str6",
            search: false,
          },
          {
            label: "状态",
            prop: "str7",
          },

        ]
      },
      data: [],
      outDialogVisible: false,
      outDialogTiltle: '出库',
      outDialogType: '',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: ''
    };
  },
  computed: {
    ...mapGetters(["userInfo", "permission"]),
    permissionList() {
      return {
        addBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
  purchaseFn(row){
      this.purchaseOpen = true
      this.purchaseTitle = row.xuqiudanmingcheng+'详情'
    },
    closeDialog(){
      this.purchaseOpen = false
    },
    handlePreview() {
      // this.$router.push({ path: `/myiframe/urlPath?name=preview-${name}&src=${this.website.design.reportUrl}/preview?_u=blade-${name}` });
    },
    handleDesign() {
      this.outDialogVisible = true
      this.outDialogType = 'add'
      this.outDialogTiltle = '新增出库'
    },
    // 行点击事件
    rowSelect(row) {
      this.outDialogVisible = true
      this.outDialogType = 'outbound'
      this.outDialogTiltle = '出库'
    },
    handleCloseDetail() {
      this.outDialogVisible = false
    },
    handleExport(name) {
      this.$message({
        type: "success",
        message: "出库单导出成功！"
      });
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      // this.onLoad(this.page, params);
      this.$message({
        type: "success",
        message: "操作成功!"
      });
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.$refs.crud.toggleSelection();
        });
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.data.push({
        xuqiudanmingcheng:'2025年一季度需求单',
        bumen :"部门一",
        str1: '类型一',
        str2: '00000001',
        str3: '2025-03-01',
        str4: '员工一',
        str5: '员工二',
        str6: '需求',
        str7: '部分出库',
        str8: '部门一'
      }, {
         xuqiudanmingcheng:'',
        bumen :"",
        str1: '类型二',
        str2: '00000002',
        str3: '2025-03-02',
        str4: '员工一',
        str5: '员工二',
        str6: '单项',
        str7: '全部出库',
        str8: '部门二'
      })
      this.loading = false
    },
    handleNodeClick(data) {
      console.log(data);
    }
  }
};
</script>

<style></style>
