index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <view class="page-container">
  3. <view class="page-body">
  4. <u--form label-width="auto" labelAlign="left"
  5. ref="uForm"
  6. :model="model"
  7. :rules="rules"
  8. :labelStyle="{
  9. fontSize: '28rpx',
  10. fontWeight: '500',
  11. }"
  12. >
  13. <u-cell-group :border="false">
  14. <view class="box">
  15. <template>
  16. <u-cell title="申领人" :border="true" :isLink="false" :clickable="false"
  17. @click="$refs.userChooseRef.show()"
  18. >
  19. <view slot="value">
  20. <u-form-item label="">
  21. {{renderItem(model.form,'outflowUser','--')}}
  22. </u-form-item>
  23. </view>
  24. </u-cell>
  25. <tq-car-user ref="userChooseRef"
  26. :isGetIcon="false"
  27. :queryType="1"
  28. @confirm="(data) => {
  29. model.form.outflowUserId = data.id
  30. model.form.outflowUser = data.label
  31. model.form.deptId = data.deptId
  32. model.form.deptName = data.deptName
  33. }"
  34. >
  35. </tq-car-user>
  36. </template>
  37. <u-cell title="申领部门" :border="true" :isLink="false" :clickable="false">
  38. <view slot="value" class="value">
  39. <u-form-item label="">
  40. {{renderItem(model.form,'deptName','--')}}
  41. </u-form-item>
  42. </view>
  43. </u-cell>
  44. <template>
  45. <u-cell :border="true" :isLink="true" :clickable="true" class="hidde-cell-title"
  46. @click="$refs.selectRef.show()"
  47. >
  48. <view slot="value" class="value">
  49. <u-form-item label="申领类型" prop="form.outflowType" :required="true">
  50. <u--input
  51. :value="model.form.outflowTypeName"
  52. placeholder="请选择"
  53. border="none"
  54. inputAlign="right"
  55. :disabled="true"
  56. disabledColor="none"
  57. :customStyle="{
  58. pointerEvents: 'none',
  59. }"
  60. >
  61. </u--input>
  62. </u-form-item>
  63. </view>
  64. </u-cell>
  65. <tq-dict-select ref="selectRef"
  66. dictType="get_type_type"
  67. @confirm="(data) => {
  68. model.form.outflowType = data.dictValue
  69. model.form.outflowTypeName = data.dictLabel
  70. $refs.uForm.validateField('form.outflowType')
  71. }"
  72. >
  73. </tq-dict-select>
  74. </template>
  75. <template v-if="model.form.outflowType==1">
  76. <u-cell :border="true" :isLink="true" class="hidde-cell-title"
  77. @click="$refs.backDateRef.show()"
  78. >
  79. <view slot="value" class="value">
  80. <u-form-item label="预计归还日期" prop="form.backDate" :required="true">
  81. <u--input
  82. :value="model.form.backDate"
  83. placeholder="请选择"
  84. border="none"
  85. inputAlign="right"
  86. :disabled="true"
  87. disabledColor="none"
  88. :customStyle="{
  89. pointerEvents: 'none',
  90. }"
  91. >
  92. </u--input>
  93. </u-form-item>
  94. </view>
  95. </u-cell>
  96. <tq-date-time ref="backDateRef"
  97. mode="date"
  98. format="YYYY-MM-DD"
  99. @confirm="(data) => {
  100. model.form.backDate = data
  101. $refs.uForm.validateField('form.backDate')
  102. }"
  103. >
  104. </tq-date-time>
  105. </template>
  106. <u-cell :border="false" :isLink="false" :clickable="false" class="hidde-cell-title">
  107. <view slot="value" class="value">
  108. <u-form-item label="备注" labelPosition="top" prop="form.remark" :required="false">
  109. <u--textarea
  110. v-model="model.form.remark"
  111. placeholder="请输入备注"
  112. border="none"
  113. :count="true"
  114. maxlength="200"
  115. >
  116. </u--textarea>
  117. </u-form-item>
  118. </view>
  119. </u-cell>
  120. </view>
  121. <view class="box">
  122. <template>
  123. <u-cell :border="true" :isLink="true" :clickable="true" class="hidde-cell-title"
  124. @click="$refs.materialListRef.show()"
  125. >
  126. <view slot="value" class="value">
  127. <u-form-item label="选择物品" prop="form.outList" :required="true">
  128. <u--input
  129. :value="model.form.materialName"
  130. placeholder=""
  131. border="none"
  132. inputAlign="right"
  133. :disabled="true"
  134. disabledColor="none"
  135. :customStyle="{
  136. pointerEvents: 'none',
  137. }"
  138. >
  139. </u--input>
  140. </u-form-item>
  141. </view>
  142. </u-cell>
  143. <tq-search-select ref="materialListRef"
  144. :multiple="true"
  145. :dataList = "materialList"
  146. @confirm="updateMeterial"
  147. :objMap="{
  148. label: 'materialName',
  149. value: 'materialId',
  150. }"
  151. :hasTip="true"
  152. >
  153. </tq-search-select>
  154. </template>
  155. </view>
  156. <template v-for="(sitem,index) in model.form.outList">
  157. <u-form :model="sitem" :ref="`outListRef`" :key="index" label-width="auto" labelAlign="left">
  158. <view class="box">
  159. <u-row>
  160. <u-col :span="10">
  161. <u-cell :border="true" :isLink="false" :clickable="false" class="hidde-cell-title">
  162. <view slot="value" class="value">
  163. <u-form-item label="物品名称:" prop="" :required="false">
  164. <view class="disflex-right" style="width:100%;">{{sitem.materialName}}</view>
  165. </u-form-item>
  166. </view>
  167. </u-cell>
  168. <u-cell :border="true" :isLink="false" :clickable="false" class="hidde-cell-title">
  169. <view slot="value" class="value">
  170. <u-form-item label="申领数量:" prop="num" :required="true">
  171. <u--input
  172. v-model="sitem.num"
  173. placeholder="请输入"
  174. border="none"
  175. type="number"
  176. :clearable="true"
  177. inputAlign="right"
  178. maxlength="10"
  179. @change="handleNumChange(sitem,index)"
  180. >
  181. </u--input>
  182. </u-form-item>
  183. </view>
  184. </u-cell>
  185. </u-col>
  186. <u-col :span="2">
  187. <view class="disflex-center" @click="deleteItem(index)">
  188. <u-icon name="minus-circle-fill" color="red" size="28"></u-icon>
  189. </view>
  190. </u-col>
  191. </u-row>
  192. </view>
  193. </u-form>
  194. </template>
  195. </u-cell-group>
  196. </u--form>
  197. </view>
  198. <view class="page-footer">
  199. <u-row style="margin-top: 40rpx;">
  200. <u-col :span="6">
  201. <u-button type="info" shape="" :hairline="false" :custom-style="{
  202. width: '100%',
  203. borderRadius: '0',
  204. background: '#FFF',
  205. height: '100rpx',
  206. fontSize: '32rpx',
  207. fontWeight: '500',
  208. }" @click="handleClear">清空
  209. </u-button>
  210. </u-col>
  211. <u-col :span="6">
  212. <u-button type="primary" shape="" :hairline="false"
  213. :custom-style="{
  214. width: '100%',
  215. borderRadius: '0',
  216. height: '100rpx',
  217. fontSize: '32rpx',
  218. fontWeight: '500',
  219. background:'linear-gradient(to right, #41B5FF, #4573FC)'
  220. }" @click="handleSubmit">提交
  221. </u-button>
  222. </u-col>
  223. </u-row>
  224. </view>
  225. </view>
  226. </template>
  227. <script>
  228. import {userProfile} from '@/api/common/user.js'
  229. import {addMaterialApply,queryOneById,queryMaterialList} from '@/api/system/material.js'
  230. import {clearProps,copyProps} from '@/utils/gdtq.js'
  231. import {isEmpty} from 'lodash'
  232. export default {
  233. components: {
  234. },
  235. data() {
  236. return {
  237. model: {
  238. form: {
  239. outflowUserId: "",
  240. outflowUser: "",
  241. deptId: "",
  242. deptName: "",
  243. outflowType: "",
  244. outflowTypeName: "",
  245. backDate: "",
  246. remark: "",
  247. // materialId: "",
  248. // materialName: "",
  249. outList: [
  250. /* {
  251. materialId: 1,
  252. materialName: 'testest',
  253. amountTotal: 0,
  254. num: ''
  255. } */
  256. ],
  257. }
  258. },
  259. rules: {
  260. 'form.outflowType': [
  261. {
  262. type: 'string',
  263. required: true,
  264. message: '请选择',
  265. trigger: ['blur', 'change']
  266. },
  267. ],
  268. 'form.backDate': {
  269. type: 'string',
  270. required: true,
  271. message: '请选择',
  272. trigger: ['blur', 'change']
  273. },
  274. 'form.outList': {
  275. type: 'array',
  276. required: true,
  277. message: '请选择',
  278. trigger: ['blur', 'change']
  279. },
  280. },
  281. /* 物品数组校验规则 start */
  282. outListRules: {
  283. num: [
  284. {
  285. type: 'number' ,
  286. required: true,
  287. message: '请输入',
  288. trigger: ['blur', 'change']
  289. },
  290. {
  291. pattern: /^[1-9]\d*$/g,
  292. // 正则检验前先将值转为字符串
  293. transform(value) {
  294. return String(value);
  295. },
  296. message: '请输入大于0的正整数',
  297. // 触发器可以同时用blur和change
  298. trigger: ['change','blur'],
  299. }
  300. ],
  301. },
  302. materialList: [],
  303. userInfo: null,
  304. }
  305. },
  306. onLoad({id}) {
  307. // console.log(id,'id')
  308. this.queryMaterialListData()
  309. if(id) {
  310. this.getInfo(id)
  311. } else {
  312. this.getUserInfo()
  313. }
  314. },
  315. onShow() {
  316. },
  317. onHide() {
  318. },
  319. onReady() {
  320. this.resetRules()
  321. },
  322. methods: {
  323. resetRules() {
  324. this.$refs.uForm.setRules(this.rules)
  325. for (let i in this.model.form.outList) {
  326. this.$refs.outListRef[i].setRules(this.outListRules);
  327. }
  328. },
  329. async queryMaterialListData() {
  330. let {code,data} = await queryMaterialList({})
  331. if(code == 0) {
  332. this.materialList = data.map((e) => {
  333. return {
  334. ...e,
  335. tip: `(可用库存${e.amountTotal})`,
  336. disabled: !(e.amountTotal>0)
  337. }
  338. })
  339. }
  340. },
  341. async getInfo(id) {
  342. let {code,data} = await queryOneById({id})
  343. if(code == 0) {
  344. copyProps(this.model.form,data)
  345. }
  346. },
  347. getUserInfo() {
  348. userProfile().then((res) => {
  349. this.userInfo = res.data
  350. this.model.form.outflowUserId = res.data.userId
  351. this.model.form.outflowUser = res.data.nickName
  352. this.model.form.deptId = res.data.deptId
  353. this.model.form.deptName = res.data.deptName
  354. })
  355. },
  356. // 提交
  357. async handleSubmit() {
  358. for (let i in this.model.form.outList) {
  359. this.$refs.outListRef[i].validate(valid => {
  360. if (!valid) return
  361. })
  362. }
  363. this.$refs.uForm.validate().then(async res => {
  364. for (let i in this.model.form.outList) {
  365. await this.$refs.outListRef[i].validate()
  366. }
  367. let ajaxData = {
  368. ...this.model.form,
  369. }
  370. let { data, code,msg } = await addMaterialApply(ajaxData)
  371. if (code == 0) {
  372. uni.showModal({
  373. title: '提示',
  374. content: `提交成功~`,
  375. showCancel:false,
  376. confirmText: '好的',
  377. success: function(res) {
  378. if (res.confirm) {
  379. uni.switchTab({url: '/pages/index/index'})
  380. }
  381. }
  382. })
  383. }
  384. }).catch(errors => {
  385. console.log('校验失败',errors)
  386. })
  387. },
  388. handleClear() {
  389. clearProps(this.model.form,['outflowUserId','outflowUser','deptId','deptName'])
  390. },
  391. updateMeterial(data) {
  392. // console.log(data,'data')
  393. if(!isEmpty(data)) {
  394. this.model.form.outList = data.map((e) => {
  395. return {
  396. materialId: e.materialId,
  397. materialName: e.materialName,
  398. amountTotal: e.amountTotal,
  399. num: ''
  400. }
  401. })
  402. } else {
  403. this.model.form.outList = []
  404. }
  405. this.model.form.materialId = data.materialId
  406. this.model.form.materialName = data.materialName
  407. this.$refs.uForm.validateField('form.outList')
  408. this.$nextTick(() => {
  409. this.resetRules()
  410. })
  411. },
  412. deleteItem(index) {
  413. this.model.form.outList.splice(index, 1)
  414. this.$nextTick(() => {
  415. this.resetRules()
  416. })
  417. },
  418. handleNumChange(row,index) {
  419. if(row.materialId) {
  420. if(row.num > row.amountTotal) {
  421. this.$modal.msg(`已超过可用申领数${row.amountTotal}`)
  422. // row.num = row.amountTotal
  423. }
  424. } else {
  425. this.$modal.msg('请先选择物品')
  426. row.num = ''
  427. }
  428. }
  429. }
  430. }
  431. </script>
  432. <style lang="scss" scoped>
  433. .disflex-center {
  434. display: flex;
  435. justify-content: center;
  436. align-items: center;
  437. }
  438. .disflex-right {
  439. display: flex;
  440. justify-content: right;
  441. align-items: center;
  442. }
  443. .page-container {
  444. font-size: 28rpx;
  445. min-height: 100%;
  446. position: relative;
  447. // padding-bottom: 60rpx;
  448. .box {
  449. margin: 20rpx;
  450. border-radius: 10rpx;
  451. background: #fff;
  452. }
  453. .page-body {
  454. padding-bottom: 120rpx;
  455. }
  456. .page-footer {
  457. padding: 0rpx 0;
  458. position: fixed;
  459. width: 100%;
  460. left: 0;
  461. bottom: 0;
  462. }
  463. }
  464. ::v-deep {
  465. .u-form-item__body {
  466. padding: 0;
  467. }
  468. .hidde-cell-title {
  469. .u-cell__body__content {
  470. width: auto;
  471. flex: none;
  472. }
  473. .u-cell__body {
  474. .value {
  475. flex: 1;
  476. }
  477. }
  478. }
  479. }
  480. </style>