addCustomer.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="addCustomer-content">
  3. <view class="content-form">
  4. <u-form :model="form" ref="uForm" label-width="180" :error-type="['toast']">
  5. <u-form-item label="客户名称" required ><u-input v-model.trim="form.customerName" placeholder="请输入客户名称(最多30个字符)" input-align="right" :maxlength="60"/></u-form-item>
  6. <u-form-item label="客户地址" required >
  7. <u-input v-model="areaInfo.label" :disabled="true" input-align="right" placeholder="请选择客户地址" @click="openAddress"/>
  8. <u-icon name="arrow-right" color="#C0C4CC" slot="right" @click="openAddress"></u-icon>
  9. </u-form-item>
  10. <u-form-item label="详细地址">
  11. <textarea :auto-height="true" input-align="right" placeholder="请输入详细地址(最多60个字符)" :maxlength="60" v-model="form.customerAddr" class="receiveAddress" placeholder-style="color:#C0C4CC;font-size:28upx;"/>
  12. </u-form-item>
  13. <u-form-item label="联系人">
  14. <u-input v-model="form.contactName" input-align="right" placeholder="请输入联系人(最多30个字符)" :maxlength="11"/>
  15. </u-form-item>
  16. <u-form-item label="联系电话">
  17. <u-input v-model.trim="form.contactTel" placeholder="请输入联系电话(最多15个字符)" input-align="right" :maxlength="15"/>
  18. </u-form-item>
  19. <u-form-item label="联系手机"><u-input v-model.trim="form.contactMobile" placeholder="请输入联系手机(最多11位字符)" input-align="right" :maxlength="11"/>
  20. </u-form-item>
  21. <u-form-item label="价格类型" required >
  22. <v-select ref="priceType" :disabled="true" placeholder="请选择价格类型" @itemChange="chooseType" code="PRICE_TYPE" style="width: 100%"></v-select>
  23. </u-form-item>
  24. <u-form-item label="收款方式" required prop="settleStyleSn">
  25. <u-input v-model="settleStyleName" input-align="right" :disabled="true" placeholder="请选择收款方式" @click="showSettle=true"/>
  26. <u-icon name="arrow-right" color="#C0C4CC" slot="right"></u-icon>
  27. </u-form-item>
  28. <u-form-item label="客户传真">
  29. <u-input v-model="form.fax" input-align="right" placeholder="请输入客户传真(最多30个字符)" :maxlength="30"/>
  30. </u-form-item>
  31. <u-form-item label="客户类型">
  32. <u-input v-model="custTypeName" input-align="right" :disabled="true" placeholder="请选择客户类型" @click="showCust=true"/>
  33. <u-icon name="arrow-right" color="#C0C4CC" slot="right" @click="showCust=true"></u-icon>
  34. </u-form-item>
  35. <u-form-item label="配送方式" >
  36. <v-select ref="dispatchType" :disabled="true" placeholder="请选择配送方式" @itemChange="choosedispatchType" code="DISPATCH_TYPE" style="width: 100%"></v-select>
  37. </u-form-item>
  38. </u-form>
  39. </view>
  40. <view class="form-footer-btn">
  41. <u-button class="handle-btn" size="medium" shape="circle" hover-class="none" @click="customerSubmit" :custom-style="customBtnStyle">保存</u-button>
  42. </view>
  43. <!-- 省市区 -->
  44. <Address ref="applyAddress" @onConfirm="areaConfirm"></Address>
  45. <!-- 选择收款方式 -->
  46. <u-picker v-model="showSettle" title="收款方式" @confirm="settleStyleChange" :range="settleTypeList" range-key="name" mode="selector" :default-selector="JSON.parse(JSON.stringify(defaultSettleIndex))"></u-picker>
  47. <!-- 客户类型 -->
  48. <u-picker v-model="showCust" title="客户类型" @confirm="custTypeChange" :range="custTypeList" range-key="name" mode="selector" :default-selector="JSON.parse(JSON.stringify(defaultCustIndex))"></u-picker>
  49. </view>
  50. </template>
  51. <script>
  52. import {settleStyleQueryAll} from '@/api/sales.js'
  53. import {customerDetail,custType,custSave,employeeAllList} from '@/api/customer.js'
  54. import Address from '@/components/address.vue'
  55. import vSelect from '@/components/select/v-select.vue'
  56. import { isvalidPhone } from '@/libs/validate.js'
  57. export default{
  58. components:{Address,vSelect},
  59. data(){
  60. return{
  61. customerData:null, // 客户信息
  62. customBtnStyle: { // 自定义按钮样式
  63. margin:0
  64. },
  65. // 客户form
  66. form:{
  67. id: null,
  68. customerName: '', // 客户名称
  69. contactTel: '', // 联系电话
  70. contactMobile: '', // 联系手机
  71. contactName: '', // 联系人
  72. provinceSn: undefined, // 省
  73. provinceName: '',
  74. citySn: undefined, // 市
  75. cityName: '',
  76. countySn: undefined, // 区
  77. countyName: '',
  78. customerAddr: '', // 详细地址
  79. fax: '', // 客户传真
  80. dispatchType: undefined, // 配送方式
  81. satelliteFlag: 0, // 是否卫星仓客户
  82. customerTypeSn: undefined, // 客户类型
  83. priceType: '', // 价格类型
  84. settleStyleSn: undefined // 收款方式
  85. },
  86. showSettle:false,//结算方式初始值
  87. settleTypeList:[],//收款方式列表
  88. settleStyleName:'',//收款方式名称
  89. custTypeList:[] ,// 客户类型数据
  90. showCust:false, //客户类型下拉弹窗初始值
  91. custTypeName:'', // 客户类型名称
  92. areaInfo: {}, // 省市区
  93. areaIdArr: [], // 省市区id数组
  94. defaultSettleIndex:[0] ,//选中收款方式的下标
  95. defaultCustIndex:[0],//选中客户类型的下标
  96. }
  97. },
  98. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  99. onReady() {
  100. this.$refs.uForm.setRules(this.rules);
  101. },
  102. onLoad(option) {
  103. this.getSettleStyle()
  104. this.getCustomerList()
  105. },
  106. methods:{
  107. // 选择价格类型
  108. chooseType(val){
  109. console.log(val,'vai')
  110. this.form.priceType=val
  111. },
  112. // 选择配送方式
  113. choosedispatchType(val){
  114. this.form.dispatchType=val
  115. },
  116. // 选择省区市
  117. areaConfirm(e) {
  118. console.log('已选择的省市区', e)
  119. this.areaInfo = e
  120. this.areaIdArr = [ e.provinceCode, e.cityCode, e.areaCode ]
  121. this.form.provinceSn=e.provinceCode
  122. this.form.citySn=e.cityCode
  123. this.form.countySn=e.areaCode
  124. this.form.provinceName=e.labelArr[0]
  125. this.form.cityName=e.labelArr[1]
  126. this.form.countyName=e.labelArr[2]
  127. },
  128. openAddress(){
  129. // 省市区 回显 参数为省市区id数组
  130. // console.log(this.areaIdArr,'this.areaIdArr')
  131. this.$refs.applyAddress.open(this.areaIdArr)
  132. },
  133. brandClean(){
  134. this.settleStyleName=''
  135. this.form.settleStyleSn=undefined
  136. },
  137. // 获取客户类型列表
  138. getCustomerList(){
  139. custType({}).then(res=>{
  140. if(res.status==200){
  141. this.custTypeList=res.data
  142. }else{
  143. this.custTypeList=[]
  144. }
  145. })
  146. },
  147. // 获取结算方式列表
  148. getSettleStyle(){
  149. settleStyleQueryAll({}).then(res=>{
  150. if(res.status==200){
  151. this.settleTypeList=res.data
  152. }else{
  153. this.settleTypeList=null
  154. }
  155. })
  156. },
  157. // 收款方式change
  158. settleStyleChange(e){
  159. console.log(e,'data')
  160. this.defaultSettleIndex=[e]
  161. this.settleStyleName=this.settleTypeList[e].name
  162. this.form.settleStyleSn=this.settleTypeList[e].settleStyleSn
  163. },
  164. // 客户类型change
  165. custTypeChange(e){
  166. this.defaultCustIndex=[e]
  167. this.custTypeName=this.custTypeList[e].name
  168. this.form.customerTypeSn=this.custTypeList[e].customerTypeSn
  169. },
  170. // 保存 (新增客户)
  171. customerSubmit(){
  172. console.log('保存===========')
  173. this.$refs.uForm.validate(valid => {
  174. if (valid) {
  175. console.log('验证通过');
  176. if (this.form.customerName ==='') {
  177. uni.showToast({
  178. title: '请输入客户名称',
  179. icon: 'none'
  180. })
  181. return false
  182. }
  183. if(this.form.contactMobile){
  184. if (!isvalidPhone(this.form.contactMobile)) {
  185. uni.showToast({
  186. title: '请输入正确的联系手机',
  187. icon: 'none'
  188. })
  189. return false
  190. }
  191. }
  192. // 省市区
  193. if(this.areaIdArr.length == 0){
  194. uni.showToast({icon: 'none',title: '请选择省市区'})
  195. return
  196. }
  197. if (this.form.priceType ==undefined) {
  198. uni.showToast({
  199. title: '请选择价格类型',
  200. icon: 'none'
  201. })
  202. return false
  203. }
  204. if (this.form.settleStyleSn ==undefined) {
  205. uni.showToast({
  206. title: '请选择收款方式',
  207. icon: 'none'
  208. })
  209. return false
  210. }
  211. const params=Object.assign({},this.form,this.areaIdArr)
  212. console.log(params,'params')
  213. if(this.form.id) {
  214. params.id = this.form.id
  215. }
  216. custSave(params).then(res=>{
  217. if(res.status == 200) {
  218. uni.showToast({
  219. title: res.message,
  220. icon: 'none'
  221. })
  222. setTimeout(()=>{
  223. uni.redirectTo({
  224. url:'/pages/sales/addSales?pageType=add&nowId='+res.data.id
  225. })
  226. },300)
  227. }
  228. })
  229. } else {
  230. console.log('验证失败');
  231. }
  232. })
  233. },
  234. }
  235. }
  236. </script>
  237. <style lang="scss">
  238. .addCustomer-content{
  239. width: 100%;
  240. height: 100vh;
  241. background-color: #fff;
  242. padding:0 40upx;
  243. display: flex;
  244. flex-direction: column;
  245. .content-customerName{
  246. // padding: 10upx;
  247. // border-radius: 10upx;
  248. // border: 1upx solid #e5e5e5;
  249. }
  250. .content-form{
  251. flex: 1;
  252. // box-shadow:0 8upx 24upx rgba(0,0,0,.1);
  253. // border: 1upx solid #e5e5e5;
  254. .receiveAddress{
  255. width: 100%;
  256. line-height: 1.5em;
  257. box-sizing: border-box;
  258. font-style: normal;
  259. text-align: end;
  260. }
  261. }
  262. .content-form:not(:last-child){
  263. border-bottom: none;
  264. }
  265. .form-footer-btn{
  266. background-color: #fff;
  267. position: fixed;
  268. bottom: 0;
  269. left: 0;
  270. width: 100%;
  271. padding: 16upx 20upx 12upx;
  272. z-index: 999;
  273. .handle-btn{
  274. width: 100%;
  275. background-color: rgb(51, 95, 182);
  276. color: #fff;
  277. }
  278. }
  279. }
  280. </style>