<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入单据编号" v-model="queryParam.number"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="流程类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-select v-model="queryParam.type" allowClear placeholder="请选择流程类型">
                    <a-select-option v-for="item in flowTypes" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="发起人" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入审核发起人" v-model="queryParam.initiatorName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            bordered
            size="middle"
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="goApproval(record,true)">详情</a>
              <a-divider v-if="btnEnableList.indexOf(2) > -1" type="vertical" />
              <a @click="goApproval(record,false)" v-if="btnEnableList.indexOf(2) > -1" style="margin-left: 8px;">审批</a>
            </span>
            <template slot="auditStatus" slot-scope="status">
              <a-tag v-if="status == 0" color="blue">待审批</a-tag>
              <a-tag v-if="status == 1" color="green">已通过</a-tag>
              <a-tag v-if="status == 2" color="red">未通过</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
      </a-card>
    </a-col>
    <bill-detail ref="modalDetail" @ok="handleOk"></bill-detail>
    <!-- 盘点任务审批 -->
    <InventoryCheckModal ref="InventoryCheckModal" @ok="handleOk" />
    <!-- pda维护商品 -->
     <PdaFlowModal ref="PdaFlowModal" @ok="handleOk" />
  </a-row>
</template>
<script>
import { postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { approvalMixin } from './mixin/approvalMixin'
import { flowTypes } from './utils/flow'
import BillDetail from '@/views/bill/dialog/BillDetail.vue'
import InventoryCheckModal from '@/views/stock/modules/InventoryCheckModal'
import PdaFlowModal from './modules/PdaFlowModal.vue'

export default {
  name: 'ApprovalList',
  mixins: [JeecgListMixin,approvalMixin],
  components: {
    BillDetail,
    InventoryCheckModal,
    PdaFlowModal
  },
  data() {
    return {
      labelCol: {
        span: 5,
      },
      wrapperCol: {
        span: 18,
        offset: 1,
      },
      flowTypes,
      queryParam: {},
      depotFlag: '0',
      customerFlag: '0',
      columns: [
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: 100,
        },
        { title: '单据编号', dataIndex: 'number', align: 'left' },
        { title: '流程类型', dataIndex: 'type', align: 'left' },
        { title: '发起人', dataIndex: 'initiatorName', align: 'left' },
        { title: '审核人', dataIndex: 'auditorName', align: 'left' },
        { title: '创建时间', dataIndex: 'submitTime',width: 170, align: 'left'},
        { title: '审批状态', dataIndex: 'auditStatus', align: 'left',scopedSlots: { customRender: 'auditStatus' }},
      ],
      url: {
        list: '/audit/pendingApprovalList',
      },
      disableMixinCreated: true
    }
  },
  beforeRouteEnter(to, from, next){
    next(vm => {
      vm.loadData()
      //初始化按钮权限
      vm.initActiveBtnStr()
      // 更新数据
      vm.$store.dispatch('updateApprovalStat')
    })
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      this.loading = true
      const url = this.url.list + '?currentPage=' + this.ipagination.current + '&pageSize=' + this.ipagination.pageSize
      postAction(url, {
        ...this.queryParam
      }).then((res) => {
        if (res.code === 200) {
          this.dataSource = res.data.rows
          this.ipagination.total = Number(res.data.total)
        }else {
          this.$message.warning(res.msg)
        }
        this.loading = false
        this.onClearSelected()
      })
    },
    handleOk(){
      this.$store.dispatch('updateApprovalStat')
      this.loadData()
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
