<template>
	<view class="p-root-setoption g_bg_f_5 g_p_10 g_pb_120" style="min-height: 100vh;padding-top: 0;">
    <div v-if="type == 'homeCity'">
      <div style="height: 10px;"></div>
      <div style="background-color: #fff;border-radius: 8px;padding: 0 10px;">
        <view class="g_flex_row_between flex_center itea"
              v-for="(item,index) in cityGroup" :key="index"
              @click="handleChooseCity(item, index)"
        >
          <view class="g_flex_column_center g_fw_500 g_c_0 g_fs_17" hover-class="none" hover-stop-propagation="false"> {{ item.name }} </view>
          <view class="g_flex_column_center" hover-class="none" hover-stop-propagation="false">
            <i class="iconfont icon-duihao icon" style="font-size: 18px;"
               :style="{
                'color':item.checked ? themecolor : 'transparent'
               }"
            ></i>
          </view>
        </view>
      </div>
    </div>
    <div v-if="type == 'homeTab'">
      <div style="height: 10px;"></div>
      <div style="background-color: #fff;border-radius: 8px;padding: 0 10px;">
        <view class="g_flex_row_between flex_center itea"
              v-for="(item,index) in tabGroup" :key="index"
              @click="handleChooseTab(item, index)"
        >
          <view class="g_flex_column_center g_fw_500 g_c_0 g_fs_17" hover-class="none" hover-stop-propagation="false"> {{ item.name }} </view>
          <view class="g_flex_column_center" hover-class="none" hover-stop-propagation="false">
            <i class="iconfont icon-duihao icon" style="font-size: 18px;"
               :style="{
                'color':item.checked ? themecolor : 'transparent'
               }"
            ></i>
          </view>
        </view>
      </div>
    </div>
    <view class="g_mt_32" hover-class="none" hover-stop-propagation="false" style="margin-top: 120px;">
      <rh-button :primaryColor='themecolor' type="primary" btnText="确定" @clickBtn="subNameInfo"
        :loading="isSubmit" size='new'
      />
    </view>
  </view>
</template>

<script>
export default {
	onLoad(options) {
		let that = this;
		that.type = options.type;
    that.value = Number(options.value);
    uni.setNavigationBarTitle({
      title: that.type == "homeCity" ? "职位默认位置" : that.type == "homeTab" ? "职位默认tab" : "",
    })
    if (that.type == "homeCity") {
      that.cityGroup.forEach(c => {
        c.checked = c.value === that.value;
      });
    } else if (that.type == "homeTab") {
      that.tabGroup.forEach(c => {
        c.checked = c.value === that.value;
      });
    }
	},
	data() {
			return {
        isSubmit:false,
        themecolor:getApp().globalData.themeColor,
				applySwitch: false,
				jobSwitch: false,
				fdbHomeCity: false,
				fdbHomeTab: false,
				appInfo: uni.getStorageSync("miniApp-info"),
        type: "",
        value: "",
        cityGroup:[
          {
            name: "全国",
            value: 1,
            checked: false,
          },
          {
            name: "当前城市",
            value: 0,
            checked: false,
          }
        ],
        tabGroup:[
          {
            name: "全部",
            value: 1,
            checked: false,
          },
          {
            name: "推荐",
            value: 0,
            checked: false,
          }
        ],
			};
		},
	methods: {
    handleChooseCity(item, index) {
      this.cityGroup.forEach((c, i) => {
        c.checked = i === index;
      });
    },
    handleChooseTab(item, index) {
      this.tabGroup.forEach((c, i) => {
        c.checked = i === index;
      });
    },
    subNameInfo(){
      let that = this;
      that.isSubmit = true;
      if (that.type == "homeCity") {
        this.G.Put(this.api.merchantManagement_updateField, { fieldName: "fdbHomeCity", fieldValue: that.cityGroup.find(c => c.checked).value }, (res) => {
          that.isSubmit = false;
          uni.navigateBack();
        });
      }if (that.type == "homeTab") {
        this.G.Put(this.api.merchantManagement_updateField, { fieldName: "fdbHomeTab", fieldValue: that.tabGroup.find(c => c.checked).value }, (res) => {
          that.isSubmit = false;
          uni.navigateBack();
        });
      }
    },
	},
};
</script>

<style lang="less">
.p-root-setoption{
  .itea{
    border-bottom: 1px solid #ccc;
    height: 60px;
    &:last-child{
      border-bottom: none;
    }
  }
  .g-components-button .bocai_btn_size_new{
		width: 240px !important;
		height: 40px !important;
		line-height: 38px !important;
	}
}
</style>