addOrder.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <view class="order">
  3. <view class="example">
  4. <u-form labelPosition="left" :model="orderForm" :rules="rules" ref="form1" labelWidth='60'>
  5. <!-- 车道,品种,客户,车号,预装数 -->
  6. <!-- 选择车道 -->
  7. <u-form-item label="车道" borderBottom prop="roadId"
  8. @click="showPopup('popupLane')">
  9. <u-input readonly v-model="orderForm.roadName" border="none"
  10. placeholder="请选择车道" />
  11. </u-form-item>
  12. <u-form-item label="品种" borderBottom prop="materialId" @click="showPopup('popupMater')"
  13. >
  14. <u-input readonly v-model="orderForm.materialName" border="none"
  15. placeholder="请选择品种"/>
  16. <view slot="right" @click.stop="addOpen(true)">
  17. <u-button
  18. type="primary"
  19. size="mini"
  20. >
  21. 新增品种
  22. </u-button>
  23. </view>
  24. </u-form-item>
  25. <u-form-item label="客户" borderBottom prop="companyId" @click="showPopup('popupCompany')">
  26. <u-input readonly v-model="orderForm.companyName" border="none"
  27. placeholder="请选择客户"/>
  28. <view slot="right" @click.stop="addOpen(false)">
  29. <u-button
  30. type="primary"
  31. size="mini"
  32. >
  33. 新增客户
  34. </u-button>
  35. </view>
  36. </u-form-item>
  37. <u-form-item label="车号" borderBottom prop="vehicle"
  38. @click="carKeyboardShow = true">
  39. <u-input readonly v-model="orderForm.vehicle" border="none"
  40. placeholder="请选择车号" />
  41. </u-form-item>
  42. <u-form-item label="预装数" borderBottom prop="number">
  43. <u-input type="number" v-model="orderForm.number" border="none"
  44. placeholder="请输入预装数" />
  45. </u-form-item>
  46. </u-form>
  47. <u-button type="primary" style="margin: 16px 0;" @click="submit('form1')">{{$t('base.common.submit')}}
  48. </u-button>
  49. </view>
  50. <!-- 车道选项 -->
  51. <PopupSelect ref="popupLane" kind="road" :hasSearch='true' :option="laneOption" @onConfirm="onConfirm" />
  52. <!-- 品种选项 -->
  53. <PopupSelect ref="popupMater" kind="material" :hasSearch='true' :option="materOption" @onConfirm="onConfirm" />
  54. <!-- 客户选项 -->
  55. <PopupSelect ref="popupCompany" kind="company" :hasSearch='true' :option="companyOption" @onConfirm="onConfirm" />
  56. <!-- 车号 -->
  57. <CarKeyboard :show.sync="carKeyboardShow" :isProvince="false" :vehicleNo="orderForm.vehicle"
  58. @confirm="carConfirm" vehicleType="car">
  59. </CarKeyboard>
  60. <u-modal @confirm="addConfirm" @cancel="addCancel" :show="addShow" :showCancelButton="true" :closeOnClickOverlay="true" :title="addTitle">
  61. <view class="add-input" slot="default">
  62. <u-input type="text" v-model="keyName" placeholder="请输入名称"/>
  63. </view>
  64. </u-modal>
  65. </view>
  66. </template>
  67. <script>
  68. import PopupSelect from '../../components/popup-select/index'
  69. import CarKeyboard from '../../components/carKeyboard/carKeyboard'
  70. import dayjs from 'dayjs'
  71. import {
  72. getCompanyList,
  73. getMaterialList,
  74. getLaneList,
  75. saveCompany,
  76. saveMaterial,
  77. saveOrder
  78. } from '../../api/order'
  79. export default {
  80. components: {
  81. PopupSelect,
  82. CarKeyboard
  83. },
  84. data() {
  85. return {
  86. carKeyboardShow: false,
  87. start: dayjs().format('YYYY-MM-DD'),
  88. addShow: false,
  89. addTitle:"",
  90. keyName:"",
  91. orderForm: {
  92. roadId: '',
  93. roadName: '',
  94. companyId:'',
  95. companyName:"",
  96. materialId:"",
  97. materialName:"",
  98. number:"",
  99. vehicle:"",
  100. },
  101. rules: {
  102. },
  103. laneOption:[],
  104. companyOption:[],
  105. materOption:[],
  106. }
  107. },
  108. onLoad(options) {
  109. this.getCompany()
  110. this.getMater()
  111. this.getLane()
  112. this.orderForm.roadId=options.id
  113. this.orderForm.roadName = options.name
  114. },
  115. methods: {
  116. //显示选择
  117. showPopup(refs) {
  118. this.$refs[refs].showPicker = true
  119. },
  120. //新增
  121. addOpen(boo){
  122. this.addShow = true
  123. this.addType = boo
  124. if(boo){
  125. this.addTitle = "新增品种"
  126. }else{
  127. this.addTitle = "新增客户"
  128. }
  129. },
  130. addCancel(){
  131. this.addShow = false
  132. this.keyName = ''
  133. },
  134. //新增
  135. addConfirm(){
  136. let that = this
  137. if(!that.keyName){
  138. uni.showToast({
  139. title: '请输入名称',
  140. icon: 'none',
  141. mask: true
  142. })
  143. return
  144. }
  145. uni.showLoading({
  146. title: '保存中',
  147. mask:true,
  148. });
  149. if(this.addType){
  150. saveMaterial({name:that.keyName}).then(res=>{
  151. if(res.statusCode == '200'){
  152. uni.showToast({
  153. title: '保存成功',
  154. icon: 'none',
  155. mask: true
  156. })
  157. that.addShow = false
  158. that.keyName = ''
  159. that.getMater()
  160. }
  161. uni.hideLoading();
  162. }).finally(()=>{
  163. uni.hideLoading();
  164. });
  165. }else{
  166. saveCompany({name:that.keyName}).then(res=>{
  167. if(res.statusCode == '200'){
  168. uni.showToast({
  169. title: '保存成功',
  170. icon: 'none',
  171. mask: true
  172. })
  173. that.addShow = false
  174. that.keyName = ''
  175. that.getCompany()
  176. }
  177. uni.hideLoading();
  178. }).finally(()=>{
  179. uni.hideLoading();
  180. });
  181. }
  182. },
  183. //获取客户
  184. getCompany(){
  185. getCompanyList().then(res=>{
  186. if(res.statusCode === 200){
  187. this.companyOption = res.data.data.map(item=>{
  188. return {
  189. text:item.name,
  190. value:item.id,
  191. ...item
  192. }
  193. })
  194. if(this.companyOption.length == 1){
  195. this.orderForm.companyId = this.companyOption[0].value
  196. this.orderForm.companyName = this.companyOption[0].text
  197. }
  198. }
  199. })
  200. },
  201. //获取物料
  202. getMater(){
  203. getMaterialList().then(res=>{
  204. if(res.statusCode === 200){
  205. this.materOption = res.data.data.map(item=>{
  206. return {
  207. text:item.name,
  208. value:item.id,
  209. ...item
  210. }
  211. })
  212. if(this.materOption.length == 1){
  213. this.orderForm.materialId = this.materOption[0].value
  214. this.orderForm.materialName = this.materOption[0].text
  215. }
  216. }
  217. })
  218. },
  219. //获取车道
  220. getLane(){
  221. getLaneList().then(res=>{
  222. if(res.statusCode === 200){
  223. this.laneOption = res.data.data.map(item=>{
  224. return {
  225. text:item.roadName,
  226. value:item.id,
  227. ...item
  228. }
  229. })
  230. if(this.laneOption.length == 1){
  231. this.orderForm.roadId = this.laneOption[0].value
  232. this.orderForm.roadName = this.laneOption[0].text
  233. }
  234. }
  235. })
  236. },
  237. onConfirm(value,kind){
  238. this.orderForm[kind+'Id'] = ''
  239. this.orderForm[kind+'Name'] = ''
  240. if(value.value){
  241. this.orderForm[kind+'Id'] = value.value
  242. this.orderForm[kind+'Name'] = value.text
  243. }
  244. },
  245. carConfirm(id){
  246. this.orderForm.vehicle = id
  247. },
  248. submit(){
  249. let _this = this
  250. // this.$refs.form1.validate().then(() => {
  251. let data = JSON.parse(JSON.stringify(_this.orderForm))
  252. uni.showLoading({
  253. title: '保存中',
  254. mask:true,
  255. });
  256. saveOrder(data).then(res => {
  257. if (res.statusCode === 200) {
  258. uni.showModal({
  259. // title: '提示',
  260. content: "任务保存成功,是否继续添加任务",
  261. showCancel: true,
  262. cancelText: "返回上一页",
  263. confirmText: "继续添加",
  264. success: function(res) {
  265. if (res.confirm) {
  266. _this.orderForm = {
  267. roadId: '',
  268. roadName: '',
  269. companyId:'',
  270. companyName:"",
  271. materialId:"",
  272. materialName:"",
  273. number:"",
  274. vehicle:"",
  275. },
  276. console.log('用户点击确定');
  277. } else if (res.cancel) {
  278. console.log('用户点击取消');
  279. uni.navigateBack({ delta: 1 })
  280. }
  281. }
  282. })
  283. }
  284. uni.hideLoading();
  285. }).finally(()=>{
  286. uni.hideLoading();
  287. });
  288. // })
  289. },
  290. }
  291. }
  292. </script>
  293. <style lang="less" scoped>
  294. .order {
  295. padding: 32rpx;
  296. .picker-title {
  297. display: flex;
  298. padding: 0 32rpx;
  299. line-height: 84rpx;
  300. justify-content: space-between;
  301. .confirm {
  302. color: #4680F9;
  303. }
  304. }
  305. .picker-wrap {
  306. height: 440rpx;
  307. .picker-view {
  308. height: 100%;
  309. .item {
  310. display: flex;
  311. justify-content: space-between;
  312. height: 88rpx;
  313. line-height: 88rpx;
  314. padding: 0 32rpx;
  315. .text {
  316. width: 33%;
  317. }
  318. .text1 {
  319. width: 33%;
  320. text-align: center;
  321. }
  322. .text2 {
  323. width: 33%;
  324. text-align: right;
  325. }
  326. }
  327. .btn-item {
  328. display: flex;
  329. justify-content: center;
  330. height: 88rpx;
  331. line-height: 88rpx;
  332. padding: 0 32rpx;
  333. align-items: center;
  334. .add-vehicle {
  335. line-height: 64rpx;
  336. height: 64rpx;
  337. background: #4680F9;
  338. width: 25%;
  339. font-size: 28rpx;
  340. }
  341. }
  342. }
  343. }
  344. .form-wrap {
  345. height: 444rpx;
  346. padding: 0 32rpx;
  347. }
  348. }
  349. .add-input{
  350. width: 100%;
  351. }
  352. // button {
  353. // // background:linear-gradient(to right,#4680F9 0%,#00e2fa 80%,#00e2fa 100%);
  354. // background: #4680F9;
  355. // line-height: 100rpx;
  356. // color: #fff;
  357. // border: none;
  358. // }
  359. uni-button:after {
  360. border: none;
  361. }
  362. uni-input {
  363. height: 72rpx;
  364. padding: 0 10rpx 0 20rpx;
  365. }
  366. .uni-forms-item__inner {
  367. padding: 20rpx 0;
  368. }
  369. // /deep/ .u-button--primary {
  370. // background-color: #4680F9;
  371. // border-color: #4680F9;
  372. // }
  373. </style>