| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- /*******************************************************************************
- * Copyright(c) 2021 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:单选下拉组件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * jyh 2022-5-5 1.00 新建
- *******************************************************************************/
- const api = require('../../../utils/api');
- const app = getApp()
- const Constants = require('../../../utils/Constants');
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- /**
- * 客户来源:customerFrom,卫生间数:toiletCount,装修类型:fitupType,房屋类型:houseType,
- * 装修风格:fitupStyle,年龄构成:ageComposition,决策者:decisionMaker,结算类型:settlement,
- * 费用项目:feeItem,业务部门:org,性别:gender orther:其他分类 supType:供应商类别
- */
- typeName: {
- type: String,
- default: 'org'
- },
- content: {
- type: String,
- default: 'org'
- },
- warehouseId: {
- type: String,
- default: 'org'
- },
- dataItem: {
- type: Object,
- default: {}
- },
- dynamicList: { //开单商品编辑临时数组
- type: Array,
- default: []
- },
- choooseFlg: {
- type: Boolean,
- default: false
- },
- docName: {
- type: String,
- value: ''
- },
- contentID: {
- type: Number,
- default: 0
- },
- channelId: {
- type: Number,
- default: null
- },
- jobIds: {
- type: Array,
- value: []
- },
- orgId: {
- type: Number,
- value: null
- },
- show: {
- type: Boolean,
- default: false,
- observer: function (newVal) {
- let show = this.properties.show
- if (!show) {
- return
- }
- // 给类型赋值
- this.setDataSource();
- let datalists = this.data.datalists;
- let datalist = datalists[this.data.typeName] || []
- if (!datalists[this.data.typeName] || datalists[this.data.typeName].length == 0) {
- let DataSourceCode = this.data.DataSourceCode
- let typeName = this.data.typeName
- this.getdata(DataSourceCode).then(res => {
- let list = res.data.data
- if (list == null || list.length <= 0) {
- this.setData({
- datalist: []
- })
- return;
- }
- let datalist = []
- // 初始款项
- if (typeName === 'initialPayment') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.kindCode,
- name: item2.kindName,
- checked: item2.id == this.properties.contentID ? true : false,
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- // 发票类型
- if (typeName === 'receiptType') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.kindCode,
- name: item2.kindName,
- checked: item2.id == this.properties.contentID ? true : false,
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- // 部门
- if (typeName === 'org') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.orgCode,
- name: item2.orgName,
- checked: item2.id == this.properties.contentID ? true : false,
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- // 员工
- if (typeName === 'staff') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.staffCode,
- name: item2.staffName,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- //结算方式
- if (typeName == 'settlement') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.macCode,
- name: item2.macName,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- //客户来源
- if (typeName == 'customerFrom') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.dataCode,
- name: item2.dataValue,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- //销售渠道
- if (typeName == 'saleChannel') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.channelCode,
- name: item2.channelName,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- //仓库
- if (typeName == 'warehouse') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.whCode,
- name: item2.whName,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- //客户意向 留店时长 邀约结果 量尺状态
- if (typeName == 'customerIntention' || typeName == 'storeRetentionTime' || typeName === 'inviteResult' || typeName === 'scaleStatus' || typeName == 'followType') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.kindCode,
- name: item2.kindName,
- checked: item2.id == this.properties.contentID ? true : false
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- // 供应商类别
- if (typeName === 'supType') {
- let nmb = 0
- let nmb_tenter = 0
- list.forEach(item2 => {
- let item = {
- id: item2.id,
- code: item2.kindCode,
- name: item2.kindName,
- checked: item2.id == this.properties.contentID ? true : false,
- }
- nmb_tenter++
- if (item2.id == this.properties.contentID) {
- nmb = nmb_tenter
- }
- datalist.push(item)
- })
- this.setData({
- radio: this.properties.contentID ? (nmb - 1) : '',
- valueKey: 'id',
- labelKey: 'name'
- })
- }
- let finallist = [...datalist]
- datalists[this.data.typeName] = [...datalist]
- this.setData({
- datalists: datalists,
- finallist: finallist
- })
- })
- } else {
- if (this.properties.contentID) {
- // 重刷选中项
- datalists[this.data.typeName].forEach(item => {
- item.checked = item.id == this.properties.contentID ? true : false;
- })
- this.setData({
- datalists: datalists,
- })
- }
- }
- }
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- DataSourceCode: '',
- // 是否点击清除按钮
- isClickClear: false,
- // datalist: [],
- finallist: [],
- condition: '',
- dataValue: '',
- name: '',
- valueKey: 'id',
- labelKey: 'name',
- radio: null,
- label_title: '可选',
- count: 0,
- datalists: {},
- pageInfo: {
- pageSize: 5,
- currentPage: 1
- }
- },
- lifetimes: {
- attached: function () {
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /**
- * @desc : 给类型赋值
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- setDataSource() {
- let DataSourceCode = ''
- let typeName = this.data.typeName
- let name = ''
- if (typeName === 'customerFrom') {
- DataSourceCode = 'customerFrom'
- name = '客户来源'
- }
- if (typeName === 'settlement') {
- DataSourceCode = 'settlement'
- name = '结算方式'
- }
- if (typeName === 'saleChannel') {
- DataSourceCode = 'saleChannel'
- name = '销售渠道'
- }
- if (typeName === 'org') {
- DataSourceCode = 'org'
- name = '业务部门'
- }
- //业务员
- if (typeName === 'staff') {
- DataSourceCode = 'staff'
- name = '员工'
- }
- if (typeName === 'customerIntention') {
- DataSourceCode = 'customerIntention'
- name = '客户意向'
- }
- if (typeName === 'storeRetentionTime') {
- DataSourceCode = 'storeRetentionTime'
- name = '留店时长'
- }
- if (typeName === 'inviteResult') {
- DataSourceCode = 'inviteResult'
- name = '邀约结果'
- }
- if (typeName === 'scaleStatus') {
- DataSourceCode = 'scaleStatus'
- name = '量尺状态'
- }
- if (typeName === 'followType') {
- DataSourceCode = 'followType'
- name = '跟进方式'
- }
- if (typeName === 'warehouse') {
- DataSourceCode = 'warehouse'
- name = '仓库'
- }
- if (typeName === 'supType') {
- DataSourceCode = 'supType'
- name = '供应商类别'
- }
- // 初始款项
- if (typeName === 'initialPayment') {
- DataSourceCode = 'initialPayment'
- name = '初始款项'
- }
- // 发票类型
- if (typeName === 'receiptType') {
- DataSourceCode = 'receiptType'
- name = '发票类型'
- }
- this.setData({
- DataSourceCode: DataSourceCode
- })
- },
- /**
- * 查询数据
- * @param {*} e
- */
- getdata: function (DataSourceCode, e) {
- let param = {
- dataSourceCode: DataSourceCode
- }
- let SELECT_API = 'get_init_data'
- return new Promise((resolve, reject) => {
- api.request(Constants.BASIC_COMMON_API + SELECT_API, 'POST', param).then(res => {
- if (res.data.code === 200) {
- resolve(res)
- } else {
- reject(res)
- }
- })
- })
- },
- /**
- * 关闭弹窗
- */
- onClose: function () {
- // this.reset()
- this.setData({
- show: false
- })
- // 为了关闭外面的下拉
- this.triggerEvent('muticlose')
- },
- /**
- * 焦点离开事件
- */
- blur_input() {
- if (this.data.datalists[this.data.typeName].length <= 0) {
- this.reset()
- }
- },
- /**
- * @desc : 值改变
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- onChange(e) {
- let datalist = this.data.datalists[this.data.typeName] || []
- if (datalist && datalist.length > e.detail) {
- datalist.forEach(it => {
- it.checked = false;
- })
- datalist[e.detail].checked = true;
- let item = datalist[e.detail];
- this.setData({
- radio: e.detail,
- // datalist: datalist,
- show: false
- })
- this.triggerEvent('commit', {
- value: item[this.data.valueKey],
- text: item[this.data.labelKey],
- item: item
- })
- }
- },
- /**
- * 过滤数据
- * @param {*} e
- */
- onChange_input: function (e) {
- let finallist = this.data.finallist
- if (finallist === null || finallist.length === 0) return
- // 复制
- finallist = [...finallist]
- let condition = this.data.condition
- this.setData({
- radio: '',
- })
- let datalist = []
- finallist.forEach(item => {
- if (item.name.indexOf(condition) >= 0) {
- datalist.push(item)
- }
- })
- // 单选框的true false显示 是radio控制
- let nmb = 0
- let nmb_tenter = 0
- datalist.forEach(item2 => {
- nmb_tenter++
- if (item2.name == this.data.clickRodioButton) {
- nmb = nmb_tenter
- this.setData({
- radio: nmb - 1
- })
- }
- })
- let datalists = this.data.datalists
- datalists[this.data.typeName] = datalist
- this.setData({
- datalists: datalists
- })
- },
- /**
- * 重置
- */
- reset: function () {
- // let datalist = this.data.datalist
- let datalist = this.data.datalists[this.data.typeName]
- let finallist = this.data.finallist
- if (finallist == null || finallist.length === 0) return
- finallist.forEach(item => {
- item.checked = false
- })
- datalist = [...finallist]
- this.setData({
- finallist: finallist,
- // datalist: datalist,
- datalists: datalists,
- condition: '',
- radio: '',
- })
- },
- /**
- * 清除数据
- */
- clear() {
- let finallist = this.data.finallist
- // 清空勾选框
- finallist.forEach(item => {
- item.checked = false
- })
- let datalist = [...finallist]
- this.triggerEvent('commit', {
- ids: '',
- names: ''
- })
- let datalists = this.data.datalists
- datalists[thsi.data.typeName] = datalist
- // 清空控件
- this.setData({
- // datalist: datalist,
- datalists: datalists,
- finallist: finallist,
- condition: '',
- isClickClear: true,
- dataValue: '',
- count: 0,
- radio: null,
- label_title: '可选',
- defaultCheackFlag: true
- })
- },
- /**
- * 提交
- */
- commit: function () {
- // let datalist = this.data.datalist
- let datalist = this.data.datalists[this.data.typeName]
- if (datalist == null || datalist.length === 0) return
- // 获取选中的那条数据
- let filters = datalist.filter(it => it.checked);
- if (filters && filters.length > 0) {
- let item = filters[0];
- this.triggerEvent('commit', {
- value: item[this.data.valueKey],
- text: item[this.data.labelKey],
- item: item
- })
- this.setData({
- show: false
- })
- }
- },
- },
- })
|