| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- const _Http = getApp().globalData.http,
- getHeight = require("../../../utils/getRheRemainingHeight"),
- file = require("../../../utils/matchingFeilType");
- Page({
- data: {
- item: null,
- result: [],
- params: {},
- radio: false,
- },
- onLoad(options) {
- console.log(options)
- if (options.item) {
- let item = JSON.parse(options.item);
- this.setData({
- item,
- params: item.params
- });
- }
- if (options.params) this.setData({
- params: JSON.parse(options.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(v => this.data.list.find(value => value.itemid == v));
- try {
- let route = pages[pages.length - 2].__route__;
- if (item) {
- let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
- item.value = this.data.radio ? [list[0].projectname, result] : [list.map(v => v.projectname), result];
- page.handleRoute(item);
- } else if (route == 'packageA/offers/detail') {
- let addList = this.data.result.map(v => {
- return {
- "sa_quotedprice_itemsid": 0,
- "itemid": v,
- "oldprice": 0,
- "price": 0,
- "discountrate": 0,
- "qty": 0
- }
- });
- pages[pages.length - 2].selectComponent("#Product").handleSelectProduct(addList, list)
- } else if (route == 'packageA/project/detail') {
- let addList = this.data.result.map(v => {
- return {
- "sa_project_itemsid": 0,
- "itemid": v,
- "qty": 1,
- "remarks": ""
- }
- });
- pages[pages.length - 2].selectComponent("#Product").handleSelectProduct(addList, list)
- } else if (route == 'packageA/contract/detail') {
- let addList = this.data.result.map(v => {
- return {
- "itemid": v,
- "qty": 1,
- "price": 0
- }
- });
- pages[pages.length - 2].selectComponent(this.data.params.modle || "#Product").handleSelectProduct(addList, list)
- } else if (route == 'packageA/salesForecasting/detail') {
- let addList = list.map(v => {
- return {
- "sa_salesforecastid": 0,
- "itemid": v.itemid,
- "orderqty": 0,
- "orderamount": 0,
- "invoiceqty": 0,
- "invoiceamount": 0,
- "outqty": 1,
- "outamount": v.marketprice
- }
- });
- pages[pages.length - 2].selectComponent("#Project").handleSelectProduct(addList, list)
- } else {
- pages[pages.length - 2].handleSelectProduct(result, list)
- }
- } catch (e) {
- console.log(e)
- wx.showToast({
- title: '操作失败',
- icon: "none"
- })
- }
- },
- 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"
- })
- res.data = res.data.map(value => {
- if (value.attinfos.length == 0) return value;
- value.attinfos = file.fileList(value.attinfos)
- let image = value.attinfos.find(v => v.fileType == "image");
- value.cover = image ? image.cover : "";
- value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
- value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
- return value;
- })
- 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)
- })
- })
- },
- /* 选中 */
- changeResult(e) {
- const {
- id
- } = e.currentTarget.dataset;
- 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
- })
- },
- /* 预览图片 */
- viewImage(e) {
- const {
- file
- } = e.currentTarget.dataset;
- if (file.length) wx.previewMedia({
- sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
- return {
- url: v.url,
- type: v.fileType
- }
- }),
- current: 0,
- showmenu: true
- })
- },
- /* 开始搜索 */
- 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() {
- getHeight.getHeight('.total', this).then(res => this.setData({
- listHeight: res
- }));
- }
- })
|