<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="94px">
      <el-form-item label="动态标题" prop="dataName">
        <el-input v-model="queryParams.title" placeholder="请输入联系人姓名" clearable />
      </el-form-item>
      <!-- <el-form-item label="联系电话" prop="tableName">
        <el-input v-model="queryParams.tableName" placeholder="请输入联系电话" clearable />
      </el-form-item>
      <el-form-item label="维修时间" prop="tableComment">
        <el-date-picker v-model="value1" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态" prop="tableComment">
        <el-select v-model="value" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleGenTable">导出</el-button>
        <el-button type="primary" plain size="mini" @click="modify(0, '3')">新增发布</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" width="50" label="序号" align="center">
      </el-table-column>
      <el-table-column prop="title" label="动态标题" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="content" label="动态内容" :show-overflow-tooltip="true" align="center">
      </el-table-column>
      <el-table-column prop="address" label="图片展示" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="imageCaption(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="modify(scope.row, '1')">修改</el-button>
          <el-button type="text" size="small" @click="modify(scope.row, '2')">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 其他 -->
    <comindex :dialogVisibl="dialogVisible" @visivie='visivie' :control="control"></comindex>
    <!-- 修改 详情 -->
    <commodify ref="refModify" :disabled="disabled" :title="title" :btn="btn" :dialogVisibl="dialogVi" @diaisibl="diaisibl"
      @onSubmit="onSubmit">
    </commodify>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import comindex from './components/index'
import commodify from './components/modify'
import { articleGET, articlePOST, articlesGET, articlePUT } from '@/api/orderform/index'
export default {
  name: "orderform",
  data() {
    return {
      dialogVisible: false,
      dialogVi: false,
      disabled: false,
      control: '',
      total: 0,
      value1: '',
      title: '动态发布',
      btn:'确认发布',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }, {
        date: '2016-05-04',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1517 弄',
        zip: 200333
      }, {
        date: '2016-05-01',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1519 弄',
        zip: 200333
      }, {
        date: '2016-05-03',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1516 弄',
        zip: 200333
      }],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: undefined,
        tableComment: undefined,
        title: ""
      },
      // 预览参数
      preview: {
        open: false,
        title: "代码预览",
        data: {},
        activeName: "domain.java"
      }
    };
  },
  components: {
    comindex,
    commodify
  },
  created() {
    this.artic()
  },
  methods: {
    // 搜索
    handleQuery() {
      this.artic()
    },
    //列表接口
    artic() {
      articleGET({ ...this.queryParams }).then((res) => {
        this.total = res.total
        this.tableData = res.rows
      })
    },
    // 重置
    resetQuery() {
      this.queryParams.title = '';
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.artic()
    },
    // 导出订单
    handleGenTable() {
      this.download('/xinrenli/article/export', {
        ...this.queryParams
      }, `role_${new Date().getTime()}.xlsx`)
    },
    // 页码切换
    getList() {
      this.artic()
    },
    // 打开查看详情
    imageCaption(sta) {
      this.control = sta.fileVos[0].url
      this.dialogVisible = true
    },
    // 修改详情
    modify(sta, val) {
      if (val == '1') {
        this.title = '动态修改'
        this.btn = '确定修改'
        this.$refs['refModify'].articles(sta.id)
        this.disabled = false
      } else if (val == '2') {
        this.$refs['refModify'].articles(sta.id)
        this.disabled = true
        this.title = '动态详情'
        this.btn = '返回'
      } else if (val == '3') {
        this.$refs['refModify'].form = {}
        this.title = '动态发布'
        this.btn = '确认发布'
      }
      this.dialogVi = true

    },
    // articles(val) {
    //   articlesGET(val).then((res) => {
    //      this.$refs['refModify'].form.content = res.data.content
    //      this.$refs['refModify'].form.title = res.data.title

    //   })
    // },
    // 其他 弹窗关闭
    visivie() {
      this.dialogVisible = false
    },
    // 详情 修改 弹窗关闭
    diaisibl() {
      this.$refs['refModify'].form.content = ''
      this.$refs['refModify'].form.title = ''
      this.dialogVi = false
    },
    // 详情 修改 确认修改
    onSubmit(val) {
      console.log(val, 'val=========')
      console.log(this.title,'ppppppppppppppp')
      if (this.title == '动态发布') {
        articlePOST({ ...this.$refs['refModify'].form }).then((res) => {
          this.$refs['refModify'].form.content = ''
          this.$refs['refModify'].form.title = ''
          this.$refs['refModify'].form.fileVos = []
          this.dialogVi = false
          this.artic()
        })
      } else if (this.title == '动态修改') {
        articlePUT({ ...this.$refs['refModify'].form }).then((res) => {
          this.$refs['refModify'].form.content = ''
          this.$refs['refModify'].form.title = ''
          this.$refs['refModify'].form.fileVos = []
          this.dialogVi = false
          this.artic()
        })
      }else if(this.title == '动态详情'){
        this.dialogVi = false
      }
    }
  }
};
</script>
