linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
subPackage/workbench/views/workLog.vue
@@ -1,8 +1,18 @@
<template>
   <view>
      <view class="content bgc-ff">
         <view class="top item flex j-c-s-b a-i-c" @click="onScan()">
            <view class="flex a-i-c">
               <u-icon name="/static/icon/nav-05.png" width="90rpx" height="90rpx"></u-icon>
               <text class="f-28 ml-10">扫码获取信息</text>
            </view>
            <u-icon name="arrow-right" size="20"></u-icon>
         </view>
         <u-form labelPosition="left" :model="info" :rules="rules" ref="form" labelWidth="90"
            :labelStyle="{fontSize:'28rpx'}">
            <u-form-item label="走访类型" prop="type" :borderBottom="false" required @click="isShowTypePicker = true">
               <u-input v-model="typeName" disabled disabledColor="#fff" border="none" placeholder="请选择"
                  placeholderClass="f-28 c-99" inputAlign="right"></u-input>
@@ -15,13 +25,14 @@
               <u-icon slot="right" name="arrow-right"></u-icon>
            </u-form-item>
            <u-form-item label="被访人姓名" prop="name" :borderBottom="false" required @click="isShowPopup = true">
            <u-form-item label="被访人姓名" prop="householdId" :borderBottom="false" required
               @click="isShowPopup = true">
               <u-input v-model="selectedHousehold.name" disabled disabledColor="#fff" border="none"
                  placeholder="请选择" placeholderClass="f-28 c-99" inputAlign="right"></u-input>
               <u-icon slot="right" name="arrow-right"></u-icon>
            </u-form-item>
            <u-form-item label="手机号" borderBottom required v-if="info.householdId">
               <u-input v-model="selectedHousehold.phoneNumber" border="none" disabled disabledColor="#f5f5f5"
               <u-input v-model="selectedHousehold.phoneNumber" border="none" disabled disabledColor="#ffffff"
                  placeholderClass="f-28 c-99" inputAlign="right"></u-input>
            </u-form-item>
            <u-form-item label="走访地址" borderBottom required v-if="info.householdId">
@@ -39,10 +50,12 @@
               <u-input v-model="info.phone" border="none" placeholder="请输入手机号" placeholderClass="f-28 c-99"
                  inputAlign="right"></u-input>
            </u-form-item> -->
            <u-form-item label="内容" borderBottom required>
               <u-input type="textarea" v-model="info.context" border="none" placeholderClass="f-28 c-99"
            <u-form-item label="内容" borderBottom required prop="context">
               <!-- <u-input type="textarea" v-model="info.context" border="none" placeholderClass="f-28 c-99"
                  inputAlign="right" placeholder="请输入内容">
               </u-input>
               </u-input> -->
               <u--textarea v-model="info.context" border="none" placeholderClass="f-28 c-99" inputAlign="right"
                  placeholder="请输入内容"></u--textarea>
            </u-form-item>
            <u-form-item label="走访时间" prop="workTime" :borderBottom="false" required @click="showSelectDate = true">
               <u-input v-model="info.workTime" disabled disabledColor="#ffffff" border="none" placeholder="请选择"
@@ -72,13 +85,21 @@
      <u-datetime-picker ref="datetimePicker" :show="showSelectDate" v-model="workTime" mode="datetime"
         :formatter="formatter" @confirm="confirmDate" @cancel="showSelectDate = false"></u-datetime-picker>
      <u-picker :show="isShowTypePicker" :columns="typeList" :defaultIndex="typeIndex"
         @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" :text="isEdit?'保存':'提交'" />
      <u-popup :show="isShowPopup" mode="bottom" :round="10" closeable="true" @close="isShowPopup = false">
      <u-picker :show="isShowLabelPicker" ref="uPicker" @change="changeHandler" :columns="labelList"
         :defaultIndex="labelIndex" @cancel="isShowLabelPicker = false" @confirm="confirmLabelType()"
         keyName="name"></u-picker>
      <!-- <footer-btn @click="submitInfo" :text="isEdit?'保存':'提交'" /> -->
      <button class="submit-btn" @click="submitInfo">{{isEdit?"保存":"提交"}}</button>
      <button class="list-btn" @click="navToRecord">走访记录</button>
      <u-popup :show="isShowPopup" mode="bottom" :round="10" :closeable="true" @close="isShowPopup = false">
         <view class="popup-content">
            <view class="popup-title f-30">
               选择居民
@@ -141,7 +162,11 @@
            info: {
               // name: "",
               // phone: "",
               context: ""
               type: "",
               householdId: "",
               context: "",
               workTime: "",
               personType: ""
            },
            rules: {
               // 'name': {
@@ -157,24 +182,30 @@
               //    trigger: ['blur', 'change']
               // },
               'info.type': {
                  type: 'string',
               type: [{
                  type: 'number',
                  required: true,
                  message: '请选择走访类型',
                  trigger: ['blur', 'change']
               },
               'info.householdId': {
               }],
               // peopleType: [{
               //    type: 'number',
               //    required: true,
               //    message: '请选择重点人群类型',
               //    trigger: ['blur', 'change']
               // }],
               householdId: [{
                  type: 'string',
                  required: true,
                  message: '请选择被访问人',
                  trigger: ['blur', 'change']
               },
               'info.context': {
               }],
               context: [{
                  type: 'string',
                  required: true,
                  message: '请输入工作内容',
                  trigger: ['blur', 'change']
               },
               }],
            },
            showSelectDate: false,
            workTime: Number(new Date()),
@@ -186,6 +217,7 @@
            isShowTypePicker: false,
            isShowLabelPicker: false,
            labelList: [],
            labelListTwo: [],
            labelIndex: [0],
            labelName: "",
            keyword: "",
@@ -194,7 +226,8 @@
            isShowPopup: false,
            address: "",
            isEdit: false,
            id: ""
            id: "",
            houseCode: ''
         }
      },
      // onLoad() {
@@ -216,7 +249,39 @@
         }
      },
      onReady() {
         //onReady 为uni-app支持的生命周期之一
         this.$refs.form.setRules(this.rules)
      },
      methods: {
         onScan() {
            uni.scanCode({
               success: (res) => {
                  let obj = this.getUrlParams(res.result);
                  this.getHouseType(obj.stdId);
               }
            })
         },
         getUrlParams(url) {
            let urlStr = url.split('?')[1]
            let obj = {};
            let paramsArr = urlStr.split('&')
            for (let i = 0, len = paramsArr.length; i < len; i++) {
               let arr = paramsArr[i].split('=')
               obj[arr[0]] = arr[1];
            }
            return obj
         },
         getHouseType(code) {
            this.houseCode = code
            this.getHouseholdList();
         },
         getDetail(id) {
            getWorkLogDetail({
@@ -230,17 +295,21 @@
                  if (data.workTime) {
                     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.$getIndex(this.labelList[0], data.personType, "id", "name").index;
                  this.labelName = this.$getIndex(this.labelList[0], data.personType, "id", "name").name;
                  this.getHouseholdList();
                  // 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;
                  // console.log(typeof data.personType)
                  // this.labelIndex = this.$getIndex(this.labelList[0], data.personType, "id", "name").index;
                  // this.labelName = this.$getIndex(this.labelList[0], data.personType, "id", "name").name;
                  this.labelName = data.labelName
                  this.getHousehold(data.householdId);
                  this.form.images = this.$setImageUrl(data.url, 2);
                  this.info.id = data.id;
                  for (let i in this.info) {
                     this.$set(this.info, i, data[i])
                  }
               }
            })
         },
@@ -256,9 +325,12 @@
         getLabelList() {
            getLabelListByParentId({
               parentId: 100
               parentId: 1000
            }).then(res => {
               this.labelList = [res.data];
               // this.labelList = [res.data];
               // this.labelListTwo = res.data
               this.labelList.push(res.data)
               this.labelList.push(res.data[0].children)
            })
         },
@@ -269,16 +341,39 @@
               console.log(res);
               this.address = res.data.currentAddress;
               this.selectedHousehold = res.data;
               this.houseCode = res.data.houseCode
               this.getHouseholdList();
            })
         },
         getHouseholdList() {
            if (!this.houseCode) {
               return
            }
            fetchHousehold({
               labelId: this.info.personType,
               searchKey: this.keyword,
               houseCode: this.houseCode,
               limit: 20
            }).then(res => {
               this.houseHoldList = res.data;
               for (var i = 0; i < this.houseHoldList.length; i++) {
                  if (this.houseHoldList[i].address === null) {
                     this.houseHoldList[i].address = ''
                  }
                  if (this.houseHoldList[i].aoiName === null) {
                     this.houseHoldList[i].aoiName = ''
                  }
                  if (this.houseHoldList[i].neiName === null) {
                     this.houseHoldList[i].neiName = ''
                  }
                  if (this.houseHoldList[i].townStreetName === null) {
                     this.houseHoldList[i].townStreetName = ''
                  }
               }
            })
         },
@@ -309,13 +404,57 @@
         },
         //选择重点人群类型
         // confirmLabelType(e) {
         //    this.labelIndex = e.indexs;
         //    this.info.personType = e.value[0].id;
         //    this.labelName = e.value[0].name;
         //    this.isShowLabelPicker = false;
         //    this.getHouseholdList();
         // },
         // 回调参数为包含columnIndex、value、values
         confirmLabelType(e) {
            console.log('confirm', e)
            // this.show = false
            this.labelIndex = e.indexs;
            this.info.personType = e.value[0].id;
            this.labelName = e.value[0].name;
            if (e.value[2]) {
               this.info.personType = e.value[2].id;
               this.labelName = e.value[2].name;
            } else {
               this.info.personType = e.value[1].id;
               this.labelName = e.value[1].name;
            }
            this.isShowLabelPicker = false;
            this.getHouseholdList();
         },
         changeHandler(e) {
            const {
               columnIndex,
               value,
               values, // values为当前变化列的数组内容
               index,
               // 微信小程序无法将picker实例传出来,只能通过ref操作
               picker = this.$refs.uPicker
            } = e
            // 当第一列值发生变化时,变化第二列(后一列)对应的选项
            if (columnIndex === 0) {
               console.log("****************", e)
               // picker为选择器this实例,变化第二列对应的选项
               picker.setColumnValues(1, value[0].children)
               // picker为选择器this实例,变化第二列对应的选项
               if (value[0].hasChildren) {
                  picker.setColumnValues(2, value[0].children[0].children)
               }
            }
            if (columnIndex === 1) {
               console.log("*******1*********", e)
               // picker为选择器this实例,变化第二列对应的选项
               if (value[1].hasChildren) {
                  picker.setColumnValues(2, value[1].children)
               }
            }
         },
         //搜索住户
         searchHousehold() {
@@ -331,7 +470,8 @@
         selectHousehold(item) {
            this.selectedHousehold = item;
            this.info.householdId = item.id;
            this.address = `${item.townStreetName}${item.neiName}${item.aoiName}${item.address || ""}`
            this.address =
               `${item.townStreetName}${item.neiName}${item.aoiName}${item.address}`
            this.isShowPopup = false;
         },
@@ -354,6 +494,10 @@
            this.$refs.form.validate().then(valid => {
               this.checkImages();
               this.info.status = 2;
               if (this.info.type == 2 && !this.info.personType) {
                  this.$showTips("请选择重点人群类型")
                  return
               }
               if (this.isEdit) {
                  this.updateWorkLogRequest()
               } else {
@@ -395,6 +539,13 @@
            uni.navigateBack();
         },
         navToRecord() {
            uni.navigateTo({
               url: "/subPackage/workLog/list"
            })
         }
      }
   }
</script>
@@ -407,7 +558,15 @@
   .content {
      margin: 20rpx 30rpx;
      padding: 0 30rpx;
   }
   .top {
      padding: 20rpx !important;
   }
   .row {
      padding: 20rpx 0;
@@ -489,4 +648,26 @@
      font-size: 28rpx;
      padding: 2rpx 10rpx;
   }
   .submit-btn {
      width: 690rpx;
      height: 78rpx;
      line-height: 78rpx;
      background: linear-gradient(163deg, #01BDFC 0%, #017BFC 100%);
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      font-size: 32rpx;
      color: #fff;
      margin-top: 50rpx;
   }
   .list-btn {
      width: 690rpx;
      height: 78rpx;
      line-height: 78rpx;
      background: linear-gradient(163deg, #c7d7dc 0%, #c3cdd8 100%);
      border-radius: 8rpx 8rpx 8rpx 8rpx;
      font-size: 32rpx;
      color: #fff;
      margin-top: 50rpx;
   }
</style>