123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- /*
- * @Author: gaorf30153 gaorf30153@hundsun.com
- * @Date: 2024-07-31 09:13:44
- * @LastEditors: gaorf30153 gaorf30153@hundsun.com
- * @LastEditTime: 2024-08-01 16:37:57
- * @FilePath: \wxminipro\plugin\components\netWork\netWork.js
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- import Api from "../../api/index.js"
- import { requestFnc } from "../../utils/request.js"
- Component({
- properties: {
- showNetWork: {
- type: Boolean,
- value: false,
- },
- branchNo: {
- type: String,
- value: "",
- },
- address: {
- type: Object,
- value: {}
- }
- },
- data: {
- active: 0,
- netWorkList: [],
- cityList:[],
- searchProvinceCode:"520000",
- searchCityCode:"",
- cityName:"",
- searchAreaCode:"",
- areaName:"",
- currentType:"",
- show:false,
- cascaderValue:"520525",
- fieldValue:"",
- options:[
- {
- name: '贵州省',
- code: '520000',
- children:[
- // {
- // code: "520100",
- // name: "贵阳市",
- // children:[]
- // },{
- // children: [],
- // code: "520200",
- // name: "六盘水市"
- // },{
- // children: [],
- // code: "520300",
- // name: "遵义市"
- // },{
- // children: [],
- // code: "520400",
- // name: "安顺市"
- // },{
- // children: [],
- // code: "520500",
- // name: "毕节市"
- // },{
- // children: [],
- // code: "520600",
- // name: "铜仁市"
- // },{
- // children: [],
- // code: "522300",
- // name: "黔西南布依族苗族自治州"
- // },{
- // children: [],
- // code: "522600",
- // name: "黔东南苗族侗族自治州"
- // },{
- // children: [],
- // code: "522700",
- // name: "黔南布依族苗族自治州"
- // }
- ]
- // children: [{ text: '杭州市', value: '330100' }],
- },
- ],
- fieldNames:{
- text: 'name',
- value: 'code',
- children: 'children'
- },
- latitude:"",
- longitude:"",
- selectedOptions:[]
- },
- attached() {
- wx.getLocation({
- type: "gcj02",
- success: (res) => {
-
- const latitude = res.latitude
- const longitude = res.longitude
- let {codes=[],names="" } = this.data.address
- let cityCode = ""
- let areaCode = ""
-
- if(codes.length === 3){
- cityCode = codes[1].code
- areaCode = codes[2].code
-
-
- let c = codes.pop()
- this.setData({
- cascaderValue: c ? c.code : ""
- })
-
- let children = []
- this.getProvice({
- data:{
- provinceCode: "520000",
- cityCode:""
- },
- cb : (data) => {
- data.map(el => el.children=[])
- children = data
- this.setData({
- options: [{
- ...this.data.options[0],
- children
- }]
- })
-
- this.onChange({detail:{value:cityCode}})
- }
- })
- }
- this.setData({
- latitude,
- longitude,
- fieldValue:names
- })
-
-
- this.getBranchList({longitude,latitude,cityCode,areaCode,cb: () => {
- // 回显的情况
- let index = this.data.netWorkList.findIndex(el => el.branchNo === this.data.branchNo)
- if(index > -1){
- this.setData({
- active: index
- })
- }
- }})
-
- },
- fail: () => {
- this.getBranchList()
- },
- })
- },
- methods: {
- selectNetWork(e) {
- let network = e.currentTarget.dataset.network
- this.triggerEvent("selectNetWork", {network,address:{codes:[...this.data.selectedOptions],names:this.data.fieldValue}})
- this.setData({
- active: e.currentTarget.dataset.index,
- })
- },
- // 关闭弹窗
- closePopup() {
- this.triggerEvent("closePopup")
- this.setData({
- showNetWork: false,
- })
- },
- // 获取线下网点
- getBranchList({longitude, latitude,cityCode,areaCode,cb}) {
- let params = {
- filename: Api.getBranchList.filename,
- data: {
- longitude,
- latitude,
- businessType: "1",
- cityCode,
- areaCode
- },
- }
- requestFnc(Api.getBranchList.url, params, (res) => {
- let list = JSON.parse(res.data)
- for (let [key, obj] of list.entries()) {
- obj.label = []
- let l = obj.businessType.split("|")
- for (let code of l) {
- let map = {
- 1: "分省密钥",
- 2: "通用密钥",
- 3: "跨发行服务机构售后",
- }
- obj.label.push(map[code])
- }
-
- if (obj.distance) {
- obj.distanceLj = `${(Number(obj.distance) / 1000).toFixed(2)}km`
- }
- }
- this.setData({
- netWorkList: list,
- })
- cb && cb()
- },() => {
- this.setData({
- netWorkList: [],
- })
- })
- },
- getProvice({data,cb}) {
- let params = {
- filename: Api.getProvice.filename,
- data
- }
- requestFnc(Api.getProvice.url, params, (res) => {
- let list = res.data || []
- cb && cb(list)
- })
- },
- onClick() {
- this.setData({
- show: true
- })
- },
- onClose() {
- this.setData({
- show: false,
- });
- },
- onFinish(e) {
-
- const { selectedOptions, value } = e.detail;
- const fieldValue = selectedOptions
- .map((option) => option.text || option.name)
- .join('/');
- this.setData({
- fieldValue,
- cascaderValue: value,
- show:false,
- selectedOptions
- })
- this.getBranchList({
- longitude:this.data.latitude,
- latitude:this.data.latitude,
- cityCode:selectedOptions[1].code,
- areaCode:selectedOptions[2].code
- })
- console.log("---onFinish----",value)
- },
- onChange(e){
- let { value=""} = e.detail
- if(value === "520000" && this.data.options[0].children.length === 0){
- this.getProvice({
- data:{
- provinceCode: "520000",
- cityCode: ""
- },
- cb: (data) => {
- let { children=[] } = this.data.options[0]
- data.map(el => el.children=[])
- children = data
- this.setData({
- options: [{
- ...this.data.options[0],
- children
- }]
- })
- }
- })
- }else{
- let c = this.data.options[0].children.findIndex(el => el.code === value)
- if(c > -1){
- let {children=[]} = this.data.options[0].children[c]
- if(children.length === 0){
- this.getProvice({
- data:{
- provinceCode: "520000",
- cityCode: value
- },
- cb: (data) => {
- let { children=[] } = this.data.options[0]
- children[c].children = data
-
- this.setData({
- "options[0].children":children
- })
- }
- })
- }
- }
-
- }
- },
- onClear(){
- console.log("---onclear---","tttrrr")
- this.getBranchList({
- longitude:this.data.longitude,
- latitude:this.data.latitude,
- cb: () => {
- this.setData({
- cascaderValue:"",
- fieldValue:""
- })
- }})
- }
- }
- })
|