| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- list: [],
- result: [],
- radio: false,
- },
- onLoad(options) {
- if (options.item) {
- let item = JSON.parse(options.item);
- this.setData({
- item,
- params: item.params,
- result: item.value.length ? item.value[1] : []
- })
- };
- if (options.params) this.setData({
- params: JSON.parse(params)
- })
- this.setData({
- radio: options.radio ? true : false
- })
- this.getList();
- },
- /* 提交 */
- submit() {
- let pages = getCurrentPages(),
- item = this.data.item,
- result = this.data.result,
- list = this.data.result.map(value => this.data.list.find(v => v.contactsid == value));
- try {
- let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
- if (page) {
- item.value = this.data.radio ? [list[0].name, result] : [list.map(v => v.name), result];
- page.handleRoute(item);
- } else {
- pages[pages.length - 2].handleSelectContacts(this.data.result, list)
- }
- } catch (e) {
- wx.showToast({
- title: '操作失败',
- icon: "none"
- })
- }
- },
- /* 开始搜索 */
- onSearch({
- detail
- }) {
- if (this.data.params.content.where.condition == detail) return;
- this.setData({
- 'params.content.where.condition': detail
- });
- this.getList(true)
- },
- onClear() {
- this.setData({
- 'params.content.where.condition': ""
- });
- this.getList(true)
- },
- /* 选中 */
- onChange(e) {
- const contactsid = e.currentTarget.dataset.item.contactsid + "";
- if (!contactsid) return;
- let result = this.data.result;
- if (this.data.radio) {
- result = [contactsid]
- } else {
- if (result.some(v => v == contactsid)) {
- result = result.filter(v => v != contactsid)
- } else {
- result.push(contactsid)
- }
- }
- this.setData({
- result
- })
- },
- //获取列表
- getList(init = false) {
- let params = this.data.params;
- if (init) params.content.pageNumber = 1;
- if (params.content.pageNumber > params.content.pageTotal) return;
- _Http.basic(params).then(res => {
- console.log("联系人", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.data,
- icon: "none"
- });
- this.setData({
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
- "params.content.pageNumber": res.pageNumber + 1,
- "params.content.pageTotal": res.pageTotal,
- })
- })
- },
- onReachBottom() {
- this.getList();
- }
- })
|