<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model:page="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu="{ row }">
        <!-- <el-button type="text">返工工艺</el-button> -->
        <el-button type="text" @click="receiveData(row)" v-if="row.status == 0">接收</el-button>
        <el-button type="text" @click="updateData(row)" v-if="row.status == 0">改数接收</el-button>
        <el-button type="text" @click="finishData(row)">完成</el-button>
      </template>
    </avue-crud>
    <!-- 改数接收 -->
    <updateMakeQty
      v-if="updateMakeQtyVisible"
      ref="updateMakeQty"
      :showDialog="updateMakeQtyVisible"
      @close="updateMakeQtyClose"
      :itemData="itemData"
    ></updateMakeQty>
  </basic-container>
</template>
<script>
import { getList, getReceiveOrder, completeOrder } from '@/api/productionManagement/reworkOrder';
import updateMakeQty from './components/updateMakeQty.vue';
export default {
  components: { updateMakeQty },
  data() {
    return {
      updateMakeQtyVisible: false,
      itemData: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      data: [],
      form: {},
      option: {
        tip: false,
        height: 'auto',
        calcHeight: 32,
        columnSort: true,
        // simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: '修改',
        viewBtnText: '详情',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        labelWidth: '200px',
        dialogWidth: 600,
        menuWidth:140,
        dialogClickModal: false,
        searchEnter: true,
        filterBtn: true,
        searchShowBtn: false,
        excelBtn: true,
        showOverflowTooltip: true,
        align: 'center',
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        column: [
          {
            label: '返工单号',
            prop: 'redono',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '路线编号',
            prop: 'seqno',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '发生单位',
            prop: 'usedept',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },

          {
            label: '零件号',
            prop: 'prtno',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '数量',
            prop: 'amount',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '处理意见',
            prop: 'detail',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '工艺路线',
            prop: 'deptcode',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '批次号',
            prop: 'splcode',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '需求交期',
            prop: 'reqdate',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
          {
            label: '接收状态',
            prop: 'status',
            search: true,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            type: 'select',
            dicData: [
              {
                label: '待接收',
                value: '0',
              },
              {
                label: '已接收',
                value: '1',
              },
            ],
            span: 24,
            width: 150,
          },

          {
            label: '备注',
            prop: 'remark',
            search: false,
            sortable: true,
            filter: true,
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            span: 24,
            width: 150,
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    updateMakeQtyClose(){
      this.updateMakeQtyVisible = false;
      this.onLoad(this.page,this.query)
    },
    updateData(row) {
      this.itemData = row;
      this.updateMakeQtyVisible = true;
    },
    receiveData(row) {
      this.$confirm('确定接收此工单?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.loading=true
        getReceiveOrder(row).then(res => {
          this.$message({
            message: '接收成功',
            type: 'success',
          });
          this.onLoad(this.page.this.query);
        });
      });
    },
    finishData(row) {
      this.$confirm('确定完成此工单?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.loading=true
        completeOrder(row).then(() => {
          this.$message({
            message: '操作成功',
            type: 'success',
          });
          this.onLoad(this.page.this.query);
        });
      });
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.query);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page, this.query);
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    searchReset() {
      this.query = {};
      this.treeDeptId = '';
      this.onLoad(this.page, this.query);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        this.data = res.data.data.records;
        this.loading = false;
        this.page.total = res.data.data.total;
        this.selectionClear();
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
