<template>
  <div class="AppConvenientService">
    <u-navbar :is-back="false" title="便民服务" title-color="#000" title-width="300" title-size="32" :background="backgroundNavbar" :title-bold="true"></u-navbar>
    <div class="card-list">
      <div class="card" v-for="(item,index) in list" :key="index">
        <h2>{{ $dict.getLabel('homeConfigMenuType', index) }}</h2>
        <div class="items-list">
          <div class="items" v-for="(t, inx) in item" :key="inx" @click="handleClick(t)">
            <img :src="t.pictureUrl" alt="" >
            <div class="items-name">{{ t.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  name: "AppConvenientService",
  appName: "便民服务",
  customNavigation: true,
  navigationBarTextStyle: 'black',
  computed: {
    ...mapState(['user', 'token']),
  },
  data() {
    return {
      list: [],
      backgroundNavbar: {
        background: '#FFF'
      }
    }
  },

  methods: {
    ...mapActions(['authCheck']),
    handleClick({ type, appId, modulePath, url, checkType, corpId }) {
      if (checkType == 3 && this.user.partyStatusForWX != 2) { //张硕让改的
        return this.$u.toast('您还不是党员，暂时无法使用该功能')
      }
      //先判读是不是系统应用
      if (type != "0") {
        if (type == "1") {
          uni.navigateToMiniProgram({ appId });
        } else if (type == "2") {
          uni.navigateTo({ url: "/subPages/h5/webview?link=" + url });
        } else if (type == "3") {
          this.$linkTo(url);
        } else if (type == "4") {
          uni.openCustomerServiceChat({
            extInfo: { url: url },
            corpId: corpId,
            fail: () => {
              this.$u.toast('请使用普通微信打开小程序进行咨询');
            }
          });
        }
      } else if (type && type == "0") {
        uni.showLoading({ title: '正在进入应用...' })
        this.authCheck({ checkType, modulePath }).finally(() => uni.hideLoading())
      }
    },
    getList() {
      this.$instance.post("/app/appminihomeconfig/listAll", null, { withoutToken: true }).then(res => {
        if (res?.data) {
          this.list = res.data.all;
        }
      })
    },
  },
  onLoad() {
    this.$dict.load("homeConfigMenuType").then(() => {
      this.getList()
    });
  },
  
}
</script>

<style lang="scss" scoped>
.AppConvenientService {
  padding: 32px;
  box-sizing: border-box;
  .card {
    background: #FFF;
    padding: 32px;
    box-sizing: border-box;
    border-radius: 16px;
    margin-bottom: 24px;

    h2 {
      color: #333333;
      font-size: 34px;
      font-weight: 600;
    }

    .items-list {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      .items {
        width: 25%;
        margin-top: 24px;
        text-align: center;
        align-self: center;
        img {
          width: 108px;
          height: 108px;
        }
        .items-name {
          margin-top: 8px;
          color: #1d2229ff;
          font-size: 26px;
          font-weight: 400;
        }
      }
    }
    
  }
}
</style>