Lufaneng 9 months ago
parent 1abc380d5e
commit f0fc6c4c28

@ -2,7 +2,11 @@
<view class="container"> <view class="container">
<!-- 顶部图片和标题 --> <!-- 顶部图片和标题 -->
<view class="header-section"> <view class="header-section">
<image class="header-image" src="/static/imgs/indexImg.png" mode="aspectFill"></image> <image
class="header-image"
src="/static/imgs/indexImg.png"
mode="aspectFill"
></image>
<view class="header-overlay"> <view class="header-overlay">
<view class="header-title">生成电梯图纸</view> <view class="header-title">生成电梯图纸</view>
<view class="header-subtitle"> <view class="header-subtitle">
@ -14,7 +18,10 @@
<!-- 选择图纸模板 --> <!-- 选择图纸模板 -->
<view class="section"> <view class="section">
<view class="section-title">选择图纸模板</view> <view class="section-title">选择图纸模板</view>
<uv-skeletons v-if="loading" :loading="loading" :skeleton="[ <uv-skeletons
v-if="loading"
:loading="loading"
:skeleton="[
{ {
type: 'flex', type: 'flex',
num: 2, num: 2,
@ -34,9 +41,16 @@
}, },
], ],
}, },
]"></uv-skeletons> ]"
></uv-skeletons>
<view class="template-grid" v-else> <view class="template-grid" v-else>
<view class="template-item" :class="{ active: currentTemplate.id === item.id }" @click="selectTemplate(item)" v-for="item in templateList" :key="item.id"> <view
class="template-item"
:class="{ active: currentTemplate.id === item.id }"
@click="selectTemplate(item)"
v-for="item in templateList"
:key="item.id"
>
<view class="tag" v-if="item.price_cents"> <view class="tag" v-if="item.price_cents">
¥ {{ item.price_cents / 100 }} ¥ {{ item.price_cents / 100 }}
</view> </view>
@ -49,20 +63,50 @@
<!-- 设置参数 --> <!-- 设置参数 -->
<view class="section" v-if="has_access"> <view class="section" v-if="has_access">
<view class="section-title">设置参数</view> <view class="section-title">设置参数</view>
<uv-skeletons v-if="params_loading" :loading="params_loading" :skeleton="[ <uv-skeletons
v-if="params_loading"
:loading="params_loading"
:skeleton="[
{ {
type: 'line', type: 'line',
num: 3, num: 3,
gap: '20rpx', gap: '20rpx',
}, },
]"></uv-skeletons> ]"
></uv-skeletons>
<view class="form" v-else> <view class="form" v-else>
<uv-form labelAlign="left" labelWidth="auto" labelPosition="left" :model="formField" :rules="rules" ref="form"> <uv-form
<uv-form-item :prop="item.name" :label="item.name + ''" v-for="item in currentTemplate.params?.filter( labelAlign="left"
labelWidth="auto"
labelPosition="left"
:model="formField"
:rules="rules"
ref="form"
>
<uv-form-item
:prop="item.name"
:label="item.name + ''"
v-for="item in currentTemplate.params?.filter(
(item) => item.enabled (item) => item.enabled
) || []"> ) || []"
<div class="required" v-if="item.required" style="color: #f12323;">*</div> :key="item.name"
<uv-input @click="openPicker(item)" :readonly="item.type === 'select'" :type="item.type === 'number' ? 'digit' : 'text'" v-model="item.value" color="#000" border="bottom" :placeholderStyle="{ color: '#666778' }" placeholder="请输入"></uv-input> >
<div class="required" v-if="item.required" style="color: #f12323">
*
</div>
<uv-input
@click="openPicker(item)"
@input="handleInputChange(item)"
:readonly="item.type === 'select' || item.name === '土建图号'"
:type="item.type === 'number' ? 'digit' : 'text'"
v-model="item.value"
color="#000"
border="bottom"
:placeholderStyle="{ color: '#666778' }"
:placeholder="
item.name === '土建图号' ? '将根据土建图型号自动生成' : '请输入'
"
></uv-input>
</uv-form-item> </uv-form-item>
<!-- <uv-form-item prop="password" label="载重kg"> <!-- <uv-form-item prop="password" label="载重kg">
<uv-input <uv-input
@ -125,20 +169,49 @@
</view> </view>
<view class="section" v-else> <view class="section" v-else>
<div class="status">申请状态{{ get_access_status(currentTemplate.access_status) }}</div> <div class="status">
<uv-button size="small" v-if="currentTemplate.access_status !== 'pending'" @click="openApplyModal" text="申请权限" color="#3F70FF"></uv-button> 申请状态{{ get_access_status(currentTemplate.access_status) }}
</div>
<uv-button
size="small"
v-if="currentTemplate.access_status !== 'pending'"
@click="openApplyModal"
text="申请权限"
color="#3F70FF"
></uv-button>
</view> </view>
<!-- 底部按钮 --> <!-- 底部按钮 -->
<view class="bottom-actions"> <view class="bottom-actions">
<uv-button :loading="generating" @click="modalRefOpen" text="生成图纸" color="#3F70FF"></uv-button> <uv-button
:loading="generating"
@click="modalRefOpen"
text="生成图纸"
color="#3F70FF"
></uv-button>
<uv-button @click="viewHistory" text="查看记录"></uv-button> <uv-button @click="viewHistory" text="查看记录"></uv-button>
</view> </view>
<uv-modal ref="modalRef" showCancelButton content="确定生成图纸?" @confirm="confirmGenerate"></uv-modal> <uv-modal
<uv-modal ref="applyModalRef" showCancelButton title="申请权限" @confirm="confirmApply" @cancel="cancelApply"> ref="modalRef"
showCancelButton
content="确定生成图纸?"
@confirm="confirmGenerate"
></uv-modal>
<uv-modal
ref="applyModalRef"
showCancelButton
title="申请权限"
@confirm="confirmApply"
@cancel="cancelApply"
>
<view class="apply-modal-content"> <view class="apply-modal-content">
<view class="apply-label">申请理由</view> <view class="apply-label">申请理由</view>
<uv-textarea v-model="applyReason" placeholder="请输入申请理由" maxlength="200" count></uv-textarea> <uv-textarea
v-model="applyReason"
placeholder="请输入申请理由"
maxlength="200"
count
></uv-textarea>
</view> </view>
</uv-modal> </uv-modal>
<uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker> <uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
@ -146,7 +219,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from "vue"; import { ref, onMounted, nextTick } from "vue";
import { import {
onShow, onShow,
onLoad, onLoad,
@ -162,28 +235,28 @@ import { usePermission } from "@/hooks/usePermission";
const authStore = useAuthStore(); const authStore = useAuthStore();
const userStore = useUserStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const params_loading = ref(false) const params_loading = ref(false);
const has_access = ref(false); const has_access = ref(false);
const applyModalRef = ref(null); const applyModalRef = ref(null);
const applyReason = ref(""); const applyReason = ref("");
const applyLoading = ref(false); const applyLoading = ref(false);
const get_access_status = access_status => { const get_access_status = (access_status) => {
let str = '' let str = "";
if (access_status === 'none') { if (access_status === "none") {
str = '无权限' str = "无权限";
} else if (access_status === 'pending') { } else if (access_status === "pending") {
str = '等待审批...' str = "等待审批...";
} else if (access_status === 'rejected') { } else if (access_status === "rejected") {
str = '已拒绝' str = "已拒绝";
} else if (access_status === 'approved') { } else if (access_status === "approved") {
str = '已同意' str = "已同意";
} else { } else {
str = access_status str = access_status;
}
return str
} }
return str;
};
const modalRefOpen = () => { const modalRefOpen = () => {
if (!has_access.value) { if (!has_access.value) {
@ -193,22 +266,22 @@ const modalRefOpen = () => {
}); });
return; return;
} }
let flag = false let flag = false;
let name let name;
currentTemplate.value.params currentTemplate.value.params
?.filter((item) => item.enabled) ?.filter((item) => item.enabled)
.forEach((item) => { .forEach((item) => {
if (item.required && !item.value) { if (item.required && !item.value) {
flag = true flag = true;
name = item.name name = item.name;
} }
}); });
if (flag) { if (flag) {
uni.showToast({ uni.showToast({
title: `请检查【${name}`, title: `请检查【${name}`,
icon: 'none' icon: "none",
}) });
return return;
} }
modalRef.value.open(); modalRef.value.open();
}; };
@ -226,6 +299,12 @@ const columns = ref([[]]);
const confirm = (val) => { const confirm = (val) => {
console.log(val); console.log(val);
currentParams.value.value = val.value[0]; currentParams.value.value = val.value[0];
//
if (currentParams.value.name === "土建图型号") {
nextTick(() => {
generateDrawingNumber();
})
}
}; };
// //
@ -257,7 +336,7 @@ const confirmApply = async () => {
}); });
applyModalRef.value.close(); applyModalRef.value.close();
applyReason.value = ""; applyReason.value = "";
getList() getList();
} catch (error) { } catch (error) {
uni.showToast({ uni.showToast({
title: "申请失败,请重试", title: "申请失败,请重试",
@ -273,27 +352,70 @@ const cancelApply = () => {
applyReason.value = ""; applyReason.value = "";
}; };
//
const handleInputChange = (item) => {
//
if (item.name === "土建图型号") {
nextTick(() => {
generateDrawingNumber();
})
}
};
//
const generateDrawingNumber = () => {
const params = currentTemplate.value.params;
if (!params) return;
//
const modelParam = params.find((p) => p.name === "土建图型号");
const numberParam = params.find((p) => p.name === "土建图号");
if (!modelParam || !numberParam || !modelParam.value) return;
//
const now = new Date();
const year = now.getFullYear().toString().slice(-2); //
const month = (now.getMonth() + 1).toString().padStart(2, "0"); //
// 4+
const randomPart = generateRandomCode();
// GSE400-V25-10-0002A
numberParam.value = `${modelParam.value}-V${year}${month}-${randomPart}`;
};
// 4+1
const generateRandomCode = () => {
const numbers = Math.floor(Math.random() * 10000)
.toString()
.padStart(4, "0");
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const letter = letters.charAt(Math.floor(Math.random() * letters.length));
return numbers + letter;
};
const generating = ref(false); const generating = ref(false);
const modalRef = ref(null); const modalRef = ref(null);
const confirmGenerate = () => { const confirmGenerate = () => {
const params = {}; const params = {};
let flag = false let flag = false;
let name = '' let name = "";
currentTemplate.value.params currentTemplate.value.params
?.filter((item) => item.enabled) ?.filter((item) => item.enabled)
.forEach((item) => { .forEach((item) => {
if (item.required && !item.value) { if (item.required && !item.value) {
flag = true flag = true;
name = item.name name = item.name;
} }
params[item.name] = item.value; params[item.name] = item.value;
}); });
if (flag) { if (flag) {
uni.showToast({ uni.showToast({
title: `请检查【${name}`, title: `请检查【${name}`,
icon: 'none' icon: "none",
}) });
return return;
} }
RPC.post("/template_create_task", { RPC.post("/template_create_task", {
template_id: currentTemplate.value.id, template_id: currentTemplate.value.id,
@ -325,13 +447,15 @@ const getList = () => {
? JSON.parse(JSON.stringify(templateList.value[0])) ? JSON.parse(JSON.stringify(templateList.value[0]))
: {}; : {};
if (currentTemplate.value.has_access) { if (currentTemplate.value.has_access) {
params_loading.value = true params_loading.value = true;
has_access.value = true has_access.value = true;
RPC.post('/template/detail', { id: currentTemplate.value.id }).then(res => { RPC.post("/template/detail", { id: currentTemplate.value.id })
currentTemplate.value.params = res?.params .then((res) => {
}).finally(() => { currentTemplate.value.params = res?.params;
params_loading.value = false
}) })
.finally(() => {
params_loading.value = false;
});
} }
}) })
.finally(() => { .finally(() => {
@ -344,12 +468,18 @@ const selectTemplate = (item) => {
currentTemplate.value = JSON.parse(JSON.stringify(item)); currentTemplate.value = JSON.parse(JSON.stringify(item));
has_access.value = currentTemplate.value.has_access; has_access.value = currentTemplate.value.has_access;
if (currentTemplate.value.has_access) { if (currentTemplate.value.has_access) {
params_loading.value = true params_loading.value = true;
RPC.post('/template/detail', { id: currentTemplate.value.id }).then(res => { RPC.post("/template/detail", { id: currentTemplate.value.id })
currentTemplate.value.params = res?.params .then((res) => {
}).finally(() => { currentTemplate.value.params = res?.params;
params_loading.value = false //
nextTick(() => {
generateDrawingNumber();
})
}) })
.finally(() => {
params_loading.value = false;
});
} }
}; };

Loading…
Cancel
Save