<!-- 系统配置 - 权限配置 -->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="thetopbox">
      <el-form ref="form" :model="queryParams" label-width="100px">
        <el-row>
          <el-col :span="4"  style="margin-left: -30px">
            <el-form-item :label="$t('MN_F_T_345')" prop="status">
              <el-select v-model="queryParams.sendType" clearable placeholder="">
                <el-option
                  v-for="item,index in getPostionList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('MN_F_T_346')" prop="creationTime">
              <el-date-picker
                v-model="modifiedTime"
                value-format="yyyy-MM-dd"
                type="datetimerange"
                range-separator=""
                :start-placeholder="$t('CK_KS_4')"
                :end-placeholder="$t('CK_KS_5')"
                @change="changeTime"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('w_0445')" prop="creationTime">
              <el-date-picker
                v-model="modifiedTime1"
                value-format="yyyy-MM-dd"
                type="datetimerange"
                range-separator=""
                :start-placeholder="$t('CK_KS_4')"
                :end-placeholder="$t('CK_KS_5')"
                @change="changeTime1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="research()" style="margin-left: 40px"> {{ $t('MN_T_2') }}</el-button>
              <el-button class="my_reset" @click="reChongzhi"> {{ $t('MN_T_3') }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" style="background-color: #48B2FD" class="thebtn1" @click="addRules">{{$t('w_0328')}}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="730px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          :span-method="objectSpanMethod"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column align="center" prop="sort" :label="$t('MN_F_T_350')" />
          <el-table-column align="center" prop="phone" :label="$t('MN_F_T_351')" >
            <template slot-scope="scope">
                <img :src="scope.row.picture" style="width: 44px;height: 44px;border-radius: 8px" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="positionVal" :label="$t('MN_F_T_345')" />
          <el-table-column align="center" prop="link" :label="$t('MN_F_T_352')" />
          <el-table-column align="center" prop="creationTime" :label="$t('PER_DA_9')" />
          <el-table-column align="center" prop="effectiveDate" :label="$t('w_0445')" />
          <el-table-column align="center" :label="$t('MY_ORD_14')" width="150">
            <template slot-scope="scope">
              <el-button
                class="colors"
                type="text"
                style="color: #108EE9"
                size="small"
                @click.native.prevent="moveUp(scope.row)"
              >
                {{$t('MN_F_T_353')}}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #108EE9"
                @click.native.prevent="moveDown(scope.row)"
              >
                {{$t('MN_F_T_354')}}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #009B58"
                @click.native.prevent="updateTop(scope.row)"
              >
                {{$t('N_I_245')}}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #FFAD41"
                @click.native.prevent="updateShow(scope.row)"
              >
                {{ $t('MY_CK_18') }}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #C73030"
                @click.native.prevent="delRole(scope.row)"
              >
                {{ $t('CK_KS_47') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <el-dialog
      :title="title"
      :visible.sync="ruleShow"
      width="50%"
      center
      :close-on-click-modal="false"
      :before-close="handleClose"
    >
      <el-form ref="forms" :rules="rules" :model="table" label-width="80px">
        <el-form-item :label="$t('MN_F_T_290')" class="input-s" prop="position">
          <el-select v-model="table.position" clearable placeholder="">
            <el-option
              v-for="item,index in getPostionList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('MN_F_T_350')" prop="sort">
          <el-input
            v-model="table.sort"
            type="number"
            clearable
            :placeholder="$t('S_C_70')"
          />
        </el-form-item>
        <el-form-item :label="$t('MN_F_T_352')" prop="link">
          <el-input
            v-model="table.link"
            clearable
            :placeholder="$t('S_C_70')"
          />
        </el-form-item>
        <el-form-item :label="$t('w_0445')" prop="effectiveDate">
          <el-date-picker
            v-model="table.effectiveDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            :placeholder="$t('CK_KS_38')"
          />
        </el-form-item>
        <el-form-item label="上传banner" class="banner" label-width="200" prop="picture">
          <imageUpload v-model="table.picture" />
        </el-form-item>
        <div style="padding-top: 30px;display: flex;justify-content: center">
          <el-button type="text" size="small" class="button-style" @click="handleClose"> {{ $t('ENU_P_TYPE0') }}</el-button>
          <el-button v-preventReClick="3000" type="text" size="small" class="button-style" style="margin-left: 40px;background-color: #C8161D;" @click="submitBtn()">
            {{ $t('ENU_P_TYPE4') }}
          </el-button>
        </div>
      </el-form>
    </el-dialog>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="research"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import { getbdmenuList, getPubenumsList } from '@/api/system'
import { getgradeRanglist, getAwardsListChiose } from '@/api/level'
import * as api from '@/api/sms.js'
import { Message } from 'element-ui'
import { deleteAgreement } from '@/api/configManage'
import ImageUpload from '@/components/ImageUpload'
export default {
  name: 'Qxpz',
  components: {
    topBar,
    ImageUpload
  },
  data() {
    return {
      modifiedTime:[],
      modifiedTime1:[],
      title: this.$t('w_0328'),
      forms: '',
      rules: {
        position: [
          { required: true, message: this.$t('MN_F_T_355'), trigger: 'blur' }
        ],
        picture: [
          { required: true, message: this.$t('MN_F_T_356'), trigger: 'blur' }
        ],
        sort: [
          { required: true, message: this.$t('MN_F_T_357'), trigger: 'blur' }
        ],
        // link: [
        //   { required: true, message: this.$t('MN_F_T_358'), trigger: 'blur' }
        // ],
        effectiveDate: [
          { required: true, message: this.$t('MN_F_T_358'), trigger: 'blur' }
        ]
      },
      table: { position: '', picture: '', sort: '', effectiveDate: '', link: '' },
      ruleShow: false,
      moren: 'advertisementBanner',
      topList: [
        {
          name: this.$t('MN_F_T_142'),
          path: 'advertisementBanner'
        }
      ],
      defaultParams: {
        label: 'label',
        value: 'value',
        children: 'enumList'
      },
      multipleSelection: [],
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      gradeRangList: [],
      awardsList: [],
      statusList: [{ 'name': this.$t('MN_F_T_334'), 'id': '1' }, { 'name': this.$t('MN_F_T_335'), 'id': '2' }],
      statusList1: [{ 'name': this.$t('MN_F_T_359'), 'id': '0' }, { 'name': this.$t('MN_F_T_360'), 'id': '1' }],
      menuOptions: [],
      loading:false,
      tableData: [],
      total: 0,
      types: '',
      formId: '',
      getPostionList: []
    }
  },
  created() {
    this.research()
    this.getPostion()
  },
  methods: {
    // 置顶
    updateTop(item) {
      api.getPostion({ 'pkId': item.pkId }).then((res) => {
        if (res.code == '200') {
          Message({
            message: res.msg,
            type: 'success'
          })
          this.research()
        }
      })
    },
    // 上移
    moveUp(item) {
      api.moveUp({ 'pkId': item.pkId }).then((res) => {
        if (res.code == '200') {
          Message({
            message: res.msg,
            type: 'success'
          })
          this.research()
        }
      })
    },
    // 下移
    moveDown(item) {
      api.moveDown({ 'pkId': item.pkId }).then((res) => {
        if (res.code == '200') {
          Message({
            message: res.msg,
            type: 'success'
          })
          this.research()
        }
      })
    },
    getPostion() {
      api.getPostion().then((res) => {
        this.getPostionList = res.data
      })
    },
    addRules() {
      this.types = 1
      this.ruleShow = true
      this.title = this.$t('w_0328')
    },
    submitBtn() {
      console.error(this.table)
      // 添加角色
      this.ruleSubmit()
    },
    updateShow(item) {
      this.types = 2
      this.title = this.$t('PER_DA_20')
      // 更新角色信息
      this.formId = item.pkId
      api.getBannerDetails(item.pkId).then((res) => {
        if (res.code === 200) {
          this.ruleShow = true
          this.table = { position: res.data.position, picture: res.data.picture,
            sort: res.data.sort, effectiveDate: res.data.effectiveDate, link: res.data.link }
        } else {
          Message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    },
    delRole(item) {
      // 删除广告
      this.$confirm(this.$t('MN_F_T_361'), this.$t('w_0034'), {
        confirmButtonText: this.$t('w_0035'),
        cancelButtonText: this.$t('ENU_P_TYPE0'),
        type: 'warning'
      }).then(() => {
        api.delBanner(item.pkId).then((res) => {
          if (res.code === 200) {
            Message({
              message: res.msg,
              type: 'success'
            })
            this.research()
          } else {
            Message({
              message: res.msg,
              type: 'error'
            })
          }
        })
      })
    },
    ruleSubmit() {
      const datas = this.table
      const that = this
      console.error(this.types)
      this.$refs['forms'].validate(valid => {
        if (!valid) {
          return false
        } else {
          if (this.types === 1) {
            api.addBanner(datas).then((res) => {
              if (res.code === 200) {
                Message({
                  message: res.msg,
                  type: 'success'
                })
                that.ruleShow = false
                that.table = { position: '', picture: '', sort: '', effectiveDate: '', link: '' }
                that.research()
              } else {
                Message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          }
          if (this.types === 2) {
            datas.pkId = this.formId
            api.updateBanner(datas).then((res) => {
              if (res.code === 200) {
                Message({
                  message: res.msg,
                  type: 'success'
                })
                that.ruleShow = false
                that.table = { position: '', picture: '', sort: '', effectiveDate: '', link: '' }
                that.research()
              } else {
                Message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          }
        }
      })
    },
    statusChange(value) {
      if (this.table.status.length > 1) {
        this.table.status.splice(0, 1)
      }
    },
    handleClose() {
      this.ruleShow = false
      this.table = { position: '', picture: '', sort: '', effectiveDate: '', link: '' }
    },
    changeBox(row) {
      console.error(row)
    },
    addFrom() {
    },
    addRule() {
    },
    changeTime(value) {
      this.queryParams.startDate = value[0]
      this.queryParams.endDate = value[1]
    },
    changeTime1(value) {
      this.queryParams.startEffectiveDate = value[0]
      this.queryParams.endEffectiveDate = value[1]
    },
    handleChangeMunu(value) {
      console.log('🌈', value[value.length - 1])
      this.queryParams.menuId = value[value.length - 1]
    },
    // 菜单下拉选
    getPubenumsList() {
      getPubenumsList().then((res) => {
        this.menuOptions = res.data
      })
    },
    // 等级范围选择
    getgradeRanglist() {
      getgradeRanglist().then((res) => {
        this.gradeRangList = res.data
      })
    },
    // 奖衔下拉列表
    getAwardsListChiose() {
      getAwardsListChiose().then((res) => {
        this.awardsList = res.rows
      })
    },
    research() {
      // // 日期传入改为起止两个字段
      // if ("" != this.queryParams.creationTime) {
      //   this.queryParams.creationTimeStart = this.queryParams.creationTime[0];
      //   this.queryParams.creationTimeEnd = this.queryParams.creationTime[1];
      // }

      // creationTime: '', // 开始时间
      //   modifiedTime: '' // 结束时间
      this.loading = true
      api.bannerList(this.queryParams).then((res) => {
        res.rows.forEach((element, i) => {
          element.indexs = i + 1
        })
        // res.rows.forEach((element) => {
        //   element.alist = []
        //   element.blist = []
        //   element.clist = []
        //   element.themenus = ''
        //   element.theaward = ''
        //   element.thegrade = ''
        //   element.menuList.forEach((item) => {
        //     element.alist.push(item.menuVal)
        //     element.themenus = element.alist.join('/')
        //   })
        //   element.awardList.forEach((item) => {
        //     element.blist.push(item.awardVal)
        //     element.theaward = element.blist.join('/')
        //   })
        //   element.gradeList.forEach((item) => {
        //     element.clist.push(item.gradeVal)
        //     element.thegrade = element.clist.join('/')
        //   })
        // })

        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        userName: '', // 角色姓名
        roleString: '', // 权限字符
        status: '', // 状态
        startDate: '', // 开始时间
        endDate: [] // 结束时间
      }
      this.research()
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 0) {
      //   if (rowIndex % 2 === 0) {
      //     return {
      //       rowspan: 2,
      //       colspan: 1,
      //     };
      //   } else {
      //     return {
      //       rowspan: 0,
      //       colspan: 0,
      //     };
      //   }
      // }
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-upload--picture-card{
  min-width: 80px!important;
  min-height: 80px!important;
  border: 1px solid #ccc;
  border-radius: 4px;
}
::v-deep .el-select{
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner{
  width: 100%;
}
::v-deep .colors{
  padding: 5px !important;
}
::v-deep .banner .el-form-item__error{
  left: 100px;
  margin-top:10px;
}
.avatar-uploader{
  width: 68px!important;
  height: 68px!important;
}
::v-deep .input-s .el-input{
  //width:637px;
}
.button-style{
  width: 209px;
  height: 48px;
  background: #CCCCCC;
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  line-height: 48px;
  padding: 0!important;
  color: #fff;
  font-size: 18px;
}
::v-deep .el-dialog__title{
  font-weight: bold;
}
::v-deep .el-dialog__header{
  border-bottom: 1px solid rgba(0,0,0,0.1);
}
.button-s{
  padding: 0 2px!important;
}
::v-deep .el-button{
  padding: 10px 20px;
}
::v-deep .el-date-editor .el-range__close-icon{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range-separator{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range__icon{
  margin-top: -10px;
}
::v-deep .el-input__inner{
  //height:28px;
  //line-height: 28px;
}
::v-deep .el-form-item{
  margin-bottom: 15px;
}
::v-deep .el-form-item__label{
  color: #333;
  font-weight: inherit;
}
::v-deep .el-row {
  //margin-top: 20px;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    background: #ffffff;
    border-radius: 8px;
    padding-bottom: 10px;
    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #08143f;
        color: #ffffff;
      }
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      padding: 0px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #3181E5;
          width: 68px;
          //height: 32px;
        }
      }
    }
  }
}
</style>
