add-edit.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="customer-form">
  3. <u-navbar
  4. :title="id?$t('customer_meter.edit')+' '+$t('mine.mater'):$t('customer_meter.add')+' '+$t('mine.mater')"
  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='80'>
  15. <u-form-item :label="$t('customer_meter.materName')" borderBottom prop="name">
  16. <u--input
  17. v-model="form.name"
  18. border="none"
  19. :placeholder="$t('base.common.placeholderI')+$t('customer_meter.materName')"
  20. ></u--input>
  21. </u-form-item>
  22. <u-form-item :label="$t('customer_meter.materType')" borderBottom prop="type">
  23. <u-radio-group
  24. v-model="form.type"
  25. placement="row">
  26. <u-radio activeColor="#4680F9" name="101" label="销售"></u-radio>
  27. <u-radio activeColor="#4680F9" name="102" label="原材料"></u-radio>
  28. <!-- <u-radio activeColor="#4680F9" name="103" label="倒料"></u-radio> -->
  29. <!-- <u-radio activeColor="#4680F9" name="104" label="材料"></u-radio> -->
  30. </u-radio-group>
  31. </u-form-item>
  32. <u-form-item :label="$t('customer_meter.kind')" borderBottom prop="kind">
  33. <u-radio-group
  34. v-model="form.kind"
  35. placement="row">
  36. <u-radio activeColor="#4680F9" name="101" label="袋装"></u-radio>
  37. <u-radio activeColor="#4680F9" name="102" label="散装"></u-radio>
  38. </u-radio-group>
  39. </u-form-item>
  40. <u-form-item :label="$t('customer_meter.private')" borderBottom prop="privateFlag">
  41. <u-switch v-model="form.privateFlag" size="20"></u-switch>
  42. </u-form-item>
  43. <div style="margin: 16px;">
  44. <u-button type="primary" native-type="submit" @click="submit('form1')">{{$t('base.common.submit')}}</u-button>
  45. </div>
  46. </u-form>
  47. </view>
  48. </template>
  49. <script>
  50. import {addMaterial,editMaterial,getMaterialById} from '../../api/customer'
  51. export default {
  52. data(){
  53. return {
  54. form:{
  55. name:'',
  56. type:'',
  57. kind:'',
  58. privateFlag:true,
  59. },
  60. rules:{
  61. name:[{ required: true, message: this.$t('base.common.placeholderI')+this.$t('customer_meter.materName') }]
  62. },
  63. id:'',
  64. }
  65. },
  66. computed:{
  67. },
  68. onLoad(){
  69. this.getMater()
  70. },
  71. methods:{
  72. getMater(){
  73. let _this=this
  74. const routers = getCurrentPages()
  75. _this.id = routers[routers.length - 1].options?routers[routers.length - 1].options.id:''
  76. if(_this.id){
  77. getMaterialById(_this.id).then(res=>{
  78. if(res.statusCode==200){
  79. let info=res.data.data
  80. _this.form.name=info.name
  81. _this.form.type=info.type
  82. _this.form.kind=info.kind
  83. _this.form.privateFlag=info.privateFlag=='1'?true:false
  84. }
  85. })
  86. }
  87. },
  88. // onClickLeft(){
  89. // uni.navigateBack()
  90. // },
  91. submit(ref){
  92. console.log(this.id);
  93. let _this=this
  94. this.$refs[ref].validate().then(()=>{
  95. let data = JSON.parse(JSON.stringify(_this.form))
  96. data.privateFlag ? data.privateFlag='1':data.privateFlag='0'
  97. if(_this.id){
  98. data.id=_this.id
  99. console.log('编辑');
  100. editMaterial(data).then(res=>{
  101. if(res.statusCode == 200 ){
  102. uni.showModal({
  103. showCancel: false,
  104. // title: '提示',
  105. content: _this.$t("customer_meter.editOk"),
  106. success:function(res){
  107. if(res.confirm){
  108. uni.navigateBack({ delta: 1 })
  109. }
  110. }
  111. })
  112. _this.$refs[ref].resetFields()
  113. }
  114. })
  115. }else{
  116. console.log('新增');
  117. addMaterial(data).then(res=>{
  118. if(res.statusCode == 200 ){
  119. uni.showModal({
  120. showCancel: false,
  121. // title: '提示',
  122. content: _this.$t("customer_meter.addOk"),})
  123. _this.$refs[ref].resetFields()
  124. }
  125. })
  126. }
  127. })
  128. .catch(err=>{
  129. console.log('err', err);
  130. })
  131. }
  132. }
  133. }
  134. </script>
  135. <style lang="less" scoped>
  136. .customer-form{
  137. padding: 0 32rpx 32rpx;
  138. background-color: #fff;
  139. }
  140. </style>