handleDialog.vue 10.5 KB
<!-- 预警处理 -->
<template>
  <baseDialog :dialog-config="dialogConfig"
              :is-show.sync="dialogShow"
              :config="config"
              class="accountDailog"
              @handleClick="handleAddConfirm">
    <div class="add-dialog">
      <glsx-combi-form class="edit-form-container"
                       ref="editFormRef"
                       label-width="150px"
                       default-width="400px"
                       :form-ref="handleFormRef"
                       :form-obj="infoForm"
                       :form-data="editFormData"
                       :form-rules="formRules">
        <div slot="followStatusHtml"
             slot-scope="scope"
             style="width:400px">
          <el-radio-group v-model="infoForm.followStatus"
                          @change="followStatusChange">
            <el-radio v-for="item in baseData.followStatusOptions"
                      :label="item.confId">{{ item.confValue }}</el-radio>
          </el-radio-group>
        </div>
        <div slot="nextFollowerTimeHtml"
             slot-scope="scope"
             style="width:400px">
          <el-date-picker v-model="infoForm.nextFollowerTime"
                          type="datetime"
                          format="yyyy-MM-dd HH:mm"
                          value-format="yyyy-MM-dd HH:mm"
                          popper-class="no-atTheMoment"
                          placeholder="选择日期时间"
                          :picker-options="pickerOption['afterPickerOptions_timeChoose']">
          </el-date-picker>
        </div>
      </glsx-combi-form>
      <div class="div-title">跟进记录</div>
      <div class="d2-container-content">
        <d2-table ref="recordTable"
                  :has-page="false"
                  :table-data="tableData"
                  :search-form="searchFormSearch"
                  :table-params="tableParams">
        </d2-table>
      </div>
    </div>
  </baseDialog>
</template>

<script>
import { saveFollowRecord, findByMsgId } from '@api/earlyWarningManager'
import { Util, deepClone } from '@/common/util'
import { findMerchantStaffList } from '@api/index'
import { afterPickerOptions_timeChoose } from '@/common/format'
export default {
  name: 'HandleDialog',
  data() {
    return {
      config: {
        appendToBody: true,
        isShowFooter: true,
        confirm_name: '确定',
        cancel_name: '取消'
      },
      pickerOption: {
        afterPickerOptions_timeChoose: afterPickerOptions_timeChoose
      },
      userInfo: this.$store.state.d2admin.user.info,
      infoForm: {
        followStatus: 1,
        followNotes: '',
        nextFollowerId: '',
        nextFollowerTime: ''
      },
      dialogConfig: {
        title: '预警处理',
        // width: '700px'
        width: '1080px'
      },
      handleFormRef: 'handleFormRef',
      formRules: {
        followNotes: [{ required: true, message: '请输入跟进内容', trigger: 'blur' }],
        nextFollowerId: [{ required: true, message: '请选择下次跟进人', trigger: 'change' }]
      },
      editFormData: [{
        label: '处理结果',
        name: 'followStatus',
        isHide: false,
        addHtml: 'followStatusHtml',
        rules: [{ required: true, message: '请选择处理结果', trigger: 'change' }]
      }, {
        label: '本次跟进内容',
        name: 'followNotes',
        type: 'input',
        maxlength: 200,
        inputType: 'textarea',
        showLimit: true,
        rows: 4
      }, {
        label: '下次跟进人',
        name: 'nextFollowerId',
        type: 'select',
        isClear: true,
        isHide: false,
        optionList: [],
        optionId: 'userId',
        optionLabel: 'userName',
        optionsName: 'followUpPersonOpt'
      }, {
        label: '下次跟进时间',
        name: 'nextFollowerTime',
        isHide: true,
        addHtml: 'nextFollowerTimeHtml',
        rules: [{ required: true, message: '请选择下次跟进时间', trigger: 'change' }]
      }],

      searchForm: {
        id: ''
      },
      searchFormSearch: {},
      // getListApi: findByMsgId,
      tableData: [],
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: false,
        tableColumns: [{
          label: '处理结果',
          prop: 'followStatusName',
          width: '100',
          formatter: (cellValue) => {
            return cellValue.followStatusName ? cellValue.followStatusName : '--'
          },
          className: (cellValue) => {
            return {
              1: 'yellowSpot',
              2: 'greenSpot',
              3: 'ashSpot',
              0: 'ashSpot'
            }[cellValue.followStatus]
          }
        }, {
          label: '跟进内容',
          prop: 'followNotes',
          width: '250px'
        }, {
          label: '跟进人',
          prop: 'followerName'
        }, {
          label: '跟进时间',
          prop: 'createdTime',
          width: '150',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.createdTime, 'YYYY-MM-DD HH:mm:ss')
          }
        }, {
          label: '下次跟进人',
          prop: 'nextFollowerName'
        }, {
          label: '下次跟进时间',
          prop: 'nextFollowerTime',
          width: '150',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.nextFollowerTime, 'YYYY-MM-DD HH:mm')
          }
        }]
      },
      baseData: {
        followStatusOptions: [
          { confId: 1, confValue: "待处理" },
          { confId: 2, confValue: "预约处理" },
          { confId: 3, confValue: "已完成" }
        ],
        followUpPersonOpt: []
      }
    }
  },

  props: {
    visible: {
      type: Boolean,
      default: false
    },
    paramsObj: {
      type: Object,
      default: {}
    }
  },
  watch: {
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'visible' })
      }
    }
  },

  mounted() {
    console.log('this.paramsObj', this.paramsObj)
    if (this.paramsObj.status) {
      this.infoForm.followStatus = this.paramsObj.status
      this.followStatusChange(this.infoForm.followStatus)
    }
    this.findMerchantStaffList()
    this.getList()
    this.getOptionsList('editFormData', false)
  },

  methods: {
    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },

    showOrHideAttr(formName, label, isHide) {
      const idx = this[formName].findIndex(item => item.label == label)
      console.log('idx', idx)
      console.log('this[formName][idx].isHide', this[formName][idx].isHide)
      this[formName][idx].isHide = isHide
    },

    // 获取全部员工 过滤出服务商负责人可选数据
    findMerchantStaffList() {
      return new Promise((resolve, reject) => {
        findMerchantStaffList({ merchantId: -1 }).then(res => {
          // 服务商负责人(根据角色名过滤)
          const arr = []
          res?.map(val => {
            arr.push({
              userId: val.uuid,
              userName: val.staffName,
              userPhone: val.staffPhone
            })
          })
          this.baseData.followUpPersonOpt = arr
          this.getOptionsList('editFormData', false)
          resolve()
        })
      })
    },

    followStatusChange(val) {
      console.log('val', val)
      if (val == 1) {
        this.showOrHideAttr('editFormData', '下次跟进人', false)
        this.showOrHideAttr('editFormData', '下次跟进时间', true)
      } else if (val == 2) {
        this.showOrHideAttr('editFormData', '下次跟进人', false)
        this.showOrHideAttr('editFormData', '下次跟进时间', false)
      } else {
        this.showOrHideAttr('editFormData', '下次跟进人', true)
        this.showOrHideAttr('editFormData', '下次跟进时间', true)
      }
    },

    handleAddConfirm() {
      this.$refs.editFormRef.$refs[this.handleFormRef].validate(valid => {
        if (valid) {
          var params = deepClone(this.infoForm)
          params.msgId = this.paramsObj.id
          if (params.followStatus !== 3) {
            var personInfo = this.baseData.followUpPersonOpt.find(item => item.userId == params.nextFollowerId)
            params.nextFollowerName = personInfo.userName
            params.nextFollowerPhone = personInfo.userPhone
          }
          saveFollowRecord(params).then(res => {
            this.notice.okTips('操作成功')
            this.dialogShow = true
          })
        }
      })
    },

    // 找到在formList的位置,通过name来匹配
    findFormIdx(name) {
      return this.editFormData.findIndex(item => item.name === name)
    },

    getList() {
      var params = { msgId: this.paramsObj.id }
      findByMsgId(params).then(res => {
        this.tableData = res
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.add-dialog {
  margin: 20px 0;
  .div-title {
    width: 1040px;
    height: 30px;
    border-bottom: 1px solid #e5e5e5;
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    margin: 10px 0 20px 0;
  }
}
</style>
<style lang="scss">
.el-picker-panel.no-atTheMoment {
  .el-button--text.el-picker-panel__link-btn {
    display: none;
  }
}
</style>