<template>
  <page-meta
    :page-font-size="$baseFontSize() + 'px'"
    :root-font-size="$baseFontSize() + 'px'"
  ></page-meta>
  <view class="  ">
    <!-- 公共组件-每个页面必须引入 -->
    <!-- <public-module></public-module>
        <z-nav-bar title="确认订单" bgColor="#3AB3AE" fontColor="#fff"></z-nav-bar> -->

    <view class="common_address_box" style="background-color: #fff">
      <z-nav-bar
        :title="`${addressId ? '编辑' : '添加'}收货地址`"
        bgColor="#3AB3AE"
        fontColor="#fff"
      >
        <template slot="right">
          <text
            @click="handleClickDelete"
            v-if="addressId"
            style="padding-right: 20rpx; color: red"
            >删除</text
          >
        </template>
      </z-nav-bar>

      <view style="padding: 40rpx 20rpx">
        <view
          class="order_top common_radius_box color_shandow goods_box address_box"
        >
          <view class="title">
            <text>地址信息</text>
            <view class="agree">
              <radio-group class="agree">
                <view v-for="(item, index) in argee" :key="index">
                  <radio
                    class="agreeRadio"
                    :value="item.id"
                    :checked="item.id == radioValue"
                    color="#3AB3AE"
                    @click="radioCheck(index)"
                  ></radio>
                  默认收货地址
                </view>
              </radio-group>
            </view>
          </view>

          <view class="form_box">
            <uni-forms
              ref="form"
              :rules="rules"
              :modelValue="addForm"
              :label-width="80"
            >
              <uni-forms-item label="收件人" name="consigneeName" required>
                <view class="inputBox"
                  ><uni-easyinput
                    :maxlength="16"
                    :style="{
                      borderColor: '#2979FF',
                    }"
                    v-model="addForm.consigneeName"
                    placeholder="请输入收件人姓名"
                /></view>
              </uni-forms-item>
              <uni-forms-item label="手机号" required name="consigneePhone">
                <uni-easyinput
                  v-model="addForm.consigneePhone"
                  placeholder="请输入手机号"
                />
              </uni-forms-item>

              <uni-forms-item label="所在地区" required name="areaidpathtext">
                <!-- <view class="add_arrow" @click="addreShow = true"
                    >{{ addForm.areaidpathtext }}</view
                  > -->

                <view
                  class="inputBox select_address_box"
                  @click="addreShow = true"
                >
                  <view class="addresss_info">
                    <text
                      :style="`color:${addForm.areaidpathtext ? '' : '#999'};`"
                    >
                      {{
                        addForm.areaidpathtext
                          ? addForm.areaidpathtext
                          : "请选择所在地区"
                      }}
                    </text>
                  </view>
                  <view class="addresss_icon">
                    <image
                      src="@/static/icon/icon_right.png"
                      class="rightArrow"
                      style="margin-right: 10rpx"
                    ></image>
                  </view>
                </view>

                <!-- <view
                    class="inputBox select_address_box"
                    @click.native.stop="openSelectAddress"
                  >
                    <view class="addresss_info">
                      <text :style="`color:${addForm.address ? '' : '#999'};`">
                        {{
                          addForm.address ? addForm.address : "请选择所在地区"
                        }}
                      </text>
                    </view>
                    <view class="addresss_icon">
                      <uni-icons
                        v-if="addForm.address"
                        type="clear"
                        @click.native.stop="clearSelectAddress"
                        color="#c0c4cc"
                        size="23"
                        style="display: inline-block; margin-right: 10rpx"
                      ></uni-icons
                    ></view>

                  
                  </view> -->
              </uni-forms-item>
              <uni-forms-item label="详细地址" required name="detailAddress">
                <uni-easyinput
                  type="textarea"
                  v-model="addForm.detailAddress"
                  placeholder="请输入详细地址"
                />
              </uni-forms-item>
            </uni-forms>
          </view>

          <!-- </view> -->
        </view>
      </view>

      <view class="goods_nav_box">
        <uni-goods-nav
          :fill="true"
          :options="buyOptions"
          :button-group="customButtonGroup1"
          @click="onHandleClickBuy"
          @buttonClick="onHandleClickBuy"
        />
      </view>
    </view>

    <sx-address-picker
      ref="sxAddress"
      v-model="addressPopup"
      @confirm="addressConfirm($event, 'formData')"
    />

    <u-modal
      :show="showModal"
      :title="modalInfo.title"
      :content="modalInfo.content"
      showCancelButton
      @confirm="deleteAddress"
      @cancel="hancleModalCancel"
    ></u-modal>

    <u-picker
      @cancel="addcancel"
      :show="addreShow"
      ref="uPicker"
      :columns="columns"
      keyName="UName"
      @confirm="addconfirm"
      @change="changeHandler"
    ></u-picker>
  </view>
</template>

<script>
import courseDescription from "@/pages/component/commonComponents/list";
// import citySelect from '@/components/city_select/city_select.vue';
import addressList1 from "@/static/json/address.json";
import $http from "@/config/requestConfig.js";

import { mapState } from "vuex";
export default {
  components: {
    courseDescription, //课程说明
  },
  data() {
    return {
      showModal: false,
      addreShow: false, //是否显示
      addressId: null,
      columns: [], //省份数据显示，三级联动需要三维数组，展示初始数据
      columnData: [], //市数据
      columnDatas: [], //区地址
      addressList: [],
      modalInfo: {},
      radioValue: "",
      buyOptions: [
        // {
        // 		icon: 'chat',
        // 		text: '客服'
        // 	},
        // {
        //   icon: "shop",
        //   text: "店铺",
        //   // info: 2,
        //   infoBackgroundColor: "#007aff",
        //   infoColor: "#f5f5f5",
        // },
        //  {
        // 	icon: 'cart',
        // 	text: '购物车',
        // 	info: 2
        // }
      ],

      customButtonGroup1: [
        {
          with: 200,
          text: "保存",
          backgroundColor: "linear-gradient(90deg, #3AB3AE 0%, #117e4c 100%)",
          color: "#fff",
        },
      ],
      addressPopup: false,
      addressPopup2: false,
      selectedAddress: [],
      formData: {
        country: "",
        province: "",
        city: "",
        area: "",
        street: "",
      },
      formData2: {
        country: "埃及",
        // province: "上海市",
        // city: "市辖区",
        // area: "徐汇区",
        // street: "天平路街道"
      },
      addForm: {
        name: "uView UI",
        sex: "",
      },
      actions: [
        {
          name: "男",
        },
        {
          name: "女",
        },
        {
          name: "保密",
        },
      ],
      rules: {
        // 对name字段进行必填验证
        consigneeName: {
          // name 字段的校验规则
          rules: [
            // 校验 name 不能为空
            {
              required: true,
              errorMessage: "请输入收件人姓名",
            },
            // 对name字段进行长度验证
            // {
            //   minLength: 3,
            //   maxLength: 5,
            //   errorMessage: "{label}长度在 {minLength} 到 {maxLength} 个字符",
            // },
          ],
          // 当前表单域的字段中文名，可不填写

          validateTrigger: "submit",
        },
        consigneePhone: {
          // name 字段的校验规则
          rules: [
            // 校验 name 不能为空
            {
              required: true,
              errorMessage: "请输入手机号",
            },
            {
              validateFunction: (rule, value, data, callback) => {
                // 异步需要返回 Promise 对象
                return new Promise((resolve, reject) => {
                  if (!this.$base.phoneRegular.test(value)) {
                    reject(new Error("手机号格式不正确"));
                  } else {
                    resolve();
                  }

                  // setTimeout(() => {

                  // }, 500);
                });
              },
            },
          ],
          // 当前表单域的字段中文名，可不填写

          validateTrigger: "submit",
        },
        areaidpathtext: {
          // name 字段的校验规则
          rules: [
            // 校验 name 不能为空

            // {
            //   required: true,
            //   errorMessage: "请选择所在地区2",
            // },
            {
              validateFunction: (rule, value, data, callback) => {
                // 异步需要返回 Promise 对象
                return new Promise((resolve, reject) => {
                  console.log("value at line 251:", rule, value, data);
                  if (
                    this.addForm.areaidpathtext &&
                    this.addForm.areaidpathtext != ""
                  ) {
                    resolve();
                    this.$refs.form.clearValidate(["areaidpathtext"]);
                  } else {
                    reject(new Error("请选择所在地区1"));
                  }

                  // setTimeout(() => {

                  // }, 500);
                });
              },
            },
          ],
          // 当前表单域的字段中文名，可不填写

          validateTrigger: "submit",
        },
        detailAddress: {
          // name 字段的校验规则
          rules: [
            // 校验 name 不能为空
            {
              required: true,
              errorMessage: "请输入详细地址",
            },
          ],
          // 当前表单域的字段中文名，可不填写

          validateTrigger: "submit",
        },
      },
      addressData: {},
      addressChanged: false, // 地址修改标记
      argee: [
        {
          value: false,
          id: "1",
        },
      ], // 同意权限
      show: false,

      urlList: {
        detailInfo: "common/userAddress/info",
        add: "common/userAddress/save",
        edit: "common/userAddress/update",
        delete: "common/userAddress/delete",
      },
      customButton: [
        {
          width: "340rpx",
          text: "立即支付",
          backgroundColor: "linear-gradient(90deg, #3AB3AE 0%, #117e4c 100%)",
          color: "#fff",
        },
      ],
    };
  },
  onLoad(options) {
    this.options = options;

    // this.getUserInfo()
    // this.getCateList()
  },
  onHide() {
    // this.showSearchList = false
    // this.searchList = []
  },
  onShow() {
    this.addForm = {};
    this.selectPayIndex = 0;
    this.open(this.options.id);
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  onReady() {
    // 需要在onReady中设置规则
    this.$refs.form.setRules(this.rules);
  },
  methods: {
    addcancel() {
      //点击取消按钮
      this.addreShow = false;
    },
    changeHandler(e) {
      //城市选择时触发
      // console.log(e,'变化了',this.columnData, this.columnDatas)
      this.addressChanged = true;
      const {
        columnIndex, //当前选择的列，省 / 市 / 区
        value, // 当前选择的数组内容
        values, // values为当前变化列的数组内容
        index, // 当前列的下标值
        indexs, // 当前选择 省 市 区的下表值
        picker = this.$refs.uPicker,
      } = e;
      // 当第一列值发生变化时，变化第二列和第三列的值（省份变更，市和区跟着变更）
      if (columnIndex === 0) {
        // 判断当前变更的是省还是市还是区
        // picker为选择器this实例，变化第二列对应的选项

        picker.setColumnValues(1, this.columnData[index]); //设置市为该省下面的所有市，index是当前省在省份数组的下标，对应市数组中的下表就是 该省下面的所有市 的数据
        picker.setColumnValues(2, this.columnDatas[index][0]); // 设置区域为该省下面第一个市下面的所有区域
      }
      if (columnIndex === 1) {
        // 当第二列发生变化 变化对应的第三列
        picker.setColumnValues(2, this.columnDatas[indexs[0]][index]); //同上
      }
    },

    addconfirm(e) {
      //点击确定按钮
      // console.log(e,'选中的值')
      this.addressChanged = true;
      this.addreShow = false;
      this.addForm.areaidpathtext =
        e.value[0].UName + "-" + e.value[1].UName + "-" + e.value[2].UName;

      this.provId = e.value[0].provId;
      this.cityId = e.value[1].cityId;
      this.countyId = e.value[2].regionCode;

      this.addForm.province = e.value[0].UName;
      this.addForm.city = e.value[1].UName;
      this.addForm.county = e.value[2].UName;
      this.addForm.regionCode = e.value[2].regionCode;
      this.$refs.form.clearValidate(["areaidpathtext"]);
    },
    // 三级联动
    initDataPicker() {
      // console.log(this.addressList,'addressList')
      // this.$http
      // .post('api/province/getProvince')
      // .then(res => {
      // 	if (res.code == 0) {
      // this.addressList = res.provinceEntity
      //此处的province主要用作数据的初始化，即刚打开就需要进行展示的数据，这个跟第一条省份数据相关，我的第一条是北京市，所以需要columns中的三维数组，第一维度是省份数据数组，第二维度是市数据数组，第三维度是区数据数组
      let province = []; //初始数据需要展示的省份
      let province1 = [
        {
          cityId: this.addressList[0].cityList[0].cityId,
          provId: this.addressList[0].cityList[0].provId,
          cityName: this.addressList[0].cityList[0].cityName,
          UName: this.addressList[0].cityList[0].cityName,
          createDate: this.addressList[0].cityList[0].createDate,
          regionCode: this.addressList[0].cityList[0].regionCode,
          countyList: this.addressList[0].cityList[0].countyList,
        },
      ]; //因为第一个市北京市，所以就直接添加北京市下辖的直辖市了 也即初始数据需要展示的市，北京市只有一个市辖区
      let province2 = []; //初始数据需要展示的区域数据，也即是 北京市市辖区内的区

      for (let i = 0; i < this.addressList.length; i++) {
        this.addressList[i].UName = this.addressList[i].provName;
        if (this.addressList[i].cityList == null) {
          // 如果没有cityList数据，就添加一项，用省份的信息
          // console.log('存在单一',this.addressList[i].provId)
          this.addressList[i].cityList = [
            {
              cityId: this.addressList[i].provId,
              provId: this.addressList[i].provId,
              cityName: this.addressList[i].provName,
              UName: this.addressList[i].provName,
              createDate: this.addressList[i].createDate,
              regionCode: this.addressList[i].regionCode,
              countyList: [
                {
                  countyId: this.addressList[i].provId,
                  cityId: this.addressList[i].provId,
                  countyName: this.addressList[i].provName,
                  UName: this.addressList[i].provName,
                  createDate: this.addressList[i].createDate,
                  regionCode: this.addressList[i].regionCode,
                },
              ],
            },
          ];
        } else {
          for (let j = 0; j < this.addressList[i].cityList.length; j++) {
            this.addressList[i].cityList[j].UName =
              this.addressList[i].cityList[j].cityName;
            for (
              let k = 0;
              k < this.addressList[i].cityList[j].countyList.length;
              k++
            ) {
              this.addressList[i].cityList[j].countyList[k].UName =
                this.addressList[i].cityList[j].countyList[k].countyName;
            }
          }
        }
        province.push(this.addressList[i]);
      }

      this.addressList[0].cityList[0].countyList.map((item) => {
        province2.push(item);
      });

      //省数据 因为要做数据初始化，所以是三维数组
      // 数据格式 [ [所有的省份数据:{},{}] , [第一个省份下的所有的市:{},{},{}] , [第一个市下面所有的区:{},{},{}] ]
      this.columns.push(province);
      this.columns.push(province1);
      this.columns.push(province2);

      // console.log(6666666,this.columns)

      // 市数据数组，筛选address.json文件，将全国所有省下面的市数据放入数组
      // 格式[ [第一个省下面所有市,{},{},{}] , [第二个省下面所有市{},{},{}] , [第三个省下面所有市{},{},{}] ] 注意，以上的第一第二对应着 columns[0] 的数据

      this.addressList.map((item) => {
        let city = [];
        item.cityList.map((item1) => {
          city.push(item1);
        });
        this.columnData.push(city);
      });

      //区数据数组
      //数据格式: [ 所有省下面所有市的所有区 [ 第一个省下面所有市的区:[ [第一个省下面第一个市的所有区] , [第一个省下面第二个市的所有区] ,]   ,   [ 第二个省下面所有市的区:[ [第二个省下面第一个市的所有区] , [第二个省下面第二个市的所有区] ,]   ]

      let area = [];
      this.addressList.map((item, index) => {
        let area1 = []; //省下面所有市的初始化
        item.cityList.map((item1) => {
          area = []; //市下面的区初始化
          item1.countyList.map((item2) => {
            area.push(item2);
          });
          area1.push(area); // 每循环一个市，添加该市下面的所有区
        });
        this.columnDatas.push(area1); // 每循环一个省，添加该省下面的所有市
      });

      // };
      // }).catch(e => {
      // 	console.log(e,'e')
      // })
    },
    hancleModalCancel() {
      this.showModal = false;
    },
    handleClickDelete(id) {
      this.modalInfo = {
        title: "提示信息",
        content: "确定要删除该地址吗？",
      };

      this.showModal = true;
    },
    deleteAddress() {
      var data = {};
      $http
        .request({
          // url: "book/buyOrder/buySave",
          url: `${this.urlList.delete}?id=${this.addressId}`,
          method: "Get", // POST、GET、PUT、DELETE，具体说明查看官方文档
          data,
          header: {
            //默认 无 说明：请求头
            "Content-Type": "application/json",
          },
        })
        .then((res) => {
          console.log("res at line 252:", res);
          this.showModal = false;
          if (res.code == 0) {
            uni.navigateBack({
              delta: 1,
            });
          } else {
            this.$commonJS.showToast(res.message);
          }
        });
    },
    backClick() {
      this.show = false;
      this.$emit("fresh");
    },
    async onHandleClickBuy(e) {
      console.log("e at line 387:", e);
      var that = this;
      var url;
      var data = this.addForm;
      console.log("data at line 355:", data);

      this.$refs.form
        .validate()
        .then(async (res) => {
          console.log("表单数据信息：", res);
          data.isDefault = this.radioValue ? 1 : 0;
          // data.regionCode = "110101";

          data.userId = this.userInfo.id;
          if (this.addForm.id) {
            url = this.urlList.edit;
          } else {
            url = this.urlList.add;
          }
          await $http
            .request({
              // url: "book/buyOrder/buySave",
              url: url,
              method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
              data,
              header: {
                //默认 无 说明：请求头
                "Content-Type": "application/json",
              },
            })

            .then(async (res) => {
              console.log("res at line 374:", res);
              if (res && res.code == 0) {
                // this.addForm = res.result;
                // this.formData = {
                //   country: "中国",
                //   province: res.result.province,
                //   city: res.result.city,
                //   area: "",
                //   street: "",
                // };
                // await this.addressChange();
                uni.navigateBack({
                  delta: 1,
                });

                this.$forceUpdate();
              } else {
                this.$commonJS.showToast(res.message);
              }
              // this.show = true;

              // await that.getDetailInfo();
            });
        })
        .catch((err) => {
          console.log("表单错误信息：", err);
        });
    },
    addressConfirm(address, key) {
      const [country, province, city, area, street] = address;
      this.address = province ? address.filter((v, i) => i > 0) : address;
      if (address.length === 5) {
        this[key].country = country.name;
        this[key].province = province.name;
        this[key].city = city.name;
        this[key].area = area.name;
        this[key].street = street.name;
      } else {
        this[key].country = country.name;
        this[key].province = undefined;
        this[key].city = undefined;
        this[key].area = undefined;
        this[key].street = undefined;
      }
      this.addressChange();
    },
    addressChange() {
      const { country, province, city, area, street } = this.formData;

      this.selectedAddress = province
        ? [country, province, city, area, street]
        : [country];

      // this.addressStr();
    },

    clearSelectAddress() {
      this.addForm.areaidpathtext = "";

      this.$forceUpdate();
    },
    openSelectAddress() {
      this.addressPopup = true;

      this.$forceUpdate();
    },

    handleClickEdit(data) {
      console.log("data at line 145:", data);
    },

    getName(name) {
      console.log("name at line 140:", name);
      if (name) {
        if (name.length <= 2) {
          return name;
        } else {
          return name.substring(0, 1);
        }
      }
    },
    open(id) {
      this.addressList = [];
      this.columns = [];
      this.columnData = [];
      this.columnDatas = [];
      this.addressList = addressList1;
      // if (e.type == 0) {
      //   this.navName = "添加地址";
      //   this.isShowDel = false;
      // } else {
      //   this.navName = "编辑地址";
      //   this.isShowDel = true;
      //   this.editIndex = e.index;
      //   this.getAddress();
      // }
      this.initDataPicker(); //初始化省份列表

      if (id) {
        this.addressId = id;
        this.getData(id);
      } else {
        this.addForm = {};
      }
    },
    fnCopy(value, title) {
      this.$commonJS.handleMakingPhoneCalls(value, title);
    },

    gotoPhone() {
      this.$commonJS.handleMakingPhoneCalls("022-24142321");
    },

    radioChange(index) {
      this.selectPayIndex = index;
      console.log("this.selectPayIndex at line 315:", this.selectPayIndex);
      this.$forceUpdate();
    },
    handleValChange(e) {
      console.log("e at line 424:", e);
    },
    buttonClick(e) {
      console.log(e);
      this.options[2].info++;
    },

    hancleModalConfirm() {
      var data = {
        values: {
          customerType: "D",
          token: uni.getStorageSync("token"),
          customerOid: uni.getStorageSync("customerOid"),
          ...this.taiHuClassInfo,
        },
      };
      // $mars.progressBegin('申请中...');
      // $mars.post(customerType, 'applyRelearn', data, function (ret) {
      //     api.hideProgress();

      //     fnLoadDataGrid();
      // });
    },

    selectAddress(v) {
      console.log("v at line 423:", v);
      this.$emit("selectAddress", v);
      this.show = false;
    },
    async getData(id) {
      console.log("this.userInfo.id at line 368:", this.userInfo.id);
      var data = {};

      var that = this;
      console.log(this.$store.state, "11111111111");

      $http
        .request({
          // url: "book/buyOrder/buySave",
          url: `${this.urlList.detailInfo}/${id}`,
          method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
          data,
          header: {
            //默认 无 说明：请求头
            "Content-Type": "application/json",
          },
        })

        .then(async (res) => {
          console.log("res at line 374:", res);
          if (res && res.code == 0) {
            this.radioValue = res.result.isDefault;
            this.addForm = res.result;
            this.addForm.areaidpathtext =
              res.result.province +
              "-" +
              res.result.city +
              "-" +
              res.result.county;

            // this.addressChange();
          }
          this.show = true;

          this.$forceUpdate();

          // await that.getDetailInfo();
        });
    },
    getPriceData() {
      var that = this;
      setTimeout(() => {
        that.$nextTick(() => {
          that.$refs.priceDetail.getData();
        });
      }, 100);
    },
    // 检查是有权限使用搜索功能
    checkDisable() {
      console.log("点击了");
    },
    // 显示无权限弹窗
    // showNoRights() {
    // 	let that = this
    // 	uni.showModal({
    // 		content: "",
    // 		confirmText: '好的',
    // 		showCancel: false,
    // 		success: function(res) {
    // 			if (res.confirm) {
    // 				// console.log('用户点击确定');
    // 				that.clear()
    // 			}
    // 		}
    // 	})
    // },
    // 获取用户详情
    getUserInfo() {
      // 用户详情
      if (this.userInfo.id != undefined) {
        this.$http.post("book/user/info/" + this.userInfo.id).then((res) => {
          this.userMes = res.user;
          this.getCateList();
          console.log(this.userMes, "呼呼");
        });
      }
    },
    radioCheck(index) {
      // 勾选用户协议
      this.argee.forEach((item) => {
        item.isCheck = false;
      });
      if (this.radioValue == this.argee[index].id) {
        this.radioValue = null;
      } else {
        this.radioValue = this.argee[index].id;
      }

      this.$forceUpdate();
      // console.log(this.radioValue)
    },
    async handleselectCate(item, index) {
      this.dataList = [];
      var data = [];
      console.log(item, index, 99999);
      var that = this;

      // curriculumInfo

      this.$http
        .post(this.urlList.curriculumInfo, {
          customerType: "D",
          token: uni.getStorageSync("token"),
          customerOid: uni.getStorageSync("customerOid"),
          oid: item.coid,
        })
        .then(async (res) => {
          that.curriculumInfo = res.obj;
          that.dataList = res.obj.courseList;

          // socket.init();
        });

      // this.$nextTick(() => {
      //     switch (item.type) {
      //         case 1:
      //             // allDataList
      //             this.dataList = that.allDataList.result1Lst
      //             break;
      //         case 2:
      //             this.dataList = that.allDataList.result2Lst
      //             break;
      //         case 3:
      //             this.dataList = that.allDataList.result3Lst
      //             break;
      //         case 4:
      //             this.dataList = that.allDataList.result4Lst.filter(e =>
      //                 e.oid != '5fcf991c027b11e7ae62008cfae40c18' && e.oid != 'b3d8a938b8e147bc877613bb712a9cb3' && e.oid != '4d4730163135420ea962bfac4805e026' && e.oid != '49fb76ca3d6b43718d78c6aa9a3003c2' && e.oid != 'c7b047ed9246469b9ae2b1013fc3df9c'

      //             )

      //             console.log(this.dataList.length, 6666666)
      //             break;

      //     }

      //     this.currentCateIndex = item.index
      // })
      console.log(this.allDataList, this.dataList, "1688");
      // if(this.userMes.tgdzPower == 0){
      // 	let that = this
      // 	uni.showModal({
      // 		content: "购买 针灸六经法要上册和下册 后方可使用此功能",
      // 		confirmText: '好的',
      // 		showCancel: false,
      // 		success: function(res) {
      // 			if (res.confirm) {
      // 				// console.log('用户点击确定');
      // 			}
      // 		}
      // 	})
      // 	return
      // }
      // if(item.title == "时辰取穴"){
      // 	uni.navigateTo({
      // 		url: "../timeAcupoint/timeAcupoint"
      // 	})
      // 	return
      // }

      // this.currentStatusIndex = index

      this.searchValue = "";
      this.searchList = [];
      this.showSearchList = false;
      // if (index != 2) {

      // uni.createSelectorQuery().select('.statusList').boundingClientRect(function (rect) {
      // 	var height = rect.height
      // 	console.log('元素高度：',);

      // }).exec();

      // } else {
      // 	this.getJFList(dictType)
      // }

      return data;
    },
    async getDetailInfo() {
      var that = this;

      // curriculumInfo

      this.detailInfo = {
        content:
          "<img src='http://oss.taihumed.com/other/null_20210528102528870.jpg' ></img> <img src='http://101.201.146.165:8088/curriculum/detailImg/curriculum_20170420143333621.png'  ></img><p><p>没有中医基础想学中医难不难？中医学者治疗出现瓶颈怎么办？中西医究竟有什么不同呢？吴雄志教授将以全新的视角，完美整合中药学和西医学知识，让你领略当代中医生理学魅力。</p><p><br/><p></p><p><br/></p><p>【思考题】</p><p>1、简述中医的发展这些年出现了哪些变化？</p><p>2、简述中西医学科的异同？</p>",
      };

      // this.$http
      //     .post(this.urlList.detailInfo, {
      //         customerType
      //             :
      //             "D",
      //         token
      //             : uni.getStorageSync("token")
      //         ,
      //         customerOid
      //             : uni.getStorageSync("customerOid"),
      //         classOid: 'f81b558ca4ee406e97c4045c87c2539c'

      //     })
      //     .then(async res => {
      //         that.detailInfo = res.obj
      //         // that.dataList = res.obj.courseList

      //         // socket.init();

      //     });

      // this.$nextTick(() => {
      //     switch (item.type) {
      //         case 1:
      //             // allDataList
      //             this.dataList = that.allDataList.result1Lst
      //             break;
      //         case 2:
      //             this.dataList = that.allDataList.result2Lst
      //             break;
      //         case 3:
      //             this.dataList = that.allDataList.result3Lst
      //             break;
      //         case 4:
      //             this.dataList = that.allDataList.result4Lst.filter(e =>
      //                 e.oid != '5fcf991c027b11e7ae62008cfae40c18' && e.oid != 'b3d8a938b8e147bc877613bb712a9cb3' && e.oid != '4d4730163135420ea962bfac4805e026' && e.oid != '49fb76ca3d6b43718d78c6aa9a3003c2' && e.oid != 'c7b047ed9246469b9ae2b1013fc3df9c'

      //             )

      //             console.log(this.dataList.length, 6666666)
      //             break;

      //     }

      //     this.currentCateIndex = item.index
      // })
      console.log(this.allDataList, this.dataList, "1688");
      // if(this.userMes.tgdzPower == 0){
      // 	let that = this
      // 	uni.showModal({
      // 		content: "购买 针灸六经法要上册和下册 后方可使用此功能",
      // 		confirmText: '好的',
      // 		showCancel: false,
      // 		success: function(res) {
      // 			if (res.confirm) {
      // 				// console.log('用户点击确定');
      // 			}
      // 		}
      // 	})
      // 	return
      // }
      // if(item.title == "时辰取穴"){
      // 	uni.navigateTo({
      // 		url: "../timeAcupoint/timeAcupoint"
      // 	})
      // 	return
      // }

      // this.currentStatusIndex = index

      this.searchValue = "";
      this.searchList = [];
      this.showSearchList = false;
      // if (index != 2) {

      // uni.createSelectorQuery().select('.statusList').boundingClientRect(function (rect) {
      // 	var height = rect.height
      // 	console.log('元素高度：',);

      // }).exec();

      // } else {
      // 	this.getJFList(dictType)
      // }

      return data;
    },
    async setOneCateIndex(item, index) {
      this.allDataList = [];
      console.log(index, 99999);
      var that = this;

      // if(this.userMes.tgdzPower == 0){
      // 	let that = this
      // 	uni.showModal({
      // 		content: "购买 针灸六经法要上册和下册 后方可使用此功能",
      // 		confirmText: '好的',
      // 		showCancel: false,
      // 		success: function(res) {
      // 			if (res.confirm) {
      // 				// console.log('用户点击确定');
      // 			}
      // 		}
      // 	})
      // 	return
      // }
      // if(item.title == "时辰取穴"){
      // 	uni.navigateTo({
      // 		url: "../timeAcupoint/timeAcupoint"
      // 	})
      // 	return
      // }

      this.currentStatusIndex = index;
      // this.currentCateIndex = 0

      this.searchValue = "";
      this.searchList = [];
      this.showSearchList = false;
      this.$nextTick(async () => {
        await that.getData();

        this.$forceUpdate();
      });

      // this.handleselectCate(this.cateList[this.currentCateIndex])
      // if (index != 2) {

      // uni.createSelectorQuery().select('.statusList').boundingClientRect(function (rect) {
      // 	var height = rect.height
      // 	console.log('元素高度：',);

      // }).exec();

      // } else {
      // 	this.getJFList(dictType)
      // }
    },

    transformData(inputData) {
      const result = {};
      inputData.forEach((item) => {
        const { letter } = item;
        if (!result[letter]) {
          result[letter] = [];
        }
        result[letter].push(item);
      });
      // const finalResult = Object.keys(result).map(key => ({ [key]: result[key] }));
      return result;
    },
    // getJFList(id) {
    // 	$http.request({
    // 		url: "book/prescript/prescriptListForJF",
    // 		method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
    // 		data: {
    // 			loadAnimate: 'none', // 请求加载动画
    // 			'categoryId': id
    // 		},
    // 		header: { //默认 无 说明：请求头
    // 			'Content-Type': 'application/json'
    // 		},
    // 	}).then(res => {
    // 		if (res.code == 0 && res.list.length > 0) {
    // 			this.twoCateList = []
    // 			this.dataList = this.transformData(res.list)
    // 			console.log('JF经方', this.dataList)
    // 		} else {
    // 			this.twoCateList = []
    // 			this.dataList = []
    // 		}
    // 	}).catch(e => {
    // 		this.twoCateList = []
    // 		this.dataList = []
    // 		console.log(e)
    // 	})
    // },
    getCateList(id) {
      id ? "" : (id = 0);
      this.twoCateList = [];
      this.curTwoCateIndex = 0;
      // 0为获取顶级分类，其他为搜索下级分类，目前的逻辑，顶级是写死的，所以可能只会涉及到搜索第二级
      // $http.request({
      // 	url: "book/prescript/prescriptCategoryList",
      // 	method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
      // 	data: {
      // 		loadAnimate: 'none', // 请求加载动画
      // 		'categoryId': id
      // 	},
      // 	header: { //默认 无 说明：请求头
      // 		'Content-Type': 'application/json'
      // 	},
      // }).then(res => {
      // console.log(res, '脉穴分类获取成功')
      // if (res.code == 0 && res.list.length > 0) {
      // this.statusList = res.list
      // this.getTowCateList(this.statusList[0].type)
      // } else {
      // 	this.statusList = []
      // }
      // }).catch(e => {
      // 	this.statusList = []
      // 	console.log(e)
      // })
    },

    // 放大图片
    previewImage(url) {
      console.log(url);
      uni.previewImage({
        urls: [url],
        longPressActions: {
          itemList: ["很抱歉，暂不支持保存图片到本地"],
          success: function (res) {
            // console.log(res,'+++++')
          },
        },
      });
    },
    // getSearch() {
    // 	$http.request({
    // 		url: "book/prescript/searchPrescript",
    // 		method: "POST", // POST、GET、PUT、DELETE，具体说明查看官方文档
    // 		data: {
    // 			loadAnimate: 'none', // 请求加载动画
    // 			'keywords': this.searchValue,
    // 			type: this.currentStatusIndex + 1
    // 		},
    // 		header: { //默认 无 说明：请求头
    // 			'Content-Type': 'application/json'
    // 		},
    // 	}).then(res => {
    // 		console.log(res, '搜索结果')
    // 		if (res.code == 0 && res.list.length >= 0) {
    // 			this.showSearchList = true
    // 			this.searchList = res.list
    // 		} else {
    // 			this.searchList = []
    // 		}
    // 	}).catch(e => {
    // 		// this.dataList = []
    // 		this.searchList = []
    // 		console.log(e)
    // 	})
    // },
    // search(res) {
    // 	console.log(res, 'res')
    // 	// uni.showToast({
    // 	// 	title: '搜索：' + res,
    // 	// 	icon: 'none'
    // 	// })
    // 	if (res == '') {
    // 		this.showSearchList = false
    // 		this.searchList = []
    // 	} else {
    // 		this.getSearch()
    // 	}

    // },
    // input(res) {
    // 	console.log('----input:', res)
    // 	if (res == '') {
    // 		this.searchList = []
    // 	} else {
    // 		this.getSearch()
    // 	}
    // },
    // clear(res) {
    // 	console.log('----clear:', res)
    // 	// uni.showToast({
    // 	// 	title: 'clear事件，清除值为：',
    // 	// 	icon: 'none'
    // 	// })
    // 	this.searchValue = ''
    // 	this.showSearchList = false
    // },
    // blur(res) {
    // 	// console.log('----blur:', res)
    // 	// if (res == '') {
    // 	// 	this.showSearchList = false
    // 	// 	this.searchList = []
    // 	// } else {
    // 	// 	this.getSearch()
    // 	// }
    // },
    // focus(e) {
    // 	console.log('----focus:')
    // 	// uni.showToast({
    // 	// 	title: 'focus事件，输出值为：' + e.value,
    // 	// 	icon: 'none'
    // 	// })
    // 	// 等于1 就是有权限
    // 	// this.showSearchList = true

    // },
    // cancel(res) {
    // 	uni.showToast({
    // 		title: '点击取消，输入值为：' + res.value,
    // 		icon: 'none'
    // 	})
    // }
  },
  onBackPress() {
    // #ifdef APP-PLUS
    plus.key.hideSoftKeybord();
    // #endif
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/mixin.scss";
.AC_List {
  width: 100%;
  overflow: hidden;

  display: flex;
  align-items: center;
  // justify-content: space-between;
}

.curriulum_title {
  width: 100%;
  font-weight: 500;
  font-size: 28rpx;
  // line-height: 40rpx;
  //     display: flex;
  // align-items: center;
  margin-top: 10rpx;
  float: left;
  margin-bottom: 5rpx;
  color: #b0b0b0;
  // padding: 20rpx;
  box-sizing: border-box;

  text {
    margin-right: 10rpx;
  }
}

.right {
  width: calc(100% - 100rpx);
  display: flex;
  align-items: center;
}

.user_info {
  width: 100%;
  float: left;
  display: flex;
  margin-top: 10rpx;
  align-items: center;
  font-size: 32rpx;
  font-weight: 800;

  .name {
    color: #333;
    margin-right: 10rpx;
  }

  .tel {
    color: #000;
    font-size: 28rpx;
    font-weight: 600;
  }
}

.common_address_box {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
}

.normal_box {
  width: calc(100% - 60rpx);
  height: auto;
  float: left;

  // overflow: hidden;
  .normal_box_top {
    width: 100%;
    // display: flex;

    height: auto;
    margin-bottom: 40rpx;
  }

  .editIcon {
    float: right;
  }
}

.normal_logo {
  width: 80rpx !important;
  height: 80rpx !important;
  border-radius: 80rpx;
  background-color: $themeBgColor;
  color: $themeColor;
  font-size: 34rpx;
  font-weight: bold;
  text-align: center;
  line-height: 80rpx;
  float: left;
  margin-right: 20rpx;
}

.isDefault {
  color: $themeColor;
  font-size: 22rpx;
  font-weight: 600;
  border: 1rpx solid $themeColor;
  padding: 2rpx 10rpx;
  border-radius: 6rpx;
  line-height: 30rpx;
  margin-left: 18rpx;
}

/deep/.sx-address-picker__list-tab {
  padding-left: 0;
}

.inputBox {
  width: 100%;
  // padding: 20rpx;
  box-sizing: border-box;
  background-color: #f5f5f5;
  border-radius: 10rpx;
}

/deep/.uni-easyinput__content {
  background-color: #f5f5f5 !important;
  border-color: #f5f5f5 !important;
}

.select_address_box {
  min-height: 35px;
  line-height: 1;
  font-size: 14px;
  height: auto;
  padding-left: 20rpx;
  background-color: #f5f5f5 !important;
  padding-top: 20rpx;
  padding-bottom: 20rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .address_info {
    width: calc(100% - 60rpx);
  }
}

.address_box {
  background-color: #fbf9f9;
  padding: 30rpx;

  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 60rpx;
  }
}

/deep/.is-input-error-border .uni-easyinput__placeholder-class {
  color: #999 !important;
}

/deep/.uni-easyinput-error {
  color: #333 !important;
}

/deep/.uni-forms-item .is-required {
  margin-right: 10rpx !important;
  padding-top: 10rpx !important;
}

.rightArrow {
  margin-right: 40rpx;
  width: 40rpx;
  height: 40rpx;
  // position: absolute;
  // right: 30rpx;
}
</style>
