Lou
2024-01-15 1e6d7c100df5ed8c5507188158a741ee584cce5c
subPackage/workbench/views/workLog.vue
@@ -76,7 +76,7 @@
         @cancel="isShowTypePicker = false" @confirm="confirmType()" keyName="dictValue"></u-picker>
      <u-picker :show="isShowLabelPicker" :columns="labelList" :defaultIndex="labelIndex"
         @cancel="isShowLabelPicker = false" @confirm="confirmLabelType()" keyName="name"></u-picker>
      <footer-btn @click="submitInfo" />
      <footer-btn @click="submitInfo" :text="isEdit?'保存':'提交'" />
      <u-popup :show="isShowPopup" mode="bottom" :round="10" closeable="true" @close="isShowPopup = false">
         <view class="popup-content">
@@ -113,11 +113,14 @@
<script>
   import {
      addWorkLog
      addWorkLog,
      getWorkLogDetail,
      updateWorkLog
   } from "@/api/workLog/workLog.js"
   import uploadMixin from "@/mixin/uploadMixin";
   import {
      bizDictionary
      bizDictionary,
      update
   } from '@/api/system/dict.js'
   import {
      getLabelListByParentId
@@ -125,6 +128,9 @@
   import {
      fetchHousehold
   } from "@/api/house/household.js"
   import {
      getHouseholdDetail
   } from '@/api/house/household.js'
   export default {
      mixins: [uploadMixin],
      data() {
@@ -133,8 +139,8 @@
               images: []
            },
            info: {
               name: "",
               phone: "",
               // name: "",
               // phone: "",
               context: ""
            },
            rules: {
@@ -186,7 +192,9 @@
            houseHoldList: [],
            selectedHousehold: {},
            isShowPopup: false,
            address: ""
            address: "",
            isEdit: false,
            id: ""
         }
      },
      // onLoad() {
@@ -196,13 +204,65 @@
      // },
      onLoad() {
         this.getTypeList();
         this.getLabelLit();
      async onLoad(option) {
         await this.getTypeList();
         await this.getLabelLit();
         if (option.id) {
            this.isEdit = true;
            this.id = option.id;
            this.getDetail(option.id)
         }
      },
      methods: {
         getDetail(id) {
            getWorkLogDetail({
               id
            }).then(res => {
               console.log(res);
               if (res.code == 200) {
                  let data = res.data
                  this.typeIndex = this.getTypeValue(data.type).index;
                  this.typeName = this.getTypeValue(data.type).name;
                  this.workTime = Number(new Date(data.workTime))
                  this.info.type = data.type;
                  this.info.workTime = data.workTime;
                  this.info.context = data.context;
                  this.info.householdId = data.householdId;
                  this.info.personType = data.personType;
                  this.labelIndex = this.getLabelValue(data.personType).index;
                  this.labelName = this.getLabelValue(data.personType).name;
                  this.getHouseholdList();
                  this.getHousehold(data.householdId);
                  this.form.images = this.$setImageUrl(data.url, 2);
               }
            })
         },
         getTypeValue(value) {
            for (let i = 0, ii = this.typeList[0].length; i < ii; i++) {
               if (value == this.typeList[0][i].dictKey) {
                  return {
                     index: [i],
                     name: this.typeList[0][i].dictValue
                  }
               }
            }
         },
         getLabelValue(value) {
            for (let i = 0, ii = this.labelList[0].length; i < ii; i++) {
               if (value == this.labelList[0][i].id) {
                  return {
                     index: [i],
                     name: this.labelList[0][i].name
                  }
               }
            }
         },
         getTypeList() {
            bizDictionary({
@@ -218,6 +278,16 @@
               parentId: 100
            }).then(res => {
               this.labelList = [res.data];
            })
         },
         getHousehold(id) {
            getHouseholdDetail({
               id
            }).then(res => {
               console.log(res);
               this.address = res.data.currentAddress;
               this.selectedHousehold = res.data;
            })
         },
@@ -302,19 +372,44 @@
         submitInfo() {
            this.$refs.form.validate().then(valid => {
               this.checkImages();
               addWorkLog(this.info).then(res => {
                  uni.showToast({
                     icon: 'success',
                     title: '提交成功',
                     success() {
                        setTimeout(() => {
                           uni.navigateBack()
                        }, 1000)
                     }
                  })
               this.info.status = 2;
               if (this.isEdit) {
                  this.updateWorkLogRequest()
               } else {
                  this.addWorkLogRequest()
               }
            })
         },
         addWorkLogRequest() {
            addWorkLog(this.info).then(res => {
               uni.showToast({
                  icon: 'success',
                  title: '提交成功',
                  success() {
                     setTimeout(() => {
                        uni.navigateBack()
                     }, 1000)
                  }
               })
            })
         },
         updateWorkLogRequest() {
            updateWorkLog(this.info).then(res => {
               uni.showToast({
                  icon: 'success',
                  title: '提交成功',
                  success() {
                     setTimeout(() => {
                        uni.navigateBack()
                     }, 1000)
                  }
               })
            })
         }
      }
   }
</script>