addCustomer.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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-icon name="arrow-right" color="#C0C4CC" slot="right"></u-icon>
  24. </u-form-item>
  25. <u-form-item label="收款方式" required prop="settleStyleSn">
  26. <u-input v-model="settleStyleName" input-align="right" :disabled="true" placeholder="请选择收款方式" @click="showSettle=true"/>
  27. <u-icon name="arrow-right" color="#C0C4CC" slot="right"></u-icon>
  28. </u-form-item>
  29. <u-form-item label="客户传真">
  30. <u-input v-model="form.fax" input-align="right" placeholder="请输入客户传真(最多30个字符)" :maxlength="30"/>
  31. </u-form-item>
  32. <u-form-item label="客户类型">
  33. <u-input v-model="custTypeName" input-align="right" :disabled="true" placeholder="请选择客户类型" @click="showCust=true"/>
  34. <u-icon name="arrow-right" color="#C0C4CC" slot="right" @click="showCust=true"></u-icon>
  35. </u-form-item>
  36. <u-form-item label="配送方式" >
  37. <v-select ref="dispatchType" :disabled="true" placeholder="请选择配送方式" @itemChange="choosedispatchType" code="DISPATCH_TYPE" style="width: 100%"></v-select>
  38. <u-icon name="arrow-right" color="#C0C4CC" slot="right"></u-icon>
  39. </u-form-item>
  40. </u-form>
  41. </view>
  42. <view class="form-footer-btn">
  43. <u-button class="handle-btn" size="medium" shape="circle" hover-class="none" @click="customerSubmit" :custom-style="customBtnStyle">保存</u-button>
  44. </view>
  45. <!-- 省市区 -->
  46. <Address ref="applyAddress" @onConfirm="areaConfirm"></Address>
  47. <!-- 选择收款方式 -->
  48. <u-picker v-model="showSettle" title="收款方式" @confirm="settleStyleChange" :range="settleTypeList" range-key="name" mode="selector" :default-selector="JSON.parse(JSON.stringify(defaultSettleIndex))"></u-picker>
  49. <!-- 客户类型 -->
  50. <u-picker v-model="showCust" title="客户类型" @confirm="custTypeChange" :range="custTypeList" range-key="name" mode="selector" :default-selector="JSON.parse(JSON.stringify(defaultCustIndex))"></u-picker>
  51. </view>
  52. </template>
  53. <script>
  54. import {settleStyleQueryAll} from '@/api/sales.js'
  55. import {customerDetail,custType,custSave,employeeAllList} from '@/api/customer.js'
  56. import Address from '@/components/address.vue'
  57. import vSelect from '@/components/select/v-select.vue'
  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. // 省市区
  185. if(this.areaIdArr.length == 0){
  186. uni.showToast({icon: 'none',title: '请选择省市区'})
  187. return
  188. }
  189. if (this.form.priceType ==undefined) {
  190. uni.showToast({
  191. title: '请选择价格类型',
  192. icon: 'none'
  193. })
  194. return false
  195. }
  196. if (this.form.settleStyleSn ==undefined) {
  197. uni.showToast({
  198. title: '请选择收款方式',
  199. icon: 'none'
  200. })
  201. return false
  202. }
  203. const params=Object.assign({},this.form,this.areaIdArr)
  204. console.log(params,'params')
  205. if(this.form.id) {
  206. params.id = this.form.id
  207. }
  208. custSave(params).then(res=>{
  209. if(res.status == 200) {
  210. uni.showToast({
  211. title: res.message,
  212. icon: 'none'
  213. })
  214. setTimeout(()=>{
  215. uni.navigateTo({
  216. url:'/pages/sales/addSales?pageType=add&nowId='+res.data.id
  217. })
  218. },300)
  219. }
  220. })
  221. } else {
  222. console.log('验证失败');
  223. }
  224. })
  225. },
  226. }
  227. }
  228. </script>
  229. <style lang="scss">
  230. .addCustomer-content{
  231. width: 100%;
  232. height: 100vh;
  233. background-color: #fff;
  234. padding:0 40upx;
  235. display: flex;
  236. flex-direction: column;
  237. .content-customerName{
  238. // padding: 10upx;
  239. // border-radius: 10upx;
  240. // border: 1upx solid #e5e5e5;
  241. }
  242. .content-form{
  243. flex: 1;
  244. // box-shadow:0 8upx 24upx rgba(0,0,0,.1);
  245. // border: 1upx solid #e5e5e5;
  246. .receiveAddress{
  247. width: 100%;
  248. line-height: 1.5em;
  249. box-sizing: border-box;
  250. font-style: normal;
  251. text-align: end;
  252. }
  253. }
  254. .content-form:not(:last-child){
  255. border-bottom: none;
  256. }
  257. .form-footer-btn{
  258. background-color: #fff;
  259. position: fixed;
  260. bottom: 0;
  261. left: 0;
  262. width: 100%;
  263. padding: 16upx 20upx 12upx;
  264. z-index: 999;
  265. .handle-btn{
  266. width: 100%;
  267. background-color: rgb(51, 95, 182);
  268. color: #fff;
  269. }
  270. }
  271. }
  272. </style>