小小儁爺
2025-05-23 d26ff568b097248861a6cbc13bcf2acc88a54524
pages/sbgl/dqby.vue
@@ -3,184 +3,68 @@
      <page-nav title="定期保养"></page-nav>
      <view v-show="topContent.length===0">
      <view v-if="purchorderArrAll.length>0">
         <!-- <view class="mainContent" :style="{maxHeight: '1340rpx',overflow: 'scroll',padding:0}"> -->
         <!-- #ifdef H5 -->
         <u--input prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" placeholder="输入设备/工位"
            clearable border="surround" @clear='inputBoxValueClear' v-model="inputBoxValue"
            @change="changeInputBoxValue">
            <template slot="suffix">
               <u-icon name="scan" color="#909399" size="24" @click="topScanClick"></u-icon>
            </template>
         </u--input>
         <!-- #endif -->
         <!-- #ifdef APP-PLUS -->
         <u-input prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" placeholder="输入设备/工位"
            clearable border="surround" @clear='inputBoxValueClear' v-model="inputBoxValue"
            @change="changeInputBoxValue">
            <template slot="suffix">
               <u-icon name="scan" color="#909399" size="24" @click="topScanClick"></u-icon>
            </template>
         </u-input>
         <!-- #endif -->
         <u-alert :title="'设备/工位数(共'+title+'个)'" type="primary"></u-alert>
         <u-radio-group v-model="radioValue" iconPlacement="right" @change="radioValueClick" class="radioGroupClass">
            <view v-for="(item,index) in purchorderArr" :key="item.code">
               <!-- @click="radioValueClick(item.code)" -->
               <view>
                  <u-radio activeColor="red" size="18" labelSize='18' :name='item.code' :key="item.code"
                     :label="item.code+'/'+item.name"></u-radio>
               </view>
               <u-line v-if="index!==purchorderArr.length-1" color="#2979ff"></u-line>
            </view>
         </u-radio-group>
         <view class="footer" style="min-height:62rpx;">
            <u-button type="primary" size='large' :hairline="true" @click="navigateTo" text="下一步"></u-button>
         </view>
         <!-- </view> -->
      </view>
      <view v-if="purchorderArrAll.length===0">
         <div class="sacnBody">
            <div class="scanImg" @click="topScanClick"></div>
            <div class="scanText">扫描保养工位</div>
            <div class="boxImg"></div>
            <div class="scanText">暂无设备/工位</div>
         </div>
      </view>
      <view v-show="topContent.length!==0">
         <view class="mainContent">
            <view>
               <u-gap height="10" bgColor="#eff0f1"></u-gap>
               <view class="head">
                  <view class="head_block">
                     <view class="head_left">
                        <view class="head_bar"></view>
                        <view class="head_title">
                           扫描保养工位
                        </view>
                     </view>
                     <view class="marginRight20">
                        <u-icon name="scan" @click="topScanClick" color="red" size="28"></u-icon>
                     </view>
                  </view>
                  <view class="marginLeft20 marginRight20" style="max-height: 180rpx;overflow:scroll;">
                     <u-radio-group v-model="radioValue" class="flex_column">
                        <view class="marginBottom20 flex_between" @click="groupChange(item.code)"
                           v-for="item in topContent" :key="item.code">
                           <view style="display: flex;">
                              <view class="flex_column titleFont">
                                 <view>工位编码:</view>
                                 <view>工位名称:</view>
                                 <view>生产车间:</view>
                              </view>
                              <view class="flex_column contentFont">
                                 <view>{{item.code}}</view>
                                 <view>{{item.name}}</view>
                                 <view>{{item.wksp_name}}</view>
                              </view>
                           </view>
                           <u-radio size='20' :key="item.code" :name="item.code"
                              @change="groupChange(item.code)" activeColor="red"></u-radio>
                        </view>
                     </u-radio-group>
                  </view>
               </view>
               <u-gap height="12" bgColor="#eff0f1"></u-gap>
               <view class="head" style="height:86rpx;">
                  <view class="head_block">
                     <view class="head_left">
                        <view class="head_bar"></view>
                        <view class="head_title">
                           保养标准
                        </view>
                     </view>
                     <view class="marginRight20 marginTop10" style="width: 200rpx;">
                        <!-- <u-icon name="scan" @click="topScanClick" color="red" size="56"></u-icon> -->
                        <uni-data-select v-model="selectValueBZ" :clear="false" :localdata="selectRangeBZ"
                           @change="selectChangeBZ">
                        </uni-data-select>
                     </view>
                  </view>
               </view>
               <u-gap height="12" bgColor="#eff0f1"></u-gap>
               <view class="head">
                  <view class="head_block" style="margin-bottom: 10rpx;margin-top:20rpx;">
                     <view class="head_left">
                        <view class="head_bar"></view>
                        <view class="head_title">
                           保养项目内容
                        </view>
                     </view>
                     <view class="marginRight20" style="width: 200rpx;">
                        <uni-data-select v-model="selectValue" :clear="false" :localdata="selectRange"
                           @change="selectChange">
                        </uni-data-select>
                     </view>
                  </view>
                  <view :style="{maxHeight:'1000rpx',overflow: 'scroll'}">
                     <view class="center_border flex_column" style="margin: 10rpx;" v-for="item in centerContent"
                        :key="item.code">
                        <view class="flex_between marginBottom10">
                           <view class="center_title">{{item.name}}</view>
                           <view class="marginRight20" v-if="item.isscan==='Y'">
                              <u-icon name="scan" @click="centerScanClick(item.code)" color="red" size="56">
                              </u-icon>
                           </view>
                        </view>
                        <view class="flex_between marginBottom10">
                           <view class='inputClass marginTop10'>
                              <u--input :disabled='item.isDisabled' placeholder="请输入" border="surround"
                                 v-model="item.inputValue"></u--input>
                           </view>
                           <view class="flex_center">
                              <u-button type="primary" :plain="item.isOK!=='OK'" :disabled="item.isDisabled"
                                 text="正常" @click="bwClick(item,'OK')">
                              </u-button>
                              <u-button type="warning" :plain="item.isOK!=='NG'" :disabled="item.isDisabled"
                                 text="异常" @click="bwClick(item,'NG')">
                              </u-button>
                           </view>
                        </view>
                        <view class="titleFont">
                           {{item.chkdesc}}
                        </view>
                     </view>
                  </view>
               </view>
            </view>
         </view>
         <view class="footer">
            <view class="head_block" style="align-items: center;padding: 0 23rpx;height: 100rpx;">
               <view class="head_left">
                  <view class="head_bar"></view>
                  <view class="head_title">
                     点检结果
                  </view>
               </view>
               <view class="flex_center">
                  <u-button type="primary" :plain="resultValue!=='OK'" style="height: 60rpx;"
                     :disabled="centerContent.some(item=>item.isDisabled===true)||centerContent.length===0"
                     text="正常" @click="resultClick('OK')"></u-button>
                  <u-button type="warning" :plain="resultValue!=='NG'" style="margin-left: 20rpx;height: 60rpx;"
                     :disabled="centerContent.some(item=>item.isDisabled===true)||centerContent.length===0"
                     text="异常" @click="resultClick('NG')"></u-button>
               </view>
            </view>
            <u-button size="large" :loading="isDisabledSubmitButton" loadingText="正在提交,请稍等..." type="primary"
               @click="submit" :disabled="resultValue===''" text="确认提交">
            </u-button>
         </view>
      </view>
      <scan-code></scan-code>
   </view>
</template>
<script>
   import {
      RepairScanDeviceQrCodeData,
      RepairSelectScanDeviceQrCodeItem,
      RepairScanDeviceTemp,
      AppDeviceRepairSave
   } from '../../config/api.js'
   import scanCode from '@/components/scan-code/scan-code.vue'
      EqpPermissions
   } from '../../config/api.js';
   export default {
      components: {
         scanCode
      },
      onLoad(option) {
         const _this = this
         uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器
         uni.$on('scancodedate', function(content) {
            console.log("扫描到的内容为:", content)
            _this.getRepairScanDeviceQrCodeData(content)
         })
      },
      onLoad(option) {},
      onPullDownRefresh() {
         setTimeout(() => {
            this.init(() => {
@@ -188,33 +72,20 @@
            })
         }, 1000);
      },
      data() {
         return {
            isDisabledSubmitButton: false,
            topContent: [], //扫描保养工位所带出来的内容
            centerContent: [], //保养项目内容
            scanContent: '', //扫描扫出来的值
            radioValue: '', //单选框的值
            resultValue: '', //保养结果值
            inputBoxValue: '', //输入框值
            selectValueBZ: '', //标准选择的值
            selectRangeBZ: [], //标准选择的下拉选项
            title: 0,
            selectValue: 'M',
            selectRange: [{
               value: 'Y',
               text: '年'
            }, {
               value: 'S',
               text: '季'
            }, {
               value: 'M',
               text: '月'
            }, {
               value: 'W',
               text: '周'
            }, ]
            radioValue: '',
            purchorderArr: [],
            purchorderArrAll: []
         }
      },
      created() {
@@ -223,22 +94,40 @@
      mounted() {
         this.init()
         this.getRepairScanDeviceQrCodeData('111')
         this.getEqpPermissions()
      },
      methods: {
         init() {
            uni.stopPullDownRefresh();
         },
         selectChange(val) {
         changeInputBoxValue(val) {
            this.purchorderArr = this.purchorderArrAll.filter((p) => {
               return p.code.indexOf(val) !== -1
            })
            if (this.purchorderArr.length > 0) {
               this.radioValue = this.purchorderArr[0].code
            }
         },
         inputBoxValueClear() {
            this.inputBoxValue = ''
         },
         radioValueClick(val) {
            console.log(val)
            this.radioValue = val
         },
         selectChangeBZ(val) {
            console.log(val, 1)
            this.selectValueBZ = val
            this.getRepairSelectScanDeviceQrCodeItem(this.radioValue, this.selectValueBZ)
         navigateTo() {
            uni.navigateTo({
               url: './dqby2?code=' + this.radioValue
            });
         },
         // 扫码工位  的扫码框点击
         // 扫码框点击
         topScanClick() {
            let that = this;
@@ -250,18 +139,7 @@
                  console.log('条码类型:' + res.scanType);
                  console.log('条码内容:' + res.result);
                  that.scanContent = res.result;
                  let flag = false
                  that.topContent.forEach(item => {
                     if (item.code === res.result) {
                        flag = true
                     }
                  })
                  if (flag) {
                     that.$u.toast('此条码已扫描,已在列表中!')
                  } else {
                     //处理扫码事件
                     that.getRepairScanDeviceQrCodeData(that.scanContent);
                  }
                  that.changeInputBoxValue(that.scanContent);
               },
               complete: function(res) {
@@ -274,199 +152,18 @@
            });
         },
         // 保养项目内容  的扫码框点击
         centerScanClick(val) {
            let that = this;
            uni.scanCode({
               onlyFromCamera: true,
               // scanType: ['barCode', 'qrCode'],
               scanType: ['qrCode'],
               success: function(res) {
                  // console.log('条码类型:' + res.scanType);
                  console.log('条码内容:' + res.result);
                  // that.scanContent = res.result;
         async getEqpPermissions() {
            const res = await EqpPermissions()
            this.purchorderArrAll = res.data
                  if (res.result === val) {
                     that.centerContent.find(item => item.code === val).isDisabled = false
                     that.centerContent.find(item => item.code === val).isOK = 'OK'
            this.purchorderArr = res.data
                     if (that.centerContent.every(r => r.isOK === 'OK')) {
                        that.resultValue = 'OK'
                     }
                     if (that.centerContent.some(r => r.isOK === 'NG')) {
                        that.resultValue = 'NG'
                     }
                     if (that.centerContent.some(r => r.isOK === '')) {
                        that.resultValue = ''
                     }
            this.title = res.data.length
                     that.$forceUpdate()
                  } else {
                     uni.$u.toast('所扫条码与点检部位不符合!')
                  }
                  //处理扫码事件
                  // that.SearchBarcode();
               },
               complete: function(res) {},
               fail: function(res) {}
            });
         },
         // 获取保养工位
         async getRepairScanDeviceQrCodeData(val) {
            const data = {
               eqpcode: val
            }
            const res = await RepairScanDeviceQrCodeData(data)
            if (res.code === '200' && res.data[0].eapmai_code !== null) { //表示绑定了标准
               this.topContent.unshift(res.data[0])
               this.radioValue = res.data[0].code
               // this.selectValue = res.data[0].main_cycle
               // this.getRepairSelectScanDeviceQrCodeItem(res.data[0].code, res.data[0].eapmai_code)
               this.getRepairScanDeviceTemp(res.data[0].code)
            } else if (res.code === '200' && res.data[0].eapmai_code === null) {
               uni.$u.toast('当前设备未设置点检标准绑定点检项目!')
               // this.selectValueBZ = ''
               // this.centerContent = []
               // this.$forceUpdate()
            }
            // else if (res.code === '200') {
            //    uni.$u.toast('当前设备未设置点检标准绑定点检项目!')
            //    this.$forceUpdate()
            // }
         },
         // 获取保养标准
         async getRepairScanDeviceTemp(eqpcode) {
            const res = await RepairScanDeviceTemp({
               eqpcode
            })
            this.selectRangeBZ = res.data.map(({
               code,
               name
            }) => ({
               text: name,
               value: code
            }))
            this.selectValueBZ = this.selectRangeBZ[0].value
            this.getRepairSelectScanDeviceQrCodeItem(eqpcode, this.selectValueBZ)
         },
         // 获取保养项目内容
         async getRepairSelectScanDeviceQrCodeItem(eqpcode, repartempcode) {
            const data = {
               eqpcode,
               repartempcode
            }
            const res = await RepairSelectScanDeviceQrCodeItem(data)
            if (res.code === '200') {
               this.centerContent = res.data
               this.centerContent.forEach(item => {
                  item.inputValue = ''
                  item.isDisabled = item.isscan === 'Y'
                  item.isOK = item.isscan !== 'Y' ? 'OK' : ''
               })
               if (this.centerContent.every(r => r.isOK === 'OK')) {
                  this.resultValue = 'OK'
               }
               if (this.centerContent.some(r => r.isOK === 'NG')) {
                  this.resultValue = 'NG'
               }
               if (this.centerContent.some(r => r.isOK === '')) {
                  this.resultValue = ''
               }
               this.radioValue = eqpcode
               this.selectValue = this.centerContent[0].main_cycle
               this.$forceUpdate()
            } else if (res.code === '300') {
               this.selectValueBZ = ''
               this.centerContent = []
               this.$forceUpdate()
            }
         },
         // 单选按钮点击
         groupChange(val) {
            this.radioValue = val
            this.$forceUpdate()
            // this.getRepairSelectScanDeviceQrCodeItem(val, this.topContent.find(i => i.code === val).eapmai_code)
            this.getRepairScanDeviceTemp(val)
         },
         // 部位正常 异常按钮点击
         bwClick(item, val) {
            item.isOK = val
            if (this.centerContent.every(item => item.isOK !== '')) {
               if (this.centerContent.every(item => item.isOK === 'OK')) {
                  this.resultValue = 'OK'
               } else {
                  this.resultValue = 'NG'
               }
            }
            this.$forceUpdate() //强制视图更新
         },
         // 点检结果点击
         resultClick(val) {
            this.resultValue = val
            this.$forceUpdate() //强制视图更新
         },
         // 确认提交按钮
         async submit() {
            const children = []
            this.centerContent.forEach(item => {
               children.push({
                  seq: item.seq,
                  itemcode: item.code,
                  cycle: item.main_cycle,
                  value: item.inputValue,
                  result: item.isOK
               })
            })
            const data = {
               code: this.topContent.find(item => item.code === this.radioValue).code,
               name: this.topContent.find(item => item.code === this.radioValue).name,
               // standcode: this.topContent.find(item => item.code === this.radioValue).eapmai_code,
               standcode: this.selectValueBZ,
               result: this.resultValue,
               children: children
            }
            // console.log(data)
            this.isDisabledSubmitButton = true
            const res = await AppDeviceRepairSave(data, uni.getStorageSync("username"), this.selectValue)
            if (res.code === '200') {
               uni.$u.toast('提交成功!')
               this.isDisabledSubmitButton = false
               this.topContent.forEach((item, index) => {
                  if (item.code === this.radioValue) {
                     this.topContent.splice(index, 1)
                  }
               })
               this.radioValue = this.topContent[0].code
               if (this.radioValue.toString().length > 0) {
                  this.getRepairScanDeviceTemp(this.radioValue)
               }
            }
         },
      }
   }
</script>
@@ -477,4 +174,34 @@
   ::v-deep .uicon-arrow-left>span {
      display: block;
   }
   .u-input--square {
      margin: 20rpx 10rpx;
      border-radius: 40rpx;
      background-color: #fff;
      border: 1px solid #c8c8c8;
   }
   ::v-deep .u-alert__text--primary--light {
      margin-bottom: 0;
      font-size: 32rpx !important;
   }
   .radioGroupClass {
      display: flex;
      flex-direction: column;
      background-color: #fff;
      overflow-y: auto;
      max-height: 1040rpx;
      margin-top: 20rpx;
   }
   ::v-deep .u-radio-label--right {
      height: 90rpx;
      line-height: 90rpx;
      width: 92%;
      margin-left: 4%;
      // padding: 0 50rpx;
   }
</style>