<template>
  <div class="mod-config">

 <!--    <div>-->
<!--        <span @click="favoriteFunction()">-->
<!--         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>-->
<!--        </span>-->
<!--    </div>-->

    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'点检项目编码'">
        <el-input v-model="searchData.itemNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'点检项目名称'">
        <el-input v-model="searchData.itemDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
        <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      :height="height"
      :data="dataList"
      border
      style="width: 100%;">
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="160"
        label="操作">
        <template slot-scope="scope">
          <a v-if="!authUpdate" type="text" size="small" @click="updateModal(scope.row)">修改</a>
          <a type="text" size="small" v-if="scope.row.valueChooseFlag === 'Y' && !authChoose" @click="chooseModal(scope.row)">可选值</a>
          <a v-if="!authDelete" type="text" size="small" @click="deleteEamPropertiesItem(scope.row)">删除</a>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页栏 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-dialog title="点检项目" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="430px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="BU" prop="bu" :rules="rules.bu">
          <el-select v-model="modalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 230px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.sitename"
              :value = "i.buNo">
              <span style="float: left;width: 100px">{{ i.sitename }}</span>
              <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                {{ i.buDesc }}
              </span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'检测值类型'" prop="valueTypeDb" :rules="rules.valueTypeDbType">
          <el-select filterable v-model="modalData.valueTypeDb" style="width: 140px">
            <el-option label="文本" value="T"></el-option>
            <el-option label="数字" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="点检项目编码:" prop="itemNo" :rules="rules.itemNoType">
          <el-input v-model="modalData.itemNo" :disabled="modalDisableFlag" style="width: 140px"></el-input>
        </el-form-item>
        <el-form-item label="点检项目名称:" prop="itemDesc" :rules="rules.itemDescType">
          <el-input v-model="modalData.itemDesc" style="width: 230px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="参照值:">
          <el-input v-model="modalData.defaultValue" style="width: 119px"></el-input>
        </el-form-item>
        <el-form-item label="最大值:">
          <el-input v-model="modalData.maxValue" type="number" style="width: 119px"></el-input>
        </el-form-item>
        <el-form-item label="最小值:">
          <el-input v-model="modalData.minValue" type="number" style="width: 118px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item :label="'是否值可选'" prop="valueChooseFlag" :rules="rules.valueChooseFlagType">
          <el-select v-model="modalData.valueChooseFlag" style="width: 120px">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="font-size: small;vertical-align: -18px;margin-left: 15px;">
          <input type="checkbox" value="Y" name="addWorkOrderRule" v-model="modalData.imageFlag" style="vertical-align: -2px"/>  图片是否必填
        </el-form-item>
        <el-form-item style="font-size: small;vertical-align: -18px;margin-left: 15px;">
          <input type="checkbox" value="Y" name="produceControlRule" v-model="modalData.produceControlFlag" style="vertical-align: -2px"/>  是否生产管控
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="点检方法说明:">
          <el-input v-model="modalData.itemRemark" style="width: 384px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="可选值" :close-on-click-modal="false" v-drag :visible.sync="chooseModalFlag" width="430px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="点检项目名称:">
          <el-input v-model="chooseModalData.itemDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'检测值类型'">
          <el-select filterable v-model="chooseModalData.valueTypeDb" disabled style="width: 120px">
            <el-option label="文本" value="T"></el-option>
            <el-option label="数字" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="addChooseModal()">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="300"
        :data="chooseTableData"
        border
        style="width: 100%">
        <el-table-column
          prop="availableValue"
          header-align="center"
          align="left"
          min-width="200"
          label="属性值">
        </el-table-column>
        <el-table-column
          prop=""
          header-align="center"
          align="center"
          min-width="100"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" @click="updateChooseModal(scope.row)">修改</a>
            <a type="text" size="small" @click="deleteItemAvailable(scope.row)">删除</a>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog title="可选值维护" :close-on-click-modal="false" v-drag :visible.sync="itemModalFlag" width="215px" >
      <el-form :inline="true" label-position="top" style="margin-left: 22px;margin-top: -5px;" @submit.native.prevent>
        <el-form-item :label="'可选值：'">
          <el-input v-model="itemData.availableValue" :type="itemFlag" style="width: 130px;"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveItemAvailable()">保存</el-button>
        <el-button type="primary" @click="itemModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
  </div>
</template>

<script>
  import {
    eamPropertiesItemSearch,
    eamPropertiesItemSave,
    eamPropertiesItemEdit,
    eamPropertiesItemDelete,
    searchItemAvailable,
    saveItemAvailable,
    deleteItemAvailable,
    getSiteAndBuByUserName
  } from "@/api/eam/eam.js"
  import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  export default {
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.itemNo = this.searchData.itemNo.toUpperCase()
        }
      },
      itemData: {
        deep: true,
        handler: function (newV, oldV) {
          this.itemData.itemNo = this.itemData.itemNo.toUpperCase()
        }
      },
      modalData: {
        deep: true,
        handler: function (newV, oldV) {
          this.modalData.itemNo = this.modalData.itemNo.toUpperCase()
        }
      },
      chooseModalData: {
        deep: true,
        handler: function (newV, oldV) {
          this.chooseModalData.itemNo = this.chooseModalData.itemNo.toUpperCase()
        }
      }
    },
    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "点检项目" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["点检项目"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          itemNo: '',
          itemDesc: '',
          buDesc: '',
          itemType:'A',
          page: 1,
          limit: 10,
        },
        height: 200,
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        dataList: [],
        chooseTableData: [],
        dataListSelections: [],
        modalFlag: false,
        modalDisableFlag: false,
        chooseModalFlag: false,
        itemModalFlag: false,
        itemFlag: 'text',
        itemData: {
          site: '',
          buNo: '',
          itemNo: '',
          valueNo: '',
          availableValue: '',
          itemType: 'A',
          createdBy: this.$store.state.user.name
        },
        modalData: {
          site: '',
          bu: '',
          flag: '',
          itemNo: '',
          itemDesc: '',
          valueTypeDb: '',
          defaultValue: '',
          valueChooseFlag: '',
          createdBy: this.$store.state.user.name,
          maxValue: '',
          minValue: '',
          itemRemark: '',
          itemType: 'A',
          updateBy: this.$store.state.user.name,
          imageFlag: '',
          produceControlFlag: ''
        },
        departmentList: [],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1BuDesc',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'buDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: 'BU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ItemNo',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'itemNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '点检项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ItemDesc',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'itemDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '点检项目名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ItemRemark',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'itemRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '点检方法说明',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 400,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ValueType',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'valueType',
            headerAlign: "center",
            align: "center",
            columnLabel: '检测值类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1DefaultValue',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'defaultValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '参照值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1MaxValue',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'maxValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '最大值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1MinValue',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'minValue',
            headerAlign: "center",
            align: "right",
            columnLabel: '最小值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ValueChooseFlag',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'valueChooseFlag',
            headerAlign: "center",
            align: "center",
            columnLabel: '是否值可选',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ImageFlag',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'imageFlag',
            headerAlign: "center",
            align: "center",
            columnLabel: '是否图片必填',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1ProduceControlFlag',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'produceControlFlag',
            headerAlign: "center",
            align: "center",
            columnLabel: '生产管控',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1CreatedDate',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'createdDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '创建时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1CreatedBy',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'createdBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '创建人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1UpdateDate',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'updateDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '更新时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101002001,
            serialNumber: '101002001Table1UpdateBy',
            tableId: "101002001Table1",
            tableName: "点检项目表",
            columnProp: 'updateBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '更新人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        levelList: [],
        chooseModalData: {
          site: '',
          buNo: '',
          itemNo: '',
          itemDesc: '',
          itemType: 'A',
          valueTypeDb: '',
        },
        rules: {
          itemNoType: [
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          itemDescType: [
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          valueTypeDbType: [
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          valueChooseFlagType: [
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          bu: [
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ]
        },
        userBuList: [],
        authSearch: false,
        authSave: false,
        authUpdate: false,
        authDelete: false,
        authChoose: false,
        menuId: this.$route.meta.menuId,
      }
    },

    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 180
      })
    },

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName()
      // 校验用户是否收藏
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
    },

    methods: {
      // 获取用户的bu
      getSiteAndBuByUserName () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getSiteAndBuByUserName(tempData).then(({data}) => {
          if (data.code === 0) {
            this.userBuList = data.rows
          }
        })
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },

      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },

      // 校验用户是否收藏
      favoriteIsOk () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            if (this.$route.meta.menuId === data.list[i].menuId) {
              this.favorite = true
            }
          }
        })
      },

      // 收藏 OR 取消收藏
      favoriteFunction () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }
      },

      // 导出excel
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await eamPropertiesItemSearch(this.searchData).then(({data}) => {
          this.exportList = data.rows
        })
        return this.exportList
      },
      startDownload() {},
      finishDownload() {},
      fields() {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },

      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        eamPropertiesItemSearch(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
          }
        })
      },

      addModal () {
        this.modalData = {
          bu: this.userBuList[0].buNo,
          site: '',
          flag: '1',
          itemNo: '',
          itemDesc: '',
          valueTypeDb: 'T',
          defaultValue: '',
          valueChooseFlag: 'N',
          createdBy: this.$store.state.user.name,
          maxValue: '',
          minValue: '',
          itemRemark: '',
          itemType: 'A',
          updateBy: this.$store.state.user.name,
          imageFlag: '',
          produceControlFlag: ''
        }
        this.modalDisableFlag = false
        this.modalFlag = true
      },

      chooseModal (row) {
        this.chooseModalData.site = row.site
        this.chooseModalData.buNo = row.buNo
        this.chooseModalData.itemNo = row.itemNo
        this.chooseModalData.itemDesc = row.itemDesc
        this.chooseModalData.valueTypeDb = row.valueTypeDb
        searchItemAvailable(this.chooseModalData).then(({data}) => {
          this.chooseTableData = data.rows
        })
        this.chooseModalFlag = true
      },

      updateModal (row) {
        this.modalData = {
          flag: '2',
          site: row.site,
          bu: row.site + '_' + row.buNo,
          itemNo: row.itemNo,
          itemDesc: row.itemDesc,
          valueTypeDb: row.valueTypeDb,
          defaultValue: row.defaultValue,
          valueChooseFlag: row.valueChooseFlag,
          createdBy: this.$store.state.user.name,
          maxValue: row.maxValue,
          minValue: row.minValue,
          itemRemark: row.itemRemark,
          itemType: 'A',
          updateBy: this.$store.state.user.name,
          imageFlag: row.imageFlag,
          produceControlFlag: row.produceControlFlag
        }
        this.modalDisableFlag = true
        this.modalFlag = true
      },

      // 删除
      deleteEamPropertiesItem (row) {
        this.$confirm(`是否删除这个点检项目?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          eamPropertiesItemDelete(row).then(({data}) => {
            if (data && data.code === '0') {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      saveData () {
        if (this.modalData.bu === '' || this.modalData.bu == null) {
          this.$message.warning('请选择BU！')
          return
        }
        if (this.modalData.itemNo === '' || this.modalData.itemNo == null) {
          this.$message.warning('请输入点检项目编码！')
          return
        }
        if (this.modalData.itemDesc === '' || this.modalData.itemDesc == null) {
          this.$message.warning('请输入点检项目名称！')
          return
        }
        let obj1 = document.getElementsByName('addWorkOrderRule')
        let obj2 = document.getElementsByName('produceControlRule')
        let Rule1 = ''
        let Rule2 = ''
        for (let i = 0; i < obj1.length; i++) {
          if (obj1[i].checked) {
            Rule1 += obj1[i].value + ','
          }
        }
        for (let i = 0; i < obj2.length; i++) {
          if (obj2[i].checked) {
            Rule2 += obj2[i].value + ','
          }
        }
        Rule1 = Rule1.substring(0,Rule1.length-1)
        Rule2 = Rule2.substring(0,Rule2.length-1)
        this.modalData.imageFlag = Rule1
        this.modalData.produceControlFlag = Rule2
        if (this.modalData.flag === '1') {
          eamPropertiesItemSave(this.modalData).then(({data}) => {
            if (data && data.code === '0') {
              this.getDataList()
              this.modalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        } else {
          eamPropertiesItemEdit(this.modalData).then(({data}) => {
            if (data && data.code === '0') {
              this.getDataList()
              this.modalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },

      addChooseModal () {
        this.itemFlag = this.chooseModalData.valueTypeDb === 'T' ? 'text' : 'number'
        this.itemData = {
          site: this.chooseModalData.site,
          buNo: this.chooseModalData.buNo,
          itemNo: this.chooseModalData.itemNo,
          valueNo: 0,
          availableValue: '',
          itemType: 'A',
          createdBy: this.$store.state.user.name
        }
        this.itemModalFlag = true
      },

      updateChooseModal (row) {
        this.itemFlag = this.chooseModalData.valueTypeDb === 'T' ? 'text' : 'number'
        this.itemData = {
          site: row.site,
          buNo: row.buNo,
          itemNo: this.chooseModalData.itemNo,
          valueNo: row.valueNo,
          availableValue: row.availableValue,
          itemType: 'A',
          createdBy: row.createdBy
        }
        this.itemModalFlag = true
      },

      saveItemAvailable () {
        if (this.itemData.availableValue === '' || this.itemData.availableValue == null) {
          this.$message.warning('请输入可选值！')
          return
        }
        saveItemAvailable(this.itemData).then(({data}) => {
          if (data && data.code === 0) {
            searchItemAvailable(this.chooseModalData).then(({data}) => {
              this.chooseTableData = data.rows
            })
            this.itemModalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      deleteItemAvailable (row) {
        this.$confirm(`是否删除这个可选值?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteItemAvailable(row).then(({data}) => {
            if (data && data.code === 0) {
              searchItemAvailable(this.chooseModalData).then(({data}) => {
                this.chooseTableData = data.rows
              })
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn(tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable = {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let saveFlag = this.isAuth(this.menuId+":save")
        let updateFlag = this.isAuth(this.menuId+":update")
        let deleteFlag = this.isAuth(this.menuId+":delete")
        let chooseFlag = this.isAuth(this.menuId+":choose")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authSave = !saveFlag
        this.authUpdate = !updateFlag
        this.authDelete = !deleteFlag
        this.authChoose = !chooseFlag
      },
    }
  }
</script>
<style scoped lang="scss">
.register_btn {
  position: absolute;
  right: 0;
}
.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>
