<template>
    <!-- 往来单位管理页面 -->
    <div class="app-container">
        <!-- 列表 -->
        <TableModel
          :formLabel="formLabel"
          :columnsList="columnsList"
          :request-api="querySupplierListApi"
          ref="tableRef"
        >
            <template slot="btn" slot-scope="{ queryParams }">
                <el-button type="primary" @click="handleAddData()"
                    >新建</el-button
                >
                <el-button @click="handleExportData(queryParams, 'base/masupplier/export', '物资厂家清单')"
                    >导出</el-button
                >
            </template>

            <template slot="handle" slot-scope="{ data }">
                <el-button
                    type="primary"
                    size="mini"
                    @click="handleEditData(data)"
                    >编辑</el-button
                >
                <el-button
                    type="danger"
                    size="mini"
                    @click="handleDeleteData(data.id, delSupplierListApi)"
                    >删除</el-button
                >
            </template>
            <template slot="picUrl" slot-scope="{ data }">
<!--              <img :src="data.picUrl" style="width: 50px; height: 50px" alt="">-->
              <h4
                style="color: #02A7F0; cursor: pointer"
                v-if="data.picUrl === '' || data.picUrl === null"
                @click="handleEditData(data)"
              >上传</h4>
              <h4
                style="color: #02A7F0; cursor: pointer"
                v-else
                @click="openUrl(data.picUrl)"
              >查看</h4>
            </template>
            <template slot="phone" slot-scope="{ data }">
              {{ phoneCrypto(data.phone) }}
            </template>
        </TableModel>

        <!-- 新增以及修改时的弹框 -->
        <DialogModel
            :dialogConfig="dialogConfig"
            @closeDialogOuter="closeDialogOuter"
        >
            <template slot="outerContent">
                <!-- 新增以及修改数据的表单组件 -->
                <FormMasupplier
                    @closeDialog="closeDialog"
                    :editParams="editParams"
                />
            </template>
        </DialogModel>

        <!--  缩略图弹框  -->
        <el-dialog
          width="60%"
          :visible.sync="picVisible"
          title="图片预览"
          append-to-body>
          <img :src="picUrl" style="width: 100%; height: 500px" alt="">
        </el-dialog>
    </div>
</template>

<script>
import { columnsList, dialogConfig, formLabel } from './config'
import { commonMixin } from '../mixins/common'
import FormMasupplier from './components/form-masupplier.vue'
import {
  querySupplierListApi,
  delSupplierListApi
} from '@/api/material/masupplier'

export default {
    name: 'storageConfigManage',
    mixins: [commonMixin], // 混入公共方法和数据
    components: { FormMasupplier },
    created() {
      this.picVisible = false
      this.picUrl = undefined
    },
    methods: {
      querySupplierListApi,
      delSupplierListApi,
      openUrl(url) {
        this.picUrl = url
        this.picVisible = true
      }
    },
    data() {
        return {
            formLabel,
            columnsList,
            dialogConfig,
            addDialogTitle: '新建物资厂家', // 新建时弹框标题
            editDialogTitle: '修改物资厂家', // 修改时弹框标题
            picVisible: false,
            picUrl: undefined
        }
    },
}
</script>
