editDialog.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="a">
  3. <uni-popup ref="inputDialog" type="dialog">
  4. <view class="edit-view">
  5. <view class="title">{{titleOpt[detailActive]}}登记</view>
  6. <!-- <view class="tabs">
  7. <view class="tabs-item" :class="{'active': detailActive === 'xmnga'}" @click="detailClick('xmnga')">废品明细</view>
  8. <view class="tabs-item" :class="{'active': detailActive === 'upmnga'}" @click="detailClick('upmnga')">返修明细</view>
  9. <view class="tabs-item" :class="{'active': detailActive === 'cmnga'}" @click="detailClick('cmnga')">让步明细</view>
  10. <view class="tabs-item" :class="{'active': detailActive === 'umnga'}" @click="detailClick('umnga')">改型明细</view>
  11. </view> -->
  12. <view class="inp-view">
  13. <uni-forms ref="formRef" :key="detailActive" :modelValue="{formData:formData}" label-width='60px'>
  14. <template v-for="(item, index) in formData">
  15. <view :key='item.id' class="form-wrapper">
  16. <uni-forms-item label="代码" >
  17. <uni-easyinput v-model="item.typeCode" @input="(e) => handleCodeChange(e, item)" placeholder="请输入" />
  18. </uni-forms-item>
  19. <uni-forms-item label="类型" required :name="['formData', index, 'last']" :rules="[{'required': true,errorMessage: '请选择类型'}]">
  20. <!-- <picker
  21. @change="bindPickerChange"
  22. :value="warehosueVal"
  23. :range="range"
  24. range-key="name"
  25. > -->
  26. <!-- <input
  27. class="uni-input"
  28. @click="pickShow = true"
  29. :value="item.last"
  30. placeholder="请选择"
  31. /> -->
  32. <uni-data-picker placeholder="请选择类型" @change="e => handleLastChange(e, item)" popup-title="请选择类型" :localdata="item.range" v-model="item.last"
  33. >
  34. </uni-data-picker>
  35. <!-- </picker> -->
  36. <!-- <uni-data-select
  37. v-model="item.last"
  38. @change="e => handleLastChange(e, item)"
  39. :localdata="range"
  40. ></uni-data-select> -->
  41. </uni-forms-item>
  42. <uni-forms-item label="数量" required :name="['formData', index, 'first']" :rules="[{'required': true,errorMessage: '请输入数量'}]">
  43. <uni-easyinput type='number' v-model="item.first" placeholder="请输入" />
  44. </uni-forms-item>
  45. <view class="handle">
  46. <button type="warn" @click="handleDel(index)" >删除</button>
  47. </view>
  48. </view>
  49. </template>
  50. </uni-forms>
  51. </view>
  52. <view class="footer">
  53. <button type="primary" @click="handleAdd" >增加明细</button>
  54. <button type='primary' @click="handleSave">保存</button>
  55. <button @click='handleCancel'>关闭</button>
  56. </view>
  57. </view>
  58. </uni-popup>
  59. <!-- <u-action-sheet :list="range" v-model="pickShow"></u-action-sheet> -->
  60. </view>
  61. </template>
  62. <script>
  63. import { getDict } from "@/api/report/index"
  64. export default {
  65. data(){
  66. return {
  67. detailActive:'xmnga',
  68. callback:null,
  69. pickShow:false,
  70. formData:[],
  71. xmngaRange:[],
  72. upmngaRange:[],
  73. cmngaRange:[],
  74. umngaRange:[],
  75. xmngaList:[],
  76. cmngaList:[],
  77. umngaList:[],
  78. upmngaList:[],
  79. titleOpt:{
  80. xmnga:'废品明细',
  81. upmnga:'返修明细',
  82. cmnga:'让步明细',
  83. umnga:'改型明细',
  84. },
  85. pickerVal:0
  86. }
  87. },
  88. // computed:{
  89. // range(){
  90. // return this[this.detailActive + 'Range']
  91. // }
  92. // },
  93. created(){
  94. this._getDict('废品', 'xmngaRange')
  95. this._getDict('返修', 'upmngaRange')
  96. this._getDict('让步', 'cmngaRange')
  97. this._getDict('改型', 'umngaRange')
  98. },
  99. methods:{
  100. open(active, data, callback){
  101. this.xmngaList = JSON.parse(data.xmngaJson || '[]')
  102. this.cmngaList = JSON.parse(data.cmngaJson || '[]')
  103. this.umngaList = JSON.parse(data.umngaJson || '[]')
  104. this.upmngaList = JSON.parse(data.upmngaJson || '[]')
  105. this.callback = callback
  106. this.detailClick(active)
  107. this.$refs.inputDialog.open()
  108. },
  109. bindPickerChange(val) {
  110. this.pickerVal = val?.detail?.value;
  111. },
  112. handleCodeChange(e, item){
  113. item.range = this[this.detailActive + 'Range'].filter(item => item.code.includes(e))
  114. item.last = ''
  115. if(item.range.length === 1){
  116. item.last = item.range[0].text
  117. }
  118. },
  119. handleLastChange(e, item){
  120. const value = e?.detail?.value[0]?.value || e
  121. const obj = this[this.detailActive + 'Range'].find(item => item.text == value)
  122. item.typeCode = ""
  123. if(obj){
  124. item.typeCode = obj.code
  125. }
  126. },
  127. handleAdd(){
  128. this.formData.push({
  129. first:"",
  130. last:"",
  131. typeCode:"",
  132. range:this[this.detailActive + 'Range'],
  133. id: Date.now()
  134. })
  135. },
  136. handleSave(){
  137. this.$refs.formRef.validate().then(res=>{
  138. this[this.detailActive + 'List'] = uni.$u.deepClone(this.formData.map(item => ({
  139. first: item.first,
  140. last: item.last
  141. })))
  142. this.callback && this.callback({
  143. xmngaList:this.xmngaList,
  144. cmngaList:this.cmngaList,
  145. umngaList:this.umngaList,
  146. upmngaList:this.upmngaList,
  147. })
  148. this.handleCancel()
  149. }).catch(err =>{
  150. console.log('表单错误信息:', err);
  151. })
  152. },
  153. handleCancel(){
  154. this.$refs.inputDialog.close()
  155. },
  156. handleDel(index){
  157. const _this = this
  158. uni.showModal({
  159. title: `确认删除?`,
  160. content: '',
  161. confirmText: '确认',
  162. success: function (res) {
  163. if (res.confirm) {
  164. _this.formData.splice(index, 1)
  165. }
  166. }
  167. })
  168. },
  169. handlePicker(){
  170. this.pickShow = true
  171. },
  172. detailClick(name){
  173. this.formData = uni.$u.deepClone(this[name + 'List']
  174. .map((item, index) => ({
  175. ...item,
  176. typeCode:this[name + 'Range'].find(itm => itm?.value === item.last)?.code,
  177. id:index,
  178. range:this[name + 'Range'],
  179. })))
  180. this.formData.forEach(item => {
  181. this.handleLastChange(item.last, item)
  182. })
  183. if (!this.formData.length) {
  184. this.formData = [{
  185. first:"",
  186. last:"",
  187. typeCode:"",
  188. id: Date.now(),
  189. range:this[name + 'Range'],
  190. }]
  191. }
  192. this.detailActive = name
  193. },
  194. async _getDict(type, key){
  195. const res = await getDict(type)
  196. this[key] = res.map(item => ({
  197. ...item,
  198. value:item.mrpDesc,
  199. text:item.mrpDesc
  200. }))
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .edit-view{
  207. background: #fff;
  208. border-radius: 16rpx;
  209. padding: 20rpx;
  210. .inp-view{
  211. width: 90vw;
  212. max-height: 60vh;
  213. min-height: 100rpx;
  214. overflow: auto;
  215. }
  216. /deep/.uni-data-tree-dialog .selected-list{
  217. justify-content: center;
  218. }
  219. /deep/.item{
  220. text-align: center;
  221. }
  222. .title{
  223. font-size: $uni-font-size-lg;
  224. padding: 20rpx 0 ;
  225. margin-bottom: 10rpx;
  226. }
  227. /deep/.uni-forms-item__label{
  228. font-size: $uni-font-size-sm;
  229. }
  230. /deep/.uni-input-input,/deep/.uni-input-placeholder,
  231. /deep/.uni-data-select,/deep/.uni-select__input-placeholder{
  232. font-size: $uni-font-size-sm;
  233. }
  234. /deep/.uni-data-select{
  235. line-height: 42px;
  236. }
  237. .form-wrapper{
  238. padding-right: 150rpx;
  239. position: relative;
  240. .handle{
  241. position: absolute;
  242. top: 0;
  243. right: 0;
  244. button{
  245. margin-bottom: 20rpx;
  246. font-size: $uni-font-size-sm;
  247. }
  248. }
  249. }
  250. }
  251. .tabs{
  252. display: flex;
  253. justify-content: flex-start;
  254. align-items: center;
  255. margin-bottom: 20rpx;
  256. font-size: $uni-font-size-sm;
  257. margin-bottom: 10rpx;
  258. .tabs-item{
  259. background: rgba(226, 226, 226, 1);
  260. border: 1rpx solid rgba(226, 226, 226, 1);
  261. padding: 10rpx 16rpx;
  262. &.active{
  263. background: #fff;
  264. }
  265. }
  266. }
  267. .footer{
  268. display: flex;
  269. justify-content: space-between;
  270. align-items: center;
  271. padding: 20rpx;
  272. button{
  273. width: 170rpx;
  274. font-size: $uni-font-size-sm;
  275. }
  276. }
  277. </style>