add-edit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="customer-form">
  3. <u-navbar
  4. :title="id?'编辑客商':'新增客商'"
  5. :autoBack="true"
  6. :placeholder="true"
  7. >
  8. </u-navbar>
  9. <u-form
  10. labelPosition="left"
  11. :model="form"
  12. :rules="rules"
  13. ref="form1"
  14. labelWidth='90'>
  15. <u-form-item :label="$t('customer_meter.enterpriseTaxNo')" borderBottom prop="taxNo">
  16. <u--input
  17. v-model="form.taxNo"
  18. border="none"
  19. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.enterpriseTaxNo')"
  20. ></u--input>
  21. </u-form-item>
  22. <u-form-item :label="$t('customer_meter.enterpriseName')" borderBottom prop="name">
  23. <u--input
  24. v-model="form.name"
  25. border="none"
  26. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.enterpriseName')"
  27. ></u--input>
  28. </u-form-item>
  29. <u-form-item :label="$t('customer_meter.contacts')" borderBottom prop="companyContact">
  30. <u--input
  31. v-model="form.companyContact"
  32. border="none"
  33. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.contacts')"
  34. ></u--input>
  35. </u-form-item>
  36. <u-form-item :label="$t('customer_meter.contactNumber')" borderBottom prop="companyContactPhone">
  37. <u--input
  38. v-model="form.companyContactPhone"
  39. border="none"
  40. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.contactNumber')"
  41. ></u--input>
  42. </u-form-item>
  43. <u-form-item :label="$t('customer_meter.customerAttribute')" borderBottom prop="types">
  44. <u-radio-group
  45. v-model="form.types"
  46. placement="row">
  47. <u-radio activeColor="#4680F9" name="102" :label="$t('customer_meter.sale')"></u-radio>
  48. <u-radio activeColor="#4680F9" name="104" :label="$t('customer_meter.purchase')"></u-radio>
  49. </u-radio-group>
  50. </u-form-item>
  51. <u-form-item :label="$t('customer_meter.private')" borderBottom prop="privateFlag">
  52. <u-switch v-model="form.privateFlag" activeColor="#4680F9" size="20"></u-switch>
  53. </u-form-item>
  54. <u-form-item :label="$t('customer_meter.enterpriseAddress')" borderBottom prop="address">
  55. <u--input
  56. v-model="form.address"
  57. border="none"
  58. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.enterpriseAddress')+'(选填)'"
  59. ></u--input>
  60. </u-form-item>
  61. <div style="margin: 16px 0;">
  62. <u-button type="primary" native-type="submit" @click="submit('form1')">{{$t('base.common.submit')}}</u-button>
  63. </div>
  64. </u-form>
  65. </view>
  66. </template>
  67. <script>
  68. import {addCustomer,editCustomer,getCustomerById} from '../../api/customer'
  69. export default {
  70. data(){
  71. return {
  72. id:'',
  73. form:{
  74. taxNo:'',
  75. name:'',
  76. companyContact:'',
  77. companyContactPhone:'',
  78. types:'102',
  79. privateFlag:true,
  80. address:'',
  81. },
  82. rules:{
  83. name:[{ required: true, message: this.$t('base.common.placeholderI')+this.$t('customer_meter.enterpriseName') }]
  84. }
  85. }
  86. },
  87. onLoad(){
  88. this.getCustomer()
  89. },
  90. methods:{
  91. // onClickLeft(){
  92. // uni.navigateBack()
  93. // },
  94. getCustomer(){
  95. let _this=this
  96. const routers = getCurrentPages()
  97. _this.id = routers[routers.length - 1].options?routers[routers.length - 1].options.id:''
  98. if(_this.id){
  99. getCustomerById(_this.id).then(res=>{
  100. if(res.statusCode==200){
  101. let info=res.data.data
  102. _this.form.taxNo=info.taxNo
  103. _this.form.name=info.name
  104. _this.form.companyContact=info.companyContact
  105. _this.form.companyContactPhone=info.companyContactPhone
  106. _this.form.types=info.types[0]
  107. _this.form.privateFlag=info.privateFlag=='1'?true:false
  108. _this.form.address=info.address
  109. }
  110. })
  111. }
  112. },
  113. submit(ref){
  114. let _this=this
  115. this.$refs[ref].validate().then(()=>{
  116. let data = JSON.parse(JSON.stringify(_this.form))
  117. data.privateFlag ? data.privateFlag='1':data.privateFlag='0'
  118. data.types = [data.types]
  119. if(_this.id){
  120. data.id=_this.id
  121. console.log('编辑');
  122. editCustomer(data).then(res=>{
  123. if(res.statusCode == 200 ){
  124. uni.showModal({
  125. showCancel: false,
  126. // title: '提示',
  127. content: _this.$t("customer_meter.editOk"),
  128. success:function(res){
  129. if(res.confirm){
  130. uni.navigateBack({ delta: 1 })
  131. }
  132. }
  133. })
  134. _this.$refs[ref].resetFields()
  135. }
  136. })
  137. }else{
  138. console.log('新增');
  139. addCustomer(data).then(res=>{
  140. if(res.statusCode == 200 ){
  141. uni.showModal({
  142. showCancel: false,
  143. // title: '提示',
  144. content: _this.$t("customer_meter.addOk"),})
  145. _this.$refs[ref].resetFields()
  146. }
  147. })
  148. }
  149. })
  150. .catch(err=>{
  151. console.log('err', err);
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="less" scoped>
  158. .customer-form{
  159. padding: 0 32rpx 32rpx;
  160. background-color: #fff;
  161. }
  162. /deep/ .u-form-item__body{
  163. padding: 40rpx 0 20rpx;
  164. }
  165. /deep/ .u-form-item__body__left__content__label{
  166. font-weight: 600;
  167. }
  168. /deep/ .u-button--primary{
  169. background-color: #4680F9;
  170. border-color: #4680F9;
  171. }
  172. </style>