|
|
@@ -0,0 +1,343 @@
|
|
|
+/*******************************************************************************
|
|
|
+ * Copyright(c) 2024 dongke All rights reserved. / Confidential
|
|
|
+ * 类的信息:
|
|
|
+ * 1.程序名称:
|
|
|
+ * 2.功能描述:表单-(开单)
|
|
|
+ * 编辑履历:
|
|
|
+ * 作者 日期 版本 修改内容
|
|
|
+ * 周兴 2024-1-30 1.00 新建
|
|
|
+ *******************************************************************************/
|
|
|
+const common = require('@/utils/common');
|
|
|
+const Constants = require('@/utils/Constants');
|
|
|
+const chooseLocation = requirePlugin('chooseLocation');
|
|
|
+const app = getApp();
|
|
|
+Component({
|
|
|
+ /**
|
|
|
+ * 组件的属性列表
|
|
|
+ */
|
|
|
+ properties: {
|
|
|
+ // 区域
|
|
|
+ cardList: {
|
|
|
+ type: Array,
|
|
|
+ value: []
|
|
|
+ },
|
|
|
+ // 内容
|
|
|
+ contentObj: {
|
|
|
+ type: Object,
|
|
|
+ },
|
|
|
+ // 开单组件类型
|
|
|
+ type: {
|
|
|
+ type: String,
|
|
|
+ },
|
|
|
+ // 结果集
|
|
|
+ value: {
|
|
|
+ type: String,
|
|
|
+ observer: function (newVal) {
|
|
|
+ if (newVal) {
|
|
|
+ this.setData({
|
|
|
+ form: JSON.parse(newVal) || {}
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组件的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ // 是否显示pop
|
|
|
+ show: false,
|
|
|
+ $t: app.globalData.lang,
|
|
|
+ routeUrl: app.globalData['routeUrl'],
|
|
|
+ item: null,
|
|
|
+ index: null,
|
|
|
+ card: null,
|
|
|
+ // 下拉类型
|
|
|
+ dropType: null,
|
|
|
+ dropCode: null,
|
|
|
+ dropName: null,
|
|
|
+ form: {}
|
|
|
+ },
|
|
|
+ lifetimes: {
|
|
|
+ attached: function () {
|
|
|
+ },
|
|
|
+ detached: function () {
|
|
|
+ // 在组件实例被从页面节点树移除时执行
|
|
|
+ },
|
|
|
+ },
|
|
|
+ pageLifetimes: {
|
|
|
+ /**
|
|
|
+ * @desc : 生命周期函数--监听页面显示
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/19 12:16
|
|
|
+ */
|
|
|
+ show: function () {
|
|
|
+ const location = chooseLocation.getLocation();
|
|
|
+ // console.log('loc', location);
|
|
|
+ let form = this.data.form
|
|
|
+ if (location) {
|
|
|
+ form['address'] = location;
|
|
|
+ // 如果有校验信息就清除掉
|
|
|
+ let card = this.data.card;
|
|
|
+ let index = this.data.index;
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ if (card && contentObj[card][index]?.errMsg) {
|
|
|
+ contentObj[card][index].errMsg = undefined;
|
|
|
+ this.setData({
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 组件的方法列表
|
|
|
+ */
|
|
|
+ methods: {
|
|
|
+ /**
|
|
|
+ * @desc : 打开下拉/跳转选择页面
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/1/26 11:46
|
|
|
+ */
|
|
|
+ open(e) {
|
|
|
+ let item = e.currentTarget.dataset;
|
|
|
+ if (item.item.type == 'drop') {
|
|
|
+ this.setData({
|
|
|
+ show: true,
|
|
|
+ dropCode: item.key,
|
|
|
+ dropName: item.name,
|
|
|
+ dropType: item.type,
|
|
|
+ index: item.index,
|
|
|
+ card: item.card
|
|
|
+ })
|
|
|
+ } else if (item.item.type == 'choose') {
|
|
|
+ // 跳转链接
|
|
|
+ if (item.url) {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: item.url,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 非空校验
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/20 11:46
|
|
|
+ */
|
|
|
+ validData() {
|
|
|
+ let flag = true;
|
|
|
+ let cardList = this.data.cardList;
|
|
|
+ if (!cardList || cardList.length == 0) {
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+ let form = this.data.form;
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ cardList.forEach(card => {
|
|
|
+ if (contentObj[card]) {
|
|
|
+ contentObj[card].forEach(item => {
|
|
|
+ let title = this.$t(item.title ? item.title : item.code)
|
|
|
+ // 如果必须输入,就要进行判断
|
|
|
+ if (item.required && !form[item.code]) {
|
|
|
+ item.errMsg = title + '为空'
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ return flag;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 展开页签
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/20 11:46
|
|
|
+ */
|
|
|
+ expandCard(e) {
|
|
|
+ console.log('e', e);
|
|
|
+ let cardList = this.data.cardList
|
|
|
+ let index = e.currentTarget.dataset.index
|
|
|
+ if (cardList[index]) {
|
|
|
+ // 收缩的时候需要展示信息
|
|
|
+ let unExpand = cardList[index].unExpand
|
|
|
+ cardList[index].info = undefined
|
|
|
+ console.log('f1', unExpand);
|
|
|
+ if (!unExpand) {
|
|
|
+ let form = this.data.form
|
|
|
+ let infoCols = e.currentTarget.dataset.item.infoCols
|
|
|
+ console.log('f2', infoCols, form);
|
|
|
+ if (infoCols && infoCols.length > 0) {
|
|
|
+ let info = ''
|
|
|
+ infoCols.forEach(it => {
|
|
|
+ if (form[it]) {
|
|
|
+ info += form[it] + '/'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (info.length > 0) {
|
|
|
+ info = info.substring(0, info.length - 1);
|
|
|
+ cardList[index].info = info
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cardList[index].unExpand = !unExpand
|
|
|
+ this.setData({
|
|
|
+ cardList: cardList
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 选择数据
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/1/26 11:46
|
|
|
+ */
|
|
|
+ chooseData(e) {
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ let form = this.data.form
|
|
|
+ form[this.data.dropCode] = e.detail.value;
|
|
|
+ form[this.data.dropName] = e.detail.text;
|
|
|
+ let card = this.data.card;
|
|
|
+ // 选择后清空校验提示信息
|
|
|
+ if (card && contentObj[card][this.data.index]?.errMsg && e.detail) {
|
|
|
+ contentObj[card][this.data.index].errMsg = undefined;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form,
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ // 如果处理id,name还需要赋值其他,需要在页面事件中自行处理
|
|
|
+ this.triggerEvent("chooseData", { code: this.data.dropCode, item: e.detail.item })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 修改输入框的值
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/2 11:46
|
|
|
+ */
|
|
|
+ changeField(e) {
|
|
|
+ let ds = e.currentTarget.dataset
|
|
|
+ let key = ds.key
|
|
|
+ let item = ds.item
|
|
|
+ let form = this.data.form
|
|
|
+ form[key] = e.detail
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ // 输入值后清空校验提示信息
|
|
|
+ if (item.errMsg && e.detail) {
|
|
|
+ contentObj[ds.card][ds.index].errMsg = undefined;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form,
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 修改数值输入框的值
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/2 11:46
|
|
|
+ */
|
|
|
+ changeNumberField(e) {
|
|
|
+ let ds = e.currentTarget.dataset
|
|
|
+ let key = ds.key
|
|
|
+ let item = ds.item
|
|
|
+ let form = this.data.form
|
|
|
+ form[key] = e.detail.value
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ // 输入值后清空校验提示信息
|
|
|
+ if (item.errMsg && e.detail) {
|
|
|
+ contentObj[ds.card][ds.index].errMsg = undefined;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form,
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 修改电话的值
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/2 11:46
|
|
|
+ */
|
|
|
+ changePhone(e) {
|
|
|
+ let ds = e.currentTarget.dataset;
|
|
|
+ let key = ds.key;
|
|
|
+ let index = ds.index;
|
|
|
+ let card = ds.card;
|
|
|
+ let form = this.data.form
|
|
|
+ form[key] = e.detail.detail
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ if (card && contentObj[card][index]?.errMsg && e.detail.detail) {
|
|
|
+ contentObj[card][index].errMsg = undefined;
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form,
|
|
|
+ contentObj: contentObj
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 给电话赋值错误信息
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/20 11:46
|
|
|
+ */
|
|
|
+ changePhoneblur(e) {
|
|
|
+ let ds = e.currentTarget.dataset
|
|
|
+ let errMsg = e.detail.errMsg;
|
|
|
+ let card = ds.card;
|
|
|
+ let index = ds.index;
|
|
|
+ let contentObj = this.data.contentObj;
|
|
|
+ if (errMsg && card && contentObj[card][index]) {
|
|
|
+ contentObj[card][index].errMsg = errMsg;
|
|
|
+ this.setData({
|
|
|
+ errMsg: errMsg
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 小程序地图调用
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/2/18 18:16
|
|
|
+ */
|
|
|
+ onClickWxchartAddress(e) {
|
|
|
+ // 跳转新建地图实例
|
|
|
+ common.onClickWxchartAddress();
|
|
|
+ let item = e.currentTarget.dataset;
|
|
|
+ this.setData({
|
|
|
+ index: item.index,
|
|
|
+ card: item.card
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 改变选择框内容
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/1/26 11:46
|
|
|
+ */
|
|
|
+ changeCheckBox(e) {
|
|
|
+ let key = e.currentTarget.dataset.key
|
|
|
+ let checkFlag = e.currentTarget.dataset.value
|
|
|
+ let form = this.data.form
|
|
|
+ form[key] = !checkFlag
|
|
|
+ this.setData({
|
|
|
+ value: JSON.stringify(form),
|
|
|
+ form: form
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @desc : 获取语言的方法
|
|
|
+ * @author : 周兴
|
|
|
+ * @date : 2024/1/19
|
|
|
+ */
|
|
|
+ $t(name) {
|
|
|
+ if (this.data.$t[name]) {
|
|
|
+ return this.data.$t[name];
|
|
|
+ } else {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+})
|