综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

device.vue 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="form-container">
  3. <!-- 表单标题 -->
  4. <view class="form-title">
  5. <text class="title-text">设备申请表</text>
  6. <view class="title-line"></view>
  7. </view>
  8. <!-- 表单内容 -->
  9. <uni-forms ref="form" :modelValue="form" :rules="rules" label-position="top" label-width="150" class="custom-form">
  10. <flow-note :taskForm="taskForm"></flow-note>
  11. <!-- 当前节点 -->
  12. <uni-forms-item label="当前节点" class="form-item" v-if="taskName">
  13. <uni-tag :inverted="true" type="primary" :text="taskName"></uni-tag>
  14. </uni-forms-item>
  15. <!-- 流程发起人 -->
  16. <uni-forms-item label="填报人" class="form-item">
  17. <b style="font-size:30rpx;">{{ applierUserName }}</b>
  18. </uni-forms-item>
  19. <!-- 填报日期 -->
  20. <uni-forms-item label="填报日期" class="form-item">
  21. <text>{{ form.applyDate }}</text>
  22. </uni-forms-item>
  23. <!-- 选择项目 -->
  24. <uni-forms-item label="选择项目" required class="form-item" name="projectId">
  25. <uv-button type="primary" @click="openProject = true" v-if="taskName == '设备申请'">+ 选择项目</uv-button>
  26. <ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
  27. <ProjectInfo :project="projectObj"></ProjectInfo>
  28. </uni-forms-item>
  29. <!-- 设备选择 -->
  30. <uni-forms-item label="选择设备" required class="form-item" name="devices">
  31. <uv-button type="primary" @click="openDevice = true" v-if="taskName == '设备申请'">+ 选择设备</uv-button>
  32. <device-picker :visible.sync="openDevice" :selected.sync="selectDevice"
  33. @confirm="handleDeviceConfirm"></device-picker>
  34. <uni-table v-if="deviceList.length > 0">
  35. <uni-tr>
  36. <uni-th>序号</uni-th>
  37. <uni-th>出厂编号</uni-th>
  38. <uni-th>设备品牌</uni-th>
  39. <uni-th>设备名称</uni-th>
  40. <uni-th>规格型号</uni-th>
  41. <uni-th>存放地址</uni-th>
  42. </uni-tr>
  43. <uni-tr v-for="(item, index) in deviceList" :key="index">
  44. <uni-td>{{ index + 1 }}</uni-td>
  45. <uni-td>{{ item.code }}</uni-td>
  46. <uni-td>{{ item.brand }}</uni-td>
  47. <uni-td>{{ item.name }}</uni-td>
  48. <uni-td>{{ item.series }}</uni-td>
  49. <uni-td>{{ item.place }}</uni-td>
  50. </uni-tr>
  51. </uni-table>
  52. </uni-forms-item>
  53. <!-- 申领事由 -->
  54. <uni-forms-item label="申领事由" required class="form-item" name="applyReason">
  55. <uni-easyinput type="textarea" v-model="form.applyReason" placeholder="请输入申领事由"
  56. :disabled="taskName != '设备申请'" />
  57. </uni-forms-item>
  58. <!-- 日期选择 -->
  59. <view class="date-range">
  60. <uni-forms-item label="使用日期" required class="form-item" name="dateRange">
  61. <uni-datetime-picker v-model="dateRange" type="daterange" rangeSeparator="至" :clearIcon="false"
  62. :disabled="taskName != '设备申请'" @change="handleDateRangeChange" />
  63. </uni-forms-item>
  64. <uni-forms-item label="共计" class="form-item">
  65. <text>{{ form.days + '天' }}</text>
  66. </uni-forms-item>
  67. </view>
  68. <!-- 安排设备意见 -->
  69. <uni-forms-item label="拟发放设备" class="form-item" v-if="taskName == '安排设备'">
  70. <uni-table v-if="modifyDeviceList.length > 0">
  71. <uni-tr>
  72. <uni-th>序号</uni-th>
  73. <uni-th>出厂编号</uni-th>
  74. <uni-th>设备品牌</uni-th>
  75. <uni-th>设备名称</uni-th>
  76. <uni-th>规格型号</uni-th>
  77. <uni-th>存放地址</uni-th>
  78. <uni-th>操作</uni-th>
  79. </uni-tr>
  80. <uni-tr v-for="(item, index) in modifyDeviceList" :key="index">
  81. <uni-td>{{ index + 1 }}</uni-td>
  82. <uni-td>{{ item.code }}</uni-td>
  83. <uni-td>{{ item.brand }}</uni-td>
  84. <uni-td>{{ item.name }}</uni-td>
  85. <uni-td>{{ item.series }}</uni-td>
  86. <uni-td>{{ item.place }}</uni-td>
  87. <uni-td>
  88. <uv-button type="primary" size="mini" @click="replaceRowData(item, index)">重新选择</uv-button>
  89. <uv-button type="error" size="mini" @click="deleteRowData(item, index)">删除</uv-button>
  90. </uni-td>
  91. </uni-tr>
  92. </uni-table>
  93. <uv-button type="primary" @click="addRowdata()" v-if="taskName == '安排设备'">新增设备</uv-button>
  94. </uni-forms-item>
  95. <!-- 安排设备意见 -->
  96. <uni-forms-item label="安排设备意见" class="form-item" v-if="taskName == '安排设备'">
  97. <uni-easyinput type="textarea" v-model="form.dispatchComment" placeholder="请输入安排设备意见"
  98. :disabled="taskName != '安排设备'" />
  99. </uni-forms-item>
  100. <!-- 分管审核意见 -->
  101. <uni-forms-item label="分管审核意见" class="form-item" v-if="taskName == '分管审核'">
  102. <uni-easyinput type="textarea" v-model="form.managerComment" placeholder="请输入分管审核意见"
  103. :disabled="taskName != '分管审核'" />
  104. </uni-forms-item>
  105. <!-- 归还确认 -->
  106. <uni-forms-item label="已归还设备" class="form-item" v-if="taskName == '归还确认'">
  107. <uni-table v-if="returnDevicesList.length > 0">
  108. <uni-tr>
  109. <uni-th>序号</uni-th>
  110. <uni-th>出厂编号</uni-th>
  111. <uni-th>设备品牌</uni-th>
  112. <uni-th>设备名称</uni-th>
  113. <uni-th>规格型号</uni-th>
  114. <uni-th>存放地址</uni-th>
  115. </uni-tr>
  116. <uni-tr v-for="(item, index) in returnDevicesList" :key="index">
  117. <uni-td>{{ index + 1 }}</uni-td>
  118. <uni-td>{{ item.code }}</uni-td>
  119. <uni-td>{{ item.brand }}</uni-td>
  120. <uni-td>{{ item.name }}</uni-td>
  121. <uni-td>{{ item.series }}</uni-td>
  122. <uni-td>{{ item.place }}</uni-td>
  123. </uni-tr>
  124. </uni-table>
  125. </uni-forms-item>
  126. <!-- 需维修设备 -->
  127. <uni-forms-item label="需维修设备" class="form-item" v-if="taskName == '归还确认'">
  128. <uni-data-select v-model="form.repairDevices" :localdata="modifyDeviceList" multiple
  129. :disabled="taskName != '归还确认'" />
  130. </uni-forms-item>
  131. <!-- 备注 -->
  132. <uni-forms-item label="备注" class="form-item" v-if="taskName == '归还确认'">
  133. <uni-easyinput type="textarea" v-model="form.remark" placeholder="请输入备注" :disabled="taskName != '归还确认'" />
  134. </uni-forms-item>
  135. <!-- 归还日期 -->
  136. <uni-forms-item label="归还日期" class="form-item" v-if="taskName == '归还确认'">
  137. <uni-datetime-picker v-model="form.returnDate" type="date" :disabled="taskName != '归还确认'" />
  138. </uni-forms-item>
  139. <!-- 操作按钮 -->
  140. <view class="form-actions">
  141. <uv-button style="margin-bottom: 5px;" type="warning" @click="saves">保存</uv-button>
  142. <uv-button type="primary" @click="submit" v-if="taskName == '设备申请'">提交申请</uv-button>
  143. <template v-else>
  144. <uv-button type="primary" @click="completeApply">完成审批</uv-button>
  145. </template>
  146. </view>
  147. </uni-forms>
  148. </view>
  149. </template>
  150. <script>
  151. import { parseTime } from "@/utils/common.js"
  152. import { listDeviceApproval, getDeviceApproval, updateDeviceApproval, submitDeviceApproval, modifyDeviceApproval } from '@/api/oa/device/deviceApproval'
  153. import FlowNote from '@/pages/components/flowNote.vue';
  154. import ProjectPicker from '@/pages/components/ProjectPicker.vue';
  155. import ProjectInfo from '@/pages/components/ProjectInfo.vue';
  156. import DevicePicker from "@/pages/components/DevicePicker.vue";
  157. export default {
  158. components: {
  159. FlowNote,
  160. ProjectPicker,
  161. ProjectInfo,
  162. DevicePicker
  163. },
  164. props: {
  165. taskForm: Object,
  166. taskName: String,
  167. startUserName: String,
  168. },
  169. created() {
  170. this.applierUserName = this.startUserName;
  171. this.initForm();
  172. },
  173. data() {
  174. return {
  175. form: {
  176. user: {
  177. nickName: ''
  178. },
  179. dept: {
  180. deptName: ''
  181. },
  182. projectId: '',
  183. applyDate: '',
  184. applyReason: '',
  185. beginDate: '',
  186. endDate: '',
  187. days: 0,
  188. dispatchComment: '',
  189. managerComment: '',
  190. devices: [],
  191. repairDevices: [],
  192. remark: '',
  193. returnDate: ''
  194. },
  195. dateRange: [],
  196. rules: {
  197. projectId: {
  198. rules: [{ required: true, errorMessage: '请选择项目' }]
  199. },
  200. devices: {
  201. rules: [{ required: true, errorMessage: '请选择设备' }]
  202. },
  203. applyReason: {
  204. rules: [{ required: true, errorMessage: '请输入申领事由' }]
  205. },
  206. dateRange: {
  207. rules: [{ required: true, errorMessage: '请选择使用日期' }]
  208. }
  209. },
  210. applierUserName: '',
  211. openProject: false,
  212. selectedProject: null,
  213. projectObj: {},
  214. openDevice: false,
  215. selectDevice: [],
  216. deviceList: [],
  217. modifyDeviceList: [],
  218. returnDevicesList: [],
  219. formTotal: 0
  220. };
  221. },
  222. methods: {
  223. initForm() {
  224. getDeviceApproval(this.taskForm.formId).then(res => {
  225. if (res.data) {
  226. this.formTotal = 1;
  227. this.form = res.data;
  228. this.deviceList = res.data.devices || [];
  229. this.modifyDeviceList = res.data.modifyDevices || [];
  230. this.returnDevicesList = res.data.returnDevices || [];
  231. if (this.form.beginDate && this.form.endDate) {
  232. this.dateRange = [this.form.beginDate, this.form.endDate];
  233. }
  234. } else {
  235. this.form.applier = this.$store.getters.userId;
  236. this.form.applyDate = parseTime(new Date(), "{y}-{m}-{d}");
  237. let name = this.applierUserName.split('-');
  238. this.form.user.nickName = name[0];
  239. this.form.dept.deptName = name[1];
  240. this.formTotal = 0;
  241. }
  242. });
  243. },
  244. handleConfirm(project) {
  245. this.selectedProject = project;
  246. this.projectObj = project;
  247. this.form.projectId = project.projectId;
  248. },
  249. handleDeviceConfirm(devices) {
  250. this.deviceList = Array.isArray(devices) ? devices : [devices];
  251. this.form.devices = this.deviceList.map(item => item.deviceId);
  252. },
  253. handleDateRangeChange(e) {
  254. if (Array.isArray(e) && e.length === 2) {
  255. const [start, end] = e;
  256. this.form.beginDate = start;
  257. this.form.endDate = end;
  258. this.calculateDay();
  259. }
  260. },
  261. calculateDay() {
  262. if (this.form.beginDate && this.form.endDate) {
  263. const begin = new Date(this.form.beginDate);
  264. const end = new Date(this.form.endDate);
  265. if (!isNaN(begin.getTime()) && !isNaN(end.getTime())) {
  266. this.form.days = Math.ceil((end - begin) / (1000 * 60 * 60 * 24)) + 1;
  267. }
  268. }
  269. },
  270. replaceRowData(row, index) {
  271. this.openDevice = true;
  272. this.currentIndex = index;
  273. },
  274. deleteRowData(row, index) {
  275. this.modifyDeviceList.splice(index, 1);
  276. },
  277. addRowdata() {
  278. this.openDevice = true;
  279. this.currentIndex = -1;
  280. },
  281. submit() {
  282. this.$refs.form.validate().then(() => {
  283. submitDeviceApproval(this.form).then(res => {
  284. uni.showToast({
  285. title: '提交成功',
  286. icon: 'success'
  287. });
  288. uni.navigateBack();
  289. });
  290. });
  291. },
  292. saves() {
  293. try {
  294. // 构建提交数据
  295. let submitData = {
  296. ...this.form,
  297. formId: this.taskForm.formId,
  298. deviceApplyId: this.taskForm.formId,
  299. };
  300. let formData = new FormData();
  301. let jsonForm = JSON.stringify(submitData);
  302. formData.append("form", jsonForm);
  303. console.log(formData.get('form'));
  304. // 根据表单状态选择接口
  305. if (this.formTotal !== 0) {
  306. modifyDeviceApproval(formData).then(res => {
  307. console.log('修改响应:', res);
  308. if (res.code === 200) {
  309. uni.showToast({
  310. title: '保存成功',
  311. icon: 'success'
  312. });
  313. } else {
  314. uni.showToast({
  315. title: res.msg || '保存失败',
  316. icon: 'error'
  317. });
  318. }
  319. }).catch(error => {
  320. console.error('修改错误:', error);
  321. uni.showToast({
  322. title: error.message || '保存失败',
  323. icon: 'error'
  324. });
  325. });
  326. } else {
  327. submitDeviceApproval(formData).then(res => {
  328. console.log('提交响应:', res);
  329. if (res.code === 200) {
  330. uni.showToast({
  331. title: '保存成功',
  332. icon: 'success'
  333. });
  334. } else {
  335. uni.showToast({
  336. title: res.msg || '保存失败',
  337. icon: 'error'
  338. });
  339. }
  340. }).catch(error => {
  341. console.error('提交错误:', error);
  342. uni.showToast({
  343. title: error.message || '保存失败',
  344. icon: 'error'
  345. });
  346. });
  347. }
  348. } catch (error) {
  349. console.error('保存方法错误:', error);
  350. uni.showToast({
  351. title: error.message || '保存失败',
  352. icon: 'error'
  353. });
  354. }
  355. },
  356. completeApply() {
  357. modifyDeviceApproval(this.form).then(res => {
  358. uni.showToast({
  359. title: '审批完成',
  360. icon: 'success'
  361. });
  362. uni.navigateBack();
  363. });
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .form-container {
  370. padding: 32rpx;
  371. }
  372. .form-title {
  373. text-align: center;
  374. margin-bottom: 32rpx;
  375. .title-text {
  376. font-size: 36rpx;
  377. font-weight: bold;
  378. }
  379. .title-line {
  380. height: 2rpx;
  381. background: #eee;
  382. margin-top: 16rpx;
  383. }
  384. }
  385. .date-range {
  386. // display: flex;
  387. flex-wrap: wrap;
  388. gap: 32rpx;
  389. }
  390. .form-actions {
  391. justify-content: center;
  392. gap: 32rpx;
  393. margin-top: 32rpx;
  394. }
  395. ::v-deep .uni-forms-item__label {
  396. font-weight: bold;
  397. }
  398. </style>