import React, { Component } from "react"; import Taro, { getCurrentInstance } from "@tarojs/taro"; import { Text, View, Picker, Button, Image } from "@tarojs/components"; import ImagePicker from "../../components/common/imagePicker"; import InquiryModal from "../../components/common/inquiryModal"; import AuditModal from "../../components/common/auditModal"; import AccountModal from "../../components/common/accountModal"; import { getPridDetail, getAccountList, selectList, AccountExamine, getMainExpenseDetail, getDepartmentList, subMainAccount, } from "../../utils/servers/servers"; import { getAccountName, getSecondaryAccountName, getTypeName, getVehicleName, commonAdd, copyText, getNewOptions, removeNull, } from "../../utils/tools"; import { AtTextarea, AtButton, AtIcon, AtModal, AtModalHeader, AtModalContent, AtRadio, AtModalAction, } from "taro-ui"; import { resourceAddress } from "../../utils/config"; import Reviewed from '../../image/reviewed.png' import Rejected from '../../image/rejected.png' import Passed from '../../image/passed.png' import "taro-ui/dist/style/components/form.scss"; import "taro-ui/dist/style/components/button.scss"; import "taro-ui/dist/style/components/loading.scss"; import "taro-ui/dist/style/components/icon.scss"; import "taro-ui/dist/style/components/textarea.scss"; import "taro-ui/dist/style/components/input.scss"; import "./index.less"; class Drafts extends Component { $instance = getCurrentInstance(); constructor(props) { super(props); this.state = { data: {}, list: [], total: 0, accountvisible: "", bankData: {}, upaccount: false, accountsList: [], reason: "", visible: false, }; } componentDidMount() { this.getDepartmentList() this.$instance.router.params && this.$instance.router.params.id && ( this.getDetail() // this.getAccountList(), // this.getMyList() ) } componentDidShow() { let pages = Taro.getCurrentPages(); let currPage = pages[pages.length - 1]; // 获取当前页面 const { data } = this.state const obj = { buyerName: currPage.data.name || data.buyerName, orderNo: currPage.data.orderNo || data.orderNo, contractNo: currPage.data.contractNo || data.contractNo, } this.setState({ data: { ...this.state.data, ...obj }, }) } // 部门数据 getDepartmentList() { getDepartmentList({}).then(v => { let thedata = v.data; let theArr = []; if (!thedata) { if (v.error && v.error.length) { Taro.showToast({ title: v.error[0].message, icon: 'none' }) } } else { thedata.map(function (item, index) { theArr.push({ key: index, name: item.name, id: item.id }); }); } this.setState({ departmentArr: theArr }); }).catch(() => { Taro.showToast({ title: '系统错误,请稍后再试', icon: 'none' }) }) } // 报销账户列表 getMyList(sta) { let data1 = { status: 1 } let data2 = { pageNo: 1, pageSize: 99, } selectList(sta ? data2 : data1).then(v => { if (v.error.length === 0) { let list = v.data.list || [] if (list?.length > 0) { if (sta) { this.setState({ accountsList: list }) } else { let obj = { name: list[0].name, bank: list[0].bank, accounts: list[0].accounts, eaaid: list[0].id, } this.setState({ data: { ...this.state.data, ...obj }, }) } } } else { Taro.showToast({ title: v.error[0].message, icon: 'none' }) } }).catch(() => { Taro.showToast({ title: '系统错误,请稍后再试', icon: 'none' }) }) } // 详情 getDetail() { getMainExpenseDetail({ id: this.$instance.router.params.id, }).then(v => { if (v.error.length === 0) { this.setState({ data: v.data, }) v.data.status == 0 && this.getMyList() } else { Taro.showToast({ title: v.error[0].message, icon: 'none' }) } }).catch(() => { Taro.showToast({ title: '系统错误,请稍后再试', icon: 'none' }) }) } getUrls(url) { let list = []; for (let i of (url || '').split(',')) { if (i) { list.push({ 'url': resourceAddress + i }) } } return list } // 报销详情金额列表 getAccountList() { getAccountList({ eaid: this.$instance.router.params.id, }).then(v => { if (v.error.length === 0) { let sum = 0 for (var i = 0; i < v.data.length; i++) { // sum += v.data[i].amount sum = commonAdd(sum, v.data[i].amount) } this.setState({ list: v.data, total: sum, }) } else { Taro.showToast({ title: v.error[0].message, icon: 'none' }) } }).catch(() => { Taro.showToast({ title: '系统错误,请稍后再试', icon: 'none' }) }) } // 审批 examine(val) { Taro.showLoading({ title: '处理中...' }); AccountExamine({ id: this.state.data.id, reason: this.state.reason, status: val, }) .then((v) => { Taro.hideLoading(); if (v.error.length === 0) { Taro.showToast({ title: "操作成功", icon: "none", }); Taro.navigateBack({ delta: 1 }) // this.getDetail() } else { Taro.showToast({ title: v.error[0].message, icon: "none" }); } }) .catch((err) => { Taro.showToast({ title: "系统错误,请稍后再试", icon: "none" }); }); } onSubmit(val) { this.setState({ loading: true, }); const { data } = this.state let comData = { id: data.id, orderNo: data.orderNo, applyDep: data.applyDep, payDep: data.payDep, eaaid: data.eaaid, remarks: data.remarks, status: val } let comData1 = { id: data.id, status: val } subMainAccount(removeNull(val == 4 ? comData1 : comData)) .then((v) => { this.setState({ loading: false, }) if (v.error.length === 0) { Taro.showToast({ title: "操作成功!", icon: "none", }); // Taro.switchTab({ // url: "/pages/recordlist/index", // }); Taro.navigateBack({ delta: 1 }) } else { Taro.showToast({ title: v.error[0].message, icon: "none", }); } }) .catch(() => { this.setState({ loading: false, }); }); } // 取消添加 onAccountClose() { this.setState({ accountvisible: "", }) } // 添加收款账户 onAccountOk() { this.setState({ accountvisible: "", }, () => { this.getMyList() }) } // 确认收款账户 selectOn() { let list = this.state.accountsList for (var i = 0; i < list.length; i++) { if (list[i].id == this.state.aid) { const obj = { eaaid: list[i].id, name: list[i].name, bank: list[i].bank, accounts: list[i].accounts, } this.setState({ upaccount: false, data: { ...this.state.data, ...obj }, }) } } } render() { const { data, } = this.state const departmentArr = this.state.departmentArr || []; const isEdit = data.status == 0 && data.processStatus == 0 return ( {/* {getAccountName(data.type, data.typeOther)} */} { 报销编号: {data.checkNo} { e.stopPropagation(); copyText(data.checkNo) }} >复制编号 } {/* 总金额: {data.totalAmount}元 */} 报销至订单: { isEdit && Taro.navigateTo({ url: "/pages/dataindex/index" }) }}> {data.contractNo} {isEdit && } 报销时间: {data.createTimeStr} {"报销详细"} 申请人: {data.aname} 报销公司: {isEdit ? item.id === data.applyDep)} range={departmentArr} rangeKey='name' mode='selector' onChange={(e) => { const obj = { applyDep: departmentArr[e.detail.value].id, applyDepName: departmentArr[e.detail.value].name } this.setState({ data: { ...data, ...obj }, }) }}> {data.applyDepName} : {data.applyDepName}} 支付公司: {isEdit ? item.id === data.payDep)} range={departmentArr} rangeKey='name' mode='selector' onChange={(e) => { const obj = { payDep: departmentArr[e.detail.value].id, payDepName: departmentArr[e.detail.value].name } this.setState({ data: { ...data, ...obj }, }) }}> {data.payDepName} : {data.payDepName}} 报销事由: {isEdit ? { const obj = { remarks: e } this.setState({ data: { ...data, ...obj } }) }} height={75} maxLength={50} placeholder={(data.type == 4 || data.type == 5) ? "请填写说明:" : "请填写报销事由"} /> : {data.remarks}} 报销费用详细 { data.sonList?.map((it) => 报销金额: {it.amount}(元) 报销类型: {getAccountName(it.type, it.typeOther)} {it.type == 2 && (" - " + getSecondaryAccountName(it.secondaryType, it.secondaryTypeOther))} {it.type == 1 && 公出企业: {it.userNames} } {it.type == 1 ? "公出时间" : "费用时间"}: {!it.releaseStart ? "" : (it.releaseStart.slice(0, 10) + " 至 " + it.releaseEnd.slice(0, 10))} {/* 差旅费显示 */} {it.type == 1 && it.detList?.map(item => item.type == 1 ? 交通费: {getVehicleName(item.vehicle, item.vehicleOther)} ({item.startDistrict + " - " + item.endDistrict}) {item.amount}(元) : {getTypeName(item.type) + ":"} {item.amount}(元) ) } {/* 通用 */} {(it.type == 0 || it.type == 2 || it.type == 4 || it.type == 5) && it.detList?.map(item => {!!item.agreeTimeStr && {it.type == 5 ? "支付时间:" : "需付款时间:"} {item.agreeTimeStr.slice(0, 10)} } {it.type == 4 ? "预借支金额:" : it.type == 5 ? "抵扣金额:" : "金额:"} {item.amount}(元) ) } {/* 第三方付款 */} {it.type == 3 && it.detList?.map(item => {!!item.agreeTimeStr && 需付款时间: {item.agreeTimeStr.slice(0, 10)} } 付款方式: {["公对公转账"][item.payType]} 发票类型: {["普票", "专票"][item.invoiceType]} 发票号: {item.invoiceNo} 付款单位: {item.payerName} 开户银行: {item.openBank} 银行账户: {item.bankAccounts} 开户行地址: {item.openBankAddress} 金额: {item.amount}(元) ) } { it.settlementAmount != 0 && it.type != 4 && it.type != 5 && 抵扣金额: {it.settlementAmount}(元) } 附件: {this.getUrls(it.attachmentUrl) && this.getUrls(it.attachmentUrl).length > 0 && } ) } { data.type != 4 && data.debitTotalAmount && 预借支: {data.debitTotalAmount}(元) } {/* { data.type != 4 && data.type != 5 && 总金额: {data.totalAmount}(元) } */} { data.type != 4 && data.type != 5 && 本次报销金额: {data.amount}(元) } 报销账户 { !data.eaaid && isEdit ? { this.setState({ accountvisible: true }) }}> 暂未有收款账户 去添加 > : {isEdit && { this.setState({ upaccount: true, // aid: bankData.id, }, () => { this.getMyList(true) }) }} >修改} 收款人:{data.name} 收款银行:{data.bank} 收款账户:{data.accounts} } { data.status != 0 && { e.stopPropagation(); this.setState({ visible: true, id: data.id }); }} > 查看审核详情 } { data.examine == 1 && 填写审批意见 { this.setState({ reason: value, }); }} maxLength={30} placeholder="请填写审批意见" /> { if (!this.state.reason) { Taro.showToast({ title: "请先填写审批意见", icon: "none" }); return; } this.setState({ isInquiryOpened: true, inquiryTitle: "提醒", inquiryContent: "您确定要驳回此申请吗?", inquiryFn: () => { this.examine(3); }, }); }} > 驳回 { if (!this.state.reason) { Taro.showToast({ title: "请先填写审批意见", icon: "none" }); return; } this.setState({ isInquiryOpened: true, inquiryTitle: "提醒", inquiryContent: "您确定要同意此申请吗?", inquiryFn: () => { this.examine(1); }, }); }} > 同意 } { isEdit && { this.onSubmit(1) }} > 提交报销订单 } { data.examine == 2 && data.status == 3 && { this.setState({ isInquiryOpened: true, inquiryTitle: "提醒", inquiryContent: "您确定取消该报销订单吗?", inquiryFn: () => { this.onSubmit(4); }, }); }} > 取消报销订单 注:取消后,请重新发起报销 } {/* 收款账户添加 */} { this.state.accountvisible != "" && } {/* 收款账户列表 */} 请选择收款账户 { this.setState({ aid: e }) }} /> {/* 二级确认弹窗 */} { this.setState({ isInquiryOpened: false, inquiryTitle: "", inquiryContent: "", isNo: true, }); }} onDetermine={() => { this.state.inquiryFn(); this.setState({ isInquiryOpened: false, inquiryTitle: "", inquiryContent: "", isNo: true, inquiryFn: () => { }, }); }} /> {/* 审核详情 */} {this.state.visible && { this.setState({ visible: false }) }} />} ); } } export default Drafts;