finish.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="finish-page">
  3. <navigation title="完工"></navigation>
  4. <view class="form-box">
  5. <u--form labelPosition="left" labelWidth="160rpx" :model="info" :rules="rules" ref="form">
  6. <view class="form">
  7. <u-form-item label="设备号" borderBottom>
  8. <u--input v-model="equipmentText" placeholder="设备号" border="none" disabled disabledColor="#fff">
  9. </u--input>
  10. </u-form-item>
  11. <u-form-item label="停机原因" prop="reasonId" borderBottom>
  12. <uni-data-select v-model="info.reasonId" :localdata="reasonActions" placeholder="请选择停机原因">
  13. </uni-data-select>
  14. </u-form-item>
  15. <view class="flex-box">
  16. <view class="content">
  17. <u-form-item label="备品备件" prop="materialId" borderBottom>
  18. <uni-data-select v-model="info.materialId" :localdata="materiaActions"
  19. placeholder="请选择备品备件">
  20. </uni-data-select>
  21. </u-form-item>
  22. <u-form-item label="数量" prop="materialCount" borderBottom>
  23. <u--input v-model="info.materialCount" placeholder="请输入数量" border="none">
  24. </u--input>
  25. </u-form-item>
  26. </view>
  27. <image class="icon" src="@/static/add.jpg" @click="addItem"></image>
  28. </view>
  29. <view class="flex-box" v-for="(item,i) of items" :key="i">
  30. <view class="content">
  31. <u-form-item label="备品备件" borderBottom>
  32. <uni-data-select v-model="item.materialId" :localdata="materiaActions"
  33. placeholder="请选择备品备件">
  34. </uni-data-select>
  35. </u-form-item>
  36. <u-form-item label="数量" borderBottom>
  37. <u--input v-model="item.materialCount" placeholder="请输入数量" border="none">
  38. </u--input>
  39. </u-form-item>
  40. </view>
  41. <image class="icon" src="../../static/delete.jpg" @click="deleteItem(i)"></image>
  42. </view>
  43. <u-form-item label="备注" prop="remark" borderBottom>
  44. <u--textarea v-model="info.remark" placeholder="请输入备注"></u--textarea>
  45. </u-form-item>
  46. <u-form-item label="完工照片" prop="completeImg">
  47. <u-upload name="img" :fileList="imgFileList" :maxCount="3" :sizeType="['compressed']"
  48. @afterRead="afterRead" @delete="deletePic"></u-upload>
  49. </u-form-item>
  50. </view>
  51. </u--form>
  52. </view>
  53. <view class="submit">
  54. <u-button @click="onSubmit" type="primary">提交</u-button>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import $baseUrl from '@/https/index.js';
  60. export default {
  61. data() {
  62. return {
  63. equipmentText: '',
  64. reasonActions: [],
  65. materiaActions: [],
  66. imgFileList: [],
  67. info: {
  68. id: '',
  69. reasonId: '',
  70. remark: '',
  71. completeImg: '',
  72. materialList: [],
  73. materialId: '1',
  74. materialCount: ''
  75. },
  76. rules: {
  77. reasonId: {
  78. type: 'number',
  79. required: true,
  80. message: '请选择停机原因',
  81. trigger: ['blur', 'change']
  82. },
  83. // materialId: {
  84. // type: 'number',
  85. // required: true,
  86. // message: '请选择备品备件',
  87. // trigger: ['blur', 'change']
  88. // },
  89. // materialCount: {
  90. // type: 'string',
  91. // required: true,
  92. // message: '请输入数量',
  93. // trigger: ['blur', 'change']
  94. // },
  95. // remark: {
  96. // type: 'string',
  97. // required: true,
  98. // message: '请填写备注',
  99. // trigger: ['blur', 'change']
  100. // },
  101. // completeImg: {
  102. // type: 'string',
  103. // required: true,
  104. // message: '请上传完工照片',
  105. // trigger: ['blur', 'change']
  106. // },
  107. },
  108. items: []
  109. }
  110. },
  111. onLoad(option) {
  112. this.info.id = option.id
  113. this.equipmentText = option.num
  114. },
  115. onShow() {
  116. this.getReasonList()
  117. this.getMaterialList()
  118. },
  119. methods: {
  120. onSubmit() {
  121. if (this.imgFileList.length > 0) {
  122. let completeImgArr = []
  123. for (var i = 0; i < this.imgFileList.length; i++) {
  124. completeImgArr.push(this.imgFileList[i].url)
  125. }
  126. this.info.completeImg = completeImgArr.toString()
  127. }
  128. this.info.materialList = []
  129. var defaultValue = {
  130. materialId: this.info.materialId,
  131. materialCount: this.info.materialCount
  132. }
  133. this.info.materialList.push(defaultValue)
  134. for (var i = 0; i < this.items.length; i++) {
  135. var inputValue = {
  136. materialId: this.items[i].materialId,
  137. materialCount: this.items[i].materialCount
  138. }
  139. this.info.materialList.push(inputValue)
  140. }
  141. this.$refs.form.validate().then(res => {
  142. this.$api.completeOrder(this.info).then(res => {
  143. uni.showToast({
  144. title: '提交成功!',
  145. duration: 2000
  146. });
  147. setTimeout(function() {
  148. uni.navigateBack();
  149. }, 2000);
  150. }).catch(err => {})
  151. }).catch(err => {
  152. console.log('表单错误信息:', err);
  153. })
  154. },
  155. addItem() {
  156. this.items.push({
  157. "materialId": '',
  158. "materialCount": ''
  159. })
  160. },
  161. deleteItem(i) {
  162. this.items.splice(i, 1);
  163. },
  164. // 停机原因
  165. getReasonList() {
  166. this.$api.dictList({
  167. baseType: 'CATEGORY_FAUT'
  168. }).then(res => {
  169. this.reasonActions = res.rows
  170. for (var i = 0; i < this.reasonActions.length; i++) {
  171. this.reasonActions[i].value = this.reasonActions[i].id
  172. this.reasonActions[i].text = this.reasonActions[i].baseDesc
  173. }
  174. }).catch(err => {})
  175. },
  176. // 备品备件
  177. getMaterialList() {
  178. this.$api.materialList({
  179. materielType: 'type_spare'
  180. }).then(res => {
  181. this.materiaActions = res.rows
  182. for (var i = 0; i < this.materiaActions.length; i++) {
  183. this.materiaActions[i].value = this.materiaActions[i].id
  184. this.materiaActions[i].text = this.materiaActions[i].materielName
  185. }
  186. }).catch(err => {})
  187. },
  188. // 删除图片
  189. deletePic(event) {
  190. console.log(event)
  191. this[`${event.name}FileList`].splice(event.index, 1)
  192. this.$refs.form.validate()
  193. },
  194. // 新增图片
  195. async afterRead(event) {
  196. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  197. let lists = [].concat(event.file)
  198. const fileList = this[`${event.name}FileList`]
  199. let fileListLen = fileList.length
  200. lists.map((item) => {
  201. fileList.push({
  202. ...item,
  203. status: 'uploading',
  204. message: '上传中'
  205. })
  206. })
  207. const url = '/common/upload'
  208. for (let i = 0; i < lists.length; i++) {
  209. uni.uploadFile({
  210. url: $baseUrl.url + url,
  211. filePath: lists[i].url,
  212. name: 'file',
  213. header: {
  214. Authorization: "Bearer " + uni.getStorageSync('token'),
  215. },
  216. success: (res) => {
  217. let data = JSON.parse(res.data)
  218. let item = fileList[fileListLen]
  219. fileList.splice(fileListLen, 1, Object.assign(item, {
  220. status: 'success',
  221. message: '',
  222. url: data.msg
  223. }))
  224. }
  225. });
  226. }
  227. },
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .finish-page {
  233. padding-bottom: 20rpx;
  234. .add-bg {
  235. width: 100%;
  236. height: 330rpx;
  237. }
  238. .form-box {
  239. .form {
  240. background-color: #fff;
  241. margin: 0 24rpx;
  242. padding: 10rpx 24rpx;
  243. border-radius: 12rpx;
  244. /deep/.uni-select {
  245. border: none;
  246. padding: 0;
  247. }
  248. .flex-box {
  249. display: flex;
  250. align-items: center;
  251. .content {
  252. width: 90%;
  253. }
  254. .icon {
  255. width: 55rpx;
  256. height: 55rpx;
  257. margin-left: 2%;
  258. }
  259. }
  260. }
  261. }
  262. .submit {
  263. margin: 34rpx;
  264. }
  265. }
  266. </style>