|
|
@@ -0,0 +1,169 @@
|
|
|
+const _Http = getApp().globalData.http;
|
|
|
+
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ params: {}, //请求体
|
|
|
+ result: [], //返回结果
|
|
|
+ radio: false, //是否为单选
|
|
|
+ idname: "sa_customersid", //idkey
|
|
|
+ showName: "enterprisename", //表单用 显示名称
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ if (options.params) {
|
|
|
+ let params = JSON.parse(options.params);
|
|
|
+ if (!params.content.pageNumber || !params.content.pageTotal) {
|
|
|
+ params.content.pageNumber = 1;
|
|
|
+ params.content.pageTotal = 1;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ params
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (options.title) wx.setNavigationBarTitle({
|
|
|
+ title: options.title,
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ radio: options.radio ? true : false,
|
|
|
+ idname: options.idname || this.data.idname,
|
|
|
+ showName: options.showName || this.data.showName,
|
|
|
+ });
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ getList(init = false) {
|
|
|
+ //init 用于初始化分页
|
|
|
+ if (init.detail != undefined) init = init.detail;
|
|
|
+ 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)
|
|
|
+ this.selectComponent('#ListBox').RefreshToComplete();
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ 'params.content.pageNumber': res.pageNumber + 1,
|
|
|
+ 'params.content.pageTotal': res.pageTotal,
|
|
|
+ 'params.content.total': res.total,
|
|
|
+ list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
|
|
|
+ })
|
|
|
+ this.getTags();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ tabChange(e) {
|
|
|
+ this.data.params.content.where.type = e.detail.title == '客户' ? 2 : 1;
|
|
|
+ this.getList(true);
|
|
|
+ },
|
|
|
+ /* 获取列表标签 */
|
|
|
+ getTags() {
|
|
|
+ let list = this.data.list,
|
|
|
+ ownerids = list.map(v => v.sa_customersid);
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20221018102001,
|
|
|
+ "content": {
|
|
|
+ nocache: true,
|
|
|
+ "ownertable": "sa_customers",
|
|
|
+ ownerids
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("标签", res)
|
|
|
+ if (res.data == '失败') return this.getTags1();
|
|
|
+ for (let key in res.data) {
|
|
|
+ let index = list.findIndex(v => v.sa_customersid == key);
|
|
|
+ list[index].tags = res.data[key]
|
|
|
+ };
|
|
|
+ this.setData({
|
|
|
+ list
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 竞争对手标签 */
|
|
|
+ getTags1() {
|
|
|
+ let list = this.data.list,
|
|
|
+ ownerids = list.map(v => v.sa_competitorid);
|
|
|
+ _Http.basic({
|
|
|
+ "id": 20221018102001,
|
|
|
+ "content": {
|
|
|
+ nocache: true,
|
|
|
+ "ownertable": "sa_competitor",
|
|
|
+ ownerids
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("标签1", res)
|
|
|
+ for (let key in res.data) {
|
|
|
+ let index = list.findIndex(v => v.sa_competitorid == key);
|
|
|
+ list[index].tags = res.data[key]
|
|
|
+ };
|
|
|
+ this.setData({
|
|
|
+ list
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 删除项 */
|
|
|
+ deteleItem(id) {
|
|
|
+ this.setData({
|
|
|
+ list: this.data.list.filter(v => v[this.data.idname] != id),
|
|
|
+ "params.content.total": this.data.params.content.total - 1
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 选中 */
|
|
|
+ changeResult(e) {
|
|
|
+ let {
|
|
|
+ id
|
|
|
+ } = e.currentTarget.dataset, result = this.data.result;
|
|
|
+ if (this.data.radio) {
|
|
|
+ result = [id];
|
|
|
+ } else {
|
|
|
+ result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ result
|
|
|
+ });
|
|
|
+ if (this.data.radio) this.submit();
|
|
|
+ },
|
|
|
+ /* 提交 */
|
|
|
+ submit() {
|
|
|
+ let result = this.data.result,
|
|
|
+ obj = this.data.radio ? {
|
|
|
+ id: result,
|
|
|
+ item: this.data.list.find(value => value[this.data.idname] == result),
|
|
|
+ value: [this.data.list.find(value => value[this.data.idname] == result)[this.data.showName], result]
|
|
|
+ } : {
|
|
|
+ result,
|
|
|
+ list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
|
|
|
+ value: [result.map(v => {
|
|
|
+ let data = this.data.list.find(value => value[this.data.idname] == v);
|
|
|
+ return data ? data[this.data.showName] : ""
|
|
|
+ }), result]
|
|
|
+ }
|
|
|
+ getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
|
|
|
+ },
|
|
|
+ /* 开始搜索 */
|
|
|
+ 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);
|
|
|
+ },
|
|
|
+ onReady() {
|
|
|
+ this.selectComponent("#ListBox").setHeight(".total", this);
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ //回收数据
|
|
|
+ getApp().globalData.handleSelect = null;
|
|
|
+ }
|
|
|
+})
|