PurchaseForm.vue 53 KB

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