add.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view>
  3. <uni-section padding>
  4. <uni-forms ref="baseForm" :modelValue="baseFormData" :rules="rules" label-width="80px" label-align="right">
  5. <uni-forms-item label="产品" required name="cpId">
  6. <uni-data-select v-model="baseFormData.cpId" placeholder="请选择产品" :localdata="cpData" @change="xzcp" />
  7. </uni-forms-item>
  8. <uni-forms-item label="产品编码">
  9. <uni-easyinput v-model="baseFormData.cpbm" placeholder="请输入产品编码" disabled />
  10. </uni-forms-item>
  11. <uni-forms-item label="产品名称">
  12. <uni-easyinput v-model="baseFormData.cpName" placeholder="请输入产品名称" disabled />
  13. </uni-forms-item>
  14. <uni-forms-item label="单价">
  15. <uni-easyinput v-model="baseFormData.dj" placeholder="请输入单价" disabled />
  16. </uni-forms-item>
  17. <uni-forms-item label="客户" required name="lrId">
  18. <uni-data-select v-model="baseFormData.lrId" placeholder="请选择客户" :localdata="khData" @change="xzkh" />
  19. </uni-forms-item>
  20. <uni-forms-item label="收货人">
  21. <uni-easyinput v-model="baseFormData.shxm" placeholder="请输入收货人" disabled />
  22. </uni-forms-item>
  23. <uni-forms-item label="收货电话">
  24. <uni-easyinput v-model="baseFormData.shdh" placeholder="请输入收货电话" disabled />
  25. </uni-forms-item>
  26. <uni-forms-item label="收货地址" required name="shdz">
  27. <uni-easyinput v-model="baseFormData.shdz" placeholder="请输入收货地址" />
  28. </uni-forms-item>
  29. <uni-forms-item label="下单数量">
  30. <uni-easyinput v-model="baseFormData.xdsl" type="number" placeholder="请输入下单数量" @blur="sl" />
  31. </uni-forms-item>
  32. <uni-forms-item label="金额">
  33. <uni-easyinput v-model="baseFormData.je" placeholder="请输入金额" />
  34. </uni-forms-item>
  35. <uni-forms-item label="买家留言">
  36. <uni-easyinput v-model="baseFormData.xdbz" placeholder="请输入买家留言" />
  37. </uni-forms-item>
  38. <uni-forms-item label="支付凭据">
  39. <uni-easyinput v-model="baseFormData.zfpj" placeholder="请输入支付凭据" />
  40. </uni-forms-item>
  41. <uni-forms-item label="运单号">
  42. <uni-easyinput v-model="baseFormData.ydh" placeholder="请输入运单号" />
  43. </uni-forms-item>
  44. <uni-forms-item label="取货码">
  45. <uni-easyinput v-model="baseFormData.qhm" placeholder="请输入取货码" />
  46. </uni-forms-item>
  47. <uni-forms-item label="发货时间">
  48. <uni-datetime-picker type="datetime" v-model="baseFormData.fhsjs" placeholder="请选择发货时间" />
  49. </uni-forms-item>
  50. <uni-forms-item label="到货时间">
  51. <uni-datetime-picker type="datetime" v-model="baseFormData.dhsjs" placeholder="请选择到货时间" />
  52. </uni-forms-item>
  53. <view class="bottomButton">
  54. <button v-show="baseFormData.ddzt == null || baseFormData.ddzt == 0" type="primary" @click="submit()" size="mini">保存</button>
  55. </view>
  56. </uni-forms>
  57. </uni-section>
  58. </view>
  59. </template>
  60. <script>
  61. import { ObjdictList } from '@/api/dict.js'
  62. import { addDdjy } from '@/api/order.js'
  63. import { showConfirm } from '@/common/common.js'
  64. export default {
  65. data() {
  66. return {
  67. baseFormData: {},
  68. rules: {
  69. cpId: {
  70. rules: [{
  71. required: true,
  72. errorMessage: '产品不能为空'
  73. }]
  74. },
  75. lrId: {
  76. rules: [{
  77. required: true,
  78. errorMessage: '客户不能为空'
  79. }]
  80. },
  81. shdz: {
  82. rules: [{
  83. required: true,
  84. errorMessage: '收货地址不能为空'
  85. }]
  86. },
  87. },
  88. cpData: [],
  89. khData: [],
  90. }
  91. },
  92. onLoad(options) {
  93. if (Object.keys(options).length !== 0) {
  94. this.baseFormData = JSON.parse(options.item)
  95. this.baseFormData.fhsjs = new Date(this.baseFormData.fhsj)
  96. this.baseFormData.dhsjs = new Date(this.baseFormData.dhsj)
  97. }
  98. },
  99. mounted() {
  100. this.getCpList()
  101. this.getKhList()
  102. },
  103. methods: {
  104. sl(e) {
  105. let sl = e.detail.value
  106. if (!sl || sl < 1) {
  107. showConfirm("请输入正确下单数量")
  108. } else {
  109. if (this.baseFormData.dj) {
  110. this.baseFormData.je = this.baseFormData.dj * sl
  111. }
  112. }
  113. },
  114. xzkh(e) {
  115. let kh = this.khData.filter(obj => obj.value == e)
  116. this.baseFormData.shxm = kh[0].obj[1]
  117. this.baseFormData.shdh = kh[0].obj[2]
  118. this.baseFormData.shdz = kh[0].obj[3]
  119. },
  120. xzcp(e) {
  121. let kh = this.cpData.filter(obj => obj.value == e)
  122. this.baseFormData.cpbm = kh[0].obj[2]
  123. this.baseFormData.cpName = kh[0].obj[1]
  124. this.baseFormData.dj = kh[0].obj[3]
  125. this.baseFormData.xdsl = 1
  126. this.baseFormData.je = this.baseFormData.dj
  127. },
  128. getCpList() {
  129. ObjdictList({
  130. dictType: 'cpxz',
  131. outType: 0,
  132. para1: uni.getStorageSync('userInfo').jgId
  133. }).then(res => {
  134. if (res.data.data) {
  135. Object.keys(res.data.data).map(e => {
  136. let obj = res.data.data[e]
  137. this.cpData.push({
  138. value: obj[0],
  139. text: obj[1],
  140. obj: {
  141. ...obj
  142. }
  143. })
  144. })
  145. }
  146. })
  147. },
  148. getKhList() {
  149. ObjdictList({
  150. dictType: 'kh',
  151. outType: 0,
  152. para1: uni.getStorageSync('userInfo').jgId
  153. }).then(res => {
  154. if (res.data.data) {
  155. Object.keys(res.data.data).map(e => {
  156. let obj = res.data.data[e]
  157. this.khData.push({
  158. value: obj[0],
  159. text: obj[1],
  160. obj: {
  161. ...obj
  162. }
  163. })
  164. })
  165. }
  166. })
  167. },
  168. submit() {
  169. if (this.baseFormData.fhsjs) {
  170. this.baseFormData.fhsj = this.baseFormData.fhsjs.replaceAll('-', '').replace(' ', '').replaceAll(':', '')
  171. }
  172. if (this.baseFormData.dhsjs) {
  173. this.baseFormData.dhsj = this.baseFormData.dhsjs.replaceAll('-', '').replace(' ', '').replaceAll(':', '')
  174. }
  175. this.$refs['baseForm'].validate().then(res => {
  176. addDdjy(this.baseFormData).then(r => {
  177. if (r.code == 200) {
  178. uni.showToast({
  179. title: `保存成功!`,
  180. duration: 2000,
  181. success: function(res) {
  182. setTimeout(function() {
  183. uni.switchTab({
  184. url: '/pages/order/index'
  185. });
  186. uni.$emit('update', { isReset: true })
  187. }, 2000)
  188. }
  189. })
  190. }
  191. })
  192. }).catch(err => {
  193. console.log("err", err)
  194. uni.showModal({
  195. title: '错误提示',
  196. content: err[0].errorMessage,
  197. showCancel: false,
  198. success: function(res) {
  199. if (res.confirm) {
  200. console.log('用户点击确定');
  201. } else if (res.cancel) {
  202. console.log('用户点击取消');
  203. }
  204. }
  205. });
  206. })
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .bottomButton {
  213. height: 140rpx;
  214. width: 60%;
  215. margin: 0 auto;
  216. text-align: center;
  217. button {
  218. width: 40%;
  219. }
  220. button+button {
  221. margin-left: 15px;
  222. }
  223. }
  224. </style>