PurchaseForm.vue 52 KB

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