<template>
  <a-card :bordered="false" class="expenseManagementList-wrap">
    <!-- 搜索条件 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="15">
          <a-col :md="6" :sm="24">
            <a-form-item label="费用单号">
              <a-input id="expenseManagementList-purchaseNo" v-model.trim="queryParam.purchaseNo" allowClear placeholder="请输入费用单号"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="创建时间">
              <a-range-picker v-model="queryParam.creatDate" id="expenseManagementList-creatDate"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="费用类型">
              <v-select
                v-model="queryParam.billStatus"
                ref="billStatus"
                id="expenseManagementList-billStatus"
                code="PAYMENT_TYPE"
                placeholder="请选择费用类型"
                allowClear></v-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="24">
              <a-form-item label="单据状态">
                <v-select
                  v-model="queryParam.billStatus"
                  ref="billStatus"
                  id="expenseManagementList-billStatus"
                  code="PAYMENT_TYPE"
                  placeholder="请选择单据状态"
                  allowClear></v-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="结算状态">
                <v-select
                  v-model="queryParam.billStatus"
                  ref="billStatus"
                  id="expenseManagementList-billStatus"
                  code="PAYMENT_TYPE"
                  placeholder="请选择结算状态"
                  allowClear></v-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="expenseManagementList-refresh">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm()" :disabled="disabled" id="expenseManagementList-reset">重置</a-button>
              <a @click="advanced=!advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮 -->
    <div class="table-operator">
      <a-button id="expenseManagementList-add" type="primary" @click="handleEdit()">新增费用单</a-button>
    </div>
    <!-- alert -->
    <a-alert type="info" showIcon style="margin-bottom:15px">
      <div slot="message">共 <strong>6</strong> 条记录，金额共计 <strong>￥14</strong></div>
    </a-alert>
    <!-- 列表 -->
    <s-table
      class="sTable"
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      bordered>
      <!-- 采购单号 -->
      <template slot="purchaseNo" slot-scope="text, record">
        <span style="color: #ed1c24;cursor: pointer;">{{record.purchaseNo}}</span>
      </template>
      <!-- 采购入库单号 -->
      <template slot="purchaseNos" slot-scope="text, record">
        <span style="color: #ed1c24;cursor: pointer;">{{record.purchaseNo}}</span>
      </template>
      <!-- 状态 -->
      <template slot="state" slot-scope="text, record">
        <span>{{record.state == 1 ? '已启用' : '已禁用'}}</span>
      </template>
      <!-- 操作 -->
      <template slot="action" slot-scope="text, record">
        <a-button size="small" type="primary" @click="handleExamine(record, 1)" id="expenseManagement-adopt-btn">通过</a-button>
        <a-button size="small" @click="handleExamine(record, 2)" id="expenseManagement-unadopt-btn" style="margin: 0 0 10px 8px">不通过</a-button>
        <a-button size="small" type="primary" @click="handleEdit(record)" id="expenseManagement-edit-btn" style="margin: 0 0 10px 8px">编辑</a-button>
        <a-button size="small" type="primary" @click="handleSubmit(record)" id="expenseManagement-submit-btn" style="margin: 0 0 10px 8px">提交</a-button>
        <a-button size="small" type="dashed" @click="handleDetail(record)" id="expenseManagement-detail-btn" style="margin: 0 0 10px 8px">详情</a-button>
        <a-button size="small" type="danger" @click="handleDel(record)" id="expenseManagement-del-btn" style="margin: 0 0 0 8px">删除</a-button>
      </template>
    </s-table>
    <!-- 详情 -->
    <expense-management-detail-modal :openModal="openModal" :itemId="itemId" @close="openModal=false" />
  </a-card>
</template>

<script>
import { STable, VSelect } from '@/components'
// import { getRoleList, getServiceList } from '@/api/manage'
import expenseManagementDetailModal from './detailModal.vue'
export default {
  components: { STable, VSelect, expenseManagementDetailModal },
  data () {
    return {
      disabled: false, //  查询、重置按钮是否可操作
      advanced: false,  //  高级搜索 展开/关闭
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        { title: '费用单号', scopedSlots: { customRender: 'purchaseNo' }, align: 'center' },
        { title: '创建时间', dataIndex: 'creatDates', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '费用类型', dataIndex: 'creatDate', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '金额', dataIndex: 'totalPrice', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
        { title: '单据状态', dataIndex: 'totalP', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '结算状态', dataIndex: 'totalNums', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: 270, align: 'center' }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        // return customerBundleDelayList( Object.assign(parameter, this.queryParam) ).then(res => {
        //   const data = res.data
        //   const no = (data.pageNo - 1) * data.pageSize
        //   for (var i = 0; i < data.list.length; i++) {
        //     data.list[i].no = no + i + 1
        //   }
        //   this.disabled = false
        //   return data
        // })
        const _this = this
        return new Promise(function(resolve, reject){
          const data = {
            pageNo: 1,
            pageSize: 10,
            list: [
              { id: '1', purchaseNo: 'jgqp11111111111', creatDate: '产品1', custName: 'jgqp111123545', totalP: '箭冠品牌', totalNums: '产品分类1', totalPrice: '5', payType: '122' }
            ],
            count: 10
          }
          const no = (data.pageNo - 1) * data.pageSize
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = no + i + 1
          }
          _this.disabled = false
          resolve(data)
        })
      },
      openModal: false,  //  查看详情  弹框
      itemId: '',  //  当前id
    }
  },
  methods: {
    //  新增/编辑
    handleEdit(row){
      this.$router.push({ path: `/financialManagement/expenseManagement/add`})
    },
    //  提交
    handleSubmit(row){
      const _this = this
      _this.itemId = item.id
      _this.$confirm({
        title: '提示',
        content: '确定要进行提交操作吗？',
        centered: true,
        onOk () {
          // dealerProductTypeDel({ id: _this.itemId }).then(res => {
          //   if (res.status == 200) {
          //     _this.$message.success(res.message)
          //     _this.$refs.table.refresh()
          //   }
          // })
        }
      })
    },
    //  详情
    handleDetail(row){
      this.itemId = row.id
      this.openModal = true
      // this.$router.push({ path: `/financialManagement/expenseManagement/detail/${row.id}`})
    },
    //  审核
    handleExamine(row, type){
      const _this = this
      this.$confirm({
        title: '提示',
        content: '操作后不可恢复，确定要进行'+ (type==1 ? ' 通过 ' : ' 不通过 ') +'操作吗？',
        okText: '确定',
        cancelText: '取消',
        centered: true,
        onOk () {
          // delectRolePower({
          //   id: row.id
          // }).then(res => {
          //   console.log(res, 'res1111')
          //   if (res.status == 200) {
          //     _this.$message.success(res.message)
          //     _this.$refs.table.refresh()
          //   }
          // })
        }
      })
    },
    //  删除
    handleDel (row) {
      const _this = this
      _this.itemId = row.id
      _this.$confirm({
        title: '提示',
        content: '删除后原数据不可恢复，是否删除？',
        centered: true,
        onOk () {
          // dealerProductTypeDel({ id: _this.itemId }).then(res => {
          //   if (res.status == 200) {
          //     _this.$message.success(res.message)
          //     _this.$refs.table.refresh()
          //   }
          // })
        }
      })
    },
    //  重置
    resetSearchForm () {
      this.queryParam.orderBundleNo = ''
      this.queryParam.orderBundle.custMobile = ''
      this.queryParam.bundleName = ''
      this.queryParam.itemName = ''
      this.oldTime = undefined
      this.newTime = undefined
      this.$refs.table.refresh(true)
    },
  }
}
</script>
<style lang="less">
  .expenseManagementList-wrap{
    .sTable{
      margin-top: 15px;
    }
  }
</style>