<template>
  <div class="mod-service-notifyTemplate">
    <div class="main-container">
      <div class="operation-bar">
        <div class="default-btn primary-btn"
           v-if="isAuth('platform:notifyTemplate:save')"
           @click="addOrUpdateHandle()"
           >{{$t('crud.addTitle')}}</div>
      </div>
      <div class="table-con prod-table">
        <el-table
          ref="notifyTemplateTable"
          :data="dataList"
          header-cell-class-name="table-header"
          row-class-name="table-row-low"
          style="width: 100%">
          <el-table-column
            :label="$t('brand.serialNumber')"
            type="index"
            width="80">
          </el-table-column>
          <el-table-column
            :label="$t('platform.msgTemplate')"
            prop="templateId"
            width="200">
          </el-table-column>
          <el-table-column
            :label="$t('platform.msgType')"
            prop="sendType"
            width="200">
            <template slot-scope="scope">
              <span v-if="scope.row.sendType === 1">{{$t("platform.orderPay")}}</span>
              <span v-else-if="scope.row.sendType === 2">{{$t("platform.paySuccNotify")}}</span>
              <span v-else-if="scope.row.sendType === 3">{{$t("platform.merAgreeReturn")}}</span>
              <span v-else-if="scope.row.sendType === 4">{{$t("order.refusedRefund")}}</span>
              <span v-else-if="scope.row.sendType === 5">{{$t("platform.wriOffRem")}}</span>
              <span v-else-if="scope.row.sendType === 6">{{$t("platform.shipRem")}}</span>
              <span v-else-if="scope.row.sendType === 7">{{$t("platform.groupFailRem")}}</span>
              <span v-else-if="scope.row.sendType === 8">{{$t("platform.groupSuccRem")}}</span>
              <span v-else-if="scope.row.sendType === 9">{{$t("platform.startGroupRem")}}</span>
              <span v-else-if="scope.row.sendType === 10">{{$t("platform.memUpRem")}}</span>
              <span v-else-if="scope.row.sendType === 11">{{$t("platform.timeoutRem")}}</span>
              <span v-else-if="scope.row.sendType === 12">{{$t("platform.register")}}</span>
              <span v-else-if="scope.row.sendType === 13">{{$t("platform.login")}}</span>
              <span v-else-if="scope.row.sendType === 14">{{$t("platform.updatePassword")}}</span>
              <span v-else-if="scope.row.sendType === 15">{{$t("platform.vaild")}}</span>
              <span v-else-if="scope.row.sendType === 16">{{$t("platform.orderBalanceRefundSuccess")}}</span>
              <span v-else-if="scope.row.sendType === 102">{{$t("platform.confirmReceRem")}}</span>
              <span v-else-if="scope.row.sendType === 103">{{$t("platform.buyerRefundRem")}}</span>
              <span v-else-if="scope.row.sendType === 104">{{$t("platform.buyerReturnRem")}}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            :label="$t('platform.notifyConten')"
            prop="message"
            width="500">
          </el-table-column>
          <el-table-column
            :label="$t('platform.canUseNotice')"
            prop="templateTypes"
            width="180">
            <template slot-scope="scope">
              <span v-if="scope.row.sub ">{{$t('shop.officialAccount') + ' '}}</span>
              <span v-if="scope.row.sms ">{{$t('sysManagement.shortMessage') + ' '}}</span>
              <span v-if="scope.row.app ">{{$t('platform.applet') + ' '}}</span>
            </template>
          </el-table-column>
          <el-table-column
            :label="$t('platform.smsTemplateCode')"
            prop="templateCode"
            width="180">
          </el-table-column>
          <el-table-column
            :label="$t('platform.sendType')"
            prop="sendType">
            <template slot-scope="scope">
              <span v-if="scope.row.sendType>100">{{$t('platform.seller')}}</span>
              <span v-else size="small">{{$t('platform.buyer')}}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('publics.operating')"
            fixed="right"
            width="100">
            <template slot-scope="scope">
              <div
                v-if="isAuth('platform:notifyTemplate:update')"
                class="default-btn text-btn"
                @click="addOrUpdateHandle(scope.row.templateId)"
              >{{$t('crud.updateBtn')}}</div>
            </template>
          </el-table-column>

        </el-table>
        <el-pagination
          v-if="dataList.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    </div>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
  </div>
</template>
<script>
import AddOrUpdate from './notifyTemplate-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    this.getDataList()
  },
  mounted () {
  },
  methods: {
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/platform/notifyTemplate/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
      console.log(this.dataList)
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    deleteHandle (row) {
      // `确定进行[${row.status === 0 ? '启用' : '禁用'}]操作?`
      var tip = this.$i18n.t('remindPop.makeSure') + '[' + (row.status === 0 ? this.$i18n.t('brand.enAble') : this.$i18n.t('brand.disable'))
      tip = tip + ']' + this.$i18n.t('remindPop.operation') + '?'
      this.$confirm(tip, this.$i18n.t('remindPop.remind'), {
        confirmButtonText: this.$i18n.t('remindPop.confirm'),
        cancelButtonText: this.$i18n.t('remindPop.cancel'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/platform/notifyTemplate/' + row.templateId),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    },
    handleSizeChange (val) {
      this.page.pageSize = val
      this.getDataList()
    },
    handleCurrentChange (val) {
      this.page.currentPage = val
      this.getDataList()
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
