123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- const _Http = getApp().globalData.http,
- currency = require("../../utils/currency"),
- CNY = sum => currency(sum, {
- symbol: "¥",
- precision: 2
- }).format();
- let downCount = {};
- import {
- getCustomText
- } from "../../utils/customItemType";
- Page({
- data: {
- list: [],
- results: [], //选中结果
- classList: [], //生成订单时所选
- sum: 0, //价格合
- privacyFieldC: []
- },
- onLoad() {
- this.getList()
- let domainrelatedaccounts = wx.getStorageSync('domainrelatedaccounts');
- if (domainrelatedaccounts.length) {
- this.setData({
- domainrelatedaccounts
- })
- } else {
- _Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- "pageNumber": 1,
- "pageSize": 9999,
- "typename": "domainrelatedaccounts"
- }
- }).then(res => {
- console.log("查询领域对应列表", res)
- if (res.msg == '成功' && res.data.length) {
- domainrelatedaccounts = res.data;
- wx.setStorageSync('domainrelatedaccounts', domainrelatedaccounts)
- this.setData({
- domainrelatedaccounts
- })
- }
- })
- }
- console.log("domainrelatedaccounts", domainrelatedaccounts)
- try {
- let privacyFieldC = wx.getStorageSync('auth').wfavorites.forms.list.formcols.map(v => v.title);
- this.setData({
- privacyFieldC
- })
- console.log("privacyFieldC", privacyFieldC)
- } catch (error) {
- console.error("查询隐私字段", error)
- this.setData({
- privacyFieldC: []
- })
- }
- },
- /* 打开设置定制项 */
- customization(e) {
- const {
- item
- } = e.target.dataset;
- //修改定制项产品
- getApp().globalData.customizedProduct = (item, custom) => {
- let obj = {
- "width": 0,
- "length": 0,
- }
- for (const key in custom) {
- let name = key.replace("favorites", '')
- obj[name] = custom[key]
- }
- return new Promise((resolve) => {
- console.log('定制信息', custom)
- let index = this.data.list.findIndex(v => v.sa_favoritesid == item.sa_favoritesid);
- item = Object.assign(item, custom);
- item.customText = getCustomText(item, 'favorites')
- this.setData({
- [`list[${index}]`]: item
- })
- this.computeSum()
- resolve(true)
- /* _Http.basic({
- "id": 20231121143403,
- "content": {
- "itemid": item.itemid,
- "sa_favoritesid": item.sa_favoritesid,
- "favoritesqty": item.favoritesqty,
- "qty": item.favoritesqty,
- ...obj,
- ...custom,
- "iscollection": true
- },
- }).then(res => {
- console.log("修改定制", res)
- wx.showToast({
- title: res.msg != '成功' ? res.msg : '修改成功',
- icon: "none"
- });
- this.getList()
- resolve(true)
- }) */
- })
- }
- if (item) this.selectComponent("#Custom").onClick(item)
- },
- /* 获取列表 */
- getList() {
- _Http.basic({
- "id": 20231121145103,
- "content": {
- nocache: true,
- istool: 0,
- "pageNumber": 1,
- "pageSize": getApp().globalData.favoriteCount + 5,
- "where": {
- "condition": ""
- }
- }
- }).then(res => {
- console.log('收藏夹列表', res)
- this.selectComponent('#ListBox').RefreshToComplete();
- this.selectComponent("#ListBox").setHeight(".head", this);
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- })
- this.setData({
- list: res.data.map(v => {
- v.showPrice = CNY(v.gradeprice)
- if (v.iscustomsize) v.customText = ""; //getCustomText(v, 'favorites')
- return v
- })
- });
- if (wx.getStorageSync('favorites')) {
- this.setData({
- ...wx.getStorageSync('favorites')
- });
- this.computeSum();
- }
- })
- },
- /* 选中单品 */
- clickBut(e) {
- this.data.classList.length >= 2 ? wx.showToast({
- title: '请选择订单领域(订单只允许同领域的商品)',
- icon: "none",
- duration: 3000
- }) : this[e.target.id](0);
- },
- /* 是否选择全部 */
- setIsAll() {
- let isAll = this.data.isAll;
- this.setData({
- results: isAll ? [] : this.data.list.map(v => v.sa_favoritesid),
- isAll: !isAll
- })
- this.computeSum();
- },
- /* 计算总价/产品领域分类 */
- computeSum() {
- let results = this.data.results,
- sum = 0,
- classList = [];
- if (results.length) results = results.filter(v => {
- let item = this.data.list.find(va => va.sa_favoritesid == v);
- if (item) {
- sum = currency(sum).add(currency(item.favoritesqty).multiply(item.gradeprice)).value;
- /* 领域分类 */
- let index = classList.findIndex(value => value.type == item.tradefield[0].tradefield);
- if (index == -1) {
- classList.push({
- type: item.tradefield[0].tradefield,
- list: [item],
- name: item.tradefield[0].tradefield + "(1件商品)"
- })
- } else {
- classList[index].list.push(item)
- classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
- }
- };
- return item
- });
- wx.setStorageSync('shopping', {
- results
- })
- console.log("计算价格results", results)
- this.setData({
- sum: CNY(sum),
- isAll: results.length == this.data.list.length,
- results,
- classList
- });
- },
- /* 提交 */
- submit(e) {
- this[e.target.id](e.detail.value)
- },
- /* 处理生成订单 */
- handleSubmit(index) {
- let data = this.data.classList[index];
- let illegals = data.list.filter(v => v.iscustomsize && v.customText == "").map(v => v.erpitemname);
- if (illegals.length) return wx.showModal({
- title: '提示',
- content: `${illegals}定制信息有误,请检查!`,
- showCancel: false
- })
- wx.showLoading({
- title: '生成中...',
- })
- let tradefield = this.data.domainrelatedaccounts.find(v => v.value == data.type);
- _Http.basic({
- "id": 20221008134803,
- "version": 1,
- "content": {
- "pageNumber": 1,
- "pageTotal": 1,
- "pageSize": 9999,
- "where": {
- "condition": "",
- "isused": 1,
- "isnotspecialfund": 0, //是否专用
- },
- }
- }).then(acc => {
- console.log("账户列表", acc)
- let list = acc.data.filter(v => tradefield.subvalues.some(s => s == v.sa_accountclassid))
- _Http.basic({
- "id": 20221128183202,
- "content": {
- istool: 0,
- type: "标准订单",
- "tradefield": data.type, //必选
- sa_brandid: this.data.sa_brandid,
- sa_accountclassid: list.length ? list[0].sa_accountclassid : 0,
- "items": data.list.map(v => {
- return {
- "sa_orderitemsid": 0,
- "itemid": v.itemid,
- "qty": v.favoritesqty,
- "sa_brandid": v.brand.length ? v.brand[0].sa_brandid : this.data.sa_brandid || 0,
- width: v.favoriteswidth || 0,
- length: v.favoriteslength || 0,
- }
- })
- }
- }).then(res => {
- wx.hideLoading()
- console.log("转化订单", res)
- if (res.msg != '成功') return wx.showToast({
- title: res.msg,
- icon: "none"
- });
- this.setData({
- results: [],
- isAll: false
- })
- wx.showModal({
- title: '提示',
- content: '生成成功!是否立即前往',
- complete: (s) => {
- if (s.confirm) wx.navigateTo({
- url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
- })
- }
- });
- })
- })
- },
- addToShoppingCart(index) {
- let data = this.data.classList[index];
- let illegals = data.list.filter(v => v.iscustomsize && v.customText == "").map(v => v.erpitemname);
- if (illegals.length) return wx.showModal({
- title: '提示',
- content: `${illegals}定制信息有误,请检查!`,
- showCancel: false
- })
- wx.showLoading({
- title: '处理中...',
- })
- _Http.basic({
- "id": 20231024110003,
- "content": {
- "items": data.list.map(v => {
- return {
- "sa_brandid": v.brand.length ? v.brand[0].sa_brandid : 0,
- "itemid": v.itemid,
- "qty": v.favoritesqty,
- "itemno": v.itemno,
- "tradefield": data.type,
- "length": v.favoriteslength || 0,
- "width": v.favoriteswidth || 0
- }
- })
- }
- }).then(res => {
- wx.hideLoading()
- console.log("加入购物车", res)
- wx.showToast({
- title: res.msg != '成功' ? res.msg : "加入成功",
- icon: "none"
- });
- if (res.msg != '成功') return;
- this.setData({
- results: [],
- isAll: false
- })
- })
- },
- /* 切换选中项 */
- changeResults(e, my = false) {
- const {
- item
- } = my ? e : e.currentTarget.dataset;
- let results = this.data.results,
- sa_brandid = this.data.sa_brandid;
- console.log(item)
- if (sa_brandid && sa_brandid != item.sa_brandid) return;
- if (results.length == 0) {
- results.push(item.sa_favoritesid);
- sa_brandid = item.sa_brandid;
- } else {
- let index = results.findIndex(v => v == item.sa_favoritesid)
- if (index == -1) {
- results.push(item.sa_favoritesid);
- } else {
- results.splice(index, 1);
- if (results.length == 0) sa_brandid = null;
- }
- };
- this.setData({
- results,
- sa_brandid
- })
- this.computeSum();
- },
- /* 删除产品 */
- deteleItem(e) {
- const {
- item
- } = e.currentTarget.dataset;
- wx.showModal({
- title: '提示',
- content: `是否确认删除${item.itemname}?`,
- complete: ({
- confirm
- }) => {
- e.detail.instance.close();
- if (confirm) _Http.basic({
- "id": 20231121143403,
- "content": {
- "itemid": item.itemid,
- "iscollection": false
- }
- }).then(res => {
- wx.showToast({
- title: res.msg != '成功' ? res.msg : "删除成功",
- icon: "none"
- });
- if (res.msg != '成功') return;
- this.setData({
- results: this.data.results.filter(v => v != item.sa_favoritesid)
- })
- this.getList(true)
- this.computeSum();
- getApp().globalData.getFavoriteCount()
- })
- }
- })
- },
- /* 输入框失去焦点调整数量 */
- inputBlur(e) {
- const {
- index
- } = e.currentTarget.dataset;
- let item = this.data.list[index];
- let favoritesqty = 0;
- if (item.orderminqty > e.detail.value) {
- wx.showToast({
- title: '输入数量低于最低起订量!',
- icon: "none"
- })
- favoritesqty = item.orderminqty;
- } else if (item.orderminqty < e.detail.value) {
- var currencyRounding = value => currency(value, {
- increment: item.orderaddqty
- });
- favoritesqty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
- } else {
- favoritesqty = e.detail.value;
- }
- this.setData({
- [`list[${index}].favoritesqty`]: 0
- });
- this.setData({
- [`list[${index}].favoritesqty`]: favoritesqty
- });
- this.handleChangeQty(item, index)
- },
- /* 步进器调整数量 */
- stepperChange(e) {
- const {
- index
- } = e.currentTarget.dataset;
- let item = this.data.list[index];
- if (e.type == 'plus') {
- item.favoritesqty += item.orderaddqty
- } else {
- item.favoritesqty -= item.orderaddqty
- }
- this.setData({
- [`list[${index}]`]: item
- })
- this.handleChangeQty(item, index)
- },
- handleChangeQty(item, index) {
- this.computeSum();
- clearTimeout(downCount['count' + index])
- downCount['count' + index] = setTimeout(() => {
- _Http.basic({
- "id": 20231121143403,
- "content": {
- "sa_favoritesid": item.sa_favoritesid,
- "itemid": item.itemid,
- "favoritesqty": item.favoritesqty,
- "qty": item.favoritesqty,
- "width": item.width || 0,
- "length": item.length || 0,
- "iscollection": true
- },
- }, false).then(res => {
- console.log("修改数量", res)
- })
- }, 1000)
- }
- })
|