<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="800px">
        <el-form ref="form" inline :model="form" :rules="rules" size="small" label-width="150px">
          <!--          <el-form-item label="劳务人" v-show="false">-->
          <!--            <el-input v-model="form.user.id"  />-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="劳务人">-->
          <!--            <el-input v-model="form.user.id"  />-->
          <!--          </el-form-item>-->
          <el-form-item label="劳务人">
            <user-select v-model="form.user.id" style="width:185px" @userInfo="fillUser" />
          </el-form-item>
          <el-form-item label="性别">
            <el-input v-model="form.user.gender" disabled />
          </el-form-item>
          <el-form-item label="手机">
            <el-input v-model="form.user.phone" disabled />
          </el-form-item>
          <el-form-item label="开户行">
            <el-input v-model="form.user.userBanks[0].bankName" disabled />
          </el-form-item>
          <el-form-item label="银行卡号">
            <el-input v-model="form.user.userBanks[0].bankNo" disabled />
          </el-form-item>

          <el-form-item label="应发金额">
            <el-input v-model="form.payableFee" />
          </el-form-item>
          <el-form-item label="个人所得税">
            <el-input v-model="form.tax" />
          </el-form-item>
          <el-form-item label="实发金额">
            <el-input v-model="form.paidFee" />
          </el-form-item>
          <el-form-item label="资金来源">
            <el-select v-model="form.feeSource" filterable placeholder="请选择" style="width:185px">
              <el-option
                v-for="item in dict.fee_source"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <!--          <el-form-item label="审批人">-->
          <!--            <el-input v-model="form.approveUserId"  />-->
          <!--          </el-form-item>-->
          <el-form-item label="劳务时间">
            <el-input v-model="form.serviceTime" style="" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="user.nickName" label="劳务人" />
        <el-table-column prop="payableFee" label="应发金额" />
        <el-table-column prop="tax" label="个人所得税" />
        <el-table-column prop="paidFee" label="实发金额" />
        <el-table-column prop="feeSource" label="资金来源">
          <template slot-scope="scope">
            {{ dict.label.fee_source[scope.row.feeSource] }}
          </template>
        </el-table-column>
        <!--        <el-table-column prop="approveUserId" label="审批人" />-->
        <el-table-column prop="serviceTime" label="劳务时间" />
        <!--        <el-table-column prop="applyTime" label="申请时间" />-->
        <el-table-column prop="remark" label="备注" />
        <el-table-column v-if="checkPer(['admin','serviceFee:edit','serviceFee:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudServiceFee from '@/api/system/serviceFee'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'
import UserSelect from '@/views/system/user/user-select.vue'

const defaultForm = { user: { userBanks: [{}] }, approveUser: {}, serviceFeeId: null, userId: null, payableFee: null, tax: null, paidFee: null, feeSource: null, approveUserId: null, serviceTime: null, applyTime: null, remark: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'ServiceFee',
  components: { UserSelect, pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['fee_source'],
  cruds() {
    return CRUD({ title: '劳务费', url: 'api/serviceFee', idField: 'serviceFeeId', sort: 'serviceFeeId,desc', crudMethod: { ...crudServiceFee }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'serviceFee:add'],
        edit: ['admin', 'serviceFee:edit'],
        del: ['admin', 'serviceFee:del']
      },
      rules: {
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    fillUser(user) {
      this.form.user = { userBanks: [{}] }
      console.log(user)
      this.form.user = Object.assign({}, this.form.user, user)
    }
  }
}
</script>

<style scoped>

</style>
