<!-- 工序列表 -->
<template>
  <div class="fullHeight">
    <div class="searchBox whiteBlock">
      <el-form :inline="true" size="medium" :model="searchForm" ref="searchForm">
        <el-form-item label="工序名称">
          <el-input placeholder="请输入" v-model="searchForm.processName"></el-input>
        </el-form-item>
        <el-button type="primary" size="medium" plain @click="getPointList">查询</el-button>
        <el-button type="warning" size="medium" plain @click="refresh">刷新</el-button>
        <el-button type="primary" size="medium" @click="toAdd">新增</el-button>
      </el-form>
    </div>
    <div class="table_wrap whiteBlock">
      <el-table class="tables" :data="tableData">
        <el-table-column type="index" label="序号" align="center" width="200"></el-table-column>
        <el-table-column prop="processName" label="工序名称" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" align="center"></el-table-column>

        <el-table-column :label="$t('message.personnelPosition.beaconManage.table.operation')" align="center" width="400">
          <template slot-scope="scope">
            <div style="display: flex; justify-content: center">
              <div class="operationText" @click="editBtn(scope.row)" style="margin-right:30px">
                <img src="@/assets/images/icon-edit.png" width="15px" height="15px" />
                <span>编辑</span>
              </div>
              <div @click="toDelete(scope.row)" class="operationText">
                <img src="@/assets/images/icon-delete.png" width="15px" height="15px" />
                <span>删除</span>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagerBox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="$store.state.PAGESIZRS"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        background
      ></el-pagination>
    </div>
    <!-- 新增工序 -->
    <el-dialog :modal-append-to-body="false" :title="cardDialogTitle" :visible.sync="cardDialog" width="667px" @close="close">
      <div class="dialog_content">
        <el-form size="medium" :model="cardForm" ref="cardForm" :rules="cardFormRules" label-width="150px" class="dialogFormBox">
          <el-form-item label="工序名称：" prop="processName">
            <el-input
              :disabled="cardDialogTitle == '详情'"
              v-model="cardForm.processName"
              :placeholder="isAdding ? '请输入' : ''"
            ></el-input>
          </el-form-item>

          <div class="dialog-footer">
            <el-button class="cancleBtn" @click="closeEvent" icon="el-icon-circle-close" size="medium">取消</el-button>
            <el-button v-if="isAdding != false" type="primary" icon="el-icon-circle-check" @click="addCardFn" size="medium">确认</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  beamFieldProcessPage,
  beamFieldProcessAdd,
  beamFieldProcessDelete,
  beamFieldProcessEdit,
} from '@/assets/js/api/smartBeamField.js'
// import QRCode from "qrcodejs2";
export default {
  data() {
    return {
      searchForm: {
        processName: ''
      },
      cardDialogTitle: '',
      tableData: [],
      total: 0,
      pageNo: 1,
      pageSize: 10,
      cardForm: {
        processName: ''
      },
      qrCode: '',
      cardDialog: false,
      projectSn: '',
      cardFormRules: {
        processName: [{ required: true, message: '请输入工序名称', trigger: 'blur' }]
        // addr: [
        //   { required: true, message: "请选择区域", trigger: "blur" },
        // ],
      },
      frequencyType: ['次', '次/日', '次/周', '次/月', '次/年'],
      mapOperateType: 1,
      accountList: [], //检查人员列表
      options: [30, 50, 100, 200, 300],
      map: null,
      locationList: [],
      isAdding: true
    }
  },
  mounted() {
    this.projectSn = this.$store.state.projectSn
    this.getPointList()
  },
  methods: {
    //查看详情
    deilBtn(obj) {
      this.isAdding = false
      this.cardDialogTitle = '详情'
      this.cardDialog = true
      this.cardForm = JSON.parse(JSON.stringify(obj))
    },
    //关键字查询查询
    select(e) {
      console.log('select', e)
      this.placeSearch.setCity(e.poi.adcode)
      this.placeSearch.search(e.poi.name)
    },
    //查看条数
    handleSizeChange(val) {
      this.pageSize = val
      this.getPointList()
    },
    //查看页
    handleCurrentChange(val) {
      this.pageNo = val
      this.getPointList()
    },
    // 查询
    getPointList() {
      let data = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        projectSn: this.projectSn,
        processName: this.searchForm.processName
      }
      beamFieldProcessPage(data).then(res => {
        console.log('----桥梁列表', res)
        this.tableData = res.result.records
        this.total = res.result.total
      })
    },
    // 刷新
    toRefresh() {
      this.getPointList()
    },
    editBtn(obj) {
      console.log('编辑的信息', obj)
      this.cardDialog = true
      this.isAdding = true
      this.cardForm = JSON.parse(JSON.stringify(obj))
      this.cardDialogTitle = '编辑工序'
    },
    // 新增
    toAdd() {
      this.cardDialog = true
      this.isAdding = true
      this.cardDialogTitle = '新建工序'
    },
    // 删除
    toDelete(val) {
      // console.log('删除', val)
      this.$confirm('此操作将永久删除该工序, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let data = {
            id: val.id
          }
          beamFieldProcessDelete(data).then(res => {
            if (res.success) {
              this.getPointList()
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            } else {
              this.$message({
                type: 'error',
                message: res.message
              })
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 新增工序
    addCardFn() {
      this.$refs.cardForm.validate(valid => {
        if (valid) {
          // 新增
          let data = JSON.parse(JSON.stringify(this.cardForm))
          data.projectSn = this.$store.state.projectSn
          if (this.cardDialogTitle == '新建工序') {
            beamFieldProcessAdd(data).then(res => {
              console.log('新增', res)
              if (res.code == 200) {
                this.$message.success('添加成功！')
                this.getPointList()
              }
            })
          } else if (this.cardDialogTitle == '编辑工序') {
            beamFieldProcessEdit(data).then(res => {
              if (res.success) {
                this.$message.success(res.message)
                this.getPointList()
              }
            })
          }
          this.cardDialog = false
        }
      })
    },

    close() {
      this.cardForm = {}
      this.$nextTick(() => {
        this.$refs.cardForm.clearValidate()
      })
    },
    //新增弹框取消
    closeEvent() {
      this.cardDialog = false
      this.$refs.cardForm.resetFields()
      this.cardForm.startTime = ''
      this.cardForm.endTime = ''
    },
    refresh() {
      this.searchForm = {}
      this.getPointList()
    }
  }
}
</script>

<style lang="less" scoped>
.download {
  text-decoration: none;
  color: blue;
}
.smallInput {
  display: inline-block;
  width: 148px !important;
  /deep/.el-input__inner {
    width: 148px;
  }
  /deep/.el-input {
    width: 100% !important;
  }
}
::v-deep .el-input__inner {
  height: 30px !important;
}

::v-deep .el-range-editor--medium .el-range__icon,
.el-range-editor--medium .el-range__close-icon {
  line-height: 10px;
}
::v-deep .el-select__caret {
  line-height: 36px;
}

.dialogFormBox {
  width: 580px;
}
.addrTitle {
  font-size: 16px;
  line-height: 56px;
}
</style>
