PurchaseForm.vue 50 KB

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