| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- sc_orderid: '',
- detail: {},
- tabsList: [{
- label: "订单明细",
- idname: "sc_orderid",
- model: "#Product"
- }, {
- label: "附件",
- idname: "sc_orderid",
- model: "#Files"
- }, {
- label: "操作记录",
- idname: "sc_orderid",
- model: "#Record"
- }],
- tabsActive: 0,
- tabbarList: []
- },
- onLoad(options) {
- getApp().globalData.Language.getLanguagePackage(this, '积分订单详情');
- if (options.id) {
- this.setData({ sc_orderid: options.id });
- this.getDetail();
- }
- },
- getDetail() {
- _Http.basic({
- id: 2026052510105106,
- content: { sc_orderid: this.data.sc_orderid }
- }).then(res => {
- if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" });
- const item = res.data;
- // 处理商品图片
- if (item.items && item.items.length) {
- item.items.forEach(i => {
- try {
- if (i.attinfos && i.attinfos.length) {
- let att = i.attinfos[0];
- i.imgUrl = att.subfiles ? _Http.getSpecifiedImage(att) : (att.url || '');
- } else {
- i.imgUrl = '';
- }
- } catch (e) {
- i.imgUrl = '';
- }
- });
- }
- this.setData({ detail: item });
- this.setTabbar();
- // 直接设置商品列表到 Product 组件
- try {
- let Product = this.selectComponent('#Product');
- if (Product) {
- Product.setList(item.sc_orderid, item.items || []);
- }
- } catch (e) {}
- // 新建订单且无收货地址时,自动选中默认地址
- if (item.status === '新建' && !item.rec_contactsid) {
- this.setDefaultAddress(item);
- }
- });
- },
- setTabbar() {
- const { status } = this.data.detail;
- const tabbarList = [];
- if (status === '新建') {
- tabbarList.push({ icon: "icon-tijiao1", label: "提交" });
- }
- this.setData({ tabbarList });
- },
- onTabbarClick(e) {
- let label = e.currentTarget.dataset.label;
- switch (label) {
- case '提交':
- this.submitOrder();
- break;
- }
- },
- /* 提交订单 */
- submitOrder() {
- // 校验收货地址是否已填写
- if (!this.data.detail.rec_contactsid) {
- return wx.showToast({ title: '请填写收货信息!', icon: 'none' });
- }
- wx.showModal({
- title: '提示',
- content: '确认提交该订单吗?',
- confirmText: '确定',
- cancelText: '取消',
- complete: ({ confirm }) => {
- if (confirm) {
- _Http.basic({
- id: 2026052510111906,
- content: { sc_orderid: this.data.sc_orderid }
- }).then(res => {
- wx.showToast({
- title: res.code == '1' ? '提交成功' : res.msg,
- icon: res.code == '1' ? 'success' : 'none'
- });
- if (res.code == '1') this.getDetail();
- });
- }
- }
- });
- },
- /* 选择收货地址 */
- selectAddress() {
- if (this.data.detail.status != '新建') return;
- wx.navigateTo({
- url: `/pages/tabbar/mine/address/index?userid=${this.data.detail.userid}&enterpriseid=${this.data.detail.sys_enterpriseid}&select=1`
- });
- getApp().globalData.handleSelect = this.setAddress.bind(this);
- },
- /* 设置收货地址(参照 web 版:乐观更新 + 仅传 contactsid) */
- setAddress({ item }) {
- // 乐观更新:先更新 UI,再调接口
- this.setData({
- 'detail.rec_name': item.name || '',
- 'detail.rec_phonenumber': item.phonenumber || '',
- 'detail.rec_province': item.province || '',
- 'detail.rec_city': item.city || '',
- 'detail.rec_county': item.county || '',
- 'detail.rec_address': item.address || ''
- });
- _Http.basic({
- id: 2026052510105206,
- content: {
- sc_orderid: this.data.sc_orderid,
- rec_contactsid: item.contactsid
- }
- }).then(s => {
- if (s.code == '1') {
- wx.showToast({ title: '设置成功', icon: 'success' });
- wx.navigateBack();
- this.getDetail();
- } else {
- wx.showToast({ title: s.msg, icon: 'none' });
- }
- });
- },
- /* 自动选中默认地址 */
- setDefaultAddress(item) {
- const userid = item.userid || wx.getStorageSync('userMsg').userid;
- _Http.basic({
- id: "20221022165503",
- content: {
- nocache: true,
- pageNumber: 1,
- pageSize: 1,
- where: {
- createuserid: userid,
- isdefault: 1
- }
- }
- }).then(res => {
- if (res.code == '1' && res.data && res.data.length > 0) {
- const defaultAddr = res.data[0];
- // 乐观更新 UI
- this.setData({
- 'detail.rec_name': defaultAddr.name || '',
- 'detail.rec_phonenumber': defaultAddr.phonenumber || '',
- 'detail.rec_province': defaultAddr.province || '',
- 'detail.rec_city': defaultAddr.city || '',
- 'detail.rec_county': defaultAddr.county || '',
- 'detail.rec_address': defaultAddr.address || ''
- });
- // 调用接口设置收货地址
- _Http.basic({
- id: 2026052510105206,
- content: {
- sc_orderid: this.data.sc_orderid,
- rec_contactsid: defaultAddr.contactsid
- }
- }).then(s => {
- if (s.code == '1') {
- this.getDetail();
- }
- });
- }
- });
- },
- /* 修改备注 */
- changeRemarks(e) {
- let value = e.detail.value;
- if (value == this.data.detail.remarks) return;
- wx.showModal({
- title: '提示',
- content: '确认修改备注吗?',
- confirmText: '确定',
- cancelText: '取消',
- complete: (res) => {
- if (res.cancel) {
- this.setData({ 'detail.remarks': this.data.detail.remarks });
- }
- if (res.confirm) {
- let items = (this.data.detail.items || []).map(v => ({
- sc_orderitemsid: v.sc_orderitemsid,
- qty: v.qty
- }));
- _Http.basic({
- id: 2026060210000006,
- content: {
- sc_orderid: this.data.sc_orderid,
- remarks: value,
- items
- }
- }).then(s => {
- wx.showToast({
- title: s.code == '1' ? '修改成功' : s.msg,
- icon: s.code == '1' ? 'success' : 'none'
- });
- if (s.code == '1') this.getDetail();
- });
- }
- }
- });
- },
- /* 修改商品数量(防抖) */
- _qtyTimer: null,
- _qtyItemData: null,
- onChangeProduct(e) {
- let { sc_orderitemsid, qty } = e.detail;
- // 更新本地数据中对应商品的数量
- let items = this.data.detail.items || [];
- let idx = items.findIndex(v => v.sc_orderitemsid === sc_orderitemsid);
- if (idx > -1) {
- let item = items[idx];
- let totalpoints = item.points * qty;
- this.setData({
- [`detail.items[${idx}].qty`]: qty,
- [`detail.items[${idx}].totalpoints`]: totalpoints,
- 'detail.totalpoints': items.reduce((sum, v, i) => sum + (i === idx ? totalpoints : (v.totalpoints || 0)), 0)
- });
- }
- // 保存变更的商品信息
- this._qtyItemData = { sc_orderitemsid, qty };
- // 清除上次定时器
- if (this._qtyTimer) clearTimeout(this._qtyTimer);
- // 设置防抖,500ms后执行
- this._qtyTimer = setTimeout(() => {
- this._qtyTimer = null;
- let changeData = this._qtyItemData;
- if (!changeData) return;
- // 构造所有商品的items数组
- let allItems = (this.data.detail.items || []).map(v => ({
- sc_orderitemsid: v.sc_orderitemsid,
- qty: v.qty
- }));
- _Http.basic({
- id: 2026060210000006,
- content: {
- sc_orderid: this.data.sc_orderid,
- remarks: this.data.detail.remarks || '',
- items: allItems
- }
- }).then(res => {
- if (res.code != '1') {
- wx.showToast({ title: res.msg, icon: 'none' });
- }
- });
- }, 500);
- },
- /* 更新总价 */
- onUpdateTotal(e) {
- this.setData({ 'detail.totalpoints': e.detail.totalpoints });
- },
- /* 刷新商品列表 */
- onRefreshProducts() {
- this.getDetail();
- },
- tabsChange({ detail }) {
- this.setData({ tabsActive: detail });
- this.partialRenewal();
- },
- partialRenewal(init = false) {
- try {
- let ac = this.data.tabsList[this.data.tabsActive];
- let model = ac.model;
- if (model && model !== '#Product') {
- let Component = this.selectComponent(model);
- if (Component && Component.getList) {
- let id = this.data.detail[ac.idname || 'sc_orderid'];
- Component.getList(id, init);
- }
- }
- } catch (error) {}
- },
- onUnload() {
- getCurrentPages().forEach(page => {
- if (page.__route__ == 'bgj/pointsBasedOrder/index') {
- page.setData({ isback: true });
- }
- });
- }
- });
|