Houjie
2025-06-03 2fda34643bc22e25f6c569415da5f955c81536bf
pages/reportRepair/reportRepair.vue
@@ -11,42 +11,31 @@
               <uni-data-select v-model="formData.num" :localdata="equipmentList" @change="changeEquipmentList"
                  placeholder="请选择" />
            </uni-forms-item> -->
            <uni-forms-item required name="num" label="设备编号:">
            <uni-forms-item required :label-width="100" name="num" label="设备编号:">
               <uni-easyinput v-model=" formData.numSear" placeholder="请选择" :disabled="true" suffixIcon="search"
                  @iconClick="OnenterpriseId()" />
            </uni-forms-item>
            <uni-forms-item required name="name" label="故障简称:">
            <uni-forms-item required :label-width="100" name="name" label="故障简称:">
               <uni-data-select v-model="formData.faultName" :localdata="formData.faultNameList"
                  @change="changefaultNameList" placeholder="请选择" />
            </uni-forms-item>
            <uni-forms-item required name="faultType" label="故障分类:">
            <uni-forms-item required :label-width="100" name="faultType" label="故障分类:">
               <uni-easyinput v-model="formData.faultType" :disabled='true' />
            </uni-forms-item>
            <uni-forms-item required name="faultDescription" label="故障描述:">
            <uni-forms-item required :label-width="100" name="faultDescription" label="故障描述:">
               <uni-easyinput v-model="formData.faultDescription" :disabled='true' />
            </uni-forms-item>
            <uni-forms-item required name="desc" label="故障开始时间:">
               <uni-datetime-picker type="datetime" v-model="formData.loadTime" />
            </uni-forms-item>
            <uni-forms-item required name="name" label="是否停机:">
            <uni-forms-item required name="name" :label-width="100" label="是否停机:">
               <uni-data-select v-model="formData.breakdownFlag" :localdata="isTrueList" @change="changeisTrueList"
                  placeholder="请选择" />
            </uni-forms-item>
            <uni-forms-item name="outNum" label="报修图片:">
               <view class="grid col-4 grid-square flex-sub">
                  <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
                     :data-url="imgList[index]">
                     <image :src="imgList[index]" mode="aspectFill"></image>
                     <view class="cu-tag bg-red radius" @tap.stop="DelImg" :data-index="index">
                        <text class='cuIcon-close'></text>
                     </view>
                  </view>
                  <view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
                     <text class='cuIcon-cameraadd'></text>
                  </view>
               </view>
            <uni-forms-item required :label-width="110" name="desc" label="故障开始时间:">
               <uni-datetime-picker type="datetime" v-model="formData.loadTime" />
            </uni-forms-item>
            <uni-forms-item name="outNum" label="报修图片:">
               <uni-file-picker limit="9" :value="fileLists" :image-styles="imageStyles" :sourceType="sourceType"
                  @select="select" @progress="progress" @success="success" @fail="fail" @delete="deletea" />
            </uni-forms-item>
            <uni-forms-item name="faultDescription" label="备注:">
@@ -57,7 +46,7 @@
      <view class="padding flex flex-direction">
         <view class="flex-sub bg-blue padding-sm margin-xl radius text-sm text-center text-white"
            @click.stop="ProductionTask()" hover-class="is-hover">提交</view>
            @click.stop="ProductionTask()"   hover-class="is-hover">提交</view>
      </view>
@@ -68,8 +57,18 @@
   import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
   export default {
      mixins: [MescrollMixin], // 使用mixin
      data() {
         return {
            // 图片回显
            fileLists: [],
            // 上传图片的样式
            imageStyles: {
               width: 90,
               height: 90,
            },
            // uni.chooseImage值,从相册选择,拍摄
            sourceType: ['album', 'camera'],
            id: '',
            equipmentList: [],
            isTrueList: [{
@@ -92,7 +91,7 @@
               faultNameList: [],
               faultName: '',
               faultType: '',
               breakdownFlag: '',
               breakdownFlag: '1',
               loadTime: Date.now(),
               faultDescription: ''
            },
@@ -128,7 +127,9 @@
            announcement1: [],
            msg1Count: 0,
            msg2Count: 0,
            msg1Title: ""
            msg1Title: "",
            equipmentId: '',
            AuthLsit:[]
         }
      },
      computed: {
@@ -166,7 +167,7 @@
         this.getSera()
      },
      created() {
         // this.getEquipment();
         this.getfaultReasonList();
      },
      methods: {
@@ -186,6 +187,7 @@
               console.log(this.announcement1);
               //设置列表数据
               if (res.data.success) {
                  this.equipmentId = this.announcement1.id
                  this.formData.numSear = this.announcement1.equipmentCode + '[' + this.announcement1
                     .equipmentName +
                     ']'
@@ -207,17 +209,21 @@
         },
         changefaultNameList(e) {
            this.formData.faultName = e;
            if (e == '1902250920983339009') {
               this.formData.faultType = this.formData.faultNameList[0].faultCategory_dictText;
               this.formData.faultDescription = this.formData.faultNameList[0].faultDescription;
            } else if (e == '1909114668383875074') {
               this.formData.faultType = this.formData.faultNameList[1].faultCategory_dictText;
               this.formData.faultDescription = this.formData.faultNameList[1].faultDescription;
            } else if (e == '1909877534952710145') {
               this.formData.faultType = this.formData.faultNameList[2].faultCategory_dictText;
               this.formData.faultDescription = this.formData.faultNameList[2].faultDescription;
            this.setFaultReason(this.formData.faultName)
         },
         setFaultReason(value) {
            for (let i = 0; i < this.formData.faultNameList.length; i++) {
               if (this.formData.faultNameList[i].id === value) {
                  this.formData.faultType = this.formData.faultNameList[i].faultCategory_dictText
                  this.formData.faultDescription = this.formData.faultNameList[i].faultDescription
               }
            }
         },
         getfaultReasonList() {
            this.$http.get(this.url.faultReasonList).then(res => {
               //设置列表数据
@@ -235,96 +241,67 @@
               this.$tip.error("联网失败")
            })
         },
         // getEquipment() {
         //    this.$http.get(this.url.getEquipmentList).then(res => {
         //       //设置列表数据
         //       if (res.data.success) {
         //          this.equipmentList = res.data.result
         //       } else {
         //          uni.showToast({
         //             icon: "error",
         //             title: res.data.message,
         //             duration: 2000
         //          });
         //       }
         //    }).catch(() => {
         //       this.$tip.error("联网失败")
         //    })
         // },
         // changeEquipmentList(e) {
         //    this.formData.num = e;
         // },
         changeisTrueList(e) {
            this.formData.breakdownFlag = e;
         },
         select(e) {
            const tempFilePaths = e.tempFilePaths;
         ChooseImage() {
            var that = this;
            uni.chooseImage({
               count: 4,
               sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
               sourceType: ['album'], // 从相册选择
               success: (res) => {
                  // 存储选择的图片路径
                  that.imgList = res.tempFilePaths;
            // if (!Array.isArray(tempFilePaths) || tempFilePaths.length === 0) {
            //    uni.showToast({
            //       title: '请选择文件',
            //       icon: 'none'
            //    });
            //    return;
            // }
                  // 初始化 formData.avatar 为空字符串
                  that.formData.avatar = [];
            uni.showLoading({
               title: '上传中...'
            });
                  // 创建上传任务的 Promise 数组
                  const uploadPromises = res.tempFilePaths.map((filePath, index) => {
                     return new Promise((resolve, reject) => {
                        that.$http.upload(that.url.upload, {
                              filePath: filePath,
                              name: 'file'
                           })
                           .then(uploadRes => {
                              // 假设服务器返回的结果中包含文件路径
                              const filePath = uploadRes.data.result[0];
                              this.formData.avatar.push(filePath)
                              resolve(filePath);
                           })
                           .catch(err => {
                              console.error('图片' + index + '上传失败:', err);
                              reject(err);
                           });
                     });
                  });
                  // 并发执行所有上传任务
                  Promise.all(uploadPromises)
                     .then((uploadedFilePaths) => {
                        console.log('所有图片上传成功:', that.formData.avatar);
            const uploadPromises = tempFilePaths.map((filePath, index) => {
               return new Promise((resolve, reject) => {
                  this.$http.upload(this.url.upload, {
                        filePath: filePath,
                        name: 'file'
                     })
                     .catch((err) => {
                        console.error('图片上传失败:', err);
                        that.$tip.error('图片上传失败');
                     .then(uploadRes => {
                        // 假设服务器返回的结果中包含文件路径
                        const serverFilePath = uploadRes.data.result[0];
                        this.formData.avatar.push(serverFilePath);
                        resolve(uploadRes); // 返回结果给 Promise.all
                     })
                     .catch(err => {
                        console.error(`图片 ${index + 1} 上传失败:`, err);
                        reject(err);
                     });
               }
               });
            });
         },
         ViewImage(e) {
            uni.previewImage({
               urls: this.imgList,
               current: e.currentTarget.dataset.url
            });
         },
         DelImg(e) {
            uni.showModal({
               title: '提示',
               content: '确定要删除这段回忆吗?',
               cancelText: '再看看',
               confirmText: '再见',
               success: res => {
                  if (res.confirm) {
                     this.imgList.splice(e.currentTarget.dataset.index, 1)
                  }
               }
            })
            Promise.all(uploadPromises)
               .then(() => {
                  uni.hideLoading();
                  uni.showToast({
                     title: '全部上传成功'
                  });
               })
               .catch(err => {
                  uni.hideLoading();
                  uni.showToast({
                     title: '部分上传失败',
                     icon: 'none'
                  });
                  console.error('上传异常:', err);
               });
         },
         // 删除
         deletea(e) {
            console.log('删除图片', e);
         },
         ProductionTask() {
            if (this.formData.num == 0 || this.formData.num == undefined) {
               uni.showToast({
@@ -338,6 +315,14 @@
               uni.showToast({
                  icon: "none",
                  title: '故障简称为空!',
                  duration: 2000
               });
               return false
            }
            if (this.formData.breakdownFlag == 0 || this.formData.breakdownFlag == undefined) {
               uni.showToast({
                  icon: "none",
                  title: '是否停机为空!',
                  duration: 2000
               });
               return false
@@ -365,16 +350,23 @@
                     title: '提交成功',
                     duration: 2000
                  });
                  this.$Router.replaceAll({
                     name: 'reportRepairList'
                  console.log(this.equipmentId)
                  uni.reLaunch({
                     url: `/pages/reportRepair/reportRepairList/reportRepairList?equipmentId=${this.equipmentId}`
                  })
               } else {
                  uni.showToast({
                     icon: "error",
                     title: res.data.message,
                     duration: 2000
                  });
               }
            }).catch(() => {
               this.$tip.loaded();
               uni.hideLoading();
               uni.showToast({
                  icon: "error",
                  title: '提交失败',
                  title: '网络连接失败',
                  duration: 2000
               });
            });