Newer
Older
GDT_FRONT / src / views / property / editPropertyScore.vue
[wangxitong] on 21 Jun 2022 9 KB first commit
<template>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" append-to-body width="1020px">
    <el-form ref="dataForm" :rules="rules" :model="form" label-offDate="right" label-width="250px">
      <el-row :gutter="20">
        <el-col :offset="2" :span="20" >
          <el-form-item label="考评人" prop="name">
            <el-input v-model.trim="form.name" :disabled="isEditMode" type="text" placeholder="必填" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :offset="2" :span="20" >
          <el-form-item label="物业公司" prop="property">
            <el-select v-model="form.property" placeholder="必填" :disabled="isEditMode">
              <el-option
                v-for="item in typeList"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :offset="2" :span="20" >
          <el-form-item label="考评时间" prop="startTime">
            <el-date-picker
              style="width: 100%"
              v-model="timeRange"
              :disabled="isEditMode"
              type="datetimerange"
              range-separator="至"
              value-format="yyyy-MM-dd hh:mm:ss"
              start-placeholder="起始时间"
              end-placeholder="终止时间"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-for="(item) in scoreList" :key="item.code">
        <el-col :offset="2" :span="20" >
          <el-form-item :label="item.name" :prop="'score.'+`${item.code}`">
            <el-rate
              style="margin-top: 10px"
              v-if="form.score[item.code]!==undefined"
              v-model="form.score[item.code]"
              :disabled="isEditMode"
              allow-half
              show-score
              text-color="#ff9900"
              score-template="{value}分"
              @change="changeRage"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :offset="2" :span="20" >
          <el-form-item label="详细评价">
            <el-input v-model.trim="form.evaluate" :disabled="isEditMode" :rows="3" type="textarea" placeholder="请输入对物业公司评价" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" v-if="!isEditMode">
      <el-button :loading="btnLoading" type="primary" @click="saveData">
        保存
      </el-button>
      <el-button @click="cancel">
        取消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import {  getServiceListPage, addPropertyScore, updatePropertyScore } from '@/api/property'
import {  staffSearch } from '@/api/person'
import {  getDictByCode } from '@/api/system/dict'

export default {
  name: 'EditPropertyScore',
  data() {
    return {
      timeRange: [], // 时间范围
      isShow: true,
      scoreList: [],
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型:create,update
      isEditMode: true,
      form: {
        id:'',
        name:'',
        property: '',
        startTime: '',
        endTime: '',
        evaluate:'',
        score:{}
      }, // 表单
      typeList:[],
      areaList:[],
      textMap: {
        update: '编辑物业考评',
        create: '新增物业考评',
        detail:  '物业考评详情'
      }, // 表头显示标题
      btnLoading: false, // 保存按钮的加载中状态
      rules: {
        name : [{ required: true, message: '考评人不能为空', trigger: ['blur', 'change'] }],
        property : [{ required: true, message: '物业公司不能为空', trigger: ['blur', 'change'] }],
        startTime: [{ required: true, message: '考评时间不能为空', trigger: ['blur', 'change'] }],
      } // 前端校验规则
    }
  },
  computed: {
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.form.startTime = val[0]
        this.form.endTime = val[1]
      } else {
        this.form.startTime = ''
        this.form.endTime = ''
      }
    }
  },
  created() {
    this.fetchTypeList()
  },
  methods: {
    /**
     * 改变分数后,迫使 Vue 实例重新渲染
     */
    changeRage() {
      this.$forceUpdate();
    },
    fetchTypeList(){
      //物业服务
      // const params = {
      //   keywords:'',
      //   offset: 1,
      //   limit: 20
      // }
      // getServiceListPage(params).then(response => {
      //   if (response.code === 200) {
      //     this.scoreList= response.data.rows
      // })
      this.scoreList = [
        {id:'', name: '对公众环境卫生进行清洁工作', code : 'wy900001', money: '1', remarks:''},
        {id:'', name: '公共设施设备的维护、保养和维修', code : 'wy900002', money: '2', remarks:''},
        {id:'', name: '物业管理范围内的园区治安管理', code : 'wy900003', money: '1', remarks:''},
        {id:'', name: '物业管理范围内的急抢修处理与管理', code : 'wy900004', money: '2', remarks:''},
        {id:'', name: '物业管理范围内的生态环境管理', code : 'wy900005', money: '1', remarks:''},
      ]
      this.scoreList.forEach((value, index) => {
        if(value.code){
          this.rules['score.'+ value.code] =
            [{ required: true, message: value.name + '不能为空', trigger: ['blur', 'change'] }]
            this.form.score[value.code] = 0
        }
      })
      // 物业公司
      getDictByCode('property').then(response => {
        if (response.code === 200) {
          this.typeList = response.data
        }
      })
    },
    // 初始化对话框
    initDialog: function(dialogStatus, row = null) {
      this.dialogStatus = dialogStatus
      this.dialogFormVisible = true
      this.btnLoading = false
      if (dialogStatus === 'create') { // 如果是新增,清除验证
        this.isEditMode = false
        this.resetForm()
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      } else if (dialogStatus === 'update') { // 如果是修改,将row中数据填写到输入框中
        this.form.id = row.id
        this.form.name = row.name
        this.form.property = row.property
        this.form.startTime = row.startTime
        this.form.endTime = row.endTime
        this.form.evaluate = row.evaluate
        for(var item in this.form.score){
          this.form.score[item] = row.score[item]?row.score[item]:0
        }
        this.timeRange = [this.form.startTime,this.form.endTime]
        this.isEditMode = false
      }else if (dialogStatus === 'detail') {
        this.form.id = row.id
        this.form.name = row.name
        this.form.property = row.property
        this.form.startTime = row.startTime
        this.form.endTime = row.endTime
        this.form.evaluate = row.evaluate
        for(var item in this.form.score){
          this.form.score[item] = row.score[item]?row.score[item]:0
        }
        this.timeRange = [this.form.startTime,this.form.endTime]
        this.isEditMode = true
      }
    },
    // 重置表单
    resetForm() {
      this.form.id = ''
      this.form.name = ''
      this.form.property = ''
      this.form.startTime = ''
      this.form.endTime = ''
      this.form.evaluate = ''
      for(var item in this.form.score){
        this.form.score[item] = 0
      }
      this.timeRange = []
    },
    // 保存数据
    saveData: function() {
      if (this.dialogStatus === 'update') {
        this.updateData()
      } else if (this.dialogStatus === 'create') {
        this.createData()
      }
    },
    // 新增数据
    createData: function() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.btnLoading = true
          addPropertyScore(this.form).then(response => {
            if (response.code === 200) {
              this.$confirm('新增成功,是否继续新增?', '提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'info'
              }).then(() => { // 选是
                this.resetForm()
                this.btnLoading = false
                this.$nextTick(() => {
                  this.$refs['dataForm'].clearValidate()
                })
              }).catch(() => { // 选否,关闭窗口,并刷新页面
                this.$emit('watchChild')
                this.dialogFormVisible = false
              })
            }
          }).catch(_ => { // 异常情况,loading置为false
            this.btnLoading = false
          })
        }
      })
    },
    // 修改数据
    updateData: function() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.btnLoading = true
          updatePropertyScore(this.form).then(response => {
            if (response.code === 200) {
              this.$message.success('修改成功')
              this.$refs['dataForm'].clearValidate()
              this.$emit('watchChild')
              this.dialogFormVisible = false
            }
          }).catch(_ => { // 异常情况,loading置为false
            this.btnLoading = false
          })
        }
      })
    },
    cancel: function() {
      this.dialogFormVisible = false
      // this.$emit('watchChild')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

  .el-dialog{
    width:700px
  }
  .el-select{
    width: 100%;
  }
</style>