<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @input="resetSearch" clearable filled v-model="msg.Name" label="小程序名称"
            @clear="resetSearch" maxlength="20" />
        </div>
        <div class="col-3">
          <q-input @input="resetSearch" clearable filled v-model="msg.AppID" label="AppID"
            @clear="resetSearch" maxlength="20" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="dataList" :columns="columns">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">小程序信息</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="新增小程序" @click="EditProgram(null)" />
          </div>
        </template>
        <template v-slot:body-cell-Image="props">
          <q-td :props="props">
            <q-img :src="props.row.Image" />
          </q-td>
        </template>
        <template v-slot:body-cell-Id="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="EditProgram(props.row)" />
            <q-btn flat size="xs" icon="delete" color="negative" style="font-weight:400;" label="删除"
              @click="deleteProgram(props.row)" />
          </q-td>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
      </q-table>
      <program-form v-if="isShowProgram" :save-obj="programObj" @close="closeProgramForm" @success="refreshPage">
      </program-form>
    </div>
  </div>
</template>

<script>
  import {
    GetContributeAppletPageList,
    DelContributeApplet
  } from '../../api/system/wechat'
  import programForm from '../../components/system/program-form'
  export default {
    meta: {
      title: "小程序信息"
    },
    components: {
      programForm
    },
    data() {
      return {
        msg: {
          pageIndex: 1,
          pageSize: 10,
          rowsPerPage: 10,
          Name: '', //小程序名称
          AppID:'' //AppID
        },
        pageCount:0,
        dataList: [],
        loading: true,
        columns: [{
            name: 'Name',
            label: '小程序名称',
            field: 'Name',
            align: 'left'
          },{
            name: 'AppID',
            label: 'AppID',
            field: 'AppID',
            align: 'left'
          },
          {
            name: 'Image',
            label: '图标',
            field: 'Image',
            align: 'left'
          },
          {
            name: 'Page',
            label: '路径',
            field: 'Page',
            align: 'left'
          },
          {
            name: 'UpdateByName',
            label: '修改人',
            align: 'left',
            field: row => row.UpdateByName
          },
          {
            name: 'UpdateTime',
            label: '修改时间',
            align: 'left',
            field: row => row.UpdateTime
          },
          {
            name: 'Id',
            label: '操作',
            field: 'Id'
          }
        ],
        isShowProgram:false,
        programObj:{}
      }
    },

    mounted() {
      this.getList();
    },
    methods: {
      //重新查询
      resetSearch() {
        this.msg.pageIndex = 1;
        this.getList();
      },
      changePage(val) {
        this.msg.pageIndex = val;
        this.getList()
      },
      //删除系列
      deleteProgram(item) {
        let delMsg = {
          AppletId: item.AppID
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除该小程序？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          DelContributeApplet(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.refreshPage();
            }
          })
        }).onCancel(() => {

        });
      },
      //刷新页面
      refreshPage() {
        this.getList();
      },
      //获取课程系列分页列表
      getList() {
        this.loading = true;
        GetContributeAppletPageList(this.msg).then(res => {
          this.loading = false;
          this.dataList = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        })
      },
      //新增修改课程系列
      EditProgram(obj) {
        if (obj) {
          this.programObj = obj
        } else {
          this.programObj = null
        }
        this.isShowProgram = true;
      },
      //关闭弹窗
      closeProgramForm() {
        this.isShowProgram = false
      }
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
