<!--
  @description: 交通费报销
  @Modifier: sunxinman/肖文龙
  @routerPath: /fee/trafficfeeApply-list
  @date: 2020/06/12
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />交通费报销
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section
        :class="{ SearchContent_show: toggleSearchStatus }"
        class="p0-16 clearfix SearchContent"
      >
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
            label-width="98px"
            label-position="left"
          >
            <!-- 表单编号 -->
            <el-form-item label="表单编号">
              <el-input v-model="searchForm.formNumber" placeholder="请输入表单编号" style="width: 228px" />
            </el-form-item>
            <!-- 表单名称 -->
            <el-form-item label="表单名称">
              <el-input v-model="searchForm.name" placeholder="请输入表单编号" style="width: 228px" />
            </el-form-item>
            <!-- 状态 -->
            <el-form-item
              label="状态"
              prop="stageType"
              class="list_seach_select"
            >
              <el-select v-model="searchForm.auditStatus" placeholder="请选择" style="width:228px">
                <el-option
                  v-for="(item,index) in trafficfeeStatusList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!-- 创建时间 -->
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="searchForm.createTimeData"
                :format="elValueFormatDate"
                :value-format="elValueSaveFormat"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:228px"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" size="small" @click="onSearch">
            搜索
          </el-button>
          <el-button
            plain
            type="info"
            size="small"
            @click="resetForm('searchForm')"
          >
            重置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <el-button
        type="primary"
        class="mb10"
        plain
        @click="add"
      >
        发起交通费报销
      </el-button>
      <section>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <!-- 表单编号 -->
          <el-table-column
            prop="formNumber"
            align="center"
            label="表单编号"
            width="200"
          />
          <!-- 表单名称 -->
          <el-table-column
            header-align="center"
            label="表单名称"
            prop="name"
            min-width="200"
          />
          <!-- 评审费总额（元） -->
          <el-table-column
            header-align="center"
            prop="auditTotalMoney"
            label="评审费总额（元）"
            align="right"
            min-width="150"
          />
          <!-- 业务部门 -->
          <el-table-column
            header-align="center"
            prop="leadDepart"
            label="业务部门"
            align="center"
            min-width="100"
          />
          <!-- 摘要 -->
          <el-table-column
            header-align="center"
            prop="brief"
            label="摘要"
            min-width="200"
            align="center"
          />
          <!-- 创建时间 -->
          <el-table-column
            header-align="center"
            prop="createTime"
            label="创建时间"
            min-width="140"
            align="center"
          />
          <!-- 状态 -->
          <el-table-column
            header-align="center"
            label="状态"
            align="center"
            width="110"
          >
            <template slot-scope="scope">
              <span
                v-for="(item, index) in trafficfeeStatusList"
                v-if="scope.row.auditStatus === item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            fixed="right"
            align="center"
            width="100"
          >
            <template slot-scope="scope">
              <!--null 已保存 02驳回 -->
              <el-link
                v-if="!scope.row.auditStatus||scope.row.auditStatus==='02'"
                type="primary"
                @click.stop="edit(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                v-if="!scope.row.auditStatus||scope.row.auditStatus==='02'"
                type="primary"
                @click.stop="deleteRow(scope.row)"
              >
                [删除]
              </el-link>
              <!--00 审核中 01 审核通过 -->
              <el-link
                v-if="scope.row.auditStatus==='00'||scope.row.auditStatus==='01'"
                type="primary"
                @click.stop="view(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
  </div>
</template>
<script>
/* 接口*/
import { queryTrafficFeePageListInfo, deleteTrafficFee } from '@api/fee/trafficfee' // 项目列表 项目删除
/* 公用方法*/
import { filterObj, restoreInitialValue, moneyFormat } from '@/assets/js/utils' // 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'
import { trafficfeeGroupMixin } from '../mixins/trafficfeeGroupMixin'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
export default {
  name: 'TrafficfeeApply',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, trafficfeeGroupMixin],
  data() {
    return {
      date: '',
      loading: true,
      // 搜索
      searchForm: {
        createTime: '', // 开始时间
        createTimeOne: '', // 结束时间
        auditStatus: '', // 状态
        formNumber: '', // 表单编号
        name: '', // 表单名称
        createTimeData: []// 创建时间-不传给后端
      },
      tableData: []
    }
  },
  watch: {
    // 监听创建时间
    'searchForm.createTimeData'(val) {
      this.searchForm.createTime = val[0]
      this.searchForm.createTimeOne = val[1]
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 获取数据
    loadData() {
      const params = this.getQueryParams() // 查询条件
      queryTrafficFeePageListInfo(params)
        .then(response => {
          this.loading = false
          this.tableData = response.data.records
          this.paginationData.total = response.data.total
          this.tableData.forEach(item => {
            item.auditTotalMoney = moneyFormat(item.auditTotalMoney ? Number(item.auditTotalMoney).toFixed(2) : item.auditTotalMoney)// 评审费总金额
            item.createTime = this.$Moment(item.createTime).format(this.momentDateTime)// 创建时间
          })
        })
        .catch(() => {})
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      delete param.createTimeData// 删除不传给后端的参数
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm() {
      restoreInitialValue(this.searchForm)// 重置参数
      this.onSearch()
    },
    // 编辑
    edit(row) {
      this.$router.push({
        name: 'TrafficfeeApplyStep',
        params: {
          trafficFeeId: row.id // 交通费id
        }
      })
    },
    // 查看
    view(row) {
      this.$router.push({
        name: 'TrafficfeeApplyContent',
        params: {
          trafficFeeId: row.id // 交通费id
        }
      })
    },
    // 发起交通费报销
    add() {
      this.$router.push({
        name: 'TrafficfeeApplyStep'
      })
    },
    // 删除
    deleteRow(row) {
      this.$confirm('确认删除本条记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteTrafficFee(row.id).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          // 搜索
          this.onSearch()
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
