123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- agency: {
- sys_enterpriseid: 0
- },
- skeletonShow: false,
- loading: false,
- sa_brandid: null,
- tradefield: null,
- sa_accountclassid: 0,
- brandList: [],
- domainList: [],
- type: "标准订单",
- },
- /* 切换订单类型 */
- onSelectType(e) {
- this.setData({
- type: e.currentTarget.dataset.name
- })
- this.getAccList();
- },
- onLoad(options) {
- this.getOrderList()
- this.setData({
- type: options.type || '标准订单',
- sa_projectid: options.sa_projectid || 0,
- sa_contractid: options.sa_contractid || 0,
- userrole: wx.getStorageSync('userrole')
- })
- if (this.data.userrole == '经销商') {
- this.getBrand();
- this.getDomain();
- };
- 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)
- },
- /* 获取品牌 */
- getBrand(id) {
- let content = {
- nocache: true,
- "pageSize": 999,
- }
- if (id) content.sys_enterpriseid = id;
- _Http.basic({
- "id": 20220924163702,
- content
- }).then(res => {
- console.log("查询品牌", res)
- if (res.data.length) this.setData({
- brandList: res.data,
- sa_brandid: res.data[0].sa_brandid
- });
- })
- },
- /* 获取orderList */
- getOrderList() {
- _Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- "typename": "ordertype"
- }
- }).then(res => {
- console.log("订单类型", res)
- let orderList = [];
- try {
- orderList = res.data.map(v => v.value);
- } catch (error) {
- }
- if (orderList.length == 0) orderList.push("标准订单")
- this.setData({
- orderList,
- type: orderList[0]
- })
- })
- },
- /* 选择品牌 */
- onSelectBrand(e) {
- let {
- item
- } = e.currentTarget.dataset;
- if (this.data.sa_brandid == item.sa_brandid) return;
- this.setData({
- sa_brandid: item.sa_brandid
- })
- },
- /* 获取领域 */
- getDomain(id) {
- let content = {
- nocache: true,
- "pageNumber": 1,
- "pageSize": 99999,
- "where": {
- "condition": ""
- }
- };
- if (id) content.sys_enterpriseid = id;
- _Http.basic({
- "id": 20221223141802,
- content
- }).then(res => {
- console.log("获取领域", res)
- if (res.data.length) this.setData({
- domainList: res.data,
- tradefield: res.data[0].tradefield,
- skeletonShow: false
- });
- this.getAccList();
- })
- },
- /* 选择领域 */
- onSelect(e) {
- let {
- item
- } = e.currentTarget.dataset;
- if (this.data.tradefield == item.tradefield) return;
- this.setData({
- tradefield: item.tradefield
- })
- this.getAccList();
- },
- onSelectAcc(e) {
- let {
- item
- } = e.currentTarget.dataset;
- console.log(item)
- this.setData({
- sa_accountclassid: item.sa_accountclassid
- })
- },
- getAccList() {
- this.setData({
- optionalAccount: [],
- sa_accountclassid: 0
- })
- if (['标准订单', '特殊订单'].includes(this.data.type || '标准订单')) {
- let tradefield = this.data.domainrelatedaccounts.find(v => v.value == this.data.tradefield);
- if (tradefield) _Http.basic({
- "id": 20221008134803,
- "version": 1,
- "content": {
- "pageNumber": 1,
- "pageTotal": 1,
- "pageSize": 9999,
- "where": {
- "condition": "",
- "isused": 1,
- "isnotspecialfund": this.data.type == '标准订单' ? 0 : 1, //是否专用
- },
- }
- }).then(res => {
- console.log("账户列表", res)
- let list = res.data.filter(v => tradefield.subvalues.some(s => s == v.sa_accountclassid))
- if (res.msg == '成功') this.setData({
- optionalAccount: list,
- sa_accountclassid: list.length ? list[0].sa_accountclassid : 0
- })
- })
- }
- },
- submit() {
- if (this.data.userrole == '业务员' && !this.data.agency.sys_enterpriseid) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: '您还未选择经销商!是否立即前往',
- complete: (res) => {
- if (res.confirm) that.selectAgency()
- }
- })
- return;
- };
- if (this.data.loading) return;
- this.setData({
- loading: true
- })
- // sa_accountclassid: 0,
- _Http.basic({
- "id": 20221108111402,
- content: {
- sa_orderid: 0,
- rec_contactsid: 0,
- pay_enterpriseid: 0,
- sa_contractid: this.data.sa_contractid,
- sa_projectid: this.data.sa_projectid,
- "sa_brandid": this.data.sa_brandid, //品牌ID
- "type": this.data.type, //订单类型
- "tradefield": this.data.tradefield, //必选
- sys_enterpriseid: this.data.agency.sys_enterpriseid,
- sa_accountclassid: this.data.sa_accountclassid
- }
- }).then(res => {
- this.setData({
- loading: false
- })
- console.log("创建" + this.data.type, res);
- wx.showToast({
- title: res.msg != '成功' ? res.msg || '创建失败' : '创建成功',
- icon: "none",
- mask: true
- });
- if (res.msg == '成功') setTimeout(() => {
- wx.redirectTo({
- url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
- });
- }, 500)
- })
- },
- /* 业务员逻辑 ↓ */
- selectAgency() {
- wx.navigateTo({
- url: `/select/agent/index?params=${JSON.stringify({
- "id": 20230219195002,
- "content": {
- nocache:true,
- "ismanage": "0",
- "where": {
- "condition": ""
- }
- }
- })}&radio=true`,
- })
- getApp().globalData.handleSelect = this.setAgency.bind(this);
- },
- /* 设置经销商 */
- setAgency({
- item
- }) {
- let that = this;
- wx.showModal({
- title: '提示',
- content: `是否确定选择"${item.enterprisename}"作为指定经销商?`,
- complete: (res) => {
- if (res.confirm) {
- that.setData({
- agency: item
- })
- that.getBrand(item.sys_enterpriseid)
- that.getDomain(item.sys_enterpriseid)
- wx.navigateBack()
- }
- }
- })
- }
- })
|