PurchaseForm.vue 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <template>
  2. <view>
  3. <cu-custom :backUrl="'/pages/index/index'" :isBack="true" bgColor="bg-gradual-blue" >
  4. <block slot="content">采购申请</block>
  5. </cu-custom>
  6. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  7. <u-form-item label="采购编号" borderBottom prop="purchaseNo">
  8. <u--input placeholder='自动生成' v-model="inputForm.purchaseNo" disabled></u--input>
  9. </u-form-item>
  10. <u-form-item label="采购名称" borderBottom prop="purchaseSketch" :required="true">
  11. <u--input placeholder='请填写采购名称' v-model="inputForm.purchaseSketch" ></u--input>
  12. </u-form-item>
  13. <u-form-item label="经办人" borderBottom prop="handledBy">
  14. <u--input placeholder='' v-model="inputForm.handledBy" disabled></u--input>
  15. </u-form-item>
  16. <u-form-item label="经办人部门" borderBottom prop="handledByOfficeName">
  17. <u--input placeholder='' v-model="inputForm.handledByOfficeName" disabled></u--input>
  18. </u-form-item>
  19. <u-form-item label="采购申请时间" borderBottom prop="purchaseDate" :required="true">
  20. <el-date-picker
  21. v-model="inputForm.purchaseDate"
  22. type="date"
  23. placeholder="请选择采购申请时间"
  24. style="width:100%"
  25. size="default"
  26. placement="bottom-start"
  27. clearable>
  28. </el-date-picker>
  29. </u-form-item>
  30. <u-form-item label="采购方式" borderBottom prop="purchaseMode" :required="true">
  31. <jp-picker placeholder='请选择采购方式' v-model="inputForm.purchaseMode" rangeKey="label" rangeValue="value" :range="[
  32. { label: '办公室采购', value: '1' },
  33. { label: '自行采购', value: '2' },
  34. ]"></jp-picker>
  35. </u-form-item>
  36. <u-form-item label="备注" borderBottom prop="remarks">
  37. <u--textarea placeholder='请填写备注信息' :rows="5" :maxlength="500" v-model="inputForm.remarks" ></u--textarea>
  38. </u-form-item>
  39. <el-row :gutter="15" :key="index_experience" v-for="(item,index_experience) in this.inputForm.detailInfos">
  40. <el-col :span="24">
  41. <u-form-item label="" >
  42. <el-divider content-position="left"> 采购详情 {{index_experience + 1}}</el-divider>
  43. </u-form-item>
  44. </el-col>
  45. <el-col :span="24">
  46. <u-form-item label="采购人" :prop="'detailInfos[' + index_experience + '].purchaserAgent'" :required="true"
  47. :rules="[
  48. ]">
  49. <u--input v-model="inputForm.detailInfos[index_experience].purchaserAgent" placeholder="请选择采购人" @focus="openUserPullForm(index_experience)" clearable></u--input>
  50. </u-form-item>
  51. <u-form-item label="采购人部门" :prop="'detailInfos[' + index_experience + '].procurementOffice'" :required="true"
  52. :rules="[
  53. ]">
  54. <u--input v-model="inputForm.detailInfos[index_experience].procurementOffice" placeholder="" clearable></u--input>
  55. </u-form-item>
  56. <u-form-item label="采购类型" :prop="'detailInfos[' + index_experience + '].procurementType'" :required="true"
  57. :rules="[
  58. ]">
  59. <u--input v-model="inputForm.detailInfos[index_experience].procurementType" placeholder="请选择采购类型" @focus="showPicker(index_experience)" clearable></u--input>
  60. </u-form-item>
  61. <my-dropdown :index_experience="index_experience" :inputForm="inputForm"></my-dropdown>
  62. <!--<u-form-item label="商品名称" :prop="'detailInfos[' + index_experience + '].tradeName'"
  63. :rules="[
  64. ]">
  65. <u--input v-model="inputForm.detailInfos[index_experience].tradeName" placeholder="请选择物品名称" clearable></u--input>
  66. </u-form-item>-->
  67. <supplier-selector :index_experience="index_experience" :inputForm="inputForm"></supplier-selector>
  68. <!-- <u-form-item label="供应商" :prop="'detailInfos[' + index_experience + '].supplierName'" -->
  69. <!-- :rules="[-->
  70. <!-- ]">-->
  71. <!-- <u--input v-model="inputForm.detailInfos[index_experience].supplierName" placeholder="请选择供应商" @focus="showGoods(index_experience)" clearable></u--input>-->
  72. <!-- </u-form-item>-->
  73. <u-form-item label="商品单价(元)" :prop="'detailInfos[' + index_experience + '].tradePrice'"
  74. :rules="[
  75. ]">
  76. <u--input @blur="onInputCode(index_experience, $event,'tradePrice')" v-model="inputForm.detailInfos[index_experience].tradePrice" placeholder="请输入商品单价(元)" clearable></u--input>
  77. </u-form-item>
  78. <u-form-item label="商品数量" :prop="'detailInfos[' + index_experience + '].tradeNumber'"
  79. :rules="[
  80. ]">
  81. <u--input @blur="onInputCode(index_experience, $event,'tradeNumber')" v-model="inputForm.detailInfos[index_experience].tradeNumber" placeholder="请输入商品数量" clearable></u--input>
  82. </u-form-item>
  83. <u-form-item label="商品总价" :prop="'detailInfos[' + index_experience + '].priceSum'"
  84. :rules="[
  85. ]">
  86. <u--input v-model="inputForm.detailInfos[index_experience].priceSum" placeholder="请输入商品总价" :readonly="true" clearable></u--input>
  87. </u-form-item>
  88. <u-form-item label="单位" :prop="'detailInfos[' + index_experience + '].company'"
  89. :rules="[
  90. ]">
  91. <u--input v-model="inputForm.detailInfos[index_experience].company" placeholder="请输入单位" clearable></u--input>
  92. </u-form-item>
  93. <u-form-item label="备注" :prop="'detailInfos[' + index_experience + '].remarks'"
  94. :rules="[
  95. ]">
  96. <u--input v-model="inputForm.detailInfos[index_experience].remarks" placeholder="请输入备注" clearable></u--input>
  97. </u-form-item>
  98. <u-form-item label="文件上传">
  99. <el-upload
  100. class="upload-demo"
  101. :action="`http://cpaoa.xgccpm.com/api/public-modules-server/oss/file/webUpload/upload`"
  102. :on-remove="(file, fileList) => handleRemove(file, fileList, index_experience,'detail')"
  103. :file-list="inputForm.detailInfos[index_experience].fileInfoLost"
  104. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,index_experience,'detail')"
  105. :limit="3">
  106. <el-button size="small" type="primary">点击上传</el-button>
  107. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  108. <template slot="file" slot-scope="{ file }" v-if="shouldShowFile(file,index_experience,'detail') || testFlag">
  109. <span @click="handleFileClick(file)">{{ file.name }}</span>
  110. <el-button type="text" icon="el-icon-close" @click="handleDelete(file,index_experience,'detail')">✕</el-button>
  111. </template>
  112. </el-upload>
  113. </u-form-item>
  114. </el-col>
  115. <el-col :span="24" style="text-align: center">
  116. <u-form-item label="" >
  117. <el-button style="width: 100%" type="danger" @click="removeRow(index_experience)" plain>删除采购详情 {{index_experience + 1}}</el-button>
  118. </u-form-item>
  119. </el-col>
  120. </el-row>
  121. <u-form-item label="" >
  122. <el-button style="width: 100%" type="primary" @click="addRow()" plain>新增采购详情</el-button>
  123. </u-form-item>
  124. <u-form-item label="附件">
  125. <el-upload
  126. class="upload-demo"
  127. :action="`http://cpaoa.xgccpm.com/api/public-modules-server/oss/file/webUpload/upload`"
  128. :on-remove="(file, fileList) => handleRemove(file, fileList, '','')"
  129. :file-list="inputForm.files"
  130. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,'','')"
  131. :limit="3">
  132. <el-button size="small" type="primary">点击上传</el-button>
  133. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  134. <template slot="file" slot-scope="{ file }" v-if="shouldShowFile(file) || testFlag">
  135. <span @click="handleFileClick(file)">{{ file.name }}</span>
  136. <el-button type="text" icon="el-icon-close" @click="handleDelete(file)">✕</el-button>
  137. </template>
  138. </el-upload>
  139. </u-form-item>
  140. </u--form>
  141. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-else-if="nodeFlag">
  142. <u-form-item label="采购编号" borderBottom prop="purchaseNo">
  143. <u--input placeholder='自动生成' v-model="inputForm.purchaseNo" disabled></u--input>
  144. </u-form-item>
  145. <u-form-item label="采购名称" borderBottom prop="purchaseSketch" :required="true">
  146. <u--input placeholder='请填写采购名称' disabled v-model="inputForm.purchaseSketch" ></u--input>
  147. </u-form-item>
  148. <u-form-item label="经办人" borderBottom prop="handledBy">
  149. <u--input placeholder='' v-model="inputForm.handledBy" disabled></u--input>
  150. </u-form-item>
  151. <u-form-item label="经办人部门" borderBottom prop="handledByOfficeName">
  152. <u--input placeholder='' v-model="inputForm.handledByOfficeName" disabled></u--input>
  153. </u-form-item>
  154. <u-form-item label="采购申请时间" borderBottom prop="purchaseDate" :required="true">
  155. <el-date-picker
  156. :disabled="true"
  157. v-model="inputForm.purchaseDate"
  158. type="date"
  159. placeholder="请选择采购申请时间"
  160. style="width:100%"
  161. size="default"
  162. placement="bottom-start"
  163. clearable>
  164. </el-date-picker>
  165. </u-form-item>
  166. <u-form-item label="采购方式" borderBottom prop="purchaseMode" :required="true">
  167. <jp-picker placeholder='请选择采购方式' v-model="inputForm.purchaseMode" :disabled="true" rangeKey="label" rangeValue="value" :range="[
  168. { label: '办公室采购', value: '1' },
  169. { label: '自行采购', value: '2' },
  170. ]"></jp-picker>
  171. </u-form-item>
  172. <u-form-item label="备注" borderBottom prop="remarks">
  173. <u--textarea placeholder='请填写备注信息' :disabled="true" :rows="5" :maxlength="500" v-model="inputForm.remarks" ></u--textarea>
  174. </u-form-item>
  175. <el-row :gutter="15" :key="index_experience" v-for="(item,index_experience) in this.inputForm.detailInfos">
  176. <el-col :span="24">
  177. <u-form-item label="" >
  178. <el-divider content-position="left"> 采购详情 {{index_experience + 1}}</el-divider>
  179. </u-form-item>
  180. </el-col>
  181. <el-col :span="24">
  182. <u-form-item label="采购人" :prop="'detailInfos[' + index_experience + '].purchaserAgent'" :required="true"
  183. :rules="[
  184. ]">
  185. <el-input v-model="inputForm.detailInfos[index_experience].purchaserAgent" :disabled="true" placeholder="请选择采购人" @focus="openUserPullForm(index_experience)" clearable></el-input>
  186. </u-form-item>
  187. <u-form-item label="采购人部门" :prop="'detailInfos[' + index_experience + '].procurementOffice'" :required="true"
  188. :rules="[
  189. ]">
  190. <el-input v-model="inputForm.detailInfos[index_experience].procurementOffice" :disabled="true" placeholder="" clearable></el-input>
  191. </u-form-item>
  192. <u-form-item label="采购类型" :prop="'detailInfos[' + index_experience + '].procurementType'" :required="true"
  193. :rules="[
  194. ]">
  195. <el-input v-model="inputForm.detailInfos[index_experience].procurementType" :disabled="true" placeholder="请选择采购类型" @focus="showPicker(index_experience)" clearable></el-input>
  196. </u-form-item>
  197. <my-dropdown :index_experience="index_experience" :disabled="true" :inputForm="inputForm"></my-dropdown>
  198. <!-- <u-form-item label="商品名称" :prop="'detailInfos[' + index_experience + '].tradeName'" -->
  199. <!-- :rules="[-->
  200. <!-- ]">-->
  201. <!-- <el-input v-model="inputForm.detailInfos[index_experience].tradeName" placeholder="请选择物品名称" @focus="showGoods(index_experience)" clearable></el-input>-->
  202. <!-- </u-form-item>-->
  203. <supplier-selector :index_experience="index_experience" :disabled="true" :inputForm="inputForm"></supplier-selector>
  204. <!-- <u-form-item label="供应商" :prop="'detailInfos[' + index_experience + '].supplierName'" -->
  205. <!-- :rules="[-->
  206. <!-- ]">-->
  207. <!-- <el-input v-model="inputForm.detailInfos[index_experience].supplierName" placeholder="请选择供应商" @focus="showGoods(index_experience)" clearable></el-input>-->
  208. <!-- </u-form-item>-->
  209. <u-form-item label="商品单价(元)" :prop="'detailInfos[' + index_experience + '].tradePrice'"
  210. :rules="[
  211. ]">
  212. <el-input @change="changeValue" :disabled="true" v-model="inputForm.detailInfos[index_experience].tradePrice" placeholder="请输入商品单价(元)" clearable></el-input>
  213. </u-form-item>
  214. <u-form-item label="商品数量" :prop="'detailInfos[' + index_experience + '].tradeNumber'"
  215. :rules="[
  216. ]">
  217. <el-input @change="changeValue" v-model="inputForm.detailInfos[index_experience].tradeNumber" :disabled="true" placeholder="请输入商品数量" clearable></el-input>
  218. </u-form-item>
  219. <u-form-item label="商品总价" :prop="'detailInfos[' + index_experience + '].priceSum'"
  220. :rules="[
  221. ]">
  222. <el-input v-model="inputForm.detailInfos[index_experience].priceSum" :disabled="true" placeholder="请输入商品总价" clearable></el-input>
  223. </u-form-item>
  224. <u-form-item label="单位" :prop="'detailInfos[' + index_experience + '].company'"
  225. :rules="[
  226. ]">
  227. <el-input v-model="inputForm.detailInfos[index_experience].company" :disabled="true" placeholder="请输入单位" clearable></el-input>
  228. </u-form-item>
  229. <u-form-item label="备注" :prop="'detailInfos[' + index_experience + '].remarks'"
  230. :rules="[
  231. ]">
  232. <el-input v-model="inputForm.detailInfos[index_experience].remarks" :disabled="true" placeholder="请输入备注" clearable></el-input>
  233. </u-form-item>
  234. <u-form-item label="文件上传">
  235. <el-upload
  236. :disabled="true"
  237. class="upload-demo"
  238. :action="`http://cpaoa.xgccpm.com/api/public-modules-server/oss/file/webUpload/upload`"
  239. :on-remove="(file, fileList) => handleRemove(file, fileList, index_experience,'detail')"
  240. :file-list="inputForm.detailInfos[index_experience].fileInfoLost"
  241. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,index_experience,'detail')"
  242. :limit="3">
  243. <el-button size="small" :disabled="true" type="primary">点击上传</el-button>
  244. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  245. <template slot="file" slot-scope="{ file }" v-if="shouldShowFile(file,index_experience,'detail') || testFlag">
  246. <span @click="handleFileClick(file)">{{ file.name }}</span>
  247. <el-button type="text" icon="el-icon-close" @click="handleDelete(file,index_experience,'detail')">✕</el-button>
  248. </template>
  249. </el-upload>
  250. </u-form-item>
  251. </el-col>
  252. <el-col :span="24" style="text-align: center">
  253. <u-form-item label="" >
  254. <el-button style="width: 100%" :disabled="true" type="danger" @click="removeRow(index_experience)" plain>删除采购详情 {{index_experience + 1}}</el-button>
  255. </u-form-item>
  256. </el-col>
  257. </el-row>
  258. <u-form-item label="" >
  259. <el-button style="width: 100%" type="primary" :disabled="true" @click="addRow()" plain>新增采购详情</el-button>
  260. </u-form-item>
  261. <u-form-item label="附件">
  262. <el-upload
  263. :disabled="true"
  264. class="upload-demo"
  265. :action="`http://cpaoa.xgccpm.com/api/public-modules-server/oss/file/webUpload/upload`"
  266. :on-remove="(file, fileList) => handleRemove(file, fileList, '','')"
  267. :file-list="inputForm.files"
  268. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,'','')"
  269. :limit="3">
  270. <el-button size="small" :disabled="true" type="primary">点击上传</el-button>
  271. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  272. <template slot="file" slot-scope="{ file }" v-if="shouldShowFile(file) || testFlag">
  273. <span @click="handleFileClick(file)">{{ file.name }}</span>
  274. <el-button type="text" icon="el-icon-close" @click="handleDelete(file)">✕</el-button>
  275. </template>
  276. </el-upload>
  277. </u-form-item>
  278. </u--form>
  279. <user-select ref="userPicker" @input="handleEvent"></user-select>
  280. <ba-tree-picker ref="treePicker" :multiple='false' @select-change="selectChange" title="类型选择"
  281. :localdata="listData" valueKey="value" textKey="label" childrenKey="children" />
  282. <goods-info-picker ref="goodsPicker" :multiple='false' @select-goods-change="selectGoodsChange" title="物品名称"
  283. :localdata="goodsListData" valueKey="value" textKey="label" childrenKey="children" />
  284. </view>
  285. </template>
  286. <script>
  287. import userSelect from '@/components/user-select/user-select-radio.vue'
  288. import OSSService from "@/api/sys/OSSService"
  289. import SupplierSelector from './SupplierSelector';
  290. import MyDropdown from './MyDropdown';
  291. import goodsInfoPicker from '../collect/GoodsInfoPicker'
  292. import MaterialTypeService from '@/api/materialManagement/MaterialTypeService'
  293. import WareHouseService from '@/api/materialManagement/WareHouseService'
  294. import materialManagementService from '@/api/materialManagement/MaterialManagementService'
  295. import CommonApi from '@/api/common/CommonApi'
  296. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
  297. import {mapState, mapMutations, mapActions} from 'vuex'
  298. import registerService from '@/api/human/register/RegisterService'
  299. export default {
  300. components: {
  301. userSelect,
  302. baTreePicker,
  303. goodsInfoPicker,
  304. 'my-dropdown': MyDropdown,
  305. 'supplier-selector': SupplierSelector
  306. },
  307. computed: mapState({
  308. userInfo: (state) => state.user.userInfo,
  309. avatar: (state) => state.user.avatar
  310. }),
  311. data () {
  312. return {
  313. showFileList: [], // 控制每个文件是否显示的数组
  314. showFileList2: [], // 控制每个文件是否显示的数组
  315. testFlag: false,
  316. nodeFlag: false,
  317. loading: false,
  318. listData: [],
  319. fileList3: [],
  320. goodsListData: [],
  321. materialList: [],
  322. searchForm: {
  323. wareHouseType: '',
  324. },
  325. inputForm: {
  326. purchaseNo: '',
  327. purchaseSketch: '',
  328. handledBy: '',
  329. handledById: '',
  330. handledByOffice: '',
  331. handledByOfficeName: '',
  332. purchaseDate: '',
  333. purchaseMode: '',
  334. remarks: '',
  335. detailInfos: [],
  336. files: [], // 附件信息
  337. procInsId: ''
  338. },
  339. rules: {
  340. 'purchaseDate': [
  341. {
  342. required: true,
  343. message: '采购申请时间不能为空',
  344. trigger: ['blur', 'change']
  345. }
  346. ],
  347. 'purchaseSketch': [
  348. {
  349. required: true,
  350. message: '采购名称不能为空',
  351. trigger: ['blur', 'change']
  352. }
  353. ],
  354. 'purchaseMode': [
  355. {
  356. required: true,
  357. message: '采购方式不能为空',
  358. trigger: ['blur', 'change']
  359. }
  360. ],
  361. }
  362. }
  363. },
  364. materialTypeService: null,
  365. ossService: null,
  366. wareHouseService: null,
  367. commonApi: null,
  368. // 页面加载时执行
  369. created() {
  370. this.commonApi = new CommonApi()
  371. this.materialTypeService = new MaterialTypeService()
  372. this.ossService = new OSSService()
  373. this.wareHouseService = new WareHouseService()
  374. this.materialTypeService.cgList().then((data)=>{
  375. this.materialList = data
  376. }).catch((e)=>{
  377. throw e
  378. })
  379. this.inputForm.handledBy = this.userInfo.name
  380. this.inputForm.handledById = this.userInfo.id
  381. this.inputForm.handledByOffice = this.userInfo.officeDTO.id
  382. this.inputForm.handledByOfficeName = this.userInfo.officeDTO.name
  383. // 监听事件
  384. uni.$on('eventName', (data) => {
  385. // 在这里处理传递过来的数据
  386. //循环遍历采购详情,估计index将用户id与用户名称放入到采购人里面
  387. this.inputForm.detailInfos.forEach((detail,index) => {
  388. if (index === parseInt(data.index)) {
  389. detail.purchaserAgent = data.name
  390. detail.purchaserAgentId = data.id
  391. detail.procurementOffice = data.officeDTO.name
  392. }
  393. })
  394. });
  395. },
  396. props: {
  397. businessId: {
  398. type: String,
  399. default: ''
  400. },
  401. formReadOnly: {
  402. type: Boolean,
  403. default: false
  404. },
  405. status: {
  406. type: String,
  407. default: ''
  408. }
  409. },
  410. watch: {
  411. 'businessId': {
  412. handler (newVal) {
  413. if (this.businessId) {
  414. this.init(this.businessId)
  415. } else {
  416. this.$nextTick(() => {
  417. // this.$refs.inputForm.reset()
  418. })
  419. }
  420. },
  421. immediate: true,
  422. deep: false
  423. }
  424. },
  425. methods: {
  426. // 显示选择器
  427. showPicker(index) {
  428. this.$refs.treePicker._show(index);
  429. },
  430. showGoods(index) {
  431. this.searchForm.wareHouseType = this.inputForm.detailInfos[index].procurementTypeId
  432. this.wareHouseService.wareHouseSummaryList({
  433. 'current': 0,
  434. 'size': -1,
  435. 'orders': [],
  436. ...this.searchForm
  437. }).then((data) => {
  438. this.goodsListData = data.records
  439. })
  440. this.$refs.goodsPicker._show(index);
  441. },
  442. //监听选择
  443. selectChange(ids, names, index) {
  444. // this.inputForm.detailInfos.forEach((detail,inde) => {
  445. // if (inde === parseInt(index)) {
  446. // detail.collectType = names
  447. // detail.collectTypeId = ids[0]
  448. // }
  449. // })
  450. this.$set(this.inputForm.detailInfos, index, {
  451. ...this.inputForm.detailInfos[index],
  452. procurementType: names,
  453. procurementTypeId: ids[0]
  454. });
  455. },
  456. //监听选择
  457. selectGoodsChange(ids, names, index,tradeNumber) {
  458. // this.inputForm.detailInfos.forEach((detail,inde) => {
  459. // if (inde === parseInt(index)) {
  460. // detail.goodsName = names
  461. // detail.tradeNumber = tradeNumber
  462. // }
  463. // })
  464. this.$set(this.inputForm.detailInfos, index, {
  465. ...this.inputForm.detailInfos[index],
  466. tradeName: names,
  467. surplusNumber: tradeNumber
  468. });
  469. },
  470. init (id) {
  471. this.nodeFlag = true
  472. this.inputForm.id = id
  473. if (id) {
  474. materialManagementService.findById(id).then((data) => {
  475. // 只有从我发起的还有已办事项抄送给我 进入流程页面的时候才会有这个值
  476. if (this.status === 'testSee') {
  477. this.nodeFlag = true
  478. } else {
  479. this.commonApi.getTaskNameByProcInsId(data.procInsId).then((data) => {
  480. if (this.isNotEmpty(data)) {
  481. if (data === '重新发起申请' || this.isEmpty(data)) {
  482. this.nodeFlag = false
  483. } else {
  484. this.nodeFlag = true
  485. }
  486. }
  487. })
  488. }
  489. this.inputForm = this.recover(this.inputForm, data)
  490. this.inputForm.purchaseDate = new Date(data.purchaseDate);
  491. if (this.inputForm.files) {
  492. this.inputForm.files.forEach( (item,index) => {
  493. this.$set(this.showFileList, index, true);
  494. })
  495. }
  496. this.inputForm.detailInfos.forEach( (item,index) => {
  497. if (this.isNotEmpty(item.fileInfoLost)) {
  498. this.fileList3[index] = []
  499. item.fileInfoLost.forEach( (item,index2) => {
  500. this.fileList3[index].push(item)
  501. this.$set(this.showFileList2, index2, true);
  502. })
  503. }
  504. this.inputForm.detailInfos[index].priceSum = parseFloat(parseFloat(this.inputForm.detailInfos[index].tradePrice)
  505. * parseFloat(this.inputForm.detailInfos[index].tradeNumber)).toFixed(2)
  506. })
  507. })
  508. }
  509. },
  510. buildTree(nodes, parentId = '0') {
  511. const tree = [];
  512. for (const node of nodes) {
  513. if (node.parentId === parentId) {
  514. const children = this.buildTree(nodes, node.id);
  515. if (children.length) {
  516. node.children = children;
  517. }
  518. tree.push(node);
  519. }
  520. }
  521. return tree;
  522. },
  523. formatDate(date) {
  524. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  525. const year = dateNew.getFullYear();
  526. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  527. const day = dateNew.getDate().toString().padStart(2, '0');
  528. return `${year}-${month}-${day}`;
  529. },
  530. isEmpty(value) {
  531. let result = false;
  532. if (value == null || value == undefined) {
  533. result = true;
  534. }
  535. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  536. result = true;
  537. }
  538. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  539. result = true;
  540. }
  541. return result;
  542. },
  543. isNotEmpty (value) {
  544. return !this.isEmpty(value)
  545. },
  546. /**
  547. * 判断是否为空
  548. */
  549. isNull(val) {
  550. if (val instanceof Array) {
  551. if (val.length === 0) return true;
  552. } else if (val instanceof Object) {
  553. if (JSON.stringify(val) === "{}") return true;
  554. } else {
  555. if (
  556. val === "null" ||
  557. val == null ||
  558. val === "undefined" ||
  559. val === undefined ||
  560. val === ""
  561. )
  562. return true;
  563. return false;
  564. }
  565. return false;
  566. },
  567. addRow() {
  568. // 点击新增按钮时,向表格中添加一行空数据
  569. this.inputForm.detailInfos.push({ purchaserAgent: this.userInfo.name,
  570. purchaserAgentId: this.userInfo.id, procurementOffice: this.userInfo.officeDTO.name });
  571. let valueData = this.materialList;
  572. // 将扁平数据转换为树形结构
  573. const result = this.buildTree(valueData);
  574. this.listData = result
  575. },
  576. removeRow(index) {
  577. // 点击删除按钮时,从表格中移除指定行
  578. // this.tableData.splice(index, 1);
  579. this.inputForm.detailInfos.splice(index, 1);
  580. },
  581. formatDateNew(date) {
  582. const year = date.getFullYear();
  583. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  584. const day = date.getDate().toString().padStart(2, '0');
  585. const hours = date.getHours().toString().padStart(2, '0');
  586. const minutes = date.getMinutes().toString().padStart(2, '0');
  587. const seconds = date.getSeconds().toString().padStart(2, '0');
  588. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  589. },
  590. // 采购人下拉弹窗
  591. openUserPullForm(index) {
  592. // 点击 "采购人" 输入框时打开userPullForm页面,传入index用于区分不同的行
  593. // uni.navigateTo({
  594. // url: '/pages/materialManagement/collect/UserPullForm?index=' + index // userPullForm页面的路径
  595. // });
  596. this.$refs.userPicker.open(index,"");
  597. },
  598. handleEvent(data,index,type) {
  599. // 在这里处理子组件传递过来的数据
  600. this.inputForm.detailInfos[index].purchaserAgentId = data.id
  601. this.inputForm.detailInfos[index].purchaserAgent = data.label
  602. this.inputForm.detailInfos[index].procurementOffice = data.parentLabel
  603. this.inputForm.detailInfos[index].deptId = data.parentId
  604. // 进行进一步处理...
  605. },
  606. handleUploadSuccess (res, file, fileList, index, type) {
  607. // 将 fileList 转换为你期望的格式
  608. const formattedFiles = fileList.map(fileItem => {
  609. return {
  610. name: fileItem.name,
  611. size: fileItem.size,
  612. url: fileItem.response ? '/' + fileItem.response.url : fileItem.url,
  613. lsUrl: fileItem.response ? fileItem.response.lsUrl : fileItem.lsUrl, // 如果没有 lsUrl,可以根据需要设置为空字符串或其他默认值
  614. createBy: this.userInfo,
  615. by: this.userInfo.id,
  616. createTime: this.formatDateNew(new Date())
  617. };
  618. });
  619. if (type === 'detail') {
  620. // 将格式化后的数据设置到 detailInfos 的 fileInfoLost 属性中
  621. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  622. // 遍历 fileList,找到上传成功的文件,设置对应索引的 showFileList2 为 true
  623. fileList.forEach((item, i) => {
  624. if (item === file) {
  625. this.$set(this.showFileList2, i, true);
  626. }
  627. });
  628. } else {
  629. this.inputForm.files = formattedFiles
  630. fileList.forEach((item, index) => {
  631. if (item === file) {
  632. this.$set(this.showFileList, index, true);
  633. }
  634. });
  635. }
  636. // this.inputForm.files = formattedFiles;
  637. // fileList.forEach((item, index) => {
  638. // if (item === file) {
  639. // this.$set(this.showFileList, index, true);
  640. // }
  641. // });
  642. // 强制更新视图
  643. this.$forceUpdate();
  644. },
  645. handleRemove(file, fileList, index, type) {
  646. // 处理移除文件逻辑
  647. // file 是移除的文件
  648. // fileList 是当前文件列表
  649. const formattedFiles = fileList.map(fileItem => {
  650. return {
  651. name: fileItem.name,
  652. size: fileItem.size,
  653. url: '/' + fileItem.response.url,
  654. createBy: this.userInfo,
  655. by: this.userInfo.id,
  656. createTime: this.formatDateNew(new Date())
  657. };
  658. });
  659. if (type === 'detail') {
  660. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  661. } else {
  662. this.inputForm.files = formattedFiles
  663. }
  664. // 如果你想要更新文件列表,可以在这里更新 inputForm.fileInfoLost
  665. // this.inputForm.fileInfoLost = fileList;
  666. },
  667. saveForm(callback) {
  668. return new Promise((resolve, reject) => {
  669. // 表单规则验证
  670. // ...
  671. let errors = [];
  672. if (this.isNotEmpty(this.inputForm.purchaseDate)) {
  673. this.inputForm.purchaseDate = this.formatDate(this.inputForm.purchaseDate);
  674. }
  675. if (this.isEmpty(this.inputForm.detailInfos)) {
  676. errors.push('至少填写一条采购详情信息');
  677. } else {
  678. let i = this.inputForm.detailInfos.length;
  679. for (let j = 0; j < i; j++) {
  680. let k = j + 1
  681. if (this.isEmpty(this.inputForm.detailInfos[j].purchaserAgent)) {
  682. this.$message.error('采购详情第' + k + '行请选择采购人')
  683. this.loading = false
  684. return
  685. }
  686. if (this.isEmpty(this.inputForm.detailInfos[j].procurementType)) {
  687. this.$message.error('采购详情第' + k + '行请选择采购类型')
  688. this.loading = false
  689. return
  690. }
  691. if (this.isEmpty(this.inputForm.detailInfos[j].tradeName)) {
  692. this.$message.error('采购详情第' + k + '行请填写商品名称')
  693. this.loading = false
  694. return
  695. }
  696. }
  697. for (let j = 0; j < i; j++) {
  698. for (let k = j + 1; k < i; k++) {
  699. if (this.inputForm.detailInfos[j].procurementType === this.inputForm.detailInfos[k].procurementType) { // 如果采购类型相同
  700. if (this.inputForm.detailInfos[j].tradeName === this.inputForm.detailInfos[k].tradeName) { // 如果商品名称相同
  701. if (this.inputForm.detailInfos[j].supplierName === this.inputForm.detailInfos[k].supplierName) {
  702. this.$message.warning(`采购详情中,同种采购类型、同一供应商的商品名称只能输入一条`)
  703. this.loading = false
  704. throw new Error('采购详情中,同种采购类型、同一供应商的商品名称只能输入一条')
  705. }
  706. }
  707. }
  708. }
  709. }
  710. }
  711. // 计算总价
  712. const tradeTotalPrice = this.inputForm.detailInfos.reduce((total, item) => {
  713. // 将每个 detailInfo 的 priceSum 加到总价中
  714. return total + parseFloat(item.priceSum || 0); // 转换为浮点数并累加,避免字符串拼接
  715. }, 0); // 初始值为 0
  716. if (errors.length > 0) {
  717. // 存在错误,显示提示信息
  718. errors.forEach(error => {
  719. uni.showToast({
  720. title: error,
  721. icon: 'none',
  722. duration: 2000
  723. });
  724. });
  725. reject('Form validation failed');
  726. } else {
  727. // 所有验证通过,执行保存操作
  728. this.$refs.inputForm.validate().then(() => {
  729. uni.showLoading();
  730. this.inputForm.status = '2';
  731. materialManagementService.save(this.inputForm).then(data => {
  732. callback(data.businessTable, data.businessId);
  733. resolve('Form saved successfully');
  734. }).catch(error => {
  735. reject('Save operation failed');
  736. });
  737. }).catch(() => {
  738. reject('Form validation failed');
  739. });
  740. }
  741. });
  742. },
  743. // 修改状态
  744. async updateStatusById (type, callback) {
  745. if (type === 'reject' || type === 'reback') {
  746. materialManagementService.findById(this.inputForm.id).then((data) => {
  747. if (data.status !== '2') { // status的值不等于“审核中”,就弹出提示
  748. this.loading = false
  749. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  750. throw new Error()
  751. } else {
  752. if (type === 'reject') {
  753. // 驳回
  754. this.inputForm.status = '4'
  755. }
  756. if (type === 'reback') {
  757. // 撤回
  758. this.inputForm.status = '3'
  759. }
  760. if (type === 'reject' || type === 'reback') {
  761. let param = {status: this.inputForm.status, id: this.inputForm.id}
  762. materialManagementService.updateStatusById(param).then(() => {
  763. this.loading = false
  764. callback()
  765. })
  766. }
  767. }
  768. })
  769. } else if (type === 'hold') {
  770. materialManagementService.findById(this.inputForm.id).then((data) => {
  771. if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
  772. this.loading = false
  773. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  774. throw new Error()
  775. } else {
  776. // 终止
  777. let param = {status: '1', id: this.inputForm.id}
  778. materialManagementService.updateStatusById(param).then(() => {
  779. this.loading = false
  780. callback()
  781. })
  782. }
  783. })
  784. }
  785. },
  786. reapplyForm (callback) {
  787. this.loading = true
  788. materialManagementService.findById(this.inputForm.id).then((data) => {
  789. if (data.status !== '4') { // 审核状态不是“驳回”,就弹出提示
  790. this.loading = false
  791. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  792. throw new Error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  793. } else {
  794. this.startFormTrue(callback)
  795. }
  796. })
  797. },
  798. // 送审
  799. async startFormTrue (callback) {
  800. if (this.isNotEmpty(this.inputForm.purchaseDate)) {
  801. this.inputForm.purchaseDate = this.formatDate(this.inputForm.purchaseDate);
  802. }
  803. this.$refs.inputForm.validate().then(res => {
  804. this.inputForm.status = '2'
  805. // 计算总价
  806. const tradeTotalPrice = this.inputForm.detailInfos.reduce((total, item) => {
  807. // 将每个 detailInfo 的 priceSum 加到总价中
  808. return total + parseFloat(item.priceSum || 0); // 转换为浮点数并累加,避免字符串拼接
  809. }, 0); // 初始值为 0
  810. materialManagementService.save(this.inputForm).then((data) => {
  811. this.inputForm.id = data.businessId
  812. callback(data.businessTable, data.businessId, this.inputForm)
  813. this.$refs.inputForm.resetFields()
  814. this.loading = false
  815. }).catch(() => {
  816. this.$refs.inputForm.resetFields()
  817. }).catch((e) => {
  818. })
  819. })
  820. },
  821. // 通过
  822. async agreeForm (callback) {
  823. if (this.isNotEmpty(this.inputForm.purchaseDate)) {
  824. this.inputForm.purchaseDate = this.formatDate(this.inputForm.purchaseDate);
  825. }
  826. this.$refs.inputForm.validate().then(res => {
  827. this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((data) => {
  828. if (this.isNotEmpty(data)) {
  829. if (data === '公司领导审批') {
  830. this.inputForm.status = '5'
  831. }
  832. }
  833. materialManagementService.save(this.inputForm).then((data) => {
  834. callback(data.businessTable, data.businessId, this.inputForm)
  835. this.$refs.inputForm.resetFields()
  836. this.loading = false
  837. }).catch(() => {
  838. this.loading = false
  839. this.$refs.inputForm.resetFields()
  840. })
  841. })
  842. })
  843. },
  844. // 值改变事件
  845. changeValue () {
  846. let i = this.inputForm.detailInfos.length
  847. for (let j = 0; j < i; j++) {
  848. if (this.isNotEmpty(this.inputForm.detailInfos[j].tradePrice)) {
  849. if (this.isNotEmpty(this.inputForm.detailInfos[j].tradeNumber)) {
  850. // parseFloat(item.account).toFixed(2)
  851. this.inputForm.detailInfos[j].priceSum = parseFloat(parseFloat(this.inputForm.detailInfos[j].tradePrice) * parseFloat(this.inputForm.detailInfos[j].tradeNumber)).toFixed(2)
  852. } else {
  853. this.inputForm.detailInfos[j].priceSum = ''
  854. }
  855. } else {
  856. this.inputForm.detailInfos[j].priceSum = ''
  857. }
  858. }
  859. },
  860. async handleFileClick(file) {
  861. await this.ossService.getTemporaryUrl(file.url).then((data) => {
  862. file.lsUrl = data
  863. })
  864. if (this.isImage(file.name)) {
  865. // 如果是图片文件,则执行放大显示图片的逻辑
  866. this.handleImageClick(file);
  867. } else {
  868. // window.open(file.lsUrl, '_blank')
  869. window.location.href = file.lsUrl
  870. // 如果不是图片文件,则执行其他操作,比如下载文件等
  871. }
  872. },
  873. // 判断文件是否是图片类型
  874. isImage(fileName) {
  875. const ext = fileName.toLowerCase().split('.').pop(); // 获取文件的后缀名
  876. return ['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(ext); // 判断后缀名是否是图片类型
  877. },
  878. handleImageClick(file) {
  879. // 在点击图片时执行放大显示的逻辑
  880. this.$alert(`<img src="${file.lsUrl}" style="max-width: 100%; max-height: 100%;" />`, '图片详情', {
  881. dangerouslyUseHTMLString: true,
  882. customClass: 'custom-alert'
  883. });
  884. },
  885. handleDelete(file,lineIndex,type) {
  886. // 处理删除文件的逻辑
  887. if (type === 'detail') {
  888. const index = this.inputForm.detailInfos[lineIndex].fileInfoLost.indexOf(file);
  889. if (index !== -1) {
  890. this.inputForm.detailInfos[lineIndex].fileInfoLost.splice(index, 1);
  891. this.showFileList2.splice(index, 1); // 从showFileList中移除对应的元素
  892. }
  893. } else {
  894. // 从文件列表中移除文件
  895. const index = this.inputForm.files.indexOf(file);
  896. if (index !== -1) {
  897. this.inputForm.files.splice(index, 1);
  898. this.showFileList.splice(index, 1); // 从showFileList中移除对应的元素
  899. }
  900. }
  901. },
  902. shouldShowFile(file,index,type) {
  903. if (type === 'detail') {
  904. if (this.inputForm.detailInfos[index].fileInfoLost && this.inputForm.detailInfos[index].fileInfoLost.length > 0) {
  905. // 返回一个布尔值,确定是否显示上传成功后的文件
  906. return this.showFileList2[this.inputForm.detailInfos[index].fileInfoLost.indexOf(file)];
  907. }
  908. }else {
  909. if (this.inputForm.files && this.inputForm.files.length > 0) {
  910. // 返回一个布尔值,确定是否显示上传成功后的文件
  911. return this.showFileList[this.inputForm.files.indexOf(file)];
  912. }
  913. }
  914. return false; // 默认返回 false 或者其他适当的
  915. },
  916. onInputCode(index, event,type) {
  917. const inputValue = event
  918. const formattedValue = this.formatInput(inputValue);
  919. if (type === 'tradePrice') {
  920. this.$set(this.inputForm.detailInfos[index], 'tradePrice', formattedValue)
  921. }
  922. if (type === 'tradeNumber') {
  923. this.$set(this.inputForm.detailInfos[index], 'tradeNumber', formattedValue)
  924. }
  925. if (this.isNotEmpty(this.inputForm.detailInfos[index].tradePrice && this.inputForm.detailInfos[index].tradeNumber)) {
  926. let priceSum =
  927. parseFloat(parseFloat(this.inputForm.detailInfos[index].tradePrice) * parseFloat(this.inputForm.detailInfos[index].tradeNumber)).toFixed(2)
  928. this.$set(this.inputForm.detailInfos[index], 'priceSum', priceSum)
  929. }
  930. },
  931. // 通用的输入限制和格式化方法
  932. formatInput(inputValue, decimalLimit = 2) {
  933. console.log('inputValue', inputValue)
  934. // 如果输入值不是数字或者不是有效的小数,则返回空字符串
  935. if (!/^\d*\.?\d*$/.test(inputValue)) {
  936. return '';
  937. }
  938. // 只保留数字和一个小数点
  939. let value = inputValue.replace(/[^\d.]/g, '');
  940. // 只允许一个小数点
  941. const dotIndex = value.indexOf('.');
  942. if (dotIndex !== -1) {
  943. const substr = value.substr(dotIndex + 1);
  944. if (substr.indexOf('.') !== -1) {
  945. value = value.substr(0, dotIndex + 1) + substr.replace(/\./g, '');
  946. }
  947. }
  948. // 限制小数位数为指定的decimalLimit位数
  949. if (dotIndex !== -1) {
  950. const integerPart = value.substring(0, dotIndex);
  951. const decimalPart = value.substring(dotIndex + 1);
  952. if (decimalPart.length > decimalLimit) {
  953. uni.showToast({
  954. title: '商品数量小数点后只能输入两位,请正确输入!',
  955. icon: 'none',
  956. duration: 2000
  957. });
  958. return ''; // 返回空字符串
  959. }
  960. value = integerPart + '.' + decimalPart;
  961. }
  962. return value;
  963. },
  964. }
  965. }
  966. </script>
  967. <style>
  968. .cu-form-group .title {
  969. min-width: calc(4em + 40px);
  970. }
  971. .custom-alert {
  972. max-width: 80% !important;
  973. max-height: 80% !important;
  974. }
  975. /* 样式示例,您可能需要根据实际情况调整 */
  976. .upload-demo {
  977. width: 40%;
  978. }
  979. </style>