<template>
  <ai-list class="AppRuralTourism" v-if="!addShowType">
    <template #title>
      <ai-title title="乡村旅游" :isShowBottomBorder="false" :instance="instance" :isShowArea="true" v-model="areaId" @change="changeArea"></ai-title>
    </template>
    <template #tabs>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane v-for="(item, index) in paneList" :key="index" :label="item.label" :name="item.name" lazy>
          <ruralList
            ref="ruralListref"
            v-if="activeName"
            :instance="instance"
            :dict="dict"
            @goto="goto"
            :type="type"
            @showAddRoral="showAddRoral"
            :activeName="activeName"
            @showEditRoral="showEditRoral" />
        </el-tab-pane>
      </el-tabs>
    </template>
  </ai-list>
  <addRural
    v-else-if="addShowType == 'addRural'"
    :instance="instance"
    :dict="dict"
    :detailId="detailId"
    :detailTitle="detailTitle"
    :isEdit="isEdit"
    :areaId="areaId"
    :type="type"
    :disabledLevel="disabledLevel"
    @goto="goto">
  </addRural>
  <addProducts
    v-else-if="addShowType == 'addProduct'"
    :instance="instance"
    :dict="dict"
    :detailId="detailId"
    :detailTitle="detailTitle"
    :isEdit="isEdit"
    :areaId="areaId"
    :disabledLevel="disabledLevel"
    @goto="goto">
  </addProducts>
</template>

<script>
  import {mapState} from 'vuex'
  import ruralList from './components/ruralList'
  import addRural from './components/addRural'
  import addProducts from './components/addProducts'

  export default {
    name: 'AppRuralTourism',
    label: "乡村旅游",
    props: {
      instance: Function,
      dict: Object,
      permissions: Function,
      openim: Function
    },
    components: {
      ruralList,
      addRural,
      addProducts
    },
    provide() {
      return {
        home: this
      }
    },
    data() {
      return {
        activeName: 'ruralAddress',
        paneList: [
          {
            label: '地区简介',
            name: 'ruralAddress',
            type: '0'
          },
          {
            label: '特色农产品',
            name: 'ruralProdect',
            type: '3'
          },
          {
            label: '旅游故事',
            name: 'ruralStory',
            type: '1'
          },
          {
            label: '旅游服务',
            name: 'ruralWork',
            type: '2'
          }
        ],
        areaId: '',
        addShowType: '', //新增 addRural其他 addProduce //新增农产品
        detailTitle: '地区简介', //详情标题
        isEdit: false, //详情编辑或查看
        detailId: '', //详情内容id
        areaType: '',
        type: '0',  //新增类型
        disabledLevel: 0, //新增页面地区冻结层数
      };
    },
    computed: {
      ...mapState(['user'])
    },
    methods: {
      changeArea() {
        let activeName = this.activeName
        this.activeName = ''
        this.$nextTick(() => {
          this.activeName = activeName
        });
        this.instance.post(`admin/area/queryAreaFullNameByList?ids=` + this.areaId).then(res => {
          if (this.areaId) {
            this.disabledLevel = res.data[this.areaId].length
            console.log(this.disabledLevel)
          }
        })
      },
      openIM() {
        if (this.openim) this.openim();
      },
      handleClick(tab) {
        this.detailTitle = this.paneList[tab.index].label
        this.type = this.paneList[tab.index].type
        this.activeName = ''
        this.$nextTick(() => {
          this.activeName = tab.name;
        });
      },
      goto() {
        this.addShowType = ''
        this.isEdit = false
      },
      showAddRoral() {
        this.detailId = ''
        this.isAddType()
      },
      showEditRoral(item) {
        console.log(item)
        this.detailId = item.id
        this.isEdit = true
        this.isAddType()
      },
      isAddType() {
        if (this.activeName == 'ruralProdect') {
          this.addShowType = 'addProduct'
        } else {
          this.addShowType = 'addRural'
        }
      }
    },
    created() {
      this.areaId = this.user.info.areaId;
      this.areaType = this.user.info.areaMap[this.user.info.areaId].length;
      this.disabledLevel = this.areaType
    }
  }
</script>

<style lang="scss" scoped>
.AppPatientFiles {
  height: 100%;
  background: #f3f6f9;

  .application-header {
    width: 100%;
    background-color: #fff;
    // border-bottom: 1px solid #D8DCE3;
    padding: 0 16px;
    box-sizing: border-box;

    .el-row {
      height: 100%;

      .el-col {
        height: 100%;
        line-height: 48px;
        text-align: left;

        .left-img {
          width: 16px;
          height: 16px;
          margin-right: 8px;
          font-size: 16px;
          color: #333;
          // vertical-align: text-top;
        }

        .search {
          float: right;

          .el-input {
            width: 280px;
            height: 32px;
            border-radius: 0 !important;
          }

          button {
            width: 40px;
          }
        }
      }
    }
  }

  .table-content {
    width: 100%;

    .table-list {
      width: 100%;
      height: 636px;
      background-color: #fff;
      padding: 12px 16px 0;
      box-sizing: border-box;
      position: relative;

      .table-title {
        padding-bottom: 8px;
        border-bottom: 1px solid #eee;

        .el-select {
          width: 160px;
          height: 32px;
          background-color: #fff;
          margin-right: 8px;
        }

        .input-title {
          display: inline-block;
          width: 72px;
          height: 32px;
          background: rgba(245, 245, 245, 1);
          font-size: 14px;
          color: #666;
          border: 1px solid rgba(208, 212, 220, 1);
          box-sizing: border-box;
          line-height: 30px;
          text-align: center;
          border-right: 0;
        }

        .el-date-editor {
          margin-right: 8px;
        }

        .down {
          width: 100%;
          padding-top: 12px;

          .down-line {
            display: inline-block;
            width: 534px;
            height: 24px;
            border-top: 1px solid #eee;
          }

          .down-content {
            display: inline-block;
            width: 108px;
            height: 24px;
            line-height: 24px;
            border-radius: 0 0 8px 8px;
            border: 1px solid #eee;
            border-top: 0;
            box-sizing: border-box;
            color: #333;
            font-size: 12px;
            vertical-align: top;
            text-align: center;
            transition: all 0.3s ease-in-out;

            i {
              transition: all 0.3s ease-in-out;
            }

            .icon-down {
              transform: rotate(90deg);
            }

            .icon-top {
              transform: rotate(270deg);
            }
          }
        }

        .complete-date {
          margin-top: 12px;
        }
      }

      .el-table {
        width: 100%;
        box-sizing: border-box;

        .item-status {
          display: inline-block;
          width: 40px;
          height: 20px;
          line-height: 20px;
          text-align: center;
          font-size: 12px;
          margin: 0 12px 8px 16px;
        }

        .status-red {
          background-color: #ffecef;
          color: #ff4466;
        }

        .status-org {
          background-color: #fff3e8;
          color: #ff8822;
        }

        .status-blue {
          background-color: #eff6ff;
          color: #2266ff;
        }
      }

      .pagination {
        position: absolute;
        bottom: 32px;
        left: 0;
        width: 100%;
        text-align: center;
      }

      .el-table::before {
        height: 0;
      }
    }
  }

  table {
    width: 100%;
  }
}
</style>
<style lang="scss" scoped>
.AppRuralTourism {
  .el-tabs__item {
    height: 32px;
    line-height: 32px;
    font-size: 14px;
    background-color: #f5f5f5;
    color: #666666;
    box-sizing: border-box;
    border-bottom: solid 1px #d0d4dc !important;
  }

  .el-tabs__item.is-active {
    color: #5088ff;
    background-color: #fff;
    border-bottom: solid 1px transparent !important;
  }
}
</style>

