addCustomer.vue 9.5 KB

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