| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <template>
- <view class="">
- <u--form
- style="margin: 0 20px"
- labelPosition="left"
- :model="form"
- :rules="rules"
- ref="uForm"
- labelWidth="140rpx"
- >
- <u-form-item label="审批建议" prop="reason" required>
- <u--textarea
- style="width: 100%"
- height="120"
- border="surround"
- placeholder="请输入审批建议"
- v-model="form.reason"
- ></u--textarea>
- </u-form-item>
- </u--form>
- <view class="btnList">
- <u-button
- style="width: 45%; margin-bottom: 10rpx"
- :loading="loading"
- type="success"
- :text="taskDefinitionKey === 'storeman' ? '申请出库' : '通过'"
- @click="handleAudit(1)"
- >
- </u-button>
- <u-button
- style="width: 45%"
- :loading="loading"
- type="error"
- text="驳回"
- @click="rejectTask(0)"
- ></u-button>
- </view>
- <view class="btnConcel" v-if="taskDefinitionKey !== 'deptLeaderApprove'">
- <u-button @click="showAction = true">更多</u-button>
- </view>
- <u-action-sheet
- :actions="actionList"
- :closeOnClickOverlay="true"
- :closeOnClickAction="true"
- title="更多操作"
- :show="showAction"
- @close="showAction = false"
- @select="selectActionClick"
- ></u-action-sheet>
- </view>
- </template>
- <script>
- import {
- approveTaskWithVariables,
- rejectTask,
- cancelTask,
- } from "@/api/wt/index.js";
- import { outStorage } from "@/api/warehouseManagement/index.js";
- export default {
- name: "taskSubmit",
- props: {
- businessId: {
- default: "",
- },
- taskId: {
- default: "",
- },
- id: {
- default: "",
- },
- taskDefinitionKey: {
- default: "",
- },
- },
- data() {
- return {
- showAction: false,
- loading: false,
- taskFormData: {},
- actionList: [
- {
- name: "作废",
- fontSize: "28",
- color: "#ffaa7f",
- },
- ],
- form: {
- technicianId: "",
- reason: "",
- },
- rules: {
- reason: {
- type: "string",
- required: true,
- message: "请输入审批建议",
- trigger: "blur",
- },
- },
- };
- },
- mounted() {
- this.$refs.uForm.setRules(this.rules);
- },
- methods: {
- async syncTaskFormData() {
- try {
- const data = await this.getTableValue();
- this.taskFormData = data || {};
- } catch (e) {
- console.warn("获取 taskForm 数据失败", e);
- this.taskFormData = {};
- }
- return this.taskFormData;
- },
- selectActionClick(item) {
- if (item.name == "作废") {
- uni.showModal({
- title: "提示",
- content: "是否确认作废?",
- success: async (modalRes) => {
- if (modalRes.confirm) {
- if (!this.form.reason) {
- return uni.showToast({
- title: "审批建议不能为空",
- icon: "none",
- });
- }
- this.loading = true;
- await this.syncTaskFormData();
- cancelTask({
- taskId: this.taskId,
- id: this.id,
- reason: this.form.reason,
- businessId: this.businessId,
- variables: {
- taskFormData: this.taskFormData,
- },
- })
- .then(() => {
- this.loading = false;
- this.$emit("handleAudit", {
- title: "作废",
- });
- })
- .catch(() => {
- this.loading = false;
- uni.showToast({ title: "流程作废失败", icon: "none" });
- });
- }
- },
- });
- }
- },
- async handleAudit(status) {
- if (!!status) {
- try {
- await this.$refs.uForm.validate();
- } catch (e) {
- return;
- }
- }
- await this.syncTaskFormData();
- let storageData = this.taskFormData.returnStorageData;
- if (!!status) {
- if (!storageData?.extInfo?.verifyDeptCode) {
- return uni.showToast({ title: "请选择部门", icon: "none" });
- }
- if (!storageData?.fromUser) {
- return uni.showToast({ title: "请选择领料人", icon: "none" });
- }
- }
- if (!this.form.reason && !!status) {
- return uni.showToast({ title: "请输入审批意见", icon: "none" });
- }
- if (this.taskDefinitionKey === "storeman" && !!status) {
- storageData.isSkip = 1;
- try {
- this.loading = true;
- const res = await outStorage(storageData);
- if (res.code == 0) {
- await this._approveTaskWithVariables(status);
- }
- } catch (error) {
- this.loading = false;
- uni.showToast({ title: "出库失败", icon: "none" });
- }
- } else {
- this.loading = true;
- await this._approveTaskWithVariables(status);
- }
- },
- async _approveTaskWithVariables(status) {
- try {
- let variables = {
- pass: !!status,
- taskFormData: this.taskFormData,
- };
- let API = !!status ? approveTaskWithVariables : rejectTask;
- let res = await API({
- id: this.taskId,
- reason: this.form.reason,
- variables,
- });
- if (res.code != "-1") {
- this.$emit("handleAudit", {
- status,
- title: status === 0 ? "驳回" : "",
- });
- }
- } catch (e) {
- console.error("审批操作失败", e);
- uni.showToast({ title: "操作失败", icon: "none" });
- } finally {
- this.loading = false;
- }
- },
- async rejectTask(status) {
- await this.syncTaskFormData();
- try {
- this.loading = true;
- let variables = {
- pass: !!status,
- taskFormData: this.taskFormData,
- };
- let res = await rejectTask({
- id: this.taskId,
- reason: this.form.reason,
- variables,
- });
- if (res.code != "-1") {
- this.$emit("handleAudit", {
- status,
- title: status === 0 ? "驳回" : "",
- });
- }
- } catch (e) {
- console.error("驳回操作失败", e);
- uni.showToast({ title: "驳回失败", icon: "none" });
- } finally {
- this.loading = false;
- }
- },
- getTableValue() {
- return new Promise((resolve, reject) => {
- this.$emit("getTableValue", async (data) => {
- resolve(await data);
- });
- });
- },
- },
- };
- </script>
- <style scoped>
- .btnList {
- display: flex;
- }
- .btnConcel {
- margin-top: 20rpx;
- }
- </style>
|