You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netWork.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * @Author: gaorf30153 gaorf30153@hundsun.com
  3. * @Date: 2024-07-31 09:13:44
  4. * @LastEditors: gaorf30153 gaorf30153@hundsun.com
  5. * @LastEditTime: 2024-08-01 16:37:57
  6. * @FilePath: \wxminipro\plugin\components\netWork\netWork.js
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import Api from "../../api/index.js"
  10. import { requestFnc } from "../../utils/request.js"
  11. Component({
  12. properties: {
  13. showNetWork: {
  14. type: Boolean,
  15. value: false,
  16. },
  17. branchNo: {
  18. type: String,
  19. value: "",
  20. },
  21. address: {
  22. type: Object,
  23. value: {}
  24. }
  25. },
  26. data: {
  27. active: 0,
  28. netWorkList: [],
  29. cityList:[],
  30. searchProvinceCode:"520000",
  31. searchCityCode:"",
  32. cityName:"",
  33. searchAreaCode:"",
  34. areaName:"",
  35. currentType:"",
  36. show:false,
  37. cascaderValue:"520525",
  38. fieldValue:"",
  39. options:[
  40. {
  41. name: '贵州省',
  42. code: '520000',
  43. children:[
  44. // {
  45. // code: "520100",
  46. // name: "贵阳市",
  47. // children:[]
  48. // },{
  49. // children: [],
  50. // code: "520200",
  51. // name: "六盘水市"
  52. // },{
  53. // children: [],
  54. // code: "520300",
  55. // name: "遵义市"
  56. // },{
  57. // children: [],
  58. // code: "520400",
  59. // name: "安顺市"
  60. // },{
  61. // children: [],
  62. // code: "520500",
  63. // name: "毕节市"
  64. // },{
  65. // children: [],
  66. // code: "520600",
  67. // name: "铜仁市"
  68. // },{
  69. // children: [],
  70. // code: "522300",
  71. // name: "黔西南布依族苗族自治州"
  72. // },{
  73. // children: [],
  74. // code: "522600",
  75. // name: "黔东南苗族侗族自治州"
  76. // },{
  77. // children: [],
  78. // code: "522700",
  79. // name: "黔南布依族苗族自治州"
  80. // }
  81. ]
  82. // children: [{ text: '杭州市', value: '330100' }],
  83. },
  84. ],
  85. fieldNames:{
  86. text: 'name',
  87. value: 'code',
  88. children: 'children'
  89. },
  90. latitude:"",
  91. longitude:"",
  92. selectedOptions:[]
  93. },
  94. attached() {
  95. wx.getLocation({
  96. type: "gcj02",
  97. success: (res) => {
  98. const latitude = res.latitude
  99. const longitude = res.longitude
  100. let {codes=[],names="" } = this.data.address
  101. let cityCode = ""
  102. let areaCode = ""
  103. if(codes.length === 3){
  104. cityCode = codes[1].code
  105. areaCode = codes[2].code
  106. let c = codes.pop()
  107. this.setData({
  108. cascaderValue: c ? c.code : ""
  109. })
  110. let children = []
  111. this.getProvice({
  112. data:{
  113. provinceCode: "520000",
  114. cityCode:""
  115. },
  116. cb : (data) => {
  117. data.map(el => el.children=[])
  118. children = data
  119. this.setData({
  120. options: [{
  121. ...this.data.options[0],
  122. children
  123. }]
  124. })
  125. this.onChange({detail:{value:cityCode}})
  126. }
  127. })
  128. }
  129. this.setData({
  130. latitude,
  131. longitude,
  132. fieldValue:names
  133. })
  134. this.getBranchList({longitude,latitude,cityCode,areaCode,cb: () => {
  135. // 回显的情况
  136. let index = this.data.netWorkList.findIndex(el => el.branchNo === this.data.branchNo)
  137. if(index > -1){
  138. this.setData({
  139. active: index
  140. })
  141. }
  142. }})
  143. },
  144. fail: () => {
  145. this.getBranchList()
  146. },
  147. })
  148. },
  149. methods: {
  150. selectNetWork(e) {
  151. let network = e.currentTarget.dataset.network
  152. this.triggerEvent("selectNetWork", {network,address:{codes:[...this.data.selectedOptions],names:this.data.fieldValue}})
  153. this.setData({
  154. active: e.currentTarget.dataset.index,
  155. })
  156. },
  157. // 关闭弹窗
  158. closePopup() {
  159. this.triggerEvent("closePopup")
  160. this.setData({
  161. showNetWork: false,
  162. })
  163. },
  164. // 获取线下网点
  165. getBranchList({longitude, latitude,cityCode,areaCode,cb}) {
  166. let params = {
  167. filename: Api.getBranchList.filename,
  168. data: {
  169. longitude,
  170. latitude,
  171. businessType: "1",
  172. cityCode,
  173. areaCode
  174. },
  175. }
  176. requestFnc(Api.getBranchList.url, params, (res) => {
  177. let list = JSON.parse(res.data)
  178. for (let [key, obj] of list.entries()) {
  179. obj.label = []
  180. let l = obj.businessType.split("|")
  181. for (let code of l) {
  182. let map = {
  183. 1: "分省密钥",
  184. 2: "通用密钥",
  185. 3: "跨发行服务机构售后",
  186. }
  187. obj.label.push(map[code])
  188. }
  189. if (obj.distance) {
  190. obj.distanceLj = `${(Number(obj.distance) / 1000).toFixed(2)}km`
  191. }
  192. }
  193. this.setData({
  194. netWorkList: list,
  195. })
  196. cb && cb()
  197. },() => {
  198. this.setData({
  199. netWorkList: [],
  200. })
  201. })
  202. },
  203. getProvice({data,cb}) {
  204. let params = {
  205. filename: Api.getProvice.filename,
  206. data
  207. }
  208. requestFnc(Api.getProvice.url, params, (res) => {
  209. let list = res.data || []
  210. cb && cb(list)
  211. })
  212. },
  213. onClick() {
  214. this.setData({
  215. show: true
  216. })
  217. },
  218. onClose() {
  219. this.setData({
  220. show: false,
  221. });
  222. },
  223. onFinish(e) {
  224. const { selectedOptions, value } = e.detail;
  225. const fieldValue = selectedOptions
  226. .map((option) => option.text || option.name)
  227. .join('/');
  228. this.setData({
  229. fieldValue,
  230. cascaderValue: value,
  231. show:false,
  232. selectedOptions
  233. })
  234. this.getBranchList({
  235. longitude:this.data.latitude,
  236. latitude:this.data.latitude,
  237. cityCode:selectedOptions[1].code,
  238. areaCode:selectedOptions[2].code
  239. })
  240. console.log("---onFinish----",value)
  241. },
  242. onChange(e){
  243. let { value=""} = e.detail
  244. if(value === "520000" && this.data.options[0].children.length === 0){
  245. this.getProvice({
  246. data:{
  247. provinceCode: "520000",
  248. cityCode: ""
  249. },
  250. cb: (data) => {
  251. let { children=[] } = this.data.options[0]
  252. data.map(el => el.children=[])
  253. children = data
  254. this.setData({
  255. options: [{
  256. ...this.data.options[0],
  257. children
  258. }]
  259. })
  260. }
  261. })
  262. }else{
  263. let c = this.data.options[0].children.findIndex(el => el.code === value)
  264. if(c > -1){
  265. let {children=[]} = this.data.options[0].children[c]
  266. if(children.length === 0){
  267. this.getProvice({
  268. data:{
  269. provinceCode: "520000",
  270. cityCode: value
  271. },
  272. cb: (data) => {
  273. let { children=[] } = this.data.options[0]
  274. children[c].children = data
  275. this.setData({
  276. "options[0].children":children
  277. })
  278. }
  279. })
  280. }
  281. }
  282. }
  283. },
  284. onClear(){
  285. console.log("---onclear---","tttrrr")
  286. this.getBranchList({
  287. longitude:this.data.longitude,
  288. latitude:this.data.latitude,
  289. cb: () => {
  290. this.setData({
  291. cascaderValue:"",
  292. fieldValue:""
  293. })
  294. }})
  295. }
  296. }
  297. })