PurchaseForm.vue 52 KB

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