<template>
  <div>
    <el-form v-show="sMessageForm" label-width="120px" label-position="right" ref="messageForm" style="width: 90%;margin: 0 auto">
      <el-form-item label="施工单消息">
        <el-input type="textarea" v-model="sMessage"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm('messageForm')">重 置</el-button>
        <el-button type="primary" @click="addMemo">增 加</el-button>
      </el-form-item>
    </el-form>
    <div>
      <el-card shadow="always" v-if="messageList.length>0" style="width: 95%;margin: 0 auto">
        <el-timeline style="width: 90%;margin-top: 20px">
          <el-timeline-item v-for="message in messageList" :key="message.id" :timestamp="timeString ? (message.createTime).substring(0,19):message.createMan+'  '+(message.createTime).substring(0,19)" placement="top" >
            <el-card class="stepList">
              <p>{{message.messageStr}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </el-card>
      <div v-else>
        <span style="display: block;width: 100%;line-height: 34px;text-align: center;color: #7c7c7c">暂无施工单消息</span>
      </div>
    </div>
  </div>
</template>

<script>
import {
  addBreedMessage,
  getBreedMessageList,
  getBillMessageListByPrintBill
} from '@/api/feedBack/feedBack.js'
export default {
  name: 'OrderMessage',
  data() {
    return {
      sMessageForm:true,
      idPrintBill:"",
      idPrint:"",
      idOrder: '',
      sMessage: '',
      messageList: [],
      timeString: '',
      printBillId:""
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    getList() {
      var _that = this
      var data = {
        'idBreed': _that.idPrint
      }
      getBreedMessageList(data).then(response => {
        // console.log(response)
        _that.messageList = response.data
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    getBillMessageListByPrintBill(){
      var _that = this
      var data = {
        'idPrintBill': _that.printBillId
      }
      getBillMessageListByPrintBill(data).then(response => {
        // console.log(response)
        _that.messageList = response.data
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    addMemo() {
      var _that = this
      if (_that.sMessage == '' || _that.sMessage == null) {
        _that.$message.error('消息不能为空')
        return
      }
      var data = {
        'idBreed': _that.idPrint,
        'idPrintBill': _that.idPrintBill,
        'sMessage': _that.sMessage
      }
      addBreedMessage(data).then(response => {
        console.log(response)
        if (response.httpCode == 200) {
          _that.$message({
            message: '增加成功',
            type: 'success'
          })
          _that.$emit('handleAddBreed', _that.sMessage)
          _that.sMessage = '';
          _that.getList();
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    }
  }
}
</script>

<style scoped>

</style>
