|
@@ -0,0 +1,118 @@
|
|
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
|
|
+Page({
|
|
|
|
|
+ data: {
|
|
|
|
|
+ item: null, //自定义表单组件使用
|
|
|
|
|
+ result: [], //选中结果
|
|
|
|
|
+ radio: false, //是否为单选模式
|
|
|
|
|
+ idName: 'contactsid', //选择ID
|
|
|
|
|
+ list: []
|
|
|
|
|
+ },
|
|
|
|
|
+ onLoad(options) {
|
|
|
|
|
+ if (options.item) {
|
|
|
|
|
+ let item = JSON.parse(options.item);
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ item,
|
|
|
|
|
+ params: item.params,
|
|
|
|
|
+ result: item.value.length ? item.value[1] : [],
|
|
|
|
|
+ idName:item.idName
|
|
|
|
|
+ })
|
|
|
|
|
+ };
|
|
|
|
|
+ if (options.params) this.setData({
|
|
|
|
|
+ params: JSON.parse(options.params)
|
|
|
|
|
+ })
|
|
|
|
|
+ if (options.idName) this.setData({
|
|
|
|
|
+ idName: options.idName
|
|
|
|
|
+ })
|
|
|
|
|
+ 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[this.data.idName] == value)); //选中列表
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (item) { //判断是否表单调用,表单的话吧数据交还给表单
|
|
|
|
|
+ let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
|
|
|
|
|
+ item.value = this.data.radio ? [list[0].name, result] : [list.map(v => v.name), result];
|
|
|
|
|
+ page.handleRoute(item);
|
|
|
|
|
+ } else if (this.data.params.model) {
|
|
|
|
|
+ //判断是否上级页面中的组件调用
|
|
|
|
|
+ let page = pages[pages.length - 2].selectComponent(this.data.params.model);
|
|
|
|
|
+ page.handleSelectContacts(result, list)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //上级页面调用
|
|
|
|
|
+ pages[pages.length - 2].handleSelectContacts(result, list)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.log(e)
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '操作失败',
|
|
|
|
|
+ icon: "none"
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ /* 开始搜索 */
|
|
|
|
|
+ startSearch({
|
|
|
|
|
+ detail
|
|
|
|
|
+ }) {
|
|
|
|
|
+ let condition = this.data.content?this.data.content.where.condition:this.data.params.content.where.condition;
|
|
|
|
|
+ if (detail == condition) return;
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ 'content.where.condition': detail,
|
|
|
|
|
+ 'params.content.where.condition': detail
|
|
|
|
|
+ });
|
|
|
|
|
+ this.getList(true);
|
|
|
|
|
+ },
|
|
|
|
|
+ /* 取消搜索 */
|
|
|
|
|
+ onClear() {
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ 'content.where.condition': "",
|
|
|
|
|
+ 'params.content.where.condition': ""
|
|
|
|
|
+ });
|
|
|
|
|
+ this.getList(true);
|
|
|
|
|
+ },
|
|
|
|
|
+ /* 选中 */
|
|
|
|
|
+ onChange(e) {
|
|
|
|
|
+ const id = e.currentTarget.dataset.item[this.data.idName] + "";
|
|
|
|
|
+ if (!id) return;
|
|
|
|
|
+ let result = this.data.result;
|
|
|
|
|
+ if (this.data.radio) {
|
|
|
|
|
+ result = [id]
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (result.some(v => v == id)) {
|
|
|
|
|
+ result = result.filter(v => v != id)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.push(id)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ result
|
|
|
|
|
+ })
|
|
|
|
|
+ if (this.data.radio) this.submit();
|
|
|
|
|
+ },
|
|
|
|
|
+ //获取列表
|
|
|
|
|
+ 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();
|
|
|
|
|
+ }
|
|
|
|
|
+})
|