PurchaseForm.vue 52 KB

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