<template>
  <div class="mod-config">
    <div style="width: 1000px">
      <el-form label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
        <el-row :gutter="10">
          <el-col :span="4">
            <el-form-item label="工厂编号">
              <el-select v-model="searchData.site" style="width: 100%">
                <el-option label="全部" value=" "></el-option>
                <el-option :label="site.siteid" :value="site.siteid" v-for="(site) in siteList"
                           :key="site.siteid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="货币">
              <el-input v-model="searchData.currency" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="货币描述">
              <el-input v-model="searchData.currencyDesc" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="状态">
              <el-select v-model="searchData.active" style="width: 100%" placeholder="请选择">
                <el-option label="全部" value=" "></el-option>
                <el-option label="启用" value="Y"></el-option>
                <el-option label="禁用" value="N"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <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>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>


    <!-- 展示列表 -->
    <el-table
      height="36vh"
      :data="dataList"
      @row-click="changeData"
      border
      :row-style="rowStyle"
      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">
          <template v-if="item.columnProp==='active'">
            <span> {{ scope.row[item.columnProp] === 'Y' ? '启用' : '停用' }}</span>
          </template>
          <template v-else>
            <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>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        min-width="100"
        label="操作">
        <template slot-scope="scope">
          <a type="text" @click="updateModal(scope.row)">修改</a>
          <a type="text" @click="deleteModal(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-tabs style="height: auto;" class="customer-tab" v-model="activeName" type="border-card">
      <el-tab-pane label="汇率" name="detail">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-card>
              <div>参考货币</div>
              <el-button v-if="!authSave" type="primary" @click="addModal1()">新增</el-button>
              <el-table
                :data="dataList1"
                @row-click="changeData2"
                height="36vh"
                border
                :row-style="rowStyle2"
                style="width: 100%; ">
                <el-table-column
                  v-for="(item,index) in columnList1" :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="80"
                  label="操作">
                  <template slot-scope="scope">
                    <!--                    <a type="text" size="small" @click="updateModal1(scope.row)">修改</a>-->
                    <a type="text" size="small" @click="deleteModal1(scope.row)">删除</a>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
          <el-col :span="12">
            <el-card>
              <div>
                <span>货币汇率</span>
              </div>
              <el-button v-if="!authSave" type="primary" @click="addModal2()">新增</el-button>
              <el-table
                :data="dataList2"
                height="36vh"
                border
                style="width: 100%; ">
                <el-table-column
                  v-for="(item,index) in columnList2" :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="80"
                  label="操作">
                  <template slot-scope="scope">
                    <!--                    <a type="text" size="small" @click="updateModal2(scope.row)">修改</a>-->
                    <a type="text" size="small" @click="deleteModal2(scope.row)">删除</a>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>


    <!--    货币新增修改-->
    <el-dialog title="货币" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="450px">
      <el-form label-position="top" :model="modalData" :rules="rules">
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="工厂编码" prop="site">
              <el-select v-model="modalData.site" :disabled="modalDisableFlag" style="width: 100%">
                <el-option :label="site.siteid" :value="site.siteid" v-for="(site) in siteList"
                           :key="site.siteid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="10">
            <el-form-item label="货币:" prop="currency">
              <el-input v-model="modalData.currency" :disabled="modalDisableFlag"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item label="货币描述" prop="currencyDesc">
              <el-input v-model="modalData.currencyDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="状态" prop="active">
              <el-select v-model="modalData.active" style="width: 100%" placeholder="请选择">
                <el-option label="启用" value="Y"></el-option>
                <el-option label="停用" value="N"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label=" ">
              <el-checkbox v-model="modalData.baseCurrencyFlag" false-label="N" true-label="Y">本位币</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:30px;line-height:30px;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="modalFlag1" width="300px">
      <el-form label-position="top" :model="modalData1" :rules="rules">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="参考货币" prop="currency">
              <template slot="label">
                <a @click="handleClickCurrency">参考货币</a>
              </template>
              <el-input v-model="modalData1.currency" @blur="handleBlurCurrency"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="参考货币描述" prop="currencyDesc">
              <el-input v-model="modalData1.currencyDesc" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:30px;line-height:30px;text-align:center">
        <el-button type="primary" @click="saveData1()">保存</el-button>
        <el-button type="primary" @click="modalFlag1 = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 货币汇率新增和修改  -->
    <el-dialog title="货币汇率" top="20vh" :close-on-click-modal="false" v-drag :visible.sync="modalFlag2"
               width="200px">
      <el-form label-position="top" :model="modalData2" :rules="rules">
        <el-form-item label="汇率:" prop="exchangeRate">
          <el-input-number v-model="modalData2.exchangeRate" style="width: 50%;" :controls="false" :step="0"
                           :precision="4"></el-input-number>
        </el-form-item>

        <el-form-item label="启用日期">
          <el-date-picker
            style="width: 100%"
            v-model="modalData2.activationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>

      </el-form>
      <el-footer style="height:30px;line-height:30px;text-align:center">
        <el-button type="primary" @click="saveData2()">保存</el-button>
        <el-button type="primary" @click="modalFlag2 = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="货币信息" top="18vh" :close-on-click-modal="false" v-drag :visible.sync="currencyVisible" width="500px">
      <el-form label-position="top" :model="currency">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="货币">
              <el-input v-model="currency.currency"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="货币描述">
              <el-input v-model="currency.currencyDesc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label=" ">
              <el-button type="primary" @click="queryCurrency">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :data="currencyList"
        :height="300"
        @row-dblclick="handleDblclick"
        border>
        <el-table-column
          prop="currency"
          label="货币"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="currencyDesc"
          label="货币描述"
          min-width="160">
        </el-table-column>
        <el-table-column
          prop="active"
          label="状态"
          min-width="80">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="no"
        :page-sizes="[20, 50, 100, 200, 500]"
        :page-size="size"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
import {
  //货币
  findCurrency,//查询
  addCurrency,//新增
  updateCurrency,//修改
  deleteCurrency,//删除

  //货币参考
  findRefCurrency,//查询
  addRefCurrency,//新增
  updateRefCurrency,//修改
  deleteRefCurrency,//删除

//货币汇率
  findExchangeCurrency,//查询
  addExchangeCurrency,//新增
  updateExchangeCurrency,//修改
  deleteExchangeCurrency,//删除

  queryUserSite

} from '@/api/fanucGroup/currency.js'

export default {
  data() {
    return {
      activeName: 'detail',
      currentRow: '',
      headerData: '',
      currentRow2: '',
      headerData2: '',
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: '检验方法' + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ['检验方法'],
      exportFooter: [],
      exportList: [],
      // 导出 end
      searchData: {
        site: this.$store.state.user.site,
        id: '',
        currency: '',
        currencyDesc: '',
        active: 'Y',
        baseCurrencyFlag: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
        page: 1,
        limit: 10,
      },
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      height: 200,
      dataList: [],
      dataList1: [],
      dataList2: [],
      dataListLoading: false,
      modalFlag: false,
      modalFlag1: false,
      modalFlag2: false,
      modalDisableFlag: false,
      modalDisableFlag1: false,
      modalDisableFlag2: false,
      modalData: {
        site: this.$store.state.user.site,
        id: '',
        currency: '',
        currencyDesc: '',
        active: 'Y',
        baseCurrencyFlag: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
      },
      //货币参考
      modalData1: {
        site: this.$store.state.user.site,
        id: '',
        currencyId: '',
        currency: '',
        currencyDesc: '',
        refCurrency: '',
        createDate: '',
      },
      //货币汇率
      modalData2: {
        site: this.$store.state.user.site,
        id: '',
        currency: '',
        exchangeRate: '',
        activationDate: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
      },
      // 标头展示
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableSite',
          tableId: '501004Table',
          tableName: '工厂编码',
          columnWidth: 80,
          columnProp: 'site',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '工厂编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCurrency',
          tableId: '501004Table',
          tableName: '货币',
          columnWidth: 80,
          columnProp: 'currency',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '货币',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCurrencyDesc',
          tableId: '501004Table',
          tableName: '货币描述',
          columnWidth: 160,
          columnProp: 'currencyDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '货币描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableBaseCurrencyFlag',
          tableId: '501004Table',
          tableName: '本位币',
          columnWidth: 80,
          columnProp: 'baseCurrencyFlag',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '本位币',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableActive',
          tableId: '501004Table',
          tableName: '状态',
          columnWidth: 80,
          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: 501004,
          serialNumber: '501004TableCreateDate',
          tableId: '501004Table',
          tableName: '录入时间',
          columnWidth: 120,
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '录入时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCreateBy',
          tableId: '501004Table',
          tableName: '录入人',
          columnWidth: 80,
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '录入人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableUpdateDate',
          tableId: '501004Table',
          tableName: '修改时间',
          columnWidth: 120,
          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: 501004,
          serialNumber: '501004TableUpdateBy',
          tableId: '501004Table',
          tableName: '修改人',
          columnWidth: 80,
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '修改人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList1: [
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCurrency',
          tableId: '501004Table',
          tableName: '货币',
          columnWidth: 80,
          columnProp: 'currency',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '参考货币',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCurrencyDesc',
          tableId: '501004Table',
          tableName: '货币描述',
          columnWidth: 140,
          columnProp: 'currencyDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '参考货币描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCreatDate',
          tableId: '501004Table',
          tableName: '最近汇率日期',
          columnWidth: 120,
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '最近汇率日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnList2: [
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableExchangeRate',
          tableId: '501004Table',
          tableName: '汇率',
          columnWidth: 80,
          columnProp: 'exchangeRate',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '汇率',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableActivationDate',
          tableId: '501004Table',
          tableName: '启用日期',
          columnWidth: 100,
          columnProp: 'activationDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '启用日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCreateDate',
          tableId: '501004Table',
          tableName: '录入时间',
          columnWidth: 120,
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '录入时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 501004,
          serialNumber: '501004TableCreateBy',
          tableId: '501004Table',
          tableName: '录入人',
          columnWidth: 80,
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '录入人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      rules: {
        currency: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        site: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur', 'change']
          }
        ],
      },
      options: [],
      userBuList: [],
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      menuId: this.$route.meta.menuId,

      siteList: [],
      currencyVisible: false,
      currency: {
        site: '',
        currency: '',
        currencyDesc: '',
      },
      currencyList: [],
      no: 1,
      size: 20,
      total: 0,
    }
  },

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


  //货币自动转化成大写
  watch: {
    modalData: {
      deep: true,
      handler: function (newV, oldV) {
        this.modalData.currency = this.modalData.currency.toUpperCase()
        this.$nextTick(() => {
          this.modalData1.currency = this.modalData1.currency.toUpperCase();
        });

      }
    },
    'modalData1.currency'(newVal, oldVal) {
      this.modalData1.currency = newVal.toUpperCase();
    }
  },

  created() {
    this.handleQuerySite()
    //页面在加载的时候就调用查询方法
    this.getDataList()
    // 获取用户的 site 和 bu
    // this.getSiteAndBuByUserName()
  },

  methods: {

    formatDate(date) {
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      // const hours = date.getHours().toString().padStart(2, '0');
      // const minutes = date.getMinutes().toString().padStart(2, '0');
      // const seconds = date.getSeconds().toString().padStart(2, '0');
      // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      return `${year}-${month}-${day}`;
    },

    // 查询获取数据列表
    getDataList() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      findCurrency(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
        }
      })
    },

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

    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
//货币参考
    changeData(row) {
      this.currentRow = JSON.parse(JSON.stringify(row))
      this.headerData = row
      this.refreshCurrentTabTable()
      this.changeData2({})
    },
    refreshCurrentTabTable() {
      findRefCurrency(this.currentRow).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code === 0) {
          this.dataList1 = data.rows
        } else {
          this.dataList1 = []
        }
      })
    },
//货币汇率
    changeData2(row) {
      this.currentRow2 = JSON.parse(JSON.stringify(row))
      this.headerData2 = row
      this.refreshCurrentTabTable2()
    },
    refreshCurrentTabTable2() {
      findExchangeCurrency(this.currentRow2).then(({data}) => {
        //区分请求成功和失败的状况
        if (data && data.code == 0) {
          this.dataList2 = data.rows
        } else {
          this.dataList2 = []
        }
      })
    },
    //货币
    // 新增按钮
    addModal() {
      this.handleQuerySite();
      this.modalData = {
        flag: '1',
        site: this.$store.state.user.site,
        id: '',
        currency: '',
        currencyDesc: '',
        active: 'Y',
        baseCurrencyFlag: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
      }
      this.modalDisableFlag = false
      this.modalFlag = true
    },

    // 修改按钮
    updateModal(row) {
      this.modalData = {
        flag: '2',
        id: row.id,
        site: this.$store.state.user.site,
        currency: row.currency,
        currencyDesc: row.currencyDesc,
        active: row.active,
        baseCurrencyFlag: row.baseCurrencyFlag === 'Y',
        createDate: row.createDate,
        createBy: row.createBy,
        updateDate: row.updateDate,
        updateBy: row.updateBy,
      }
      this.modalDisableFlag = true
      this.modalFlag = true
    },
    saveData() {
      if (this.modalData.baseCurrencyFlag) {
        this.modalData.baseCurrencyFlag = 'Y'
      } else {
        this.modalData.baseCurrencyFlag = 'N'
      }
      if (this.modalData.flag === '1') { // 新增
        addCurrency(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 { // 修改
        updateCurrency(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: '确定'
            })
          }
        })
      }
    },
    deleteModal(row) {
      this.$confirm(`是否删除此数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCurrency(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(() => {
      })
    },

    //货币参考
    // 新增按钮
    addModal1() {
      if (!this.currentRow) {
        this.$message.warning('请选择货币记录！')
        return
      }
      this.modalData1 = {
        flag1: '1',
        id: '',
        site: this.$store.state.user.site,
        currency: '',
        currencyDesc: '',
        refCurrency: '',
        createDate: '',
        currencyId: this.currentRow.id,
      }
      this.modalDisableFlag1 = false
      this.modalFlag1 = true
    },
    // 修改按钮
    updateModal1(row) {
      this.modalData1 = {
        flag1: '2',
        id: row.id,
        site: this.$store.state.user.site,
        currency: row.currency,
        currencyDesc: row.currencyDesc,
        refCurrency: row.refCurrency,
        createDate: row.createDate,
      }
      this.modalDisableFlag1 = true
      this.modalFlag1 = true
    },
    // 删除方法
    deleteModal1(row) {
      this.$confirm(`是否删除此数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteRefCurrency(row).then(({data}) => {
          if (data && data.code === 0) {
            this.refreshCurrentTabTable()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },
    // 新增/修改方法
    saveData1() {
      if (this.modalData1.flag1 === '1') { // 新增
        if (this.modalData1.currencyId == null || this.modalData1.currencyId === '') {
          this.$message.warning('请选择一条货币数据！')
          return
        }
        addRefCurrency(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable()
            this.modalFlag1 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else { // 修改
        updateRefCurrency(this.modalData1).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable()
            this.modalFlag1 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },

    //货币汇率
    // 新增按钮
    addModal2() {
      if (!this.currentRow2) {
        this.$message.warning('请选择参考货币记录！')
        return
      }
      this.modalData2 = {
        flag: '1',
        id: '',
        currency: this.currentRow2.currency,
        activationDate: this.formatDate(new Date()),
        exchangeRate: '',
        createDate: '',
        createBy: '',
        updateDate: '',
        updateBy: '',
        currencyRateRefcurrencyId: this.currentRow2.id,
      }
      this.modalDisableFlag2 = false
      this.modalFlag2 = true
    },

    // 修改按钮
    updateModal2(row) {
      this.modalData2 = {
        flag: '2',
        id: row.id,
        exchangeRate: row.exchangeRate,
        activationDate: row.activationDate,

      }
      this.modalDisableFlag2 = true
      this.modalFlag2 = true
    },
    saveData2() {
      if (this.modalData2.flag === '1') { // 新增
        if (this.modalData2.currency == null || this.modalData2.currency === '') {
          this.$message.warning('请选择一条货币参考数据！')
          return
        }
        addExchangeCurrency(this.modalData2).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable()
            this.refreshCurrentTabTable2()
            this.modalFlag2 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      } else { // 修改
        updateExchangeCurrency(this.modalData2).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.refreshCurrentTabTable2()
            this.modalFlag2 = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }
    },

    deleteModal2(row) {
      this.$confirm(`是否删除此数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteExchangeCurrency(row).then(({data}) => {
          if (data && data.code === 0) {
            this.refreshCurrentTabTable2()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    // 查询检验类型
    inspectionTypeSearch() {
      let tempData = {
        site: this.$store.state.user.site
      }
      inspectionTypeSearch(tempData).then(({data}) => {
        if (data.code === 0) {
          this.options = data.rows
        }
      })
    },

    // 校验用户是否收藏
    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 findAll1(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
    },

    // 动态列开始 获取 用户保存的 格式列
    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.columnDetailList = 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.columnDetailList = 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')
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authSave = !saveFlag
      this.authUpdate = !updateFlag
      this.authDelete = !deleteFlag
    },
    handleQuerySite() {
      let params = {
        username: this.$store.state.user.name,
      }
      queryUserSite(params).then(({data}) => {
        if (data && data.code === 0) {
          this.siteList = data.row2
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    rowStyle({row}) {
      if (this.currentRow.site === row.site && this.currentRow.currency === row.currency) {
        return {'background-color': '#E8F7F6', cursor: 'pointer'};
      }
    },
    rowStyle2({row}) {
      if (this.currentRow2.id === row.id) {
        return {'background-color': '#E8F7F6', cursor: 'pointer'};
      }
    },
    handleBlurCurrency() {
      let params = {
        site: this.modalData1.site,
        currency: this.modalData1.currency,
        page: 1,
        limit: this.searchData.limit,
      }
      findCurrency(params).then(({data}) => {
        if (data && data.code === 0) {
          if (data.page.list.length === 1) {
            this.modalData1.currency = data.page.list[0].currency
            this.modalData1.currencyDesc = data.page.list[0].currencyDesc
          } else {
            this.modalData1.currencyDesc = ''
          }
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    handleClickCurrency() {
      this.currency.site = this.modalData1.site
      this.currency.currency = this.modalData1.currency
      this.queryCurrency();
      this.currencyVisible = true
    },
    queryCurrency() {
      let params = {
        ...this.currency,
        page: this.no,
        limit: this.size,
      }
      findCurrency(params).then(({data}) => {
        if (data && data.code === 0) {
          this.currencyList = data.page.list
          this.total = data.page.totalCount
        } else {
          this.$message.warning(data.msg)
        }
      }).catch((error) => {
        this.$message.error(error)
      })
    },
    handleSizeChange(val) {
      this.size = val
      this.queryCurrency()
    },
    handleCurrentChange(val) {
      this.no = val
      this.queryCurrency()
    },
    handleDblclick(row) {
      this.modalData1.currency = row.currency
      this.modalData1.currencyDesc = row.currencyDesc
      this.currencyVisible = false
    }
  }
}
</script>

<style scoped>
.numInput /deep/ .el-input__inner {
  text-align: right;
}

/deep/ .inlineNumber input::-webkit-outer-spin-button,
/deep/ .inlineNumber input::-webkit-inner-spin-button {
  -webkit-appearance: none;

}

/deep/ .inlineNumber input[type="number"] {
  -moz-appearance: textfield;
  padding-right: 5px !important;
}
</style>
