addSales.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <view class="addCustomer-content">
  3. <view class="content-customerName">
  4. <view class="flex justify_between align_center customerName">
  5. <text>{{customerData?customerData.customerName:''}}</text>
  6. <u-button size="mini" :hair-line="false" plain type="primary" hover-class="none" @click="goBack" :custom-style="customBtnStyle">重新选择</u-button>
  7. </view>
  8. </view>
  9. <view class="content-box">
  10. <view class="content-form">
  11. <u-form :model="form" ref="uForm" label-width="180" :error-type="['toast']">
  12. <u-form-item label="客户地址" required >
  13. <u-input v-model="areaInfo.label" type="select" input-align="right" placeholder="请选择客户地址" @click="openAddress"/>
  14. </u-form-item>
  15. <u-form-item label="详细地址">
  16. <textarea :auto-height="true" input-align="right" placeholder="请输入详细地址(最多60个字符)" :maxlength="60" v-model="form.shippingAddress" class="receiveAddress" placeholder-style="color:#C0C4CC;font-size:28upx;"/>
  17. </u-form-item>
  18. <u-form-item label="联系人">
  19. <u-input v-model="form.consigneeName" input-align="right" placeholder="请输入联系人(最多30个字符)" :maxlength="11"/>
  20. </u-form-item>
  21. <u-form-item label="联系电话">
  22. <u-input v-model.trim="form.consigneeTel" placeholder="请输入联系电话(最多15个字符)" input-align="right" :maxlength="15"/>
  23. </u-form-item>
  24. <u-form-item label="联系手机"><u-input v-model.trim="form.contactMobile" placeholder="请输入联系手机(最多11位字符)" input-align="right" :maxlength="11"/>
  25. </u-form-item>
  26. <u-form-item label="价格类型" required >
  27. <v-select ref="priceType" input-align="right" placeholder="请选择价格类型" @itemChange="chooseType" code="PRICE_TYPE" style="width: 100%"></v-select>
  28. </u-form-item>
  29. <u-form-item label="收款方式" required prop="settleStyleSn">
  30. <u-input v-model="settleStyleName" input-align="right" type="select" placeholder="请选择收款方式" @click="showSettle=true"/>
  31. </u-form-item>
  32. <u-form-item label="铺货出库" required v-if="itemId">
  33. <view style="width: 100%;display:flex;justify-content: flex-end;">
  34. <u-radio-group v-model="form.distributionFlag" @change="radioChange" >
  35. <u-radio
  36. v-for="(item, index) in ckList" :key="index"
  37. :name="item.code"
  38. >
  39. {{item.dispName}}
  40. </u-radio>
  41. </u-radio-group>
  42. </view>
  43. </u-form-item>
  44. <u-form-item label="配送方式" >
  45. <v-select ref="dispatchType" input-align="right" placeholder="请选择配送方式" @itemChange="choosedispatchType" code="DISPATCH_TYPE" style="width: 100%"></v-select>
  46. </u-form-item>
  47. <u-form-item label="业务员">
  48. <u-input v-model="userName" input-align="right" type="select" placeholder="请选择业务员" @click="showUser=true"/>
  49. </u-form-item>
  50. <u-form-item label="备注">
  51. <textarea :auto-height="true" input-align="right" placeholder="请输入备注(最多100个字符)" :maxlength="100" v-model="form.remarks" class="receiveAddress" placeholder-style="color:#C0C4CC;font-size:28upx;"/>
  52. </u-form-item>
  53. </u-form>
  54. </view>
  55. </view>
  56. <view class="form-footer-btn">
  57. <u-button class="handle-btn" size="medium" shape="circle" hover-class="none" @click="handleSaveCust" :custom-style="customBtnStyle">新增销售单</u-button>
  58. </view>
  59. <!-- 省市区 -->
  60. <Address ref="applyAddress" :isJrMini="false" @onConfirm="areaConfirm"></Address>
  61. <!-- 选择收款方式 -->
  62. <u-picker v-model="showSettle" title="收款方式" @confirm="settleStyleChange" :range="settleTypeList" range-key="name" mode="selector" :default-selector="JSON.parse(JSON.stringify(defaultSettleIndex))"></u-picker>
  63. <!-- 业务员 -->
  64. <u-picker v-model="showUser" title="业务员" @confirm="userChange" :range="userList" range-key="name" mode="selector"></u-picker>
  65. </view>
  66. </template>
  67. <script>
  68. import {settleStyleQueryAll,salesSave} from '@/api/sales.js'
  69. import {customerDetail,employeeAllList,updateByCustomerSn} from '@/api/customer.js'
  70. import Address from '@/components/address.vue'
  71. import vSelect from '@/components/select/v-select.vue'
  72. export default{
  73. components:{Address,vSelect},
  74. data(){
  75. return{
  76. title:'',
  77. customerData:null, // 客户信息
  78. priceTypeName:'', //客户类型名称
  79. customBtnStyle: { // 自定义按钮样式
  80. margin:0
  81. },
  82. showDispatch:false,// 配送方式下拉弹窗初始值
  83. showSettle:false,//结算方式初始值
  84. settleTypeList:[],//收款方式列表
  85. settleStyleName:'',//收款方式名称
  86. areaInfo: {}, // 省市区
  87. areaIdArr: [], // 省市区id数组
  88. itemId:'',
  89. ckList:[{dispName: "是",code:1,lookupCode: "FLAG"},{dispName: "否",code:0,lookupCode: "FLAG"}],
  90. showUser:false,//业务员下拉框初始默认值
  91. userList:[], //业务员数据
  92. userName:'', //业务员姓名
  93. salesManSn:'', //业务员sn
  94. defaultSettleIndex:[0] ,//选中收款方式的下标
  95. defaultIndex:[0] ,//选中收款方式的下标
  96. defaultCustIndex:[0],//选中客户类型的下标
  97. defaultUserIndex:[0],//选中业务员的下标
  98. //销售单form
  99. form:{
  100. buyerName: '', // 客户名称
  101. buyerSn: undefined, // 客户sn
  102. consigneeTel: '', // 联系电话
  103. contactMobile: '',
  104. consigneeName: '', // 联系人
  105. shippingAddressProvinceSn: undefined, // 省
  106. shippingAddressProvinceName: '',
  107. shippingAddressCitySn: undefined, // 市
  108. shippingAddressCityName: '',
  109. shippingAddressCountySn: undefined, // 区
  110. shippingAddressCountyName: '',
  111. shippingAddress: '', // 详细地址
  112. fax: '', // 客户传真
  113. dispatchType: undefined, // 配送方式
  114. satelliteFlag: 0, // 是否卫星仓客户
  115. priceType: undefined, // 价格类型
  116. settleStyleSn: undefined, // 收款方式
  117. salesManSn: undefined, // 业务员
  118. salesManName: '',
  119. distributionFlag: '0', // 铺货出库
  120. salesTragetType: 'CUSTOMER',
  121. remarks: '' ,// 备注
  122. addrProvinceList:[],
  123. addrDistrictList:[],
  124. addrCityList:[]
  125. }
  126. }
  127. },
  128. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  129. onReady() {
  130. this.$refs.uForm.setRules(this.rules);
  131. },
  132. onLoad(option) {
  133. console.log(option.nowId,'option')
  134. this.itemId=option.nowId
  135. this.pageInit()
  136. },
  137. methods:{
  138. async pageInit(){
  139. const a = await employeeAllList({}) // 获取业务员列表数据
  140. const b = await settleStyleQueryAll({}) // 获取结算方式列表
  141. this.userList = a.status == 200 ? a.data : []
  142. this.settleTypeList = b.status == 200 ? b.data : []
  143. if(this.itemId){
  144. this.getCustomerData(this.itemId)
  145. }
  146. },
  147. getCustomerData(val){
  148. uni.showLoading({title:'加载中...',mask:true})
  149. customerDetail({id:val}).then(res=>{
  150. if(res.status==200){
  151. uni.hideLoading({})
  152. this.customerData=res.data
  153. this.areaIdArr=[this.customerData.provinceSn,this.customerData.citySn,this.customerData.countySn]
  154. this.areaInfo={label:this.customerData.provinceName+'-'+this.customerData.cityName+'-'+this.customerData.countyName}
  155. // this.setFun(res.data)
  156. this.form = Object.assign(this.form, {
  157. buyerName: this.customerData.customerName, // 客户名称
  158. buyerSn: this.customerData.customerSn, // 客户sn
  159. consigneeTel: this.customerData.contactTel, // 联系电话
  160. contactMobile: this.customerData.contactMobile,
  161. consigneeName: this.customerData.contactName, // 联系人
  162. shippingAddressProvinceSn: this.customerData.provinceSn, // 省
  163. shippingAddressProvinceName: this.customerData.provinceName,
  164. shippingAddressCitySn: this.customerData.citySn, // 市
  165. shippingAddressCityName: this.customerData.cityName,
  166. shippingAddressCountySn: this.customerData.countySn, // 区
  167. shippingAddressCountyName: this.customerData.countyName,
  168. shippingAddress: this.customerData.customerAddr, // 详细地址
  169. fax: this.customerData.fax, // 客户传真
  170. dispatchType: this.customerData.dispatchType, // 配送方式
  171. satelliteFlag: this.customerData.satelliteFlag, // 是否卫星仓客户
  172. priceType: this.customerData.priceType, // 价格类型
  173. settleStyleSn: this.customerData.settleStyleSn // 收款方式
  174. })
  175. if(this.customerData.priceType){
  176. setTimeout(()=>{
  177. this.$refs.priceType.setVal(this.customerData.priceType)
  178. },200)
  179. }
  180. if(this.customerData.dispatchType){
  181. setTimeout(()=>{
  182. this.$refs.dispatchType.setVal(this.customerData.dispatchType)
  183. },200)
  184. }
  185. this.form=Object.assign(this.form,res.data)
  186. // 回显收款方式并下拉数据默认高亮选中
  187. const ind=this.settleTypeList.findIndex((item)=>{
  188. return item.settleStyleSn==this.customerData.settleStyleSn
  189. })
  190. if(ind){
  191. this.settleStyleName=this.settleTypeList[ind].name
  192. this.defaultSettleIndex=[ind]
  193. }
  194. // 回显业务员并下拉数据默认高亮选中
  195. if(this.customerData.salesManSn){
  196. const userInd=this.userList.findIndex((item)=>{
  197. return item.customerSn==this.customerData.salesManSn
  198. })
  199. this.defaultUserIndex=[userInd]
  200. this.form.salesManName=this.userList[userInd].name
  201. this.form.salesManSn=this.userList[userInd].salesManSn
  202. }
  203. }else{
  204. this.customerData=null
  205. }
  206. })
  207. },
  208. // 客户信息信息更改后先保存
  209. handleSaveCust () {
  210. const params = {
  211. customerName: this.form.buyerName,
  212. customerSn: this.form.buyerSn,
  213. contactTel: this.form.consigneeTel, // 联系电话
  214. contactMobile: this.form.contactMobile,
  215. contactName: this.form.consigneeName, // 联系人
  216. provinceSn: this.form.shippingAddressProvinceSn, // 省
  217. provinceName: this.form.shippingAddressProvinceName,
  218. citySn: this.form.shippingAddressCitySn, // 市
  219. cityName: this.form.shippingAddressCityName,
  220. countySn: this.form.shippingAddressCountySn, // 区
  221. countyName: this.form.shippingAddressCountyName,
  222. customerAddr: this.form.shippingAddress, // 详细地址
  223. dispatchType: this.form.dispatchType, // 配送方式
  224. priceType: this.form.priceType, // 价格类型
  225. settleStyleSn: this.form.settleStyleSn // 收款方式
  226. }
  227. updateByCustomerSn(params).then(res => {
  228. if (res.status == 200) {
  229. // 保存销售单
  230. this.salesSbmit()
  231. }
  232. })
  233. },
  234. // 重新选择
  235. goBack(){
  236. uni.redirectTo({
  237. url: '/pages/sales/chooseCustomer?backPage=addSales'
  238. })
  239. },
  240. radioChange(e) {
  241. console.log(e);
  242. this.form.distributionFlag=e
  243. },
  244. // 选择价格类型
  245. chooseType(val){
  246. console.log(val,'vai')
  247. this.form.priceType=val
  248. },
  249. // 选择配送方式
  250. choosedispatchType(val){
  251. this.form.dispatchType=val
  252. },
  253. // 选择省区市
  254. areaConfirm(e) {
  255. console.log('已选择的省市区', e)
  256. this.areaInfo = e
  257. this.areaIdArr = [ e.provinceCode, e.cityCode, e.areaCode ]
  258. this.form.shippingAddressProvinceSn=e.provinceCode
  259. this.form.shippingAddressCitySn=e.cityCode
  260. this.form.shippingAddressCountySn=e.areaCode
  261. this.form.shippingAddressProvinceName=e.labelArr[0]
  262. this.form.shippingAddressCityName=e.labelArr[1]
  263. this.form.shippingAddressCountyName=e.labelArr[2]
  264. },
  265. openAddress(){
  266. // 省市区 回显 参数为省市区id数组
  267. // console.log(this.areaIdArr,'this.areaIdArr')
  268. this.$refs.applyAddress.open(this.areaIdArr)
  269. },
  270. // 收款方式change
  271. settleStyleChange(e){
  272. this.defaultSettleIndex=[e]
  273. this.settleStyleName=this.settleTypeList[e].name
  274. this.form.settleStyleSn=this.settleTypeList[e].settleStyleSn
  275. },
  276. // 业务员change
  277. userChange(e){
  278. this.defaultUserIndex=[e]
  279. this.form.salesManName=this.userList[e].name
  280. this.form.salesManSn=this.userList[e].salesManSn
  281. },
  282. // 保存 (新增销售单)
  283. salesSbmit(){
  284. console.log('保存===========')
  285. this.$refs.uForm.validate(valid => {
  286. if (valid) {
  287. console.log('验证通过');
  288. if (this.form.customerName ==='') {
  289. uni.showToast({
  290. title: '请输入客户名称',
  291. icon: 'none'
  292. })
  293. return false
  294. }
  295. // 省市区
  296. if(this.areaIdArr.length == 0){
  297. uni.showToast({icon: 'none',title: '请选择省市区'})
  298. return
  299. }
  300. if (this.form.priceType ==undefined) {
  301. uni.showToast({
  302. title: '请选择价格类型',
  303. icon: 'none'
  304. })
  305. return false
  306. }
  307. if (this.form.settleStyleSn ==undefined) {
  308. uni.showToast({
  309. title: '请选择收款方式',
  310. icon: 'none'
  311. })
  312. return false
  313. }
  314. const params={
  315. buyerName:this.customerData.customerName , // 客户名称
  316. buyerSn: this.customerData.customerSn, // 客户sn
  317. consigneeTel: this.form.consigneeTel?this.form.consigneeTel: this.customerData.contactTel, // 联系电话
  318. contactMobile:this.form.contactMobile?this.form.contactMobile: this.customerData.contactMobile, // 联系手机
  319. consigneeName:this.form.consigneeName?this.form.consigneeName: this.customerData.contactName, // 联系人
  320. shippingAddressProvinceSn:this.form.shippingAddressProvinceSn?this.form.shippingAddressProvinceSn: this.customerData.provinceSn, // 省
  321. shippingAddressProvinceName:this.form.shippingAddressProvinceName?this.form.shippingAddressProvinceName: this.customerData.customerName,
  322. shippingAddressCitySn:this.form.shippingAddressCitySn?this.form.shippingAddressCitySn: this.customerData.citySn, // 市
  323. shippingAddressCityName:this.form.shippingAddressCityName?this.form.shippingAddressCityName: this.customerData.cityName,
  324. shippingAddressCountySn:this.form.shippingAddressCountySn?this.form.shippingAddressCountySn: this.customerData.countySn, // 区
  325. shippingAddressCountyName:this.form.shippingAddressCountyName?this.form.shippingAddressCountyName: this.customerData.countyName,
  326. shippingAddress:this.form.customerAddr?this.form.customerAddr: this.customerData.customerAddr, // 详细地址
  327. fax:this.form.fax?this.form.fax: this.customerData.fax, // 客户传真
  328. dispatchType:this.form.dispatchType?this.form.dispatchType: this.customerData.dispatchType, // 配送方式
  329. satelliteFlag: 0, // 是否卫星仓客户
  330. priceType:this.form.priceType?this.form.priceType: this.customerData.priceType, // 价格类型
  331. settleStyleSn:this.form.settleStyleSn?this.form.settleStyleSn: this.customerData.settleStyleSn, // 收款方式
  332. salesManSn:this.form.salesManSn ||undefined, // 业务员
  333. salesManName: '',
  334. distributionFlag: this.form.distributionFlag, // 铺货出库
  335. salesTragetType: 'CUSTOMER',
  336. remarks: this.form.remarks // 备注
  337. }
  338. console.log(params,'params')
  339. salesSave(params).then(res=>{
  340. if(res.status == 200) {
  341. uni.showToast({
  342. title: res.message,
  343. icon: 'none'
  344. })
  345. uni.$emit("refreshSalesHomeBL")
  346. setTimeout(()=>{
  347. uni.redirectTo({
  348. url:'/pages/sales/edit?pageType=edit&data='+JSON.stringify(res.data)
  349. })
  350. },300)
  351. }
  352. })
  353. } else {
  354. console.log('验证失败');
  355. }
  356. })
  357. },
  358. }
  359. }
  360. </script>
  361. <style lang="scss">
  362. page{
  363. height: 100vh;
  364. }
  365. .addCustomer-content{
  366. width: 100%;
  367. height: 100vh;
  368. display: flex;
  369. flex-direction: column;
  370. .content-customerName{
  371. width: 100%;
  372. .customerName{
  373. width: 100%;
  374. color: #000000;
  375. font-size: 30upx;
  376. font-weight: 1000;
  377. background-color: #fff;
  378. padding:10upx 40upx 20upx;
  379. }
  380. }
  381. .content-box{
  382. padding:0 40upx;
  383. background-color: #fff;
  384. flex-grow: 1;
  385. overflow: auto;
  386. }
  387. .content-form{
  388. .receiveAddress{
  389. width: 100%;
  390. line-height: 1.5em;
  391. box-sizing: border-box;
  392. font-style: normal;
  393. text-align: end;
  394. }
  395. }
  396. .content-form:not(:last-child){
  397. border-bottom: none;
  398. }
  399. .form-footer-btn{
  400. background-color: #fff;
  401. width: 100%;
  402. padding:8px 30upx ;
  403. .handle-btn{
  404. width: 100%;
  405. background-color: rgb(51, 95, 182);
  406. color: #fff;
  407. }
  408. }
  409. }
  410. </style>