<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="600px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="发布者名字"  :label-width="widhts">
            <el-input v-model="form.name" style="width: 370px;" />
          </el-form-item>
          <!-- <el-form-item label="content">
            <el-input v-model="form.content" style="width: 370px;" />
          </el-form-item> -->
          <!-- <el-form-item label="webSite">
            <el-input v-model="form.webSite" style="width: 370px;" />
          </el-form-item> -->
          <el-form-item label="发布者手机号" :label-width="widhts">
            <el-input v-model="form.phone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="核销管理员" :label-width="widhts">
             <el-select v-model="form.uid" placeholder="请选择发布者管理员" style="width: 370px;">
    <el-option
      v-for="(item,index) in options"
      :key="index"
      :label="item.nickname"
      :value="item.uid">
    </el-option>
  </el-select>
          </el-form-item>
          <el-form-item label="发布者头像" :label-width="widhts">
            <!-- <el-input v-model="form.image" style="width: 370px;" /> -->
            <single-pic
          v-model="form.image"
          type="image"
          :num="1"
          :width="150"
          :height="150"
        />
          </el-form-item>
          <el-form-item label="发布状态" :label-width="widhts">
            <!-- <el-input v-model="form.status" style="width: 370px;" /> -->
            <el-radio-group v-model="form.status">
    <el-radio :label="0">不发布</el-radio>
    <el-radio :label="1">发布</el-radio>
  </el-radio-group>
          </el-form-item>
          <!-- <el-form-item label="contact">
            <el-input v-model="form.contact" style="width: 370px;" />
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" align="center" />
        <el-table-column v-if="columns.visible('uid')" prop="uid" label="uid" />
        <el-table-column v-if="columns.visible('name')" prop="name" label="发布者名字" align="center"  />
        <!-- <el-table-column v-if="columns.visible('webSite')" prop="webSite" label="webSite" /> -->
        <el-table-column v-if="columns.visible('phone')" prop="phone" label="发布者手机号" align="center"  />
        <el-table-column v-if="columns.visible('image')" prop="image" label="发布者头像" align="center"  >
          <template slot-scope="scope">
            <a   :href="scope.row.image" style="color: #42b983" target="_blank"
              ><img :src="scope.row.image" alt="点击打开" class="el-avatar"
            /></a>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('status')" prop="status" label="发布状态" align="center" >
          <template slot-scope="scope">
            <span v-if="scope.row.status ==0">{{'未发布'}}</span>
            <span v-if="scope.row.status ==1">{{'已发布'}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column v-if="columns.visible('contact')" prop="contact" label="contact" /> -->
        <el-table-column v-permission="['admin','activityPublisher:edit','activityPublisher:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudActivityPublisher from '@/api/activityPublisher'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";
import singlePic from "@/components/singlematerial";
import {gets} from '@/api/publisher'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '活动发布', url: 'api/activityPublisher', sort: 'id,desc', crudMethod: { ...crudActivityPublisher }})
const defaultForm = { id: null, uid: null, name: null, desc: null, content: null, webSite: null, phone: null, image: '', status: 0, contact: null, createTime: null, updateTime: null, isDel: null }
export default {
  name: 'ActivityPublisher',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList,singlePic},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['is_enable'],
  data() {
    return {
       options: [],
      widhts:'120px',
      permission: {
        add: [ 'activityPublisher:add'],
        edit: ['activityPublisher:edit'],
        del: [ 'activityPublisher:del']
      },
      rules: {
        name: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      this.publishers()
    },
    publishers(){
      let plams = {
        page: 0,
size: 500,
sort: 'uid,desc'
      }
      gets(plams).then(res=>{
        console.log(res.content)
        this.options = res.content
      })
    }
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
