<template>
  <base-list>
    <template slot="n_header">
      <el-form v-model="pagerDto" inline>
        <el-form-item label="任务名称">
          <el-input v-model="pagerDto._Co_InventoryName" />
        </el-form-item>
         <!-- <el-form-item label="客户Sku">
          <el-input v-model="pagerDto._Eq_SkuNo" />
        </el-form-item> -->
        <el-form-item label="状态">
          <el-select
            v-model="pagerDto._Eq_InventoryStatus"
            placeholder="任务状态"
            clearable
          >
            <el-option
              v-for="statu in InventoryStatus"
              :key="statu.Id"
              :label="statu.Name"
              :value="statu.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="盘点时间" style="float:left;margin:0 10px">
          <el-date-picker
            v-model="pagerDto._Range_InventoryStartTime"
            type="daterange"
            style="width:290px"
            range-separator="~"
            start-placeholder="时间开始"
            value-format="yyyy-MM-dd"
            end-placeholder="时间结束"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="pagerSerach(1)">搜索</el-button>
          <el-button icon="el-icon-plus" size="small" plain type="primary">
          <router-link :to="{name:'InventoryTaskEdit',params:{Id:0}}">添加任务</router-link></el-button>
        </el-form-item>
      </el-form>
    </template>

    <template>
      <el-table
        v-loading="dataLoading"
        :data="data"
        :highlight-current-row="true"
        :select-on-indeterminate="true"
        width="100%"
      >
        <el-table-column prop="InventoryName" label="任务名称" />
        <el-table-column prop="CreateUserName" label="创建人" />
        <el-table-column prop="InventoryStatuStr" label="状态" />
        <el-table-column prop="RoomName" label="所属库房" />
        <el-table-column prop="CreatTimeStr" label="创建时间" />
          <el-table-column prop="ExecutorName" label="执行人" />
        <el-table-column prop="InventoryStartTimeStr" label="执行时间" />
        <el-table-column prop="InventoryEndTimeStr" label="完成时间" />
         <el-table-column prop="ResultAuditName" label="盘点审核" />
          <el-table-column prop="CertifiedFinalName" label="最终确认" />
        <el-table-column label="操作" width="500">
        <template slot-scope="scope">
          <el-button size="mini">
            <router-link :to="{name:'InventoryTaskEdit',params:{Id:scope.row.Id}}"><span v-if="scope.row.InventoryStatus==1">编辑</span><span v-else-if="scope.row.InventoryStatus!=1">查看</span></router-link>
          </el-button>
           <el-button type="primary" v-if="scope.row.InventoryStatus==1" size="mini" @click="showPubTask(scope.row)">
           发布
          </el-button>
            <el-button type="primary" v-if="scope.row.InventoryStatus>=40" size="mini" @click="openedDetail(scope.row)">
           <span v-if="scope.row.InventoryStatus==40">数量确认</span><span v-else-if="scope.row.InventoryStatus==50">库存确认</span><span v-else-if="scope.row.InventoryStatus>50">盘点详情</span>
          </el-button>
           <el-button type="danger" size="mini" @click="showDeleteTask(scope.row)" v-if="scope.row.InventoryStatus!=500">
           删除
          </el-button>
        </template>
      </el-table-column>
      </el-table>
      <el-pagination
        :page-sizes="[10, 20, 40,100, 400]"
        :current-page="pagerDto.PageIndex"
        :page-size.sync="pagerDto.PageSize"
        background
        layout="prev, pager, next ,total ,jumper,sizes,slot "
        :total="pagerDto.total"
        @size-change="changePager"
        @current-change="pagerSerach"
      />
    </template>
    <el-dialog :visible.sync="detailVisible"  width="90%" center>
    <detail-View ref="detailView" @refreshTable="refreshTable" />
    </el-dialog>
  </base-list>
</template>
<script>
import BaseList from '@/components/Xyy/baselist'
import { QueryData,EditInventoryStatus } from '@/api/adminStock/InventoryTask'
import { _getCustomers } from '@/api/baseInfo'
import { GetDs } from '@/api/enum/enums'
import detailView from "./Detail";
export default {
  name: 'InventoryTaskList',
  components: { 'base-list': BaseList,detailView },
  data() {
    return {
      data: [], dataLoading: false,
      detailVisible: false,
      InventoryStatus:[],
      pagerDto: { PageIndex: 0, PageSize: 10, total: 0, QuerySort: [
        { 'Field': 'CreateTime', 'IsDesc': true }
      ] },
    }
  },
  mounted() {
   GetDs("InventoryStatuEnum").then((res)=>{
     this.InventoryStatus=res
   })
   this.pagerSerach(1)
  },
  methods: {
     openedDetail(row) {
      this.detailVisible = true;
      let data = { TaskId: row.Id, gridId: 0, op:row.InventoryStatus<60?"audit_"+row.InventoryStatus:"total" };
      this.$nextTick(() => {
        this.$refs.detailView.getParam(data);
      });
    },
    //列表操作
    showDeleteTask(m) {
      this.$confirm('是否删除该任务?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      })
        .then(() => {
          EditInventoryStatus(m.Id,"delete").then(() => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.pagerSerach()
          })
        })
        .catch(() => {})
    },
    showPubTask(m) {
      this.$confirm('任务发布后不可修改，是否发布?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      })
        .then(() => {
          EditInventoryStatus(m.Id,"pub").then(() => {
            this.$message({
              type: 'success',
              message: '发布成功!'
            })
            this.pagerSerach()
          })
        })
        .catch(() => {})
    },
    refreshTable(){
      this.detailVisible = false;
      this.pagerSerach(1);
    },
    //列表查询
    pagerSerach(index) {
      this.dataLoading = true
      if (index) {
        this.pagerDto.PageIndex = index
      }
      QueryData(this.pagerDto).then(res => {
        this.data = res.Result
        this.pagerDto.total = res.TotalCount

      }).finally(res => { this.dataLoading = false })
    },
    changePager(v) {
      this.PageSize = v
      this.pagerSerach()
    }
  }
}

</script>
