<!-- 经销商授权信息-查看 -->
<template>
  <el-dialog title="查看" :visible.sync="visible" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="formData" label-position="left" label-width="120px">
      <el-form-item v-for="column in formColumns" :label="column.title" :prop="column.key">
        <el-input v-if="column.type == 'Input'" readonly v-model="formData[column.key]" autocomplete="off"></el-input>

        <el-date-picker v-if="column.type == 'DateRange'" readonly v-model="formData[column.key]" type="daterange"
          format="yyyy-MM-dd " value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期"></el-date-picker>

        <el-date-picker v-if="column.type == 'Date'" readonly v-model="formData[column.key]" type="date"
          format="yyyy-MM-dd " value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>

      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="setVisible(false)">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {

  name: 'authprivSee',
  data() {
    const arr2Obj = function (data, keyName, valueName) {
      return Object.fromEntries(
        data.map((item) => [item[keyName], item[valueName]])
      );
    };

    const formColumns = [
      { title: '经销商名称', key: 'dealerName', type: 'Input' },
      { title: '授权区/医院', key: 'authorizedAreaName', type: 'Input' },
      { title: '授权产品', key: 'authorizedProductsName', type: 'Input' },
      { title: '授权期限', key: 'time', type: 'DateRange' },
      { title: '授权书开具时间', key: 'issueTime', type: 'Date' },
    ];

    const initFormColumns = () => formColumns;
    const initFormData = () => arr2Obj(initFormColumns(), "key", "value")

    return {
      visible: false,
      formData: { ...initFormData() },
      formColumns: initFormColumns(),

    }
  },
  methods: {
    // 控制弹窗展示
    setVisible(val) {

      this.visible = val;

    },
    setFormData(data) {

      if (data.id) {

        let objData = { ...data };

        objData['time'] = [objData.startTime, objData.endTime];

        // delete data.startTime
        // delete data.endTime
        this.formData = objData;

      }

    },
  },
  created() {
  }

}
</script>


<style lang="scss" scoped>
.authpriv {
  width: calc(100% - 24px);
  height: 100%;
  margin: 10px
}
</style>