ts_aimz/pages/copyright/createProjectInfo/createProjectInfo.js

676 lines
21 KiB
JavaScript

import ProjectService from '../../../net/api/projectApi'
import UserService from '../../../net/api/userApi'
const utils = require("../../../utils/util")
const {
isValidPhone,
isValidEmail,
objIsEmpty
} = require('../../../utils/validator')
const app = getApp()
Page({
data: {
imgAssets: app.globalData.imgAssetsUrl,
localAssets: app.globalData.localAssets,
date: utils.formatDate(new Date()),
completeDate: '', //开发完成时间
version: "V1.0", //系统版本
type: 'ALL', //默认全托管 上级页面传递type参数 all全托管 material写材料
languageList: ['JAVA'],
isShowLanguage: false, //是否显示语言选择
isShowContact: false, //是否显示联系人
currentLanguage: 'JAVA', //当前选中的语言
price: 0,
packageList: [], //套餐包
tempPackage: {}, //临时选中的优惠卷,没有点击确定按钮前
selectPackage: {}, //选中的套餐包
couponsList: [], //优惠卷
selectCoupons: {}, //选中的优惠卷
tempCoupons: {}, //临时选中的优惠卷,没有点击确定按钮
contactList: [], //联系人
selectContact: {}, //当前选中的联系人
contactPhone: '', //联系人电话
contactName: '', //联系人姓名
contactEmail: '', //联系人邮箱
csaNo: '', //客服NO
showError: false,
errorHint: '',
showSuccess: false,
successHint: '',
showCommendProject: false, //显示推荐项目名称弹窗
projectName: '',
projectNameList: [],
isUrgent: false, //是否加急
showCoupons: false, //显示优惠卷
showPackage: false, //显示套餐包
canSelCoupons: true, //是否可以使用优惠卷
canSelPackage: true, //是否可以使用套餐包
langList: [], //项目语言
showLang: false, //显示选择语言
tempLang: '', //临时选中的语言
selectLang: '',
contactCompany: '', //联系人公司
isShowUrgent: true, //是否加急
urgent: 0, //加急费用
isUrgentDisable: false, //是否禁用加急
proPrice: 0, //价格
transmitPId: '', //传递过来的套餐包ID
},
onLoad(options) {
wx.setNavigationBarTitle({
title: '创建软著',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
const typeParams = options.type //类型
const priceParams = options.price //价格
const isUrgentParams = options.isUrgent //是否加急
const pId = options.pId //套餐包ID
console.log(priceParams)
if (priceParams && priceParams > 0) {
this.setData({
price: priceParams,
proPrice: priceParams,
type: typeParams,
isUrgent: isUrgentParams,
transmitPId: pId
})
} else {
this.setData({
errorHint: '数据有误,请稍后重试',
showError: true
})
setTimeout(() => {
wx.navigateBack()
}, 1000);
}
if (this.data.type == 'ALL') {
wx.setNavigationBarTitle({
title: `创建软著(全托管)`,
})
this.setData({
isShowUrgent: true
})
} else {
wx.setNavigationBarTitle({
title: `创建软著(写材料)`,
})
this.setData({
isShowUrgent: false
})
}
//获取项目联系人
this.doGetContactList()
//获取套餐包
this.doGetPackage()
//获取优惠卷
this.doGetCoupons()
//获取客服ID
this.doGetCsaNo(false)
//获取可选语言
this.doGetProLangList()
//获取加急等费用
this.doGetPrice()
},
//获取单价
doGetPrice() {
wx.showLoading({
title: '加载中...',
})
const _self = this
ProjectService.doGetPrice()
.then(res => {
console.log(res)
_self.setData({
urgent: res.additional.urgent, //加急办理
})
}, err => {
wx.showToast({
title: '数据有误,请稍后重试',
icon: 'error',
success: () => {
wx.navigateBack()
}
})
})
},
//系统版本
inputVersion(e) {
console.log(e.detail.value)
this.setData({
version: e.detail.value
})
},
//是否加急
doUrgent() {
const _self = this
_self.setData({
isUrgent: !_self.data.isUrgent
})
_self.countPrice()
},
//计算价格
countPrice() {
const _self = this;
// 传递过来的价格
const trPrice = Number(_self.data.proPrice);
let newPrice = trPrice;
// 选中了套餐包,直接将价格设为 0
if (!objIsEmpty(_self.data.selectPackage)) {
newPrice = 0;
} else {
const isAllType = _self.data.type === 'ALL';
const hasCoupon = !objIsEmpty(_self.data.selectCoupons);
const isUrgent = _self.data.isUrgent;
// 写材料/全托管判断
if (isAllType) {
if (hasCoupon) {
newPrice = isUrgent ? trPrice + Number(_self.data.urgent) - Number(_self.data.selectCoupons.coupon.amount) : trPrice - Number(_self.data.selectCoupons.coupon.amount);
} else {
newPrice = isUrgent ? trPrice + Number(_self.data.urgent) : trPrice;
}
} else {
// 写材料情况
newPrice = hasCoupon ? trPrice - Number(_self.data.selectCoupons.coupon.amount) : trPrice;
}
}
_self.setData({
price: newPrice < 0 ? 0 : newPrice
});
},
//开发完成时间
bindDateChange(e) {
console.log(e)
this.setData({
completeDate: e.detail.value
})
},
toggleContact() {
this.setData({
isShowContact: !this.data.isShowContact
})
},
//系统语言
toggleOptions() {
this.setData({
showLang: !this.data.showLang
});
},
selectOption(e) {
const selectedValue = e.currentTarget.dataset.value;
this.setData({
currentLanguage: selectedValue,
isShowLanguage: false
});
},
inputContactName(e) {
this.setData({
contactName: e.detail.value
})
},
inputContactPhone(e) {
console.log(e)
this.setData({
contactPhone: e.detail.value
})
},
inputContactCompany(e) {
this.setData({
contactCompany: e.detail.value
})
},
inputContactEmail(e) {
this.setData({
contactEmail: e.detail.value
})
},
//选中优惠卷
selectCoupons(e) {
this.setData({
tempCoupons: e.currentTarget.dataset.value
})
},
//点击语言
changeLang(e) {
console.log(e)
this.setData({
tempLang: e.detail.value
})
},
//确定选择语言
confirmSelectLang() {
const _self = this
_self.setData({
showLang: false
})
if (_self.data.tempLang != '') {
_self.setData({
selectLang: _self.data.tempLang,
tempLang: '',
})
}
},
//确定使用选中的优惠卷
confirmSelCoupons() {
const _self = this
_self.setData({
selectCoupons: _self.data.tempCoupons,
showCoupons: false,
tempCoupons: {},
canSelPackage: false,
selectPackage: {},
tempPackage: {}
})
_self.countPrice()
},
//监听项目名称
inputProjectName(e) {
this.setData({
projectName: e.detail.value
})
},
//选中联系人
doChangeContact(e) {
console.log(e)
this.setData({
selectContact: this.data.contactList[e.detail.value]
})
},
//获取可选语言
doGetProLangList() {
const _self = this
ProjectService.doGetProLangList()
.then(res => {
console.log(res)
_self.setData({
langList: res,
selectLang: res[0]
})
}, err => {
console.log(err)
})
},
//获取产权联系人
doGetContactList() {
wx.showLoading({
title: '加载中...',
})
const _self = this
ProjectService.doGetContactList()
.then(res => {
wx.hideLoading()
console.log(res)
_self.setData({
contactList: res,
selectContact: res[0]
})
}, err => {
wx.hideLoading()
})
},
//获取套餐包
doGetPackage() {
const _self = this
const data = {
page: 1,
rows: 100,
packageType: _self.data.type,
keyong: 1,
}
ProjectService.doGetPackageList(data)
.then(res => {
console.log('套餐包')
console.log(res)
_self.setData({
packageList: res.rows
})
if (_self.data.transmitPId != '' && _self.data.transmitPId != 'undefined') {
res.rows.map(item => {
if (item.packageInfoId == _self.data.transmitPId) {
_self.setData({
selectPackage: item,
showPackage: false,
tempPackage: {},
canSelCoupons: false,
selectCoupons: {},
tempCoupons: {},
isUrgent: false, //取消加急
isUrgentDisable: true, //加急不能选择
price: 0
})
}
})
}
}, err => {
console.log(err)
_self.setData({
packageList: []
})
})
},
//获取优惠卷
doGetCoupons() {
const _self = this
const data = {
page: 1,
rows: 100,
isEffective: 1,
isUsed: 0
}
ProjectService.doGetCouponseList(data)
.then(res => {
console.log('优惠卷')
console.log(res)
_self.setData({
couponsList: res.rows
})
}, err => {
console.log(err)
_self.setData({
couponsList: []
})
})
},
//显示优惠卷
doShowCoupons() {
if (this.data.couponsList.length <= 0) {
this.setData({
showError: true,
errorHint: '您没有可以使用的优惠卷'
})
} else {
this.setData({
tempCoupons: this.data.selectCoupons,
showCoupons: !this.data.showCoupons
})
}
},
//显示套餐包
doShowPackage() {
const _self = this
if (_self.data.packageList.length > 0) {
_self.setData({
tempPackage: _self.data.selectPackage,
showPackage: true
})
} else {
_self.setData({
errorHint: '您暂时没有可以使用的套餐包',
showError: true
})
}
},
//确定套餐包
confirmSelectPackage() {
this.setData({
selectPackage: this.data.tempPackage,
showPackage: false,
tempPackage: {},
canSelCoupons: false,
selectCoupons: {},
tempCoupons: {},
isUrgent: false, //取消加急
isUrgentDisable: true, //加急不能选择
})
this.countPrice()
},
//取消选中的套餐包或优惠卷
clearSelectPackageOrCoupons() {
this.setData({
selectCoupons: {},
selectPackage: {},
tempCoupons: {},
tempPackage: {},
canSelCoupons: true,
canSelPackage: true,
isUrgent: false, //取消加急
isUrgentDisable: false, //加急可以选择
})
this.countPrice()
},
//点击选择套餐包
selectPackage(e) {
console.log(e)
this.setData({
tempPackage: e.currentTarget.dataset.value
})
},
//获取客服NO
doGetCsaNo(isShow) {
const _self = this
UserService.doGetCsaNo()
.then(res => {
console.log(res)
_self.setData({
csaNo: res.csaNo
})
if (isShow) {
_self.setData({
isShowContact: true
})
}
}, err => {
console.log(err)
})
},
//推荐项目名称
doCommendProjectName() {
const _self = this
_self.setData({
showCommendProject: true
})
},
//生成项目全称列表
doCreateFullName() {
const _self = this
wx.showLoading({
title: '生成中...',
})
const data = {
prompt: _self.data.projectName
}
ProjectService.doGetCommendProjectName(data)
.then(res => {
wx.hideLoading()
console.log(res)
if (res && res.length > 0) {
_self.setData({
projectNameList: res
})
} else {
_self.setData({
showError: true,
errorHint: '未查询到相关推荐的系统名称,请重新输入'
})
}
}, err => {
wx.hideLoading()
_self.setData({
showError: true,
errorHint: '未查询到相关推荐的系统名称,请重新输入'
})
console.log(err)
})
},
//监听项目名称输入
inputCommendProjectName(e) {
const _self = this
_self.setData({
projectName: e.detail.value
})
},
//选择推荐的项目名称
doSelectProjectName(e) {
const _self = this
console.log(e)
_self.setData({
projectName: e.currentTarget.dataset.value,
showCommendProject: false,
projectNameList: []
})
},
//显示创建联系人
doCreateContact() {
const _self = this
if (_self.data.csaNo == '') {
_self.doGetCsaNo(true)
} else {
_self.setData({
isShowContact: true
})
}
},
clearTime() {
this.setData({
completeDate: ''
})
},
//保存联系人
doSaveContact() {
//校验参数
const _self = this
if (_self.data.contactName == '') {
_self.setData({
showError: true,
errorHint: '请输入联系人姓名'
})
return
}
if (_self.data.contactPhone == '' || !isValidPhone(_self.data.contactPhone)) {
_self.setData({
showError: true,
errorHint: '请输入正确的联系电话'
})
return
}
if (_self.data.contactEmail != '') {
if (!isValidEmail(_self.data.contactEmail)) {
_self.setData({
showError: true,
errorHint: '请输入正确的邮箱'
})
return
}
}
const data = {
company: _self.data.contactCompany,
csaNo: _self.data.csaNo,
name: _self.data.contactName,
phone: _self.data.contactPhone,
email: _self.data.email
}
wx.showLoading({
title: '创建中...',
})
UserService.doCreateContact(data)
.then(res => {
_self.setData({
showSuccess: true,
successHint: '新建成功',
isShowContact: false,
contactEmail: '',
contactPhone: '',
contactName: '',
contactCompany: '',
})
//获取一遍联系人
_self.doGetContactList()
})
.catch(err => {
_self.setData({
showError: true,
errorHint: err.msg ? err.msg : '新建失败,请稍后重试',
isShowContact: false
})
})
.finally(() => {
console.log('finally')
wx.hideLoading()
})
},
//创建项目
doCreateProject() {
//校验参数
const _self = this
const isLegal = _self.doCheckProjectParams()
if (isLegal) {
wx.showLoading({
title: '创建中...',
})
//构建参数
var list = []
if (_self.data.isUrgent != '' && _self.data.isUrgent) {
list = ['URGENT']
}
const data = {
applyContactCsaNo: _self.data.selectContact.csaNo, // 联系人客服编号
applyContactId: _self.data.selectContact.projContactId, //联系人ID
applyContactName: _self.data.selectContact.name, //联系人姓名
applyContactPhone: _self.data.selectContact.phone, //联系人手机
projDevCompleteDate: _self.data.completeDate, //开发完成日期
projName: _self.data.projectName, //项目简称
projVersion: _self.data.version, //项目版本
backendCodeLang: _self.data.selectLang,
projChargeType: _self.data.type, //项目收费类型 ALL,FREE,MATERIAL,MATERIAL_AGENT,MATERIAL_AGENT_URGENT
listProjChargeAdditional: list,
packageOrderId: _self.data.selectPackage.packageOrderId ? _self.data.selectPackage.packageOrderId : '', //套餐包ID
couponId: _self.data.selectCoupons.couponId ? _self.data.selectCoupons.couponId : '', //优惠卷ID
}
ProjectService.doCreateProject(data)
.then(res => {
console.log(res)
wx.hideLoading()
_self.setData({
showSuccess: true,
successHint: '项目创建流程圆满完成,系统正在生成配套材料,请您耐心等候。'
})
setTimeout(() => {
wx.navigateBack()
}, 1500);
}, err => {
wx.hideLoading()
console.log(err)
_self.setData({
errorHint: err.msg ? err.msg : '网络错误,请稍后重试',
showError: true
})
})
}
},
//校验参数
doCheckProjectParams() {
const _self = this
if (_self.data.projectName == '') {
_self.setData({
showError: true,
errorHint: '请输入项目名称'
})
return false
}
if (Object.keys(_self.data.selectContact).length <= 0) {
_self.setData({
showError: true,
errorHint: '请选择产权联系人'
})
return false
}
return true
},
closeDialog(e) {
this.setData({
showLang: false,
showPackage: false,
showCoupons: false,
showCommendProject: false,
isShowContact: false
})
}
})