| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- import {
- set
- } from "lodash";
- // pages/order/create/create.js
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- loading: true,
- addr: {},
- ecc: {},
- eccName: '',
- goodsList: [],
- checkPrice: 0,
- logisticsList: [],
- auditUserList: [],
- bxdCustomTypeList: [],
- bxdEccList: [],
- projectThemeList: [{
- id: 1,
- name: '会销'
- },
- {
- id: 2,
- name: '科室会'
- },
- {
- id: 3,
- name: '患教活动'
- },
- {
- id: 4,
- name: '日常拜访'
- },
- {
- id: 5,
- name: '展会'
- },
- {
- id: 6,
- name: '品牌路演'
- },
- {
- id: 7,
- name: '公司内部活动'
- },
- ],
- userInfo: wx.getStorageSync('userInfo'),
- company: wx.getStorageSync('company'),
- isSales: false,
- isStraumann: false,
- order: {
- logisticsName: '',
- logisticsCode: '',
- checkUserName: '',
- checkUserId: '',
- totalAmount: '',
- bxdOrderList: [{
- companyId: wx.getStorageSync('companyId'),
- companyName: wx.getStorageSync('companyName'),
- eccCode: '',
- eccName: '',
- customerName: '', //eccName
- typeName: '',
- remark: '',
- publicRemark: '',
- activityName: '',
- projectTheme: '',
- }]
- },
- errShow: false,
- errMsg: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- let that = this;
- const eventChannel = that.getOpenerEventChannel()
- // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
- eventChannel.on('acceptDataFromOpenerPage', function (data) {
- that.setData({
- goodsList: data.goodsList,
- ["order.bxdOrderList[0].bxdOrderItem"]: data.goodsList.map(v => {
- v['prodCount'] = v.qty;
- v['prodName'] = v.picTitle;
- v['priceTotal'] = app.currency(0).add(app.currency(v.price).multiply(v.qty).value);
- v['productTotalAmount'] = v.priceTotal;
- return v;
- }),
- ["order.bxdOrderList[0].totalAmount"]: data.checkPrice,
- ["order.bxdOrderList[0].productNums"]: data.goodsList.filter((item => item.check)).reduce((qty, item1) => app.currency(qty).add(item1.qty).value, 0),
- ["order.totalAmount"]: data.checkPrice,
- checkPrice: data.checkPrice,
- });
- });
- await app.getUserInfo(this);
- await this.getAddr();
- let company = this.data.company;
- this.setData({
- isStraumann: company && company.corporationCode == 'straumann'
- });
- // let {
- // data: check
- // } = await app.ajax.gets('/admin/address/check');
- // let isSales = false;
- // if (check.code == 0) {
- // if (check.data == 2004) {
- // isSales = false
- // } else if (check.data == 2005) {
- // isSales = true
- // }
- // }
- // this.setData({
- // isSales
- // });
- // if (company && company.corporationCode == 'straumann') {
- // let {
- // data: data1
- // } = await app.ajax.gets('/admin/bxdecc/page?current=1&size=10');
- // this.setData({
- // bxdEccList: data1.data.records.map(v => {
- // return {
- // ...v,
- // name: v.eccName
- // }
- // })
- // });
- // }
- if (this.data.userInfo.auditSwitch === '1' && this.data.userInfo.auditUsers) {
- let {
- data
- } = await app.ajax.gets(`/admin/user/getUsersByIds?userIds=${this.data.userInfo.auditUsers.split(',')}`);
- this.setData({
- auditUserList: data.data.map(v => {
- return {
- id: v.userId,
- name: v.fullname
- }
- })
- });
- }
- this.getLogisticsList();
- this.setData({
- loading: false
- });
- },
- async getAddr() {
- let {
- data
- } = await app.ajax.gets("/admin/bxdClientAddress/default");
- if (data.data) {
- this.setData({
- addr: data.data,
- ["order.bxdOrderList[0]"]: {
- ...this.data.order.bxdOrderList[0],
- ...data.data,
- addrId: `clientAddrId_${data.data.addrId}`,
- receiverName: data.data.receiver,
- address: data.data.addr,
- remarks: data.data.remark,
- }
- })
- }
- },
- bindOrderRemark(e) {
- this.setData({
- ["order.bxdOrderList[0].publicRemark"]: e.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- // chooseAddr() {
- // let that = this;
- // wx.navigateTo({
- // url: '/pages/order/create/create',
- // success: function (res) {
- // // 通过eventChannel向被打开页面传送数据
- // res.eventChannel.emit('acceptDataFromOpenerPage', {
- // goodsList: cartList.filter((item => item.check)),
- // checkPrice: cartList.filter((item => item.check)).reduce((price, item1) => app.currency(price).add(item1.price).multiply(item1.qty).value, 0),
- // })
- // }
- // })
- // },
- chooseAddr: function () {
- let that = this;
- wx.navigateTo({
- url: '/pages/user/address/list/list',
- events: {
- // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
- acceptDataFromOpenerPage: function (data) {
- that.setData({
- addr: data.addr,
- ["order.bxdOrderList[0]"]: {
- ...that.data.order.bxdOrderList[0],
- ...data.addr,
- addrId: `clientAddrId_${data.addr.addrId}`,
- receiverName: data.addr.receiver,
- address: data.addr.addr,
- remarks: data.addr.remark,
- }
- })
- },
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('acceptDataFromOpenerPage', {
- check: true,
- addr: that.data.addr
- })
- }
- })
- },
- chooseEcc: function () {
- let that = this;
- wx.navigateTo({
- url: '/pages/user/ecc/ecc',
- events: {
- // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
- acceptDataFromOpenerPage: function (data) {
- that.setData({
- ecc: data.ecc,
- eccName: data.eccName,
- ["order.bxdOrderList[0].eccCode"]: data.ecc.eccCode,
- ["order.bxdOrderList[0].eccName"]: data.ecc.eccName,
- ["order.bxdOrderList[0].typeName"]: data.ecc.customTypeName,
- })
- },
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('acceptDataFromOpenerPage', {
- ecc: that.data.ecc,
- eccName: that.data.eccName
- })
- }
- })
- },
- async getLogisticsList() {
- let {
- data
- } = await app.ajax.gets("/admin/dict/getSysDictListByType?type=logisticsCode");
- let company = wx.getStorageSync('company')
- this.setData({
- logisticsList: data.data.filter(v => {
- //console.log(v.value, company.logisticsCode.split(",").indexOf(v.value))
- return company.logisticsCode.split(",").indexOf(v.value) != -1;
- }).map(v => {
- return {
- id: v.value,
- name: v.label
- }
- })
- });
- let onlyLogisticsCode = wx.getStorageSync('company').onlyLogisticsCode || '';
- let onlyLogisticsCodeIndex = 0;
- try {
- onlyLogisticsCodeIndex = this.data.logisticsList.findIndex(v => v.id == onlyLogisticsCode) > 0 ? this.data.logisticsList.findIndex(v => v.id == onlyLogisticsCode) : 0;
- } catch (e) { }
- this.setData({
- logisticsCodeValue: onlyLogisticsCodeIndex,
- ['order.logisticsName']: this.data.logisticsList[onlyLogisticsCodeIndex].name,
- ['order.logisticsCode']: this.data.logisticsList[onlyLogisticsCodeIndex].id,
- ["order.bxdOrderList[0].logisticsCode"]: this.data.logisticsList[onlyLogisticsCodeIndex].id,
- })
- },
- bindLogisticsCode(e) {
- this.setData({
- logisticsCodeValue: Number(e.detail.value),
- ['order.logisticsName']: this.data.logisticsList[Number(e.detail.value)].name,
- ['order.logisticsCode']: this.data.logisticsList[Number(e.detail.value)].id,
- ["order.bxdOrderList[0].logisticsCode"]: this.data.logisticsList[Number(e.detail.value)].id,
- })
- },
- bindCheckUser(e) {
- this.setData({
- ['order.checkUserName']: this.data.auditUserList[Number(e.detail.value)].name,
- ['order.checkUserId']: this.data.auditUserList[Number(e.detail.value)].id,
- })
- },
- bindEccUser(e) {
- this.setData({
- ['order.bxdOrderList[0].eccName']: this.data.bxdEccList[Number(e.detail.value)].name,
- ['order.bxdOrderList[0].eccCode']: this.data.bxdEccList[Number(e.detail.value)].eccCode,
- ['order.bxdOrderList[0].typeName']: this.data.bxdEccList[Number(e.detail.value)].customTypeName,
- })
- },
- bindActivityName(e) {
- this.setData({
- ['order.bxdOrderList[0].activityName']: e.detail.value
- })
- },
- bindProjectTheme(e) {
- this.setData({
- ['order.bxdOrderList[0].projectTheme']: this.data.projectThemeList[Number(e.detail.value)].name
- })
- },
- async submit() {
- let that = this;
- this.setData({
- ['order.shenhe']: "",
- ['order.fahuo']: "",
- ['order.qianshou']: "",
- });
- wx.requestSubscribeMessage({
- tmplIds: ['X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE', '6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ', 'AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg'],
- success(res) {
- if (res.errMsg == "requestSubscribeMessage:ok") {
- if (res["X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE"] == "accept") {
- that.setData({
- ['order.shenhe']: 'X3m1gQyKyTBIvEAZO7FgPcOmF-ibwXck1-acj9St0LE'
- })
- }
- if (res["6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ"] == "accept") {
- that.setData({
- ['order.fahuo']: '6Lc7eHUHQeqzxNFB3kioZCZjInjLJ5lMZOTcf7635OQ'
- })
- }
- if (res["AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg"] == "accept") {
- that.setData({
- ['order.qianshou']: 'AEJCSo1FZ12WNgJd7XUQCSzhF_pF4Sz64Cmt5074tEg'
- })
- }
- }
- },
- fail(res) { },
- complete(res) {
- that.submit1();
- }
- })
- },
- async submit1() {
- let goodsList = this.data.goodsList;
- let addr = this.data.addr;
- let order = this.data.order;
- let userInfo = this.data.userInfo;
- if (!goodsList || goodsList.length == 0) {
- wx.showToast({
- title: '请选择商品',
- icon: 'error'
- });
- return;
- }
- if (!addr || !addr.addrId) {
- wx.showToast({
- title: '请选择地址',
- icon: 'error'
- });
- return;
- }
- if (!order.logisticsCode) {
- wx.showToast({
- title: '请选择快递公司',
- icon: 'error'
- });
- return;
- }
- if (userInfo.auditSwitch === '1' && !order.checkUserId && !this.data.isStraumann) {
- wx.showToast({
- title: '请选择审核用户',
- icon: 'error'
- });
- return;
- }
- if (this.data.isStraumann && !order.bxdOrderList[0].eccName) {
- wx.showToast({
- title: '请选择客户编码',
- icon: 'error'
- });
- return;
- }
- if (this.data.isStraumann && !order.bxdOrderList[0].typeName) {
- wx.showToast({
- title: '暂无客户类型请先维护',
- icon: 'none'
- });
- return;
- }
- if (this.data.isStraumann && !order.bxdOrderList[0].activityName) {
- wx.showToast({
- title: '请输入活动名称',
- icon: 'error'
- });
- return;
- }
- if (this.data.isStraumann && !order.bxdOrderList[0].projectTheme) {
- wx.showToast({
- title: '请选择活动类型',
- icon: 'error'
- });
- return;
- }
- let {
- data: res
- } = await app.ajax.post({
- url: "/admin/bxdorder/commitOrder",
- data: order
- });
- if (res.code == 401) {
- wx.showToast({
- title: '下单失败',
- icon: 'error',
- duration: 2000
- });
- return;
- } else if (res.code == 4000) {
- this.setData({
- errShow:true,
- errMsg: `下单失败:${res.data ? '收货人公司【' + res.data + '】,' : ''}下单额度不足,请联系部门负责人`,
- })
- // this.errClose();
- } else {
- wx.showToast({
- title: '提交订单成功!',
- });
- let status = true ? '' : this.data.isStraumann ? 1 : userInfo.auditSwitch === '0' ? 1 : '0';
- setTimeout(() => {
- wx.redirectTo({
- url: `/pages/order/user/list/list?status=${status}`,
- })
- }, 1000);
- }
- },
- errClose() {
- this.setData({
- errShow: false,
- errMsg: ''
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|