<template>
  <div class="app-container">
    <div class="header_main">
      有偿使用
      <div class="return_btn" @click="onClickLeft"></div>
      <div class="add_btn" @click="goAdd"></div>
    </div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <van-swipe-cell v-for="(item,index) in applicationList" :key="index">
        <van-cell :title="item.shyqrdbxm" center :to="{name:'paidUtilizeDteail', query: {id:item.id}}" >
          <template #icon>
            <van-icon name="../../../static/images/onlineHome/icon_zjd9.png" size="30" color="#539FFD" style="margin-right: 10px;" />
          </template>
          <span>{{item.ycsyfy}}元</span>
          <br/>
          <span v-if="item.syStatus == '1'" style="color:black;font-weight:  500;">正常</span>
          <span v-if="item.syStatus == '3'" style="color: red;">终止</span>
          <template #label>
            <p><b style="color: #539FFD;">{{item.sqrzjhm}}</b><i style="margin-right: 0.5rem;"></i></p>
          </template>

        </van-cell>
        <template #right>
          <van-row>
            <van-col>
              <van-button square text="生成收费计划" v-if="item.syStatus == '1' && item.isDetail == '0'" @click="generateFeePlanClick(item)" type="info" class="add_btn" />
            </van-col>
            <van-col>
              <van-button square text="收费计划" v-if="item.syStatus == '1' && item.isDetail == '1'"  @click="handleSfjh(item)" type="info" class="delete-button" />
            </van-col>
            <van-col>
              <van-button square text="终止" v-if="item.syStatus == '1'"   @click="handleTermination(item)" type="danger" class="delete-button" />
            </van-col>
            <van-col>
              <van-button square text="修改" :to="{name:'paidUtilizeModify', query: {id:item.id}}" type="info" class="delete-button" />
            </van-col>
            <van-col>
              <van-button square text="删除"  @click="deleteList(item.id,index)" type="danger" class="delete-button" />
            </van-col>
          </van-row>
        </template>
      </van-swipe-cell>
    </van-list>
    <van-dialog v-model="showSfjh" title="收费计划"  show-cancel-button :show-confirm-button="false"   cancelButtonText="关闭" @cancel="showSfjh = false" >
      <div style="background:#fff;padding:10px 2.5%;display: flex;justify-content: space-between;">
        <van-button type="primary" style="width:150px;height: 30px;font-size: 12px;" round @click="cxscsfjhClick">重新生成收费计划</van-button>
      </div>
      <paidUtilizeFeeplanList :ycsyId="ycsyId"  style="height: 600px;overflow: auto;"  ref="sfjh"/>
    </van-dialog>
  </div>
</template>

<script>
  import { getList , getYcsy,ycsyEdit,removeList,generateFeePlan  } from "@/api/onlineHome/homestead/paidUtilize";
  import paidUtilizeFeeplanList from "@/views/yinnong/homestead/paidUtilizeFeeplan/paidUtilizeFeeplanList";
  import {getGeoServerConfigKey} from "@/api/system/config";
  export default {
    name: "paidUtilizeList",
    components: {paidUtilizeFeeplanList},
    data() {
      return {
        applicationList:[],
        houseApplyStatus:[],
        tcqllxStatus:[],
        tclxStatus:[],
        tcfsStatus:[],
        auditStatus:[],
        loading: false,
        finished: false,
        showSfjh:false,
        ycsyId:null,
        queryParams:{
          pageNum:1,
          pageSize:10,
          orderByColumn:'id',
          isAsc:'desc'
        },
        //地图服务地址
        mapGeoServerUrl:"",
      };
    },
    created() {
      this.houseGetDicts("tcqllx").then((res) => {
        this.tcqllxStatus = res.data;
      });
      this.houseGetDicts("tclx").then((res) => {
        this.tclxStatus = res.data;
      });
      this.houseGetDicts("tcfs").then((res) => {
        this.tcfsStatus = res.data;
      });
      this.houseGetDicts("audit_status").then((res) => {
        this.auditStatus = res.data;
      });
    },
    methods: {
      goAdd(){
        window.location = 'paidUtilizeAdd';
      },
      cxscsfjhClick(){
        let _this = this;
        this.$dialog.confirm({
          message: '是否重新生成收费计划？',
        })
          .then(() => {
            // on confirm
            getYcsy(_this.ycsyId).then(response => {
              generateFeePlan(response.data).then((response) => {
                if(response.code != 200) throw response.msg;
                this.$toast.success("收费计划已生成");
                _this.$refs.sfjh.getList();
              });
            });
          })
          .catch(() => {
            // on cancel
          });
      },
      getList(){
        setTimeout(() => {
          getList(this.queryParams).then(response => {
            console.log(response)
            // for (var i = 0; i < response.rows.length; i++) {
            //   response.rows[i].tclx = this.selectDictLabel(this.tcqllxStatus, response.rows[i].tclx)
            //   response.rows[i].tclx = this.selectDictLabel(this.tclxStatus, response.rows[i].tclx)
            //   response.rows[i].tcfs = this.selectDictLabel(this.tcfsStatus, response.rows[i].tcfs)
            //   response.rows[i].auditStatus = this.selectDictLabel(this.auditStatus, response.rows[i].auditStatus)
            //   this.applicationList.push(response.rows[i]);
            // }
            this.applicationList = response.rows;
            if(this.applicationList.length >= response.total){
              this.finished = true;
              return;
            }else{
              this.loading = false;
              this.finished = false;
              this.queryParams.pageNum += 1 ;
            }
          });
        }, 1000);
      },
      /** 生成收费计划 */
      generateFeePlanClick(row){
        generateFeePlan(row).then((response) => {
          this.$toast.success("收费计划已生成");
          this.getList();
        });
      },
      /** 收费计划信息 */
      handleSfjh(row){
        this.title = "收费计划";
        const id = row.id;
        this.ycsyId = id;
        this.showSfjh = true;
      },
      /** 终止 */
      handleTermination(row){
        let _this = this;
        let data = row;
        this.$dialog.confirm({
          message: '是否确认终止此条有偿使用数据？',
        }).then(function() {
          _this.loading = true;
          if(row.syStatus === "1"){
            _this.$set(data, "syStatus",  "3");
          }else{
            _this.$set(data, "syStatus",  "1");
          }
          ycsyEdit(data).then(response => {
            _this.$toast.success("操作成功");
            _this.loading = false;
            _this.getList();
          });
        });

      },
      deleteList(id,index){
        this.$dialog.confirm({
          message: '您确认删除申请草稿？',
        })
          .then(() => {
            // on confirm
            this.applicationList.splice(index,1)
            removeList(id).then(res => {
              if(res.code = 200){
                this.$toast.success('删除成功');
              }
            });
          })
          .catch(() => {
            // on cancel
          });
      },
    },
  }
</script>

<style scoped lang="scss">
  .app-container {
  .header_main{
    height: 116px;
    background: url('../../../../assets/images/sunVillage_info/list_head.png') no-repeat;
    background-size: 100% 100%;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    font-size: 36px;
    line-height: 116px;
    text-align: center;
    color: #fff;
    position: relative;
  .return_btn{
    width: 24px;
    height: 43.2px;
    background: url('../../../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
    background-size: 20px 36px;
    position: absolute;
    left: 38px;
    top: 36px;
  }
  .add_btn{
    width: 56.4px;
    height: 40.8px;
    background: url('../../../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
    background-size: 47px 34px;
    position: absolute;
    right: 38px;
    top: 36px;
  }
  }
  }
  /deep/.van-cell__title{
    flex: 0.7;
  }
  /deep/.van-cell__title span{
    font-family: Arial;
    font-size: 0.4rem;
    font-weight: normal;
  }
  /deep/.van-cell__value{
    flex: 0.3;
    color: #1D6FE9;
    font-weight: bold;
  }
  /deep/.van-swipe-cell{
    margin-bottom: 0.2rem;
    border-radius: 0.2rem;
    overflow: hidden;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  }
  /deep/van-ellipsis{
    font-weight: bold;
  }
  .delete-button {
    height: 100%;
  }
  .van-row{
    height: 100%;
  }
  .van-col{
    height: 100%;
  }
</style>
