addOrder.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. },
  113. methods: {
  114. //显示选择
  115. showPopup(refs) {
  116. this.$refs[refs].showPicker = true
  117. },
  118. //新增
  119. addOpen(boo){
  120. this.addShow = true
  121. this.addType = boo
  122. if(boo){
  123. this.addTitle = "新增品种"
  124. }else{
  125. this.addTitle = "新增客户"
  126. }
  127. },
  128. addCancel(){
  129. this.addShow = false
  130. this.keyName = ''
  131. },
  132. //新增
  133. addConfirm(){
  134. let that = this
  135. if(!that.keyName){
  136. uni.showToast({
  137. title: '请输入名称',
  138. icon: 'none',
  139. mask: true
  140. })
  141. return
  142. }
  143. uni.showLoading({
  144. title: '保存中',
  145. mask:true,
  146. });
  147. if(this.addType){
  148. saveMaterial({name:that.keyName}).then(res=>{
  149. if(res.statusCode == '200'){
  150. uni.showToast({
  151. title: '保存成功',
  152. icon: 'none',
  153. mask: true
  154. })
  155. that.addShow = false
  156. that.keyName = ''
  157. that.getMater()
  158. }
  159. uni.hideLoading();
  160. }).finally(()=>{
  161. uni.hideLoading();
  162. });
  163. }else{
  164. saveCompany({name:that.keyName}).then(res=>{
  165. if(res.statusCode == '200'){
  166. uni.showToast({
  167. title: '保存成功',
  168. icon: 'none',
  169. mask: true
  170. })
  171. that.addShow = false
  172. that.keyName = ''
  173. that.getCompany()
  174. }
  175. uni.hideLoading();
  176. }).finally(()=>{
  177. uni.hideLoading();
  178. });
  179. }
  180. },
  181. //获取客户
  182. getCompany(){
  183. getCompanyList().then(res=>{
  184. if(res.statusCode === 200){
  185. this.companyOption = res.data.data.map(item=>{
  186. return {
  187. text:item.name,
  188. value:item.id,
  189. ...item
  190. }
  191. })
  192. }
  193. })
  194. },
  195. //获取物料
  196. getMater(){
  197. getMaterialList().then(res=>{
  198. if(res.statusCode === 200){
  199. this.materOption = res.data.data.map(item=>{
  200. return {
  201. text:item.name,
  202. value:item.id,
  203. ...item
  204. }
  205. })
  206. }
  207. })
  208. },
  209. //获取车道
  210. getLane(){
  211. getLaneList().then(res=>{
  212. if(res.statusCode === 200){
  213. this.laneOption = res.data.data.map(item=>{
  214. return {
  215. text:item.roadName,
  216. value:item.id,
  217. ...item
  218. }
  219. })
  220. }
  221. })
  222. },
  223. onConfirm(value,kind){
  224. this.orderForm[kind+'Id'] = ''
  225. this.orderForm[kind+'Name'] = ''
  226. if(value.value){
  227. this.orderForm[kind+'Id'] = value.value
  228. this.orderForm[kind+'Name'] = value.text
  229. }
  230. },
  231. carConfirm(id){
  232. this.orderForm.vehicle = id
  233. },
  234. submit(){
  235. let _this = this
  236. // this.$refs.form1.validate().then(() => {
  237. let data = JSON.parse(JSON.stringify(_this.orderForm))
  238. uni.showLoading({
  239. title: '保存中',
  240. mask:true,
  241. });
  242. saveOrder(data).then(res => {
  243. if (res.statusCode === 200) {
  244. uni.showModal({
  245. // title: '提示',
  246. content: "任务保存成功,是否继续添加任务",
  247. showCancel: true,
  248. cancelText: "返回上一页",
  249. confirmText: "继续添加",
  250. success: function(res) {
  251. if (res.confirm) {
  252. _this.orderForm = {
  253. roadId: '',
  254. roadName: '',
  255. companyId:'',
  256. companyName:"",
  257. materialId:"",
  258. materialName:"",
  259. number:"",
  260. vehicle:"",
  261. },
  262. console.log('用户点击确定');
  263. } else if (res.cancel) {
  264. console.log('用户点击取消');
  265. uni.redirectTo({
  266. url: '/pages/home/home'
  267. })
  268. }
  269. }
  270. })
  271. }
  272. uni.hideLoading();
  273. }).finally(()=>{
  274. uni.hideLoading();
  275. });
  276. // })
  277. },
  278. }
  279. }
  280. </script>
  281. <style lang="less" scoped>
  282. .order {
  283. padding: 32rpx;
  284. .picker-title {
  285. display: flex;
  286. padding: 0 32rpx;
  287. line-height: 84rpx;
  288. justify-content: space-between;
  289. .confirm {
  290. color: #4680F9;
  291. }
  292. }
  293. .picker-wrap {
  294. height: 440rpx;
  295. .picker-view {
  296. height: 100%;
  297. .item {
  298. display: flex;
  299. justify-content: space-between;
  300. height: 88rpx;
  301. line-height: 88rpx;
  302. padding: 0 32rpx;
  303. .text {
  304. width: 33%;
  305. }
  306. .text1 {
  307. width: 33%;
  308. text-align: center;
  309. }
  310. .text2 {
  311. width: 33%;
  312. text-align: right;
  313. }
  314. }
  315. .btn-item {
  316. display: flex;
  317. justify-content: center;
  318. height: 88rpx;
  319. line-height: 88rpx;
  320. padding: 0 32rpx;
  321. align-items: center;
  322. .add-vehicle {
  323. line-height: 64rpx;
  324. height: 64rpx;
  325. background: #4680F9;
  326. width: 25%;
  327. font-size: 28rpx;
  328. }
  329. }
  330. }
  331. }
  332. .form-wrap {
  333. height: 444rpx;
  334. padding: 0 32rpx;
  335. }
  336. }
  337. .add-input{
  338. width: 100%;
  339. }
  340. // button {
  341. // // background:linear-gradient(to right,#4680F9 0%,#00e2fa 80%,#00e2fa 100%);
  342. // background: #4680F9;
  343. // line-height: 100rpx;
  344. // color: #fff;
  345. // border: none;
  346. // }
  347. uni-button:after {
  348. border: none;
  349. }
  350. uni-input {
  351. height: 72rpx;
  352. padding: 0 10rpx 0 20rpx;
  353. }
  354. .uni-forms-item__inner {
  355. padding: 20rpx 0;
  356. }
  357. // /deep/ .u-button--primary {
  358. // background-color: #4680F9;
  359. // border-color: #4680F9;
  360. // }
  361. </style>