<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'属性模板编码'">
        <el-input v-model="searchData.codeNo" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'属性模板名称'">
        <el-input v-model="searchData.codeDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="应用菜单">
        <el-select v-model="searchData.group" @change="getDataList()">
          <el-option :value="i.menuId" :label="i.name" v-for="i in menuList" :key="i.menuId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'模板分组'">
        <el-select filterable v-model="searchData.functionType" @change="val=>changeMenu(val)" clearable style="width: 120px">
          <!--          <el-option label="A" value="A"></el-option>-->
          <!--          <el-option label="IP" value="IP"></el-option>-->
          <!--          <el-option label="MP" value="MP"></el-option>-->
          <!--          <el-option label="BM" value="BM"></el-option>-->
          <!--          <el-option label="ECN" value="ECN"></el-option>-->
          <!--          <el-option label="TEST" value="TEST"></el-option>-->
          <!--          <el-option label="询价" value="PRICECHECK"></el-option>-->
          <el-option :label="item.functionTypeDesc" :value="item.functionType" v-for="item in typeList" :key="item.functionType"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="模板类型">
<!--        <dict-data-select ref="dictDataSelect" @change="getDataList" v-model="searchData.functionGroup" clearable :dict-type="searchData.group"-->
<!--                          :use-default-value="false"></dict-data-select>-->
        <el-select filterable  style="width: 100%;" clearable v-model="searchData.functionGroup">
          <el-option :label="item.functionGroupDesc" :value="item.functionGroup" v-for="item in relationshipList" :key="item.functionGroup"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="BU">
        <el-select v-model="searchData.buNo" @change="getDataList" clearable>
          <el-option :value="i.buNo" :label="i.buDesc" v-for="i in BUList" :key="i.buNo"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'状态'">
        <!--        <el-select filterable v-model="searchData.active" style="width: 130px">-->
        <!--          <el-option label="全部" value=""></el-option>-->
        <!--          <el-option label="是" value="Y"></el-option>-->
        <!--          <el-option label="否" value="N"></el-option>-->
        <!--        </el-select>-->
        <dict-data-select v-model="searchData.active" clearable dict-type="sys_status"
                          :use-default-value="false"></dict-data-select>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="getDataList()">查询</el-button>
        <el-button 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
      v-loading="dataListLoading"
      style="width: 100%;">
      <!--      <el-table-column-->
      <!--        prop="codeNo"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        label="属性模板编码">-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="codeDesc"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        label="属性模板名称">-->
      <!--      </el-table-column>-->
      <!--      <el-table-column-->
      <!--        prop="active"-->
      <!--        header-align="center"-->
      <!--        align="center"-->
      <!--        label="状态">-->
      <!--        <template slot-scope="scope">-->
      <!--          <div v-if="scope.row.active === 'Y'">-->
      <!--            是-->
      <!--          </div>-->
      <!--          <div v-if="scope.row.active === 'N'">-->
      <!--            否-->
      <!--          </div>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <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="{row,$index}">
          <div v-if="item.columnProp !== 'active'">
            <span v-if="!item.columnHidden">{{ row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="row[item.columnProp]" style="width: 100px; height: 80px"/></span>
          </div>
          <span v-else
                :style="{color:row.active === 'Y'?'#67C23A':'red'}">{{ row.active === 'Y' ? '启用' : '停用' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="160"
        label="操作">
        <template slot-scope="{row,$index}">
          <el-link style="cursor:pointer;" type="primary" v-if="row.isSystem !== 'Y'" @click="updateModal(row)">修改
          </el-link>
          <span style="cursor:no-drop;color: #aaa" v-else>修改</span>
          <el-link style="cursor:pointer;" type="primary" size="small" @click="detailModal(row)">属性项目</el-link>
          <el-link style="cursor:pointer;" type="primary" v-if="row.isSystem !== 'Y'"
                   @click="deletePropertiesModel(row)">删除
          </el-link>
          <span style="cursor:no-drop;color: #aaa" v-else>删除</span>
          <el-link style="cursor:pointer;" type="primary" @click="BUBtnDialog(row)">BU授权</el-link>
        </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="属性模板" top="20vh" :close-on-click-modal="false"
               @close="()=>{this.$refs.modeForm.resetFields();}" v-drag :visible.sync="modalFlag" width="500px">
      <el-form ref="modeForm" label-position="top" :model="modalData" :rules="rules">
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="属性模板编码:" prop="codeNo">
              <el-input v-model="modalData.codeNo" :disabled="this.modalData.flag !== '1'"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item label="属性模板名称:" prop="codeDesc">
              <el-input v-model="modalData.codeDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item :label="'模板分组'" prop="functionType">
              <el-select filterable  style="width: 100%;" @change="val=>changeMenu(val)" clearable v-model="modalData.functionType" :disabled="this.modalData.flag !== '1'">
                <!--                <el-option label="A" value="A"></el-option>-->
                <!--                <el-option label="IP" value="IP"></el-option>-->
                <!--                <el-option label="MP" value="MP"></el-option>-->
                <!--                <el-option label="BM" value="BM"></el-option>-->
                <!--                <el-option label="ECN" value="ECN"></el-option>-->
                <!--                <el-option label="TEST" value="TEST"></el-option>-->
                <!--                <el-option label="询价" value="PRICECHECK"></el-option>-->
                <el-option :label="item.functionTypeDesc" :value="item.functionType" v-for="item in typeList" :key="item.functionType"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item :label="'模板类型'" prop="functionGroup">
<!--              <dict-data-select :disabled="this.modalData.flag !== '1'" ref="dialogDictDataSelect" v-model="modalData.functionGroup" clearable :dict-type="modalData.group"-->
<!--                                :use-default-value="false"></dict-data-select>-->
              <el-select filterable  style="width: 100%;" v-model="modalData.functionGroup" :disabled="this.modalData.flag !== '1'">
                <el-option :label="item.functionGroupDesc" :value="item.functionGroup" v-for="item in copyRelationshipList" :key="item.functionGroup"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="应用菜单" required>
              <el-select :disabled="this.modalData.flag !== '1'"
                         v-model="modalData.group"
                         style="width: 100%;"
                         placeholder="请选择">
                <el-option
                  v-for="item in menuList"
                  :key="item.menuId"
                  :label="item.name"
                  :value="item.menuId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态:" prop="active">
              <dict-data-select v-model="modalData.active" clearable dict-type="sys_status"
                                :use-default-value="false"></dict-data-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;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="detailModelFlag" width="830px">
      <el-form :inline="true" label-position="top" @keyup.enter.native="getDataList()">
        <el-form-item :label="'属性模板编码'">
          <el-input v-model="detailData.codeNo" readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'属性模板名称'">
          <el-input v-model="detailData.codeDesc" readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="' '">
          <!--          <el-button type="primary" @click="addDetailModal()">新增</el-button>-->
          <el-button type="primary" @click="addFastModal()">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="300"
        :data="detailList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          fixed="left"
          header-align="center"
          align="center"
          width="70"
          label="排序">
          <template slot-scope="scope">
            <a type="text" size="small" @click="goUp(scope.row)">上移</a>
            <a type="text" size="small" @click="goDown(scope.row)"> 下移</a>
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item,index) in columnDetailList" :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="130"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" v-if="scope.row.valueChooseFlag === 'Y'"
               @click="chooseModal(scope.row)">可选值</a>
            <a type="text" size="small" @click="deleteModalDetails(scope.row)">删除属性</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!--    <el-dialog title="添加属性" :close-on-click-modal="false" v-drag :visible.sync="addDetailModalFlag" width="300px">-->
    <!--      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">-->
    <!--        <el-form-item >-->
    <!--          <span slot="label" style="" @click="getBaseList(1024)"><a herf="#">属性属性编码</a></span>-->
    <!--          <el-input v-model="detailData.itemNo" @blur="itemNoBlur" style="width: 120px"></el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item label="属性项目名称:">-->
    <!--          <el-input v-model="detailData.itemDesc" disabled style="width: 120px"></el-input>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--      <el-footer style="height:40px;margin-top: 10px;text-align:center">-->
    <!--        <el-button type="primary" @click="saveModalDetails()">保存</el-button>-->
    <!--        <el-button type="primary" @click="addDetailModalFlag = false">关闭</el-button>-->
    <!--      </el-footer>-->
    <!--    </el-dialog>-->

    <el-dialog title="新增" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="fastAddFlag"
               width="1000px">
      <div style="font-size: 12px">
        <!--        属性模板编码：<el-input v-model="detailData.codeNo" readonly style="width: 120px"></el-input>-->
        <!--        属性模板名称：<el-input v-model="detailData.codeDesc" readonly style="width: 120px"></el-input>-->
        <el-form :inline="true" label-position="top" :model="detailData">
          <el-form-item :label="'属性编码'">
            <el-input v-model="detailData.itemNo" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'属性名称'">
            <el-input v-model="detailData.itemDesc" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="queryTemplateItem()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: 0px;">
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px">可选属性：</span>
          <el-table
            height="400px"
            :data="itemList1"
            border
            ref="itemTable1"
            @row-click="itemClickRow1"
            @selection-change="selectionItem1"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              :selectable="selectFlag"
              width="50">
            </el-table-column>
            <el-table-column
              prop="itemNo"
              header-align="center"
              align="center"
              min-width="80"
              label="属性编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="center"
              min-width="200"
              label="属性名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 10px;padding: 1px">
          <div style="margin-top: 200px;margin-left: 18px">
            <el-button type="primary" @click="addItem()">添加>></el-button>
          </div>
          <div style="margin-top: 15px;margin-left: 18px">
            <el-button type="primary" @click="deleteItem()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px">已有属性：</span>
          <el-table
            height="400px"
            :data="itemList2"
            border
            ref="itemTable2"
            @row-click="itemClickRow2"
            @selection-change="selectionItem2"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              :selectable="selectFlag"
              width="50">
            </el-table-column>
            <el-table-column
              prop="itemNo"
              header-align="center"
              align="center"
              min-width="80"
              label="属性编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="center"
              min-width="200"
              label="属性名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="fastAddFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="可选值" :close-on-click-modal="false" v-drag :visible.sync="chooseModalFlag" width="350px">
      <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>
      <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>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
    <el-dialog title="BU授权" v-drag :visible.sync="BUDialog" width="518px">
      <el-form :inline="true" label-position="top" :model="modalData">
        <el-form-item :label="'模板编码'">
          <el-input v-model="modalData.codeNo" readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'模板名称'">
          <el-input v-model="modalData.codeDesc" readonly style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-transfer class="rq" :props="{key: 'buNo',label: 'buDesc' }"
                   filterable v-model="selectionBU"
                   :data="BUList">

      </el-transfer>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="savePropertiesBU">保存</el-button>
        <el-button type="primary" @click="BUDialog = false">关闭</el-button>
      </el-footer>
    </el-dialog>
  </div>
</template>

<script>
import {
  propertiesModelSearch,
  propertiesModelSave,
  propertiesModelEdit,
  propertiesModelDelete,
  searchItemAvailable,
  searchModalDetails,
  saveModalDetails,
  deleteModalDetails, // 多选删除
  getItemLists,
  deleteModalDetail, // 单删
  goUpItem,
  goDownItem,
} from "@/api/base/properties.js"
import Chooselist from '@/views/modules/common/Chooselist'
import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
import DictDataSelect from "../../sys/dict-data-select.vue";
import {
  saveBUPropertiesList, searchAllTypeList, searchAllTypeRelationshipList,
  searchBUList,
  searchBUPropertiesList,
  searchMenuAllListId,
  searchPropertiesGroup
} from "../../../../api/base/properties";

export default {
  components: {
    DictDataSelect,
    Chooselist
  },
  watch: {
    searchData: {
      deep: true,
      handler: function (newV, oldV) {
        this.searchData.codeNo = this.searchData.codeNo.toUpperCase()
      }
    },

    itemData: {
      deep: true,
      handler: function (newV, oldV) {
        this.itemData.itemNo = this.itemData.itemNo.toUpperCase()
      }
    },
    modalData: {
      deep: true,
      handler: function (newV, oldV) {
        this.modalData.codeNo = this.modalData.codeNo.toUpperCase()
      }
    },
    detailData: {
      deep: true,
      handler: function (newV, oldV) {
        this.detailData.codeNo = this.detailData.codeNo.toUpperCase()
        this.detailData.itemNo = this.detailData.itemNo.toUpperCase()
      }
    },
  },
  data() {
    return {
      relationshipList:[],
      copyRelationshipList:[],
      typeList:[],
      selectionBU: [],
      BUDialog: false,
      BUList: [],
      menuList: [],
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "属性模板" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["属性模板"],
      exportFooter: [],
      exportList: [],
      // 导出 end
      tagNo: '',
      searchData: {
        site: this.$store.state.user.site,
        group: '',
        buNo: '',
        codeNo: '',
        codeDesc: '',
        active: 'Y',
        functionType: '',
        functionGroup:'',
        page: 1,
        limit: 10,
      },
      height: 200,
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      // addDetailModalFlag:false,
      modalFlag: false,
      modalDisableFlag: false,
      modalData: {
        flag: '',
        codeNo: '',
        codeDesc: '',
        active: '',
        functionType: '',
        functionGroup: '',
        group: '',
        userId: this.$store.state.user.name,
        createdBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
      },
      detailData: {
        site: this.$store.state.user.site,
        codeNo: '',
        codeDesc: '',
        functionType: '',
        itemNo: '',
        itemDesc: '',
        itemType: '',
        userId: this.$store.state.user.name
      },
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableFunctionType',
          tableId: "100002001Table",
          tableName: "属性项目表",
          columnProp: 'functionTypeDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '模板分组',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },{
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableFunctionType',
          tableId: "100002001Table",
          tableName: "属性项目表",
          columnProp: 'functionGroupDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '模板类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableCodeNo',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'codeNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性模板编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableCodeDesc',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'codeDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性模板名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableActive',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'active',
          headerAlign: "center",
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableCreatedDate',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'createdDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableCreatedBy',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'createdBy',
          headerAlign: "center",
          align: "left",
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableUpdateDate',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'updateDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableUpdateBy',
          tableId: "100002001Table",
          tableName: "属性模板表",
          columnProp: 'updateBy',
          headerAlign: "center",
          align: "left",
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
      ],
      detailModelFlag: false,
      detailList: [],
      chooseTableData: [],
      dataListLoading: false,
      dataListSelections: [],
      // modalDisableFlag:false,
      chooseModalFlag: false,
      itemFlag: 'text',
      itemData: {
        itemNo: '',
        valueNo: '',
        availableValue: '',
        itemType: '',
        createdBy: this.$store.state.user.name
      },
      dataList: [],
      departmentList: [],
      // 展示列集
      columnDetailList: [
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2PropertiesItemID',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'itemNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性项目编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2PropertiesItemDesc',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'itemDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性项目名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2ValueType',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'valueType',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性值类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2DefaultValue',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'defaultValue',
          headerAlign: "center",
          align: "center",
          columnLabel: '参照值',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2MaxValue',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'maxValue',
          headerAlign: "center",
          align: "center",
          columnLabel: '最大值',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001Table2MinValue',
          tableId: "100002001Table2",
          tableName: "属性项目表",
          columnProp: 'minValue',
          headerAlign: "center",
          align: "center",
          columnLabel: '最小值',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 100002001,
          serialNumber: '100002001TableValueChooseFlag',
          tableId: "100002001Table",
          tableName: "common",
          columnProp: 'valueChooseFlag',
          headerAlign: "center",
          align: "center",
          columnLabel: '是否值可选',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      levelList: [],
      chooseModalData: {
        site: '',
        itemNo: '',
        itemDesc: '',
        itemType: '',
        valueTypeDb: '',
      },
      //---------快速添加----------
      fastAddFlag: false,
      itemList1: [],
      itemList2: [],
      itemListRow1: {},
      itemListRow2: {},
      itemSelections1: [],
      itemSelections2: [],
      rules: {
        codeNo: [
          {
            required: true,
            message: ' ',
            trigger: 'change'
          }
        ],
        codeDesc: [
          {
            required: true,
            message: ' ',
            trigger: 'change'
          }
        ],
        active: [
          {
            required: true,
            message: ' ',
            trigger: 'change'
          }
        ],
        functionType: [
          {
            required: true,
            message: ' ',
            trigger: 'change'
          }
        ],
        functionGroup: [
          {
            required: true,
            message: ' ',
            trigger: 'change'
          }
        ],
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - 210
    })
  },
  async created() {
    await this.searchBUList();
    await this.searchMenuList();
    await this.searchAllTypeList();
  },
  methods: {
    changeMenu(val){
      if (this.modalFlag){
        this.modalData.functionGroup='';
      }else {
        this.searchData.functionGroup = '';
      }
      this.getDataList();
      this.searchAllTypeRelationshipList(val)
      // this.$nextTick(()=>{
      //   this.$refs[ref].initOption();
      // })
    },
    searchAllTypeRelationshipList(args){
      let params={
        functionType: args
      }
      searchAllTypeRelationshipList(params).then(({data})=>{
        if (data && data.code === 0){
          if (this.modalFlag){
            this.copyRelationshipList = data.rows;
          }else {
            this.relationshipList = data.rows;
          }
        }else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    searchAllTypeList(){
      searchAllTypeList().then(({data})=>{
        if (data && data.code === 0) {
          this.typeList = data.rows;
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    searchMenuList() {
      let params = {
        site: this.$store.state.user.site
      }
      searchMenuAllListId(params).then(({data}) => {
        if (data && data.code === 0) {
          this.menuList = data.rows;
          if (this.menuList.length > 0) {
            this.searchData.group = this.menuList[0].menuId
            // this.searchData.menuList.push(this.menuList[0].menuId)
          }
          this.getDataList();
          // this.$nextTick(()=>{
          //   this.$refs.dictDataSelect.initOption();
          // })
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    searchBUList() {
      let params = {
        site: this.$store.state.user.site
      }
      searchBUList(params).then(({data}) => {
        if (data && data.code === 0) {
          this.BUList = data.rows;
          // if (this.BUList.length > 0) {
          //   this.searchData.buNo = this.BUList[0].buNo
          // }
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    // 获取基础数据列表S
    getBaseList(val, type) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        if (val === 1024) {
          strVal = this.detailData.itemNo
        }
        this.$refs.baseList.init(val, strVal)
      })
    },
    /* 列表方法的回调 */
    getBaseData(val) {
      if (this.tagNo === 1024) {
        this.detailData.itemNo = val.ItemNo
        this.detailData.itemDesc = val.ItemDesc
      }
    },
    //导出excel
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await propertiesModelSearch(this.searchData).then(({data}) => {
        this.exportList = data.page.list;
      })
      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
    },
    // 导出 end
    // 获取数据列表
    getDataList() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      propertiesModelSearch(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
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },

    addModal() {
      this.modalData = {
        site: this.$store.state.user.site,
        flag: '1',
        codeNo: '',
        codeDesc: '',
        active: 'Y',
        functionType: `${this.searchData.functionType?this.searchData.functionType:''}`,
        functionGroup: `${this.searchData.functionGroup?this.searchData.functionGroup:''}`,
        group: `${this.searchData.group?this.searchData.group:''}`,
        userId: this.$store.state.user.name,
        createdBy: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
      };
      this.modalDisableFlag = false;
      this.copyRelationshipList = this.relationshipList
      this.modalFlag = true;
      this.$nextTick(()=>{
        this.$refs['dialogDictDataSelect'].initOption();
      })
    },

    updateModal(row) {
      this.modalData = {
        site: row.site,
        flag: '2',
        codeNo: row.codeNo,
        codeDesc: row.codeDesc,
        active: row.active,
        group: row.group,
        functionType: row.functionType,
        functionGroup: row.functionGroup,
        userId: this.$store.state.user.name,
        updateBy: this.$store.state.user.name,
      };
      this.modalFlag = true;
    },
    // 删除
    deletePropertiesModel(row) {
      this.$confirm(`是否删除这个属性模板?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        propertiesModelDelete(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.codeNo == '' || this.modalData.codeNo == null) {
        this.$alert('请输入属性模板编码！', '错误', {
          confirmButtonText: '确定'
        })
        return false
      }
      if (this.modalData.codeDesc == '' || this.modalData.codeDesc == null) {
        this.$alert('请输入属性模板名称！', '错误', {
          confirmButtonText: '确定'
        })
        return false
      }
      if (this.modalData.active == '' || this.modalData.active == null) {
        this.$alert('选择状态！', '错误', {
          confirmButtonText: '确定'
        })
        return false
      }
      if (this.modalData.functionType === '') {
        this.$alert('选择模板类型！', '错误', {
          confirmButtonText: '确定'
        })
        return false
      }
      if (this.modalData.functionGroup === '') {
        this.$alert('选择模板分组！', '错误', {
          confirmButtonText: '确定'
        })
        return false
      }
      if (this.modalData.flag === '1') {
        propertiesModelSave(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 {
        propertiesModelEdit(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: '确定'
            })
          }
        })
      }
    },
    //打开属性清单
    detailModal(row) {
      this.detailData.site = row.site
      this.detailData.codeNo = row.codeNo
      this.detailData.codeDesc = row.codeDesc
      this.detailData.functionType = row.functionType
      searchModalDetails(this.detailData).then(({data}) => {
        this.detailList = data.rows
      })
      this.detailModelFlag = true;
    },
    deleteModalDetails(row) {
      this.$confirm(`是否删除这个属性项目?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteModalDetail(row).then(({data}) => {
          if (data && data.code === 0) {
            searchModalDetails(this.detailData).then(({data}) => {
              this.detailList = data.rows
            })
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },
    chooseModal(row) {
      this.chooseModalData.site = row.site;
      this.chooseModalData.itemNo = row.itemNo;
      this.chooseModalData.itemDesc = row.itemDesc;
      this.chooseModalData.valueTypeDb = row.valueTypeDb;
      this.chooseModalData.itemType = row.functionType;
      searchItemAvailable(this.chooseModalData).then(({data}) => {
        this.chooseTableData = data.rows
      })
      this.chooseModalFlag = true;
    },
    //---------快速添加----------

    queryTemplateItem() {
      getItemLists(this.detailData).then(({data}) => {
        this.itemList1 = data.row1;
        this.itemList2 = data.row2;
      })
    },

    addFastModal() {
      this.itemSelections1 = null
      this.itemSelections2 = null
      getItemLists(this.detailData).then(({data}) => {
        this.itemList1 = data.row1;
        this.itemList2 = data.row2;
      })
      this.fastAddFlag = true;
    },
    // 可选属性
    itemClickRow1(row) {
      this.$refs.itemTable1.toggleRowSelection(row);
    },
    // 已有属性
    itemClickRow2(row) {
      this.$refs.itemTable2.toggleRowSelection(row);
    },
    selectFlag() {
      return true;
    },
    selectionItem1(val) {
      this.itemSelections1 = val
    },
    selectionItem2(val) {
      this.itemSelections2 = val
    },
    addItem() {
      if (this.itemSelections1 == null || this.itemSelections1.length == 0) {
        this.$alert("请选择可选属性！", '提示', {
          confirmButtonText: '确定'
        })
        return false;
      }
      let inData = {
        site: this.$store.state.user.site,
        codeNo: this.detailData.codeNo,
        codeDesc: this.detailData.codeDesc,
        functionType: this.detailData.functionType,
        // itemNo: this.itemListRow1.itemNo,
        // itemDesc: this.itemListRow1.itemDesc,
        itemList: this.itemSelections1,
        itemType: this.detailData.itemType,
        userId: this.$store.state.user.name
      }
      saveModalDetails(inData).then(({data}) => {
        if (data && data.code == 0) {
          getItemLists(this.detailData).then(({data}) => {
            this.itemList1 = data.row1;
            this.itemList2 = data.row2;
          })
          this.itemSelections1 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },
    deleteItem() {
      if (this.itemSelections2 == null || this.itemSelections2.length == 0) {
        this.$alert("请选择已有属性！", '提示', {
          confirmButtonText: '确定'
        })
        return false;
      }
      let inData = {
        site: this.$store.state.user.site,
        codeNo: this.detailData.codeNo,
        codeDesc: this.detailData.codeDesc,
        functionType: this.detailData.functionType,
        // itemNo: this.itemListRow2.itemNo,
        // itemDesc:this.itemListRow2.itemDesc,
        itemList: this.itemSelections2,
        itemType: this.detailData.itemType,
        userId: this.$store.state.user.name
      }
      deleteModalDetails(inData).then(({data}) => {
        if (data && data.code === 0) {
          getItemLists(this.detailData).then(({data}) => {
            this.itemList1 = data.row1;
            this.itemList2 = data.row2;
          })
          this.itemSelections2 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },
    refreshDetailList() {
      searchModalDetails(this.detailData).then(({data}) => {
        this.detailList = data.rows
      })
    },

    goUp(row) {
      goUpItem(row).then(({data}) => {
        if (data && data.code === 0) {
          searchModalDetails(this.detailData).then(({data}) => {
            this.detailList = data.rows
          })
        }
      })

    },
    goDown(row) {
      goDownItem(row).then(({data}) => {
        if (data && data.code === 0) {
          searchModalDetails(this.detailData).then(({data}) => {
            this.detailList = data.rows
          })
        }
      })

    },
    BUBtnDialog(row) {
      this.modalData = row
      searchBUPropertiesList(row).then(({data}) => {
        if (data && data.code === 0) {
          this.selectionBU = data.row.map(item => item.buNo);
          this.BUDialog = true
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    savePropertiesBU() {
      // if (this.selectionBU.length === 0) {
      //   this.$message.warning("未选择BU")
      //   return
      // }
      let arr = this.selectionBU.map(item => {
        return {
          site: this.$store.state.user.site,
          buNo: item,
          functionType: this.modalData.functionType,
          codeNo: this.modalData.codeNo
        }
      });
      if (arr.length === 0){
        arr[0] = {
          site: this.$store.state.user.site,
          functionType: this.modalData.functionType,
          codeNo: this.modalData.codeNo
        }
      }
      saveBUPropertiesList(arr).then(({data}) => {
        if (data && data.code === 0) {
          this.$message.success(data.msg)
          this.getDataList()
          this.BUDialog = false
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
  }
}
</script>
<style scoped>
.rq /deep/ .el-transfer-panel {

}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header {
  height: 35px;
  line-height: 35px;
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox {
  line-height: 35px;
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label {
  color: #fff
}

.rq /deep/ .el-transfer-panel .el-transfer-panel__header .el-checkbox .el-checkbox__label span {
  color: #3c3c3e;
}

.rq /deep/ .el-transfer-panel .el-checkbox__inner::after {
  height: 8px;
  width: 4px;
}
</style>
