switchPopup.js
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// components/switchPopup/switchPopup.js
const app = getApp()
import api from '~/api/api'
import { getYQorderInfo } from '~/store/index'
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
value: true
// observer: function (n) {
// if (n) {
// this.checkCoupon()
// }
// }
},
title: String,
tips: String,
height: {
type: String,
value: '85%'
},
isYqdSuper: Boolean
// merchantSettingInfo: {
// type: Object,
// observer: function (n) {
// if (n) {
// this.setOrderSettingList(n)
// }
// }
// }
},
/**
* 组件的初始数据
*/
data: {
merchantSettingInfo: '',
// switchStatus: 1,
orderSettingList: [
{
label: '选择车型',
valueName: 'carTypeRequiredFlag',
value: false
},
{
label: '车架号(VIN码)',
valueName: 'standNoRequiredFlag',
value: false
},
{
label: '车牌号',
valueName: 'plateNumRequiredFlag',
value: false
},
{
label: '战败下单是否体验',
valueName: 'foEfRequiredFlag',
value: true
},
{
label: '战败下单拒升理由提交',
valueName: 'foRrRequiredFlag',
value: true
}
]
},
/** 组件生命周期 */
lifetimes: {
attached: function () {
// console.log(app.globalData.isYqdSuper)
console.log(this.data.isYqdSuper)
// app .
getYQorderInfo()
.then(merchantSettingInfo => {
console.log(merchantSettingInfo)
this.setData({ merchantSettingInfo })
this.setOrderSettingList(merchantSettingInfo)
})
.catch(err => {
console.log(err)
})
}
},
/**
* 组件的方法列表
*/
methods: {
async confirm() {
// 判断是不是园区店管理员 不是都不处理
let { isYqdSuper, merchantSettingInfo, orderSettingList } = this.data
// 是管理员请求数据 并存全局读取
if (isYqdSuper) {
let { merchantId, merchantName } = merchantSettingInfo
wx.$util.showLoading('设置中...')
let params = orderSettingList.reduce((obj, item) => {
obj[item.valueName] = item.value == true ? 'Y' : 'N'
// item
return obj
}, {})
let result = await api.setMerchantRecordingSettings({
merchantId,
merchantName,
...params
})
let { code, data } = result
if (code == 0) {
app.globalData.YQorderSetting = Object.assign(app.globalData.YQorderSetting, params)
}
wx.$util.hideLoading()
}
this.setData({
show: false
})
},
onSwitchChange(e) {
// console.log(e)
let { index } = e.currentTarget.dataset
let { orderSettingList } = this.data
// console.log(index)
orderSettingList[index]['value'] = !orderSettingList[index]['value']
// console.log(orderSettingList[index]['value'])
this.setData({
orderSettingList
})
},
setOrderSettingList(n) {
// 做转换
let { orderSettingList } = this.data
orderSettingList.forEach(element => {
// if (element.valueName == n) {
let value = n[element.valueName]
element.value = value == 'Y' ? true : false
// }
})
console.log(orderSettingList)
this.setData({
orderSettingList
})
}
}
})