dytyqx
2026-03-12 ad55477167e047ddf6ce9b6d52fe6c74e5ab63e3
pages/baogong/AddLineBind.vue
@@ -1,435 +1,435 @@
<template>
    <view>
        <view class="form" :style="{height: containerHeight + 'px',overflow: 'auto'}">
            <view class="form-item">
                <view class="title">生产资源:</view>
                <view class="right">
                    <uni-combox
                        :candidates="arrayHSourceName"
                        placeholder="请选择生产资源"
                        v-model="hform.HSourceName"
                        @input="HSourceNameChange">
                    </uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">负责人:</view>
                <view class="right">
                    <uni-combox
                        :candidates="arrayHManagerName"
                        placeholder="请选择负责人"
                        v-model="hform.HManagerName"
                        @input="HManagerNameChange">
                    </uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">班组:</view>
                <view class="right">
                    <uni-combox
                        :candidates="arrayHGroupName"
                        placeholder="请选择班组"
                        v-model="hform.HGroupName"
                        @input="HGroupNameChange">
                    </uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">创建日期:</view>
                <view class="righton">
                    <input disabled v-model="hform.HCreateDate" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">备注:</view>
                <view class="right">
                    <textarea v-model="hform.HRemark" placeholder="请输入备注" auto-height />
                </view>
            </view>
        </view>
        <!-- 操作按钮 -->
        <view class="buttons" id="buttons">
            <button class="btn-c" size="mini" @tap="save">保存</button>
            <view style="flex: 1;"></view>
            <button class="btn-a" size="mini" @tap="goBack">返回</button>
        </view>
    </view>
   <view>
      <view class="form-item">
         <view class="title">生产资源:</view>
         <view class="right">
            <uni-combox :candidates="arrayHSourceName" placeholder="请选择生产资源" v-model="hform.HSourceName"
               @input="HSourceNameChange">
            </uni-combox>
         </view>
      </view>
      <view class="form-item">
         <view class="title">负责人:</view>
         <view class="right">
            <uni-combox :candidates="arrayHManagerName" placeholder="请选择负责人" v-model="hform.HManagerName"
               @input="HManagerNameChange">
            </uni-combox>
         </view>
      </view>
      <view class="form-item">
         <view class="title">班组:</view>
         <view class="right">
            <uni-combox :candidates="arrayHGroupName" placeholder="请选择班组" v-model="hform.HGroupName"
               @input="HGroupNameChange">
            </uni-combox>
         </view>
      </view>
      <view class="form-item">
         <view class="title">创建日期:</view>
         <view class="righton">
            <input disabled v-model="hform.HCreateDate" />
         </view>
      </view>
      <view class="form-item">
         <view class="title">备注:</view>
         <view class="right">
            <textarea v-model="hform.HRemark" placeholder="请输入备注" auto-height />
         </view>
      </view>
      <!-- 操作按钮 -->
      <view class="buttons" id="buttons">
         <button class="btn-c" size="mini" @tap="save">保存</button>
         <view style="flex: 1;"></view>
         <button class="btn-a" size="mini" @tap="goBack">返回</button>
      </view>
   </view>
</template>
<script>
    import dayjs from "dayjs";
    import { CommonUtils } from "@/utils/common";
    import { getUserInfo } from "@/utils/auth";
   import dayjs from "dayjs";
   import {
      CommonUtils
   } from "@/utils/common";
   import {
      getUserInfo
   } from "@/utils/auth";
    export default {
        name: 'AddLineBind',
        data() {
            return {
                // 移除btnTop,改用固定底部布局
                // 数据列表
                HSourceNameList: [],
                HManagerNameList: [],
                HGroupNameList: [],
                // 用于uni-combox的数组
                arrayHSourceName: [],
                arrayHManagerName: [],
                arrayHGroupName: [],
                hform: {
                    HUserName: getUserInfo()['Czymc'] || uni.getStorageSync('HUserName'),
                    HSourceID: getUserInfo()['HSourceID'],
                    HSourceName: getUserInfo()['HSource'],
                    HManagerID: getUserInfo()['HKeeperID'],
                    HManagerName: getUserInfo()['HKeeper'],
                    HGroupID: getUserInfo()['HGroupID'],
                    HGroupName: getUserInfo()['HGroup'],
                    HCreateDate: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
                    HRemark: ''
                },
                // 服务器地址
                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
                // 添加窗口高度
                windowHeight: 0
            };
        },
      onUnload() {
        // 页面关闭时触发刷新
        uni.$emit('refreshDeviceList');
   export default {
      name: 'AddLineBind',
      data() {
         return {
            // 移除btnTop,改用固定底部布局
            // 数据列表
            HSourceNameList: [],
            HManagerNameList: [],
            HGroupNameList: [],
            // 用于uni-combox的数组
            arrayHSourceName: [],
            arrayHManagerName: [],
            arrayHGroupName: [],
            hform: {
               HUserName: getUserInfo()['Czymc'] || uni.getStorageSync('HUserName'),
               HSourceID: getUserInfo()['HSourceID'],
               HSourceName: getUserInfo()['HSource'],
               HManagerID: getUserInfo()['HKeeperID'],
               HManagerName: getUserInfo()['HKeeper'],
               HGroupID: getUserInfo()['HGroupID'],
               HGroupName: getUserInfo()['HGroup'],
               HCreateDate: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
               HRemark: ''
            },
            // 服务器地址
            serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
            // 添加窗口高度
            windowHeight: 0
         };
      },
        methods: {
            // 获取所有列表数据
            async getListData() {
                // 获取生产资源列表
                await this.getSourceList();
                // 获取负责人列表(人员列表)
                await this.getManagerList();
                // 获取班组列表
                await this.getGroupList();
            },
            // 获取生产资源列表
            async getSourceList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/api/newBill/getSourceList',
                        data: {
                            sWhere: ""
                        }
                    });
                    if (res[1].data.code == 1) {
                        this.HSourceNameList = res[1].data.data.Gy_Source || [];
                        for (let i = 0; i < this.HSourceNameList.length; i++) {
                            this.arrayHSourceName[i] = this.HSourceNameList[i].生产资源;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取生产资源列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取生产资源列表失败',
                        icon: 'none'
                    });
                }
            },
            // 获取负责人列表(人员列表)
            async getManagerList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/Web/GetEmployeeList_Json',
                        data: {
                            Employee: '',
                            HGroupID: 0
                        }
                    });
                    if (res[1].data.count == 1) {
                        this.HManagerNameList = res[1].data.data || [];
                        for (let i = 0; i < this.HManagerNameList.length; i++) {
                            this.arrayHManagerName[i] = this.HManagerNameList[i].HName;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取负责人列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取负责人列表失败',
                        icon: 'none'
                    });
                }
            },
            // 获取班组列表
            async getGroupList() {
                try {
                    const res = await uni.request({
                        url: this.serverUrl + '/Gy_Group/list',
                        method: 'GET',
                        data: {
                            sWhere: "",
                            user: uni.getStorageSync('HUserName')
                        }
                    });
                    if (res[1].data.count == 1) {
                        this.HGroupNameList = res[1].data.data || [];
                        for (let i = 0; i < this.HGroupNameList.length; i++) {
                            this.arrayHGroupName[i] = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
                        }
                        this.$forceUpdate();
                    } else {
                        uni.showToast({
                            title: '获取班组列表失败',
                            icon: 'none'
                        });
                    }
                } catch (error) {
                    console.log(error);
                    uni.showToast({
                        title: '获取班组列表失败',
                        icon: 'none'
                    });
                }
            },
            // 选择生产资源
            HSourceNameChange(e) {
                for (let i = 0; i < this.HSourceNameList.length; i++) {
                    if (this.HSourceNameList[i].生产资源 == e) {
                        this.hform.HSourceName = this.HSourceNameList[i].生产资源;
                        this.hform.HSourceID = this.HSourceNameList[i].HItemID;
                        this.hform.HSourceCode = this.HSourceNameList[i].资源代码 || '';
                        break;
                    }
                }
            },
            // 选择负责人
            HManagerNameChange(e) {
                for (let i = 0; i < this.HManagerNameList.length; i++) {
                    if (this.HManagerNameList[i].HName == e) {
                        this.hform.HManagerName = this.HManagerNameList[i].HName;
                        this.hform.HManagerID = this.HManagerNameList[i].HItemID;
                        break;
                    }
                }
            },
            // 选择班组
            HGroupNameChange(e) {
                for (let i = 0; i < this.HGroupNameList.length; i++) {
                    const groupName = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
                    if (groupName == e) {
                        this.hform.HGroupName = groupName;
                        this.hform.HGroupID = this.HGroupNameList[i].HItemID;
                        break;
                    }
                }
            },
            // 验证表单
            validateForm() {
                if (!this.hform.HSourceID || this.hform.HSourceID == 0) {
                    uni.showToast({
                        title: '请选择生产资源',
                        icon: 'none'
                    });
                    return false;
                }
                if (!this.hform.HManagerID || this.hform.HManagerID == 0) {
                    uni.showToast({
                        title: '请选择负责人',
                        icon: 'none'
                    });
                    return false;
                }
                return true;
            },
            // 保存数据
            async save() {
                if (!this.validateForm()) {
                    return;
                }
                uni.showLoading({
                    title: '保存中...'
                });
                try {
                    const res = await CommonUtils.doRequest2Sync({
                        url: "/ReportPlatForm/SaveGetLineBindBillList",
                        data: {
                            HUserName: this.hform.HUserName,
                            HSourceID: this.hform.HSourceID,
                            HSourceName: this.hform.HSourceName,
                            HManagerID: this.hform.HManagerID,
                            HManagerName: this.hform.HManagerName,
                            HGroupID: this.hform.HGroupID,
                            HGroupName: this.hform.HGroupName,
                            HCreateDate: this.hform.HCreateDate,
                            HRemark: this.hform.HRemark
                        },
                        method: "GET"
                    });
                    uni.hideLoading();
                    if (res.data.count == 1) {
                        uni.showToast({
                            title: '保存成功',
                            icon: 'success',
                            success: () => {
                                setTimeout(() => {
                                    // 保存成功后返回上一页
                                    uni.navigateBack();
                                }, 1500);
                            }
                        });
                    } else {
                        uni.showToast({
                            title: res.data.Message || '保存失败',
                            icon: 'none'
                        });
                    }
                } catch (err) {
                    uni.hideLoading();
                    uni.showToast({
                        title: '保存失败: ' + err,
                        icon: 'none'
                    });
                }
            },
            // 返回上一页
            goBack() {
                uni.navigateBack();
            }
        },
        onLoad() {
            // 初始化数据
            this.hform.HUserName = getUserInfo()['Czymc'] || uni.getStorageSync('HUserName');
            // 获取所有列表数据
            this.getListData();
            // 获取窗口高度
            const systemInfo = uni.getSystemInfoSync();
            this.windowHeight = systemInfo.windowHeight;
        },
        onReady() {
            // 移除原来的按钮位置计算,使用固定底部布局
        }
    }
      onUnload() {
         // 页面关闭时触发刷新
         uni.$emit('refreshDeviceList');
      },
      methods: {
         // 获取所有列表数据
         async getListData() {
            // 获取生产资源列表
            await this.getSourceList();
            // 获取负责人列表(人员列表)
            await this.getManagerList();
            // 获取班组列表
            await this.getGroupList();
         },
         // 获取生产资源列表
         async getSourceList() {
            try {
               const res = await uni.request({
                  url: this.serverUrl + '/api/newBill/getSourceList',
                  data: {
                     sWhere: ""
                  }
               });
               if (res[1].data.code == 1) {
                  this.HSourceNameList = res[1].data.data.Gy_Source || [];
                  for (let i = 0; i < this.HSourceNameList.length; i++) {
                     this.arrayHSourceName[i] = this.HSourceNameList[i].生产资源;
                  }
                  this.$forceUpdate();
               } else {
                  uni.showToast({
                     title: '获取生产资源列表失败',
                     icon: 'none'
                  });
               }
            } catch (error) {
               console.log(error);
               uni.showToast({
                  title: '获取生产资源列表失败',
                  icon: 'none'
               });
            }
         },
         // 获取负责人列表(人员列表)
         async getManagerList() {
            try {
               const res = await uni.request({
                  url: this.serverUrl + '/Web/GetEmployeeList_Json',
                  data: {
                     Employee: '',
                     HGroupID: 0,
                            HDeptID: uni.getStorageSync("HDeptID")
                  }
               });
               if (res[1].data.count == 1) {
                  this.HManagerNameList = res[1].data.data || [];
                  for (let i = 0; i < this.HManagerNameList.length; i++) {
                     this.arrayHManagerName[i] = this.HManagerNameList[i].HName;
                  }
                  this.$forceUpdate();
               } else {
                  uni.showToast({
                     title: '获取负责人列表失败',
                     icon: 'none'
                  });
               }
            } catch (error) {
               console.log(error);
               uni.showToast({
                  title: '获取负责人列表失败',
                  icon: 'none'
               });
            }
         },
         // 获取班组列表
         async getGroupList() {
            try {
               const res = await uni.request({
                  url: this.serverUrl + '/Gy_Group/list',
                  method: 'GET',
                  data: {
                     sWhere: "",
                     user: uni.getStorageSync('HUserName')
                  }
               });
               if (res[1].data.count == 1) {
                  this.HGroupNameList = res[1].data.data || [];
                  for (let i = 0; i < this.HGroupNameList.length; i++) {
                     this.arrayHGroupName[i] = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
                  }
                  this.$forceUpdate();
               } else {
                  uni.showToast({
                     title: '获取班组列表失败',
                     icon: 'none'
                  });
               }
            } catch (error) {
               console.log(error);
               uni.showToast({
                  title: '获取班组列表失败',
                  icon: 'none'
               });
            }
         },
         // 选择生产资源
         HSourceNameChange(e) {
            for (let i = 0; i < this.HSourceNameList.length; i++) {
               if (this.HSourceNameList[i].生产资源 == e) {
                  this.hform.HSourceName = this.HSourceNameList[i].生产资源;
                  this.hform.HSourceID = this.HSourceNameList[i].HItemID;
                  this.hform.HSourceCode = this.HSourceNameList[i].资源代码 || '';
                  break;
               }
            }
         },
         // 选择负责人
         HManagerNameChange(e) {
            for (let i = 0; i < this.HManagerNameList.length; i++) {
               if (this.HManagerNameList[i].HName == e) {
                  this.hform.HManagerName = this.HManagerNameList[i].HName;
                  this.hform.HManagerID = this.HManagerNameList[i].HItemID;
                  break;
               }
            }
         },
         // 选择班组
         HGroupNameChange(e) {
            for (let i = 0; i < this.HGroupNameList.length; i++) {
               const groupName = this.HGroupNameList[i].班组名称 || this.HGroupNameList[i].HName;
               if (groupName == e) {
                  this.hform.HGroupName = groupName;
                  this.hform.HGroupID = this.HGroupNameList[i].HItemID;
                  break;
               }
            }
         },
         // 验证表单
         validateForm() {
            if (!this.hform.HSourceID || this.hform.HSourceID == 0) {
               uni.showToast({
                  title: '请选择生产资源',
                  icon: 'none'
               });
               return false;
            }
            if (!this.hform.HManagerID || this.hform.HManagerID == 0) {
               uni.showToast({
                  title: '请选择负责人',
                  icon: 'none'
               });
               return false;
            }
            return true;
         },
         // 保存数据
         async save() {
            if (!this.validateForm()) {
               return;
            }
            uni.showLoading({
               title: '保存中...'
            });
            try {
               const res = await CommonUtils.doRequest2Sync({
                  url: "/ReportPlatForm/SaveGetLineBindBillList",
                  data: {
                     HUserName: this.hform.HUserName,
                     HSourceID: this.hform.HSourceID,
                     HSourceName: this.hform.HSourceName,
                     HManagerID: this.hform.HManagerID,
                     HManagerName: this.hform.HManagerName,
                     HGroupID: this.hform.HGroupID,
                     HGroupName: this.hform.HGroupName,
                     HCreateDate: this.hform.HCreateDate,
                     HRemark: this.hform.HRemark
                  },
                  method: "GET"
               });
               uni.hideLoading();
               if (res.data.count == 1) {
                  uni.showToast({
                     title: '保存成功',
                     icon: 'success',
                     success: () => {
                        setTimeout(() => {
                           // 保存成功后返回上一页
                           uni.navigateBack();
                        }, 1500);
                     }
                  });
               } else {
                  uni.showToast({
                     title: res.data.Message || '保存失败',
                     icon: 'none'
                  });
               }
            } catch (err) {
               uni.hideLoading();
               uni.showToast({
                  title: '保存失败: ' + err,
                  icon: 'none'
               });
            }
         },
         // 返回上一页
         goBack() {
            uni.navigateBack();
         }
      },
      onLoad() {
         // 初始化数据
         this.hform.HUserName = getUserInfo()['Czymc'] || uni.getStorageSync('HUserName');
         // 获取所有列表数据
         this.getListData();
         // 获取窗口高度
         const systemInfo = uni.getSystemInfoSync();
         this.windowHeight = systemInfo.windowHeight;
      },
      onReady() {
         // 移除原来的按钮位置计算,使用固定底部布局
      }
   }
</script>
<style lang="scss" scoped>
    .form {
        padding: 20rpx;
        // 添加底部内边距,为底部按钮留出空间
        padding-bottom: 160rpx; // 按钮高度 + 额外间距
    }
    .form-item {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        padding: 6rpx 0;
        margin-bottom: 20rpx;
        .title {
            width: 180rpx;
            flex-shrink: 0;
        }
        .right {
            flex: 1;
            border-radius: 22rpx;
            border: 1px solid #acacac;
            padding: 0 20rpx;
            min-height: 70rpx;
            display: flex;
            align-items: center;
            input, textarea {
                width: 100%;
                font-size: 30rpx;
            }
            textarea {
                padding: 20rpx 0;
                min-height: 100rpx;
            }
        }
        .righton {
            flex: 1;
            border-radius: 22rpx;
            border: 1px solid #e4e4e4;
            background-color: #e4e4e4;
            padding: 0 20rpx;
            min-height: 70rpx;
            display: flex;
            align-items: center;
            input {
                width: 100%;
                font-size: 30rpx;
                color: #666;
            }
        }
    }
    .buttons {
        position: fixed; // 改为固定定位
        bottom: 0; // 固定在底部
        left: 0;
        right: 0;
        width: 100%;
        display: flex;
        padding: 20rpx;
        background-color: #fff;
        border-top: 1px solid #eee;
        box-sizing: border-box; // 确保内边距不影响宽度
        z-index: 999; // 确保按钮在最上层
        button {
            border-radius: 50rpx;
            width: 180rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
        .btn-a {
            background-color: #acacac;
            color: #fff;
        }
        .btn-c {
            background-color: #3a78ff;
            color: #fff;
        }
    }
   .form {
      padding: 20rpx;
      // 使用 calc 计算高度
      height: calc(100vh - 160rpx);
      /* 减去底部按钮区域的高度 */
      overflow: auto;
      box-sizing: border-box;
      /* 确保内边距不影响高度计算 */
   }
   .form-item {
      display: flex;
      align-items: center;
      font-size: 28rpx;
      padding: 6rpx 0;
      margin-bottom: 20rpx;
      margin-left: 10px;
      .title {
         width: 180rpx;
         flex-shrink: 0;
      }
      .right {
         flex: 1;
         border-radius: 22rpx;
         border: 1px solid #acacac;
         padding: 0 20rpx;
         min-height: 70rpx;
         display: flex;
         align-items: center;
         input,
         textarea {
            width: 100%;
            font-size: 30rpx;
         }
         textarea {
            padding: 20rpx 0;
            min-height: 100rpx;
         }
      }
      .righton {
         flex: 1;
         border-radius: 22rpx;
         border: 1px solid #e4e4e4;
         background-color: #e4e4e4;
         padding: 0 20rpx;
         min-height: 70rpx;
         display: flex;
         align-items: center;
         input {
            width: 100%;
            font-size: 30rpx;
            color: #666;
         }
      }
   }
   .buttons {
      position: fixed; // 改为固定定位
      bottom: 0; // 固定在底部
      left: 0;
      right: 0;
      width: 100%;
      display: flex;
      padding: 20rpx;
      background-color: #fff;
      border-top: 1px solid #eee;
      box-sizing: border-box; // 确保内边距不影响宽度
      z-index: 999; // 确保按钮在最上层
      button {
         border-radius: 50rpx;
         width: 180rpx;
         height: 66rpx;
         line-height: 66rpx;
         font-size: 28rpx;
      }
      .btn-a {
         background-color: #acacac;
         color: #fff;
      }
      .btn-c {
         background-color: #3a78ff;
         color: #fff;
      }
   }
</style>