<style>
  .WebSiteContract .el-button.is-circle {
    padding: 6px;
  }
.WebSiteContract .preview {
   color: #409eff;text-decoration:underline
  }

</style>
<template>
  <!--契约管理-->
  <div class="WebSiteContract">
    <div class="query-box">
      <ul>
        <li>
          <label>{{$t('system.query_airName')}}</label>
          <el-input v-model="msg.Name" :placeholder="$t('system.ph_in')" @keyup.native.enter="getData" class="w210">
          </el-input>
        </li>
        <li>
          <input type="button" class="hollowFixedBtn" :value="$t('pub.searchBtn')"
            @click="resetPageIndex(),getData()" />
          <input type="button" class="normalBtn" @click="outerVisible=true,clearMsg()" :value="$t('objFill.v101.shangcqiyue')" />
        </li>
      </ul>
    </div>
    <div>
      <el-table :data="dataList" style="width: 100%" v-loading="loading"
        :default-sort="{prop: 'date', order: 'descending'}">
        <el-table-column prop="Name" :label="$t('objFill.v101.danganminc')" header-align="center" align="center">
        </el-table-column>
         <el-table-column :label="$t('fnc.chakan')" header-align="center" align="center">
          <template slot-scope="scope">
            <a v-if="scope.row.Url" :href="scope.row.Url" target="_blank" class="preview">{{$t('sm.yulan')}}</a>
          </template>
        </el-table-column>
        <el-table-column prop="IsOpen" :label="$t('admin.admin_status')" header-align="center" align="center">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.IsOpen" :active-value="1" :inactive-value="0" active-color="#13ce66"
              inactive-color="#dcdfe6" @change="UpdateIsOpen(scope.row)"></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="CreateByName" :label="$t('objFill.v101.jianliren')" header-align="center" align="center">
        </el-table-column>
        <el-table-column prop="CreateTimeStr" :label="$t('objFill.v101.jianlishij')" header-align="center" align="center">
        </el-table-column>
        <el-table-column :label="$t('system.table_operation')" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" :content="$t('system.table_edit')" placement="top-start">
              <el-button type="primary" icon="el-icon-edit" circle @click="outerVisible = true,updateData(scope.row)">
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="$t('system.table_delete')" placement="top-start">
              <el-button type="danger" icon="el-icon-delete" circle @click="deleteData(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
        layout="total,prev, pager, next, jumper" :page-size='msg.pageSize' :total=total>
      </el-pagination>
    </div>

    <el-dialog :title="$t('objFill.v101.shangcqiyue')" :visible.sync="outerVisible" center width="400px">
      <el-form :model="addMsg" ref="addMsg" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('admin.admin_status')">
              <el-radio v-model="addMsg.IsOpen" :label="1">{{$t('pub.openSel')}}</el-radio>
              <el-radio v-model="addMsg.IsOpen" :label="0">{{$t('pub.closeSel')}}</el-radio>
            </el-form-item>
            <el-form-item :label="$t('objFill.v101.danganminc')">
              <el-input type="text" v-model="addMsg.Name" maxlength="50" :placeholder="$t('objFill.v101.danganminc')">
              </el-input>
            </el-form-item>
            <el-form-item :label="$t('objFill.v101.danganshangc')">
              <el-upload :http-request="UploadAttachment" :multiple="true" accept=".pdf,.PDF" :show-file-list="false"
                action="">
                <div class="addIconDiv">
                  <i class="web_addImg iconfont icon-img_haha"></i>
                </div>
              </el-upload>
              <a v-if="addMsg.Url" :href="addMsg.Url" target="_blank" class="preview">{{$t('sm.yulan')}}</a>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <button class="normalBtn" type="primary" @click="submitForm('addMsg')">{{$t('pub.saveBtn')}}</button> &nbsp;
        <button class="hollowFixedBtn" @click="outerVisible = false">{{$t('pub.cancelBtn')}}</button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        loading: false,
        msg: {
          Name: '', //名称
          pageSize: 15,
          pageIndex: 1,
        },
        total: 0,
        currentPage: 1,
        //弹窗
        outerVisible: false,
        dataList: [],
        addMsg: {
          Id: 0, //编号
          IsOpen: 0, //状态(0-关闭，1-开启)
          Name: '', //档案名称
          Url: '', //档案路劲
        },
      }
    },
    mounted() {
      this.getData();
    },
    methods: {
      //获取配置
      getData() {
        //获取现有线路列表
        this.loading = true;
        this.apipost(
          "ws_get_GetContractPageList",
          this.msg,
          res => {
            this.loading = false;
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data.pageData;
              this.total = res.data.data.count
            } else {
              this.loading = false;
            }
          },
          err => {}
        );
      },
      handleCurrentChange(val) {
        //翻页功能按钮
        this.msg.pageIndex = val;
        this.getData();
      },
      resetPageIndex() {
        //查询初始化页码
        this.msg.pageIndex = 1;
        this.currentPage = 1;
      },
      //更新广告状态
      UpdateIsOpen(item) {
        this.apipost(
          "ws_post_UpdateContractIsOpen", {
            Id: item.Id,
            IsOpen: item.IsOpen
          },
          res => {
            if (res.data.resultCode == 1) {
              this.Success(res.data.message);
              this.getData();
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      //修改
      updateData(item) {
        this.apipost(
          "ws_get_GetContract", {
            Id: item.Id,
          },
          res => {
            if (res.data.resultCode == 1) {
              var tempData = res.data.data;
              this.addMsg.Id = tempData.Id;
              this.addMsg.IsOpen = tempData.IsOpen;
              this.addMsg.Name = tempData.Name;
              this.addMsg.Url = tempData.Url;
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      //删除
      deleteData(item) {
        var that = this;
        that.Confirm(that.$t('tips.shifoushanchu'), function () {
          that.apipost(
            "ws_post_RemoveContract", {
              Id: item.Id
            },
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getData();
              } else {
                that.Error(res.data.message);
              }
            },
            null
          );
        });
      },
      //清空数据
      clearMsg() {
        this.addMsg.Id = 0;
        this.addMsg.IsOpen = 0;
        this.addMsg.Name = "";
        this.addMsg.Url = "";
      },
      //新增、修改广告
      submitForm(addMsg) {
        this.apipost(
          "ws_post_SetContract", this.addMsg,
          res => {
            if (res.data.resultCode == 1) {
              this.getData();
              this.clearMsg();
              this.Success(res.data.message);
              this.outerVisible = false;
            } else {
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      //上传图片
      UploadAttachment(file) {
        let newArr = [];
        newArr.push(file.file);
        let fileName = file.file.name;
        var path = "/Upload/WebSite/";
        this.UploadSelfFileT(path, newArr, x => {
          var str = x.data.FilePath;
          var imgUrl = this.domainManager().ViittoFileUrl + str;
          this.addMsg.Url = imgUrl;
        });
      },
    }
  }

</script>
