<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" :search="false" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
      <el-table-column label="演出厅" align="center" prop="performHallName" />
      <el-table-column label="剧目名称" align="center" prop="performName" />
      <el-table-column label="商品名称" align="center" prop="goodsName" />
      <el-table-column label="场次信息" align="center" prop="goodsName1">
        <template slot-scope="scope">
          <span>{{ scope.row.times }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <span v-hasPermi="['otaMr:ctrip:push']" style="display: inline-block;">
            <el-button
              size="mini"
              type="text"
              style="margin-right: 10px;"
              @click="handlePush(scope.row,scope.index)"
            >{{ (scope.row.status == -1 || !scope.row.status) ? '上线' : '下线' }}</el-button>
          </span>
          <span v-hasPermi="['otaMr:ctrip:time']" style="display: inline-block;margin-right: 10px;">
            <el-button
              size="mini"
              type="text"
              style="margin-left: 10px;"
              @click="handleUpdate(scope.row,'yesPush')"
            >价格日历</el-button>
          </span>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row,scope.index,'noPush')"
            v-hasPermi="['otaMr:ctrip:scheduling']"
          >排期推送</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 编辑商品弹框 -->
    <data-edit
      ref="dataEdit"
      @getList="getList"
      :dict="dict"></data-edit>

  </div>
</template>

<script>

import { pageList, updateById,stockUpdateById } from '@/api/otaMr/ctrip'
import dataEdit from "./dialog/dataEdit.vue";

export default {
  name: "Ctrip",
  dicts: ['tiktok_process','tiktok_online','tiktok_category'],
  components: { dataEdit },
  data() {
    return {
      // 遮罩层
      loading: true,
      otaLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      otaType: '1',

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      visibleStatus: false,
      newObj: {},
      visibleType: '',
      otaForm: {},
      otaRules: {
        name: [{ required: true, message: "请输入供应商id", trigger: ["change","blur"] }],
        otaKey: [{ required: true, message: "请输入client id", trigger: ["change","blur"] }],
        otaValue: [{ required: true, message: "请输入client secret", trigger: ["change","blur"] }]
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList(this.addDateRange(this.queryParams, this.dateRange))
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total?Number(response.data.total):0;
          this.loading = false;
        }
      ).catch(()=>{
        this.dataList = []
        this.total = 0;
        this.loading = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.dataList = [];
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      this.$refs["dataEdit"].openDialog("修改数据", row, type);
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除商品名称为"' + row.goodsName + '"的数据项？').then(function() {
        return deleteById(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 推送 */
    handlePush(row) {
      this.$modal.confirm(`是否确认${ row.status == 1 ? '下线': '上线'}此商品吗？`).then(function() {
        return updateById({
          id: row.id,
          status: row.status == 1  ? 0 : 1
        });
      }).then(() => {
        this.$modal.msgSuccess(`${ row.status == 1 ? '下线': '上线' }成功`);
        this.getList();
      }).catch(() => {

      });
    },
  }
};
</script>
